Example Host software for integration of MAX3266x chips (, MAX32664GWEB) equipped with Heart Rate from Wrist Algorithm. This is “stand-alone” software that runs on the MAX32630 low-power microcontroller to display heart rate on the display of the MAXREFDES101 reference design. It is intended provide a simple example of how to initialize and communicate with the sensor hub. Windows and Android communications are not supported.
Dependencies: Maxim_Sensor_Hub_Communications BMI160 whrmDemoUI max32630hsp3
Fork of Host_Software_MAX32664GWEB_HR_wrist by
SHMAX8614X_WHRM/HostAccelHelper.cpp@15:c1d7fdf5d55a, 2019-01-10 (annotated)
- Committer:
- gmehmet
- Date:
- Thu Jan 10 08:30:00 2019 +0000
- Revision:
- 15:c1d7fdf5d55a
- Parent:
- 13:3d1a6b947396
ready to export/fork
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gmehmet | 13:3d1a6b947396 | 1 | /******************************************************************************* |
gmehmet | 13:3d1a6b947396 | 2 | * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved. |
gmehmet | 13:3d1a6b947396 | 3 | * |
gmehmet | 13:3d1a6b947396 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
gmehmet | 13:3d1a6b947396 | 5 | * copy of this software and associated documentation files (the "Software"), |
gmehmet | 13:3d1a6b947396 | 6 | * to deal in the Software without restriction, including without limitation |
gmehmet | 13:3d1a6b947396 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
gmehmet | 13:3d1a6b947396 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
gmehmet | 13:3d1a6b947396 | 9 | * Software is furnished to do so, subject to the following conditions: |
gmehmet | 13:3d1a6b947396 | 10 | * |
gmehmet | 13:3d1a6b947396 | 11 | * The above copyright notice and this permission notice shall be included |
gmehmet | 13:3d1a6b947396 | 12 | * in all copies or substantial portions of the Software. |
gmehmet | 13:3d1a6b947396 | 13 | * |
gmehmet | 13:3d1a6b947396 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
gmehmet | 13:3d1a6b947396 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
gmehmet | 13:3d1a6b947396 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
gmehmet | 13:3d1a6b947396 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
gmehmet | 13:3d1a6b947396 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
gmehmet | 13:3d1a6b947396 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
gmehmet | 13:3d1a6b947396 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
gmehmet | 13:3d1a6b947396 | 21 | * |
gmehmet | 13:3d1a6b947396 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
gmehmet | 13:3d1a6b947396 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
gmehmet | 13:3d1a6b947396 | 24 | * Products, Inc. Branding Policy. |
gmehmet | 13:3d1a6b947396 | 25 | * |
gmehmet | 13:3d1a6b947396 | 26 | * The mere transfer of this software does not imply any licenses |
gmehmet | 13:3d1a6b947396 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
gmehmet | 13:3d1a6b947396 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
gmehmet | 13:3d1a6b947396 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
gmehmet | 13:3d1a6b947396 | 30 | * ownership rights. |
gmehmet | 13:3d1a6b947396 | 31 | ******************************************************************************* |
gmehmet | 13:3d1a6b947396 | 32 | */ |
gmehmet | 13:3d1a6b947396 | 33 | #include "../SHMAX8614X_WHRM/HostAccelHelper.h" |
gmehmet | 13:3d1a6b947396 | 34 | |
gmehmet | 13:3d1a6b947396 | 35 | #include "mbed.h" |
gmehmet | 13:3d1a6b947396 | 36 | #include "bmi160.h" |
gmehmet | 13:3d1a6b947396 | 37 | #include "CircularBuffer.h" |
gmehmet | 13:3d1a6b947396 | 38 | |
gmehmet | 13:3d1a6b947396 | 39 | #define BUF_SIZE (32) |
gmehmet | 13:3d1a6b947396 | 40 | |
gmehmet | 13:3d1a6b947396 | 41 | I2C I2CM2(P5_7, P6_0); /* SDA, SCL */ |
gmehmet | 13:3d1a6b947396 | 42 | InterruptIn bmi160_int_pin(P3_6); |
gmehmet | 13:3d1a6b947396 | 43 | BMI160_I2C bmi160_dev(&I2CM2, BMI160_I2C::I2C_ADRS_SDO_LO, &bmi160_int_pin); |
gmehmet | 13:3d1a6b947396 | 44 | CircularBuffer<accel_data_t, BUF_SIZE> glbl_BMI160_QUEUE; |
gmehmet | 13:3d1a6b947396 | 45 | |
gmehmet | 13:3d1a6b947396 | 46 | |
gmehmet | 13:3d1a6b947396 | 47 | static BMI160_I2C *pbmi160; |
gmehmet | 13:3d1a6b947396 | 48 | |
gmehmet | 13:3d1a6b947396 | 49 | |
gmehmet | 13:3d1a6b947396 | 50 | |
gmehmet | 13:3d1a6b947396 | 51 | |
gmehmet | 13:3d1a6b947396 | 52 | void CSTMR_SH_HostAccelerometerInitialize() { |
gmehmet | 13:3d1a6b947396 | 53 | pbmi160 = &bmi160_dev; |
gmehmet | 13:3d1a6b947396 | 54 | pbmi160->reset(); |
gmehmet | 13:3d1a6b947396 | 55 | glbl_BMI160_QUEUE.reset(); |
gmehmet | 13:3d1a6b947396 | 56 | wait_ms(20); |
gmehmet | 13:3d1a6b947396 | 57 | } |
gmehmet | 13:3d1a6b947396 | 58 | |
gmehmet | 13:3d1a6b947396 | 59 | |
gmehmet | 13:3d1a6b947396 | 60 | void CSTMR_SH_HostAccelerometerSetDefaults() { |
gmehmet | 13:3d1a6b947396 | 61 | pbmi160->BMI160_DefaultInitalize(); |
gmehmet | 13:3d1a6b947396 | 62 | } |
gmehmet | 13:3d1a6b947396 | 63 | |
gmehmet | 13:3d1a6b947396 | 64 | int CSTMR_SH_HostAccelerometerSetSampleRate(int sampleRate) { |
gmehmet | 13:3d1a6b947396 | 65 | return pbmi160->setSampleRate(sampleRate); |
gmehmet | 13:3d1a6b947396 | 66 | } |
gmehmet | 13:3d1a6b947396 | 67 | |
gmehmet | 13:3d1a6b947396 | 68 | int CSTMR_SH_HostAccelerometerEnableDataReadyInterrupt() { |
gmehmet | 13:3d1a6b947396 | 69 | return pbmi160->enable_data_ready_interrupt(); |
gmehmet | 13:3d1a6b947396 | 70 | } |
gmehmet | 13:3d1a6b947396 | 71 | |
gmehmet | 13:3d1a6b947396 | 72 | int CSTMR_SH_HostAccelerometerGet_sensor_xyz(accel_data_t *accel_data) { |
gmehmet | 13:3d1a6b947396 | 73 | int ret = 0; |
gmehmet | 13:3d1a6b947396 | 74 | BMI160::SensorData stacc_data = {0}; |
gmehmet | 13:3d1a6b947396 | 75 | |
gmehmet | 13:3d1a6b947396 | 76 | if(pbmi160 == NULL) |
gmehmet | 13:3d1a6b947396 | 77 | return -1; |
gmehmet | 13:3d1a6b947396 | 78 | |
gmehmet | 13:3d1a6b947396 | 79 | if (pbmi160) { |
gmehmet | 13:3d1a6b947396 | 80 | ret = pbmi160->getSensorXYZ(stacc_data, BMI160::SENS_2G); |
gmehmet | 13:3d1a6b947396 | 81 | if (ret < 0) |
gmehmet | 13:3d1a6b947396 | 82 | return ret; |
gmehmet | 13:3d1a6b947396 | 83 | } |
gmehmet | 13:3d1a6b947396 | 84 | |
gmehmet | 13:3d1a6b947396 | 85 | accel_data->x = stacc_data.xAxis.scaled; |
gmehmet | 13:3d1a6b947396 | 86 | accel_data->y = stacc_data.yAxis.scaled; |
gmehmet | 13:3d1a6b947396 | 87 | accel_data->z = stacc_data.zAxis.scaled; |
gmehmet | 13:3d1a6b947396 | 88 | accel_data->x_raw = stacc_data.xAxis.raw; |
gmehmet | 13:3d1a6b947396 | 89 | accel_data->y_raw = stacc_data.yAxis.raw; |
gmehmet | 13:3d1a6b947396 | 90 | accel_data->z_raw = stacc_data.zAxis.raw; |
gmehmet | 13:3d1a6b947396 | 91 | |
gmehmet | 13:3d1a6b947396 | 92 | return ret; |
gmehmet | 13:3d1a6b947396 | 93 | } |
gmehmet | 13:3d1a6b947396 | 94 | |
gmehmet | 13:3d1a6b947396 | 95 | |
gmehmet | 13:3d1a6b947396 | 96 | int CSTMR_SH_HostAccelerometerEnqueueData(accel_data_t *accel_data) { |
gmehmet | 13:3d1a6b947396 | 97 | int ret = 0; |
gmehmet | 13:3d1a6b947396 | 98 | if(glbl_BMI160_QUEUE.full()) |
gmehmet | 13:3d1a6b947396 | 99 | ret = -1; |
gmehmet | 13:3d1a6b947396 | 100 | else { |
gmehmet | 13:3d1a6b947396 | 101 | glbl_BMI160_QUEUE.push(*accel_data); |
gmehmet | 13:3d1a6b947396 | 102 | } |
gmehmet | 13:3d1a6b947396 | 103 | return ret; |
gmehmet | 13:3d1a6b947396 | 104 | } |
gmehmet | 13:3d1a6b947396 | 105 | |
gmehmet | 13:3d1a6b947396 | 106 | int CSTMR_SH_HostAccelerometerGetDataCount() { |
gmehmet | 13:3d1a6b947396 | 107 | return glbl_BMI160_QUEUE.size(); |
gmehmet | 13:3d1a6b947396 | 108 | } |
gmehmet | 13:3d1a6b947396 | 109 | |
gmehmet | 13:3d1a6b947396 | 110 | int CSTMR_SH_HostAccelerometerDequeuData(accel_data_t *accel_data) { |
gmehmet | 13:3d1a6b947396 | 111 | int ret = 0; |
gmehmet | 13:3d1a6b947396 | 112 | |
gmehmet | 13:3d1a6b947396 | 113 | if(glbl_BMI160_QUEUE.empty()) { |
gmehmet | 13:3d1a6b947396 | 114 | ret = -1; |
gmehmet | 13:3d1a6b947396 | 115 | } else { |
gmehmet | 13:3d1a6b947396 | 116 | glbl_BMI160_QUEUE.pop(*accel_data); |
gmehmet | 13:3d1a6b947396 | 117 | } |
gmehmet | 13:3d1a6b947396 | 118 | return ret; |
gmehmet | 13:3d1a6b947396 | 119 | } |
gmehmet | 13:3d1a6b947396 | 120 | |
gmehmet | 13:3d1a6b947396 | 121 |