YOSHIHISA TABUCHI / Mbed OS Host_Software_MAX32664GWEB_HR_EXTENDEDtest

Dependencies:   BMI160 max32630hsp3 MemoryLCD USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HostAccelHelper.cpp Source File

HostAccelHelper.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 #include "HostAccelHelper.h"
00034 #include "mbed.h"
00035 #include "bmi160.h"
00036 #include "CircularBuffer.h"
00037 
00038 #define BUF_SIZE (32)
00039 
00040 I2C I2CM2(P5_7, P6_0); /* SDA, SCL */
00041 InterruptIn bmi160_int_pin(P3_6);
00042 BMI160_I2C bmi160_dev(&I2CM2, BMI160_I2C::I2C_ADRS_SDO_LO, &bmi160_int_pin);
00043 CircularBuffer<accel_data_t, BUF_SIZE> glbl_BMI160_QUEUE;
00044 
00045 
00046 static BMI160_I2C *pbmi160;
00047 
00048 
00049 
00050 
00051 void CSTMR_SH_HostAccelerometerInitialize() {
00052     pbmi160 = &bmi160_dev;
00053     pbmi160->reset();
00054     glbl_BMI160_QUEUE.reset();
00055     wait_ms(20);
00056 }
00057 
00058 
00059 void CSTMR_SH_HostAccelerometerSetDefaults() {
00060     pbmi160->BMI160_DefaultInitalize();
00061 }
00062 
00063 int CSTMR_SH_HostAccelerometerSetSampleRate(int sampleRate) {
00064     return pbmi160->setSampleRate(sampleRate);
00065 }
00066 
00067 int CSTMR_SH_HostAccelerometerEnableDataReadyInterrupt() {
00068     return pbmi160->enable_data_ready_interrupt();
00069 }
00070 
00071 int CSTMR_SH_HostAccelerometerGet_sensor_xyz(accel_data_t *accel_data) {
00072     int ret = 0;
00073     BMI160::SensorData stacc_data = {0};
00074 
00075     if(pbmi160 == NULL)
00076         return -1;
00077 
00078     if (pbmi160) {
00079         ret = pbmi160->getSensorXYZ(stacc_data, BMI160::SENS_2G);
00080         if (ret < 0)
00081             return ret;
00082     }
00083 
00084     accel_data->x = stacc_data.xAxis.scaled;
00085     accel_data->y = stacc_data.yAxis.scaled;
00086     accel_data->z = stacc_data.zAxis.scaled;
00087     accel_data->x_raw = stacc_data.xAxis.raw;
00088     accel_data->y_raw = stacc_data.yAxis.raw;
00089     accel_data->z_raw = stacc_data.zAxis.raw;
00090 
00091     return ret;
00092 }
00093 
00094 
00095 int CSTMR_SH_HostAccelerometerEnqueueData(accel_data_t *accel_data) {
00096     int ret = 0;
00097     if(glbl_BMI160_QUEUE.full())
00098         ret = -1;
00099     else {
00100         glbl_BMI160_QUEUE.push(*accel_data);
00101     }
00102     return ret;
00103 }
00104 
00105 int CSTMR_SH_HostAccelerometerGetDataCount() {
00106     return glbl_BMI160_QUEUE.size();
00107 }
00108 
00109 int CSTMR_SH_HostAccelerometerDequeuData(accel_data_t *accel_data) {
00110     int ret = 0;
00111 
00112     if(glbl_BMI160_QUEUE.empty()) {
00113         ret = -1;
00114     } else {
00115         glbl_BMI160_QUEUE.pop(*accel_data);
00116     }
00117     return ret;
00118 }
00119 
00120 
00121