esp32_BNO08x 1.4 C++ BNO08x IMU driver component for esp-idf.

BNO08xSH2HAL.hpp
Go to the documentation of this file.
1
6#pragma once
7
8// hill-crest labs includes (apache 2.0 license, compatible with MIT)
9#include "sh2.h"
10#include "sh2_SensorValue.h"
11#include "sh2_err.h"
12// esp-idf includes
13#include <esp_log.h>
14#include <esp_timer.h>
15// in-house includes
16#include "BNO08xPrivateTypes.hpp"
17
24#define UINT16_CLR_MSB(val_16bit) ((val_16bit) & 0x00FFU)
25
32#define UINT16_CLR_LSB(val_16bit) ((val_16bit) & 0xFF00U)
33
41#define UINT32_CLR_BYTE(val_32bit, byte2clear) ((val_32bit) & ~(0xFFUL << (byte2clear * 8UL)))
42
50#define UINT32_MSK_BYTE(val_32bit, byte2mask) ((val_32bit) & (0xFFUL << (byte2mask * 8UL)))
51
52// parsing universal to any packet
53
60#define PARSE_PACKET_LENGTH(header) \
61 (UINT16_CLR_LSB(static_cast<uint16_t>(header[1]) << 8U) | UINT16_CLR_MSB(static_cast<uint16_t>(header[0])))
62
63// forward dec to prevent compile errors
64 class BNO08x;
65
71 class BNO08xSH2HAL
72{
73 public:
74 static void set_hal_imu(BNO08x* hal_imu);
75
76 static int spi_open(sh2_Hal_t* self);
77 static void spi_close(sh2_Hal_t* self);
78 static int spi_read(sh2_Hal_t* self, uint8_t* pBuffer, unsigned len, uint32_t* t_us);
79 static int spi_write(sh2_Hal_t* self, uint8_t* pBuffer, unsigned len);
80 static uint32_t get_time_us(sh2_Hal_t* self);
81 static void hal_cb(void* cookie, sh2_AsyncEvent_t* pEvent);
82 static void sensor_event_cb(void* cookie, sh2_SensorEvent_t* event);
83
84 private:
85 static BNO08x* imu;
86 static void hardware_reset();
87 static bool spi_wait_for_int();
88 static uint16_t spi_read_sh2_packet_header(uint8_t* pBuffer);
89 static int spi_read_sh2_packet_body(uint8_t* pBuffer, uint16_t packet_sz);
90
91 static const constexpr char* TAG = "BNO08xSH2HAL";
92};
BNO08xPrivateTypes.hpp
BNO08x
BNO08x IMU driver class.
Definition: BNO08x.hpp:33
BNO08xSH2HAL
Fully static class containing callback implementations for sh2 HAL lib.
Definition: BNO08xSH2HAL.hpp:72
BNO08xSH2HAL::sensor_event_cb
static void sensor_event_cb(void *cookie, sh2_SensorEvent_t *event)
Sensor event callback for sh2 HAL lib, sends received reports to data_proc_task().
Definition: BNO08xSH2HAL.cpp:155
BNO08xSH2HAL::hal_cb
static void hal_cb(void *cookie, sh2_AsyncEvent_t *pEvent)
General event callback for sh2 HAL lib, used to notify tasks of reset.
Definition: BNO08xSH2HAL.cpp:141
BNO08xSH2HAL::set_hal_imu
static void set_hal_imu(BNO08x *hal_imu)
Sets the BNO08x driver object to be used with sh2 HAL lib callbacks.
Definition: BNO08xSH2HAL.cpp:18
BNO08xSH2HAL::spi_read
static int spi_read(sh2_Hal_t *self, uint8_t *pBuffer, unsigned len, uint32_t *t_us)
SPI rx callback for sh2 HAL lib.
Definition: BNO08xSH2HAL.cpp:56
BNO08xSH2HAL::spi_close
static void spi_close(sh2_Hal_t *self)
Closes SPI instance (nothing to do here, but required by sh2 HAL lib for cases where other communicat...
Definition: BNO08xSH2HAL.cpp:41
BNO08xSH2HAL::spi_write
static int spi_write(sh2_Hal_t *self, uint8_t *pBuffer, unsigned len)
SPI tx callback for sh2 HAL lib.
Definition: BNO08xSH2HAL.cpp:92
BNO08xSH2HAL::get_time_us
static uint32_t get_time_us(sh2_Hal_t *self)
Get time in microseconds callback for sh2 HAL lib.
Definition: BNO08xSH2HAL.cpp:123
BNO08xSH2HAL::spi_open
static int spi_open(sh2_Hal_t *self)
Opens SPI instance by waiting for interrupt.
Definition: BNO08xSH2HAL.cpp:28