esp32_BNO08x 1.3
C++ BNO08x IMU driver component for esp-idf.
Loading...
Searching...
No Matches
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
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
64class BNO08x;
65
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};
BNO08x IMU driver class.
Definition BNO08x.hpp:33
Fully static class containing callback implementations for sh2 HAL lib.
Definition BNO08xSH2HAL.hpp:72
static void hardware_reset()
Hardware reset callback for sh2 HAL lib, toggle RST gpio.
Definition BNO08xSH2HAL.cpp:161
static bool spi_wait_for_int()
SPI wait for HINT sh2 HAL lib callback.
Definition BNO08xSH2HAL.cpp:171
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:151
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:137
static BNO08x * imu
Definition BNO08xSH2HAL.hpp:85
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
static const constexpr char * TAG
Definition BNO08xSH2HAL.hpp:91
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
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
static int spi_read_sh2_packet_body(uint8_t *pBuffer, uint16_t packet_sz)
SPI rx packet body (invoked from SPI rx callback.)
Definition BNO08xSH2HAL.cpp:219
static int spi_write(sh2_Hal_t *self, uint8_t *pBuffer, unsigned len)
SPI tx callback for sh2 HAL lib.
Definition BNO08xSH2HAL.cpp:92
static uint16_t spi_read_sh2_packet_header(uint8_t *pBuffer)
SPI rx packet header (invoked from SPI rx callback.)
Definition BNO08xSH2HAL.cpp:189
static uint32_t get_time_us(sh2_Hal_t *self)
Get time in microseconds callback for sh2 HAL lib.
Definition BNO08xSH2HAL.cpp:119
static int spi_open(sh2_Hal_t *self)
Opens SPI instance by waiting for interrupt.
Definition BNO08xSH2HAL.cpp:28