Skip to content
Snippets Groups Projects
Select Git revision
  • 8959de9f679cfd0436d731fd91b88a68b9a75fa6
  • max32xxx default protected
  • dw-cmsisdap-path
3 results

samflash.c

Blame
  • bhi.c 12.19 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];
    
    /* Active */
    static bool bhi160_sensor_active[10] = { 0 };
    
    /* -- Utilities -------------------------------------------------------- {{{ */
    /*
     * Retrieve the data size for a sensor.  This value is needed for the creation