Skip to content
Snippets Groups Projects
Select Git revision
  • 1c056d1965b7c471ef1ad5117ece8e4fdbf6666f
  • master default protected
  • esp32-nimble-wiki
  • rahix/hw-lock-new-mutex
  • dx/somewhat-more-dynamic-config
  • schneider/sdk-0.2.1-7
  • schneider/bsec
  • dx/meh-bdf-to-stm
  • dx/flatten-config-module
  • genofire/ble-follow-py
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
37 results

bhi.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    bhi.c 9.51 KiB
    #include <stdio.h>
    #include <string.h>
    
    #include "gpio.h"
    #include "bhy_uc_driver.h"
    #include "bhy.h"
    #include "pmic.h"
    
    #include "FreeRTOS.h"
    #include "task.h"
    #include "semphr.h"
    #include "queue.h"
    
    #include "api/interrupt-sender.h"
    #include "epicardium.h"
    #include "modules/log.h"
    #include "modules/modules.h"
    #include "modules/stream.h"
    
    /* Ticks to wait when trying to acquire lock */
    #define LOCK_WAIT pdMS_TO_TICKS(BHI160_MUTEX_WAIT_MS)
    
    /* BHI160 Firmware Blob.  Contents are defined in libcard10. */
    extern uint8_t bhy1_fw[];
    
    /* Interrupt Pin */
    static const gpio_cfg_t bhi160_interrupt_pin = {
    	PORT_0, PIN_13, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
    };
    
    /* Axis remapping matrices */
    static int8_t bhi160_mapping_matrix[3 * 3] = { 0, -1, 0, 1, 0, 0, 0, 0, 1 };
    static int8_t bmm150_mapping_matrix[3 * 3] = { -1, 0, 0, 0, 1, 0, 0, 0, -1 };
    
    /*
     * From the official docs:
     *
     *    The sic matrix should be calculated for customer platform by logging
     *    uncalibrated magnetometer data.  The sic matrix here is only an example
     *    array (identity matrix). Customer should generate their own matrix.  This
     *    affects magnetometer fusion performance.
     *
     * TODO: Get data for card10
     */
    /* clang-format off */
    static float bhi160_sic_array[3 * 3] = { 1.0, 0.0, 0.0,
                                             0.0, 1.0, 0.0,
                                             0.0, 0.0, 1.0 };
    /* clang-format on */
    
    /* BHI160 Fifo */
    static uint8_t bhi160_fifo[BHI160_FIFO_SIZE];
    static size_t start_index = 0;
    
    /* BHI160 Task ID */
    static TaskHandle_t bhi160_task_id = NULL;
    
    /* BHI160 Mutex */
    static StaticSemaphore_t bhi160_mutex_data;
    static SemaphoreHandle_t bhi160_mutex = NULL;
    
    /* Streams */
    static struct stream_info bhi160_streams[10];
    
    /* -- Utilities -------------------------------------------------------- {{{ */
    /*
     * Retrieve the data size for a sensor.  This value is needed for the creation
     * of the sensor's sample queue.
     */
    static size_t bhi160_lookup_data_size(enum bhi160_sensor_type type)