12#ifndef BNO08X_REPORTS_HPP
13#define BNO08X_REPORTS_HPP
30enum class FieldKind : uint8_t {
41 FieldKind kind{FieldKind::U8};
45inline constexpr std::size_t kMaxFields = 14;
52 std::array<FieldDef, kMaxFields> f{};
56constexpr SensorSpec Run(FieldKind kind, uint8_t first, uint8_t step, uint8_t n)
noexcept {
59 for (uint8_t i = 0; i < n; ++i) {
60 s.f[i] = FieldDef{.off =
static_cast<uint8_t
>(first + (i * step)), .kind = kind};
66constexpr SensorSpec Plus(SensorSpec base, uint8_t off, FieldKind kind)
noexcept {
67 base.f[base.count] = FieldDef{.off = off, .kind = kind};
74constexpr void FillRare(std::array<SensorSpec, reg::detail::kSensorTableSize>& t)
noexcept {
75 const SensorSpec quat = Run(FieldKind::S16, 4, 2, 4);
76 const SensorSpec quat_acc = Plus(quat, 12, FieldKind::S16);
79 t[0x2B] = Run(FieldKind::U8, 4, 1, 2);
80 SensorSpec flow = Run(FieldKind::S16, 4, 2, 3);
83 Plus(Plus(Plus(Plus(Plus(flow, 10, FieldKind::U8), 11, FieldKind::U8), 12, FieldKind::U8),
88 t[0x2C] = Plus(Plus(flow, 18, FieldKind::U16), 20, FieldKind::U32);
89 SensorSpec pose = Run(FieldKind::U32, 4, 4, 1);
91 SensorSpec words = Run(FieldKind::S32, 8, 4, 13);
92 for (uint8_t i = 0; i < 13; ++i) {
93 pose = Plus(pose, words.f[i].off, FieldKind::S32);
99constexpr std::array<SensorSpec, reg::detail::kSensorTableSize> MakeSpecs() noexcept {
100 std::array<SensorSpec, reg::detail::kSensorTableSize> t{};
101 const SensorSpec vec3 = Run(FieldKind::S16, 4, 2, 3);
102 const SensorSpec quat = Run(FieldKind::S16, 4, 2, 4);
103 const SensorSpec quat_acc = Plus(quat, 12, FieldKind::S16);
104 const SensorSpec six = Run(FieldKind::S16, 4, 2, 6);
105 const SensorSpec word16 = Run(FieldKind::U16, 4, 2, 1);
106 SensorSpec lsb16 = word16;
107 lsb16.lsb_only =
true;
108 SensorSpec raw = Plus(vec3, 12, FieldKind::U32);
110 SensorSpec raw_gyro = Plus(Plus(vec3, 10, FieldKind::S16), 12, FieldKind::U32);
112 for (
const std::size_t
id : std::array<std::size_t, 5>{0x01, 0x02, 0x03, 0x04, 0x06}) {
119 t[0x0A] = Run(FieldKind::U32, 4, 4, 1);
120 t[0x0B] = Run(FieldKind::U32, 4, 4, 1);
121 for (
const std::size_t
id : std::array<std::size_t, 3>{0x0C, 0x0D, 0x0E}) {
122 t[id] = Run(FieldKind::S16, 4, 2, 1);
125 t[0x10] = Run(FieldKind::U8, 4, 1, 1);
126 t[0x11] = Plus(Run(FieldKind::U32, 4, 4, 1), 8, FieldKind::U16);
128 t[0x13] = Run(FieldKind::U8, 4, 1, 1);
132 t[0x18] = Run(FieldKind::U32, 4, 4, 1);
133 for (
const std::size_t
id :
134 std::array<std::size_t, 7>{0x19, 0x1A, 0x1B, 0x1C, 0x20, 0x21, 0x22}) {
137 t[0x1E] = Run(FieldKind::U8, 4, 1, 12);
138 t[0x1F] = Run(FieldKind::U8, 4, 1, 1);
145inline constexpr std::array<SensorSpec, reg::detail::kSensorTableSize> kSpecs = MakeSpecs();
148constexpr std::array<uint8_t, kSensorSlots> MakeQPoints() noexcept {
149 std::array<uint8_t, kSensorSlots> q{};
150 const std::array<std::array<uint8_t, 2>, 17> rows{{{{0x01, 8}},
167 for (
const auto& r : rows) {
176inline constexpr std::array<uint8_t, kSensorSlots> kQPoints = MakeQPoints();
179constexpr std::array<uint16_t, kSensorSlots> MakeMetadataIds() noexcept {
180 std::array<uint16_t, kSensorSlots> m{};
181 const std::array<std::array<uint16_t, 2>, 37> rows{{
182 {{0x01, 0xE302}}, {{0x02, 0xE306}}, {{0x03, 0xE309}}, {{0x04, 0xE303}}, {{0x05, 0xE30B}},
183 {{0x06, 0xE304}}, {{0x07, 0xE307}}, {{0x08, 0xE30C}}, {{0x09, 0xE30D}}, {{0x0A, 0xE30E}},
184 {{0x0B, 0xE30F}}, {{0x0C, 0xE310}}, {{0x0D, 0xE311}}, {{0x0E, 0xE312}}, {{0x0F, 0xE30A}},
185 {{0x10, 0xE313}}, {{0x11, 0xE315}}, {{0x12, 0xE316}}, {{0x13, 0xE317}}, {{0x14, 0xE301}},
186 {{0x15, 0xE305}}, {{0x16, 0xE308}}, {{0x18, 0xE314}}, {{0x19, 0xE318}}, {{0x1A, 0xE319}},
187 {{0x1B, 0xE31A}}, {{0x1C, 0xE31B}}, {{0x1E, 0xE31C}}, {{0x1F, 0xE31D}}, {{0x20, 0xE31E}},
188 {{0x21, 0xE31F}}, {{0x22, 0xE320}}, {{0x23, 0xE321}}, {{0x28, 0xE322}}, {{0x29, 0xE323}},
189 {{0x2A, 0xE324}}, {{0x2B, 0xE325}},
191 for (
const auto& r : rows) {
198inline constexpr std::array<uint16_t, kSensorSlots> kMetadataIds = MakeMetadataIds();
201inline constexpr std::array<const char*, kSensorSlots> kSensorNames{
nullptr,
203 "GyroscopeCalibrated",
204 "MagneticFieldCalibrated",
205 "LinearAcceleration",
208 "GyroscopeUncalibrated",
209 "GameRotationVector",
210 "GeomagneticRotationVector",
216 "MagneticFieldUncalibrated",
220 "StabilityClassifier",
231 "PersonalActivityClassifier",
241 "ArvrRotationVector",
242 "ArvrGameRotationVector",
243 "GyroIntegratedRotationVector",
250[[nodiscard]]
constexpr int32_t ReadField(std::span<const uint8_t> report, std::size_t base,
251 const FieldDef& fld)
noexcept {
252 const std::size_t o =
static_cast<std::size_t
>(fld.off) - base;
256 v =
static_cast<int32_t
>(report[o]);
259 v = S16(Le16(report, o));
262 v =
static_cast<int32_t
>(Le16(report, o));
265 v =
static_cast<int32_t
>(
269 v = S32(Le32(report, o));
278[[nodiscard]]
constexpr std::size_t FieldWidth(FieldKind kind)
noexcept {
280 if ((kind == FieldKind::S16) || (kind == FieldKind::U16)) {
282 }
else if ((kind == FieldKind::U32) || (kind == FieldKind::S32)) {
298 const auto slot =
static_cast<std::size_t
>(detail::ToUnderlying(
id));
299 return (slot <
kSensorSlots) ? detail::kQPoints[slot] : uint8_t{0};
308 const auto slot =
static_cast<std::size_t
>(detail::ToUnderlying(
id));
309 return (slot <
kSensorSlots) ? detail::kMetadataIds[slot] : uint16_t{0};
318 const auto slot =
static_cast<std::size_t
>(detail::ToUnderlying(
id));
319 const char* n = (slot <
kSensorSlots) ? detail::kSensorNames[slot] :
nullptr;
320 return (n !=
nullptr) ? n :
"Unknown";
330 const auto v =
static_cast<uint32_t
>(detail::ToUnderlying(
id));
331 const bool manual_only = (v == 0x1AU) || (v == 0x1BU) || ((v >= 0x1FU) && (v <= 0x23U)) ||
332 (v == 0x2BU) || (v == 0x2CU) || (v == 0x2DU) || (v == 0x2EU);
351[[nodiscard]]
inline bool DecodeFields(
const SensorSpec& spec, std::span<const uint8_t> report,
352 std::size_t base, Event& ev)
noexcept {
353 for (std::size_t i = 0; i < spec.count; ++i) {
354 const FieldDef& fld = spec.f[i];
355 if (((
static_cast<std::size_t
>(fld.off) - base) + FieldWidth(fld.kind)) > report.size()) {
358 ev.v[i] = ReadField(report, base, fld);
360 if (spec.hub_ts != 0xFFU) {
361 ev.hub_t_us =
static_cast<uint32_t
>(ev.v[spec.hub_ts]);
Compile-time helpers of the BNO08X driver: typed integer literals, exact hook matching,...
BNO08x protocol constants: SHTP channels, SH-2 report, command and record identifiers,...
The SHTP frame engine: header codec, strict receive validation (rules V1 to V12), the UART framer and...
Public types of the BNO08x driver: errors, Result<T>, configuration, events and the integer unit help...
SensorId
Every sensor report ID any CEVA document defines (RM S6.5; matrix section 1.8 of the design).
Definition bno08x_types.hpp:205
constexpr std::size_t kSensorSlots
Number of slots of the per-sensor tables: sensor IDs 0x01 to 0x2E.
Definition bno08x_types.hpp:250
@ RawMagnetometer
Raw magnetometer ADC counts with hub timestamp.
@ RawAccelerometer
Raw accelerometer ADC counts with hub timestamp.
@ RawGyroscope
Raw gyroscope ADC counts, temperature and hub timestamp.
The BNO08x driver: everything it declares lives here; internals in detail.
Definition bno08x.hpp:36
constexpr uint8_t QPoint(SensorId id) noexcept
The Q point of the first value of a sensor's event (0 when not fixed point).
Definition bno08x_reports.hpp:297
constexpr const char * SensorName(SensorId id) noexcept
The name of a sensor.
Definition bno08x_reports.hpp:317
constexpr bool InDatasheet(SensorId id) noexcept
Whether the data sheet itself describes the sensor ("D" in the coverage matrix); the others come from...
Definition bno08x_reports.hpp:329
constexpr uint16_t MetadataRecord(SensorId id) noexcept
The metadata record that describes a sensor (RM Figure 27).
Definition bno08x_reports.hpp:307
constexpr bool IsRawSensor(SensorId id) noexcept
Whether the sensor delivers raw ADC data (it needs its base sensor enabled, DS p30).
Definition bno08x_reports.hpp:341