idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
chip.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
19#include <idfxx/flags>
20
21#include <cstdint>
22#include <esp_chip_info.h>
23#include <string>
24
25namespace idfxx {
26
31enum class chip_model : int {
32 // clang-format off
33 esp32 = 1,
34 esp32s2 = 2,
35 esp32s3 = 9,
36 esp32c3 = 5,
37 esp32c2 = 12,
38 esp32c6 = 13,
39 esp32h2 = 16,
40 esp32p4 = 18,
41 esp32c5 = 23,
42 esp32c61 = 20,
43 // clang-format on
44};
45
53
67enum class chip_feature : uint32_t {
68 // clang-format off
69 embedded_flash = 1u << 0,
70 wifi = 1u << 1,
71 ble = 1u << 4,
72 bt_classic = 1u << 5,
73 ieee802154 = 1u << 6,
74 embedded_psram = 1u << 7,
75 // clang-format on
76};
77
78} // namespace idfxx
79
80template<>
82
83namespace idfxx {
84
99class chip_info {
100public:
107
113 [[nodiscard]] chip_model model() const noexcept { return static_cast<chip_model>(_info.model); }
114
121 return flags<chip_feature>(static_cast<std::underlying_type_t<chip_feature>>(_info.features));
122 }
123
129 [[nodiscard]] uint8_t cores() const noexcept { return _info.cores; }
130
139 [[nodiscard]] uint16_t revision() const noexcept { return _info.revision; }
140
146 [[nodiscard]] uint8_t major_revision() const noexcept { return _info.revision / 100; }
147
153 [[nodiscard]] uint8_t minor_revision() const noexcept { return _info.revision % 100; }
154
155private:
156 esp_chip_info_t _info{};
157};
158
// end of idfxx_hw_support_chip // end of idfxx_hw_support
161
162} // namespace idfxx
163
164#include "sdkconfig.h"
165#ifdef CONFIG_IDFXX_STD_FORMAT
167#include <algorithm>
168#include <format>
169namespace std {
170template<>
171struct formatter<idfxx::chip_model> {
172 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
173
174 template<typename FormatContext>
175 auto format(idfxx::chip_model m, FormatContext& ctx) const {
176 auto s = to_string(m);
177 return std::copy(s.begin(), s.end(), ctx.out());
178 }
179};
180} // namespace std
182#endif // CONFIG_IDFXX_STD_FORMAT
Chip identification and hardware information.
Definition chip.hpp:99
uint8_t cores() const noexcept
Returns the number of CPU cores.
Definition chip.hpp:129
uint8_t minor_revision() const noexcept
Returns the minor part of the chip revision.
Definition chip.hpp:153
uint8_t major_revision() const noexcept
Returns the major part of the chip revision.
Definition chip.hpp:146
uint16_t revision() const noexcept
Returns the full chip revision number.
Definition chip.hpp:139
static chip_info get() noexcept
Queries the chip and returns its information.
flags< chip_feature > features() const noexcept
Returns the chip's hardware feature flags.
Definition chip.hpp:120
chip_model model() const noexcept
Returns the chip model.
Definition chip.hpp:113
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
Definition cpu.hpp:52
chip_model
Identifies the ESP chip model.
Definition chip.hpp:31
chip_feature
Hardware feature flags for chip capabilities.
Definition chip.hpp:67
@ esp32c61
ESP32-C61.
@ esp32p4
ESP32-P4.
@ esp32s2
ESP32-S2.
@ esp32c5
ESP32-C5.
@ esp32c2
ESP32-C2.
@ esp32c3
ESP32-C3.
@ esp32h2
ESP32-H2.
@ esp32s3
ESP32-S3.
@ esp32c6
ESP32-C6.
@ embedded_psram
Chip has embedded PSRAM.
@ ble
Chip has Bluetooth LE.
@ bt_classic
Chip has Bluetooth Classic.
@ wifi
Chip has 2.4GHz WiFi.
@ ieee802154
Chip has IEEE 802.15.4 (Zigbee/Thread).
@ embedded_flash
Chip has embedded flash memory.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120