2024-11-17 05:36:11 +00:00
|
|
|
/**
|
2024-11-18 00:52:07 +00:00
|
|
|
* @file BNO08x_macros.hpp
|
2024-11-17 05:36:11 +00:00
|
|
|
* @author Myles Parfeniuk
|
|
|
|
|
*/
|
2024-11-15 07:48:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
// standard library includes
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
|
|
// esp-idf includes
|
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
|
#include <freertos/event_groups.h>
|
|
|
|
|
|
|
|
|
|
// packet parsing macros
|
2024-11-17 05:36:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Clears the most significant byte of a 16-bit value.
|
|
|
|
|
*
|
|
|
|
|
* @param val_16bit The 16-bit value to modify.
|
|
|
|
|
* @return The value with the MSB cleared.
|
|
|
|
|
*/
|
2024-11-15 07:48:33 +00:00
|
|
|
#define UINT16_CLR_MSB(val_16bit) ((val_16bit) & 0x00FFU)
|
2024-11-17 05:36:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Clears the least significant byte of a 16-bit value.
|
|
|
|
|
*
|
|
|
|
|
* @param val_16bit The 16-bit value to modify.
|
|
|
|
|
* @return The value with the MSB cleared.
|
|
|
|
|
*/
|
2024-11-15 07:48:33 +00:00
|
|
|
#define UINT16_CLR_LSB(val_16bit) ((val_16bit) & 0xFF00U)
|
2024-11-17 05:36:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Clears a specified byte in a 32-bit value.
|
|
|
|
|
*
|
|
|
|
|
* @param val_32bit The 32-bit value to modify.
|
|
|
|
|
* @param byte2clear The byte index to clear (0 = LSB, 3 = MSB).
|
|
|
|
|
* @return The value with the specified byte cleared.
|
|
|
|
|
*/
|
2024-11-15 07:48:33 +00:00
|
|
|
#define UINT32_CLR_BYTE(val_32bit, byte2clear) ((val_32bit) & ~(0xFFUL << (byte2clear * 8UL)))
|
2024-11-17 05:36:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Masks a specified byte in a 32-bit value.
|
|
|
|
|
*
|
|
|
|
|
* @param val_32bit The 32-bit value to modify.
|
|
|
|
|
* @param byte2mask The byte index to mask (0 = LSB, 3 = MSB).
|
|
|
|
|
* @return The value with the specified byte masked.
|
|
|
|
|
*/
|
2024-11-15 07:48:33 +00:00
|
|
|
#define UINT32_MSK_BYTE(val_32bit, byte2mask) ((val_32bit) & (0xFFUL << (byte2mask * 8UL)))
|
|
|
|
|
|
|
|
|
|
// parsing universal to any packet
|
|
|
|
|
|
2024-11-17 05:36:11 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Parse length from SHTP packet header.
|
|
|
|
|
*
|
|
|
|
|
* @param packet Pointer to bno08x_rx_packet_t containing data.
|
|
|
|
|
* @return Length of SHTP packet.
|
|
|
|
|
*/
|
2024-11-20 19:12:11 +00:00
|
|
|
#define PARSE_PACKET_LENGTH(header) (UINT16_CLR_LSB(static_cast<uint16_t>(header[1]) << 8U) | UINT16_CLR_MSB(static_cast<uint16_t>(header[0])))
|