# esp32_BNO08x: include/BNO08xSH2HAL.hpp Source File

Loading...
Searching...
No Matches
BNO08xSH2HAL.hpp
Go to the documentation of this file.
#pragma once
// hill-crest labs includes (apache 2.0 license, compatible with MIT)
#include "sh2.h"
#include "sh2_SensorValue.h"
#include "sh2_err.h"
// esp-idf includes
#include <esp_log.h>
#include <esp_timer.h>
// in-house includes
#include "BNO08xPrivateTypes.hpp"
#define UINT16_CLR_MSB(val_16bit) ((val_16bit) & 0x00FFU)
#define UINT16_CLR_LSB(val_16bit) ((val_16bit) & 0xFF00U)
#define UINT32_CLR_BYTE(val_32bit, byte2clear) ((val_32bit) & ~(0xFFUL << (byte2clear * 8UL)))
#define UINT32_MSK_BYTE(val_32bit, byte2mask) ((val_32bit) & (0xFFUL << (byte2mask * 8UL)))
// parsing universal to any packet
#define PARSE_PACKET_LENGTH(header) \
(UINT16_CLR_LSB(static_cast<uint16_t>(header[1]) << 8U) | UINT16_CLR_MSB(static_cast<uint16_t>(header[0])))
// forward dec to prevent compile errors
class BNO08x;
class BNO08xSH2HAL
{
public:
static void set_hal_imu(BNO08x* hal_imu);
static int spi_open(sh2_Hal_t* self);
static void spi_close(sh2_Hal_t* self);
static int spi_read(sh2_Hal_t* self, uint8_t* pBuffer, unsigned len, uint32_t* t_us);
static int spi_write(sh2_Hal_t* self, uint8_t* pBuffer, unsigned len);
static uint32_t get_time_us(sh2_Hal_t* self);
static void hal_cb(void* cookie, sh2_AsyncEvent_t* pEvent);
static void sensor_event_cb(void* cookie, sh2_SensorEvent_t* event);
private:
static BNO08x* imu;
static void hardware_reset();
static bool spi_wait_for_int();
static uint16_t spi_read_sh2_packet_header(uint8_t* pBuffer);
static int spi_read_sh2_packet_body(uint8_t* pBuffer, uint16_t packet_sz);
static const constexpr char* TAG = "BNO08xSH2HAL";
};
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::hardware_reset
static void hardware_reset()
Hardware reset callback for sh2 HAL lib, toggle RST gpio.
Definition BNO08xSH2HAL.cpp:161
BNO08xSH2HAL::spi_wait_for_int
static bool spi_wait_for_int()
SPI wait for HINT sh2 HAL lib callback.
Definition BNO08xSH2HAL.cpp:171
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:151
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:137
BNO08xSH2HAL::imu
static BNO08x * imu
Definition BNO08xSH2HAL.hpp:85
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::TAG
static const constexpr char * TAG
Definition BNO08xSH2HAL.hpp:91
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_read_sh2_packet_body
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
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::spi_read_sh2_packet_header
static uint16_t spi_read_sh2_packet_header(uint8_t *pBuffer)
SPI rx packet header (invoked from SPI rx callback.)
Definition BNO08xSH2HAL.cpp:189
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:119
BNO08xSH2HAL::spi_open
static int spi_open(sh2_Hal_t *self)
Opens SPI instance by waiting for interrupt.
Definition BNO08xSH2HAL.cpp:28