test

Dependencies:   BMI160 max32630hsp3 MemoryLCD USBDevice

Committer:
seyhmuscacina
Date:
Mon Mar 25 07:40:37 2019 +0000
Revision:
3:b8989dab0f88
Parent:
0:ac4dea3e2894
Fork the repository

Who changed what in which revision?

UserRevisionLine numberNew contents of line
seyhmus.cacina 0:ac4dea3e2894 1 /*******************************************************************************
seyhmus.cacina 0:ac4dea3e2894 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
seyhmus.cacina 0:ac4dea3e2894 3 *
seyhmus.cacina 0:ac4dea3e2894 4 * Permission is hereby granted, free of charge, to any person obtaining a
seyhmus.cacina 0:ac4dea3e2894 5 * copy of this software and associated documentation files (the "Software"),
seyhmus.cacina 0:ac4dea3e2894 6 * to deal in the Software without restriction, including without limitation
seyhmus.cacina 0:ac4dea3e2894 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
seyhmus.cacina 0:ac4dea3e2894 8 * and/or sell copies of the Software, and to permit persons to whom the
seyhmus.cacina 0:ac4dea3e2894 9 * Software is furnished to do so, subject to the following conditions:
seyhmus.cacina 0:ac4dea3e2894 10 *
seyhmus.cacina 0:ac4dea3e2894 11 * The above copyright notice and this permission notice shall be included
seyhmus.cacina 0:ac4dea3e2894 12 * in all copies or substantial portions of the Software.
seyhmus.cacina 0:ac4dea3e2894 13 *
seyhmus.cacina 0:ac4dea3e2894 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
seyhmus.cacina 0:ac4dea3e2894 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
seyhmus.cacina 0:ac4dea3e2894 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
seyhmus.cacina 0:ac4dea3e2894 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
seyhmus.cacina 0:ac4dea3e2894 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
seyhmus.cacina 0:ac4dea3e2894 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
seyhmus.cacina 0:ac4dea3e2894 20 * OTHER DEALINGS IN THE SOFTWARE.
seyhmus.cacina 0:ac4dea3e2894 21 *
seyhmus.cacina 0:ac4dea3e2894 22 * Except as contained in this notice, the name of Maxim Integrated
seyhmus.cacina 0:ac4dea3e2894 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
seyhmus.cacina 0:ac4dea3e2894 24 * Products, Inc. Branding Policy.
seyhmus.cacina 0:ac4dea3e2894 25 *
seyhmus.cacina 0:ac4dea3e2894 26 * The mere transfer of this software does not imply any licenses
seyhmus.cacina 0:ac4dea3e2894 27 * of trade secrets, proprietary technology, copyrights, patents,
seyhmus.cacina 0:ac4dea3e2894 28 * trademarks, maskwork rights, or any other form of intellectual
seyhmus.cacina 0:ac4dea3e2894 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
seyhmus.cacina 0:ac4dea3e2894 30 * ownership rights.
seyhmus.cacina 0:ac4dea3e2894 31 *******************************************************************************
seyhmus.cacina 0:ac4dea3e2894 32 */
seyhmus.cacina 0:ac4dea3e2894 33 #include "HostAccelHelper.h"
seyhmus.cacina 0:ac4dea3e2894 34 #include "mbed.h"
seyhmus.cacina 0:ac4dea3e2894 35 #include "bmi160.h"
seyhmus.cacina 0:ac4dea3e2894 36 #include "CircularBuffer.h"
seyhmus.cacina 0:ac4dea3e2894 37
seyhmus.cacina 0:ac4dea3e2894 38 #define BUF_SIZE (32)
seyhmus.cacina 0:ac4dea3e2894 39
seyhmus.cacina 0:ac4dea3e2894 40 I2C I2CM2(P5_7, P6_0); /* SDA, SCL */
seyhmus.cacina 0:ac4dea3e2894 41 InterruptIn bmi160_int_pin(P3_6);
seyhmus.cacina 0:ac4dea3e2894 42 BMI160_I2C bmi160_dev(&I2CM2, BMI160_I2C::I2C_ADRS_SDO_LO, &bmi160_int_pin);
seyhmus.cacina 0:ac4dea3e2894 43 CircularBuffer<accel_data_t, BUF_SIZE> glbl_BMI160_QUEUE;
seyhmus.cacina 0:ac4dea3e2894 44
seyhmus.cacina 0:ac4dea3e2894 45
seyhmus.cacina 0:ac4dea3e2894 46 static BMI160_I2C *pbmi160;
seyhmus.cacina 0:ac4dea3e2894 47
seyhmus.cacina 0:ac4dea3e2894 48
seyhmus.cacina 0:ac4dea3e2894 49
seyhmus.cacina 0:ac4dea3e2894 50
seyhmus.cacina 0:ac4dea3e2894 51 void CSTMR_SH_HostAccelerometerInitialize() {
seyhmus.cacina 0:ac4dea3e2894 52 pbmi160 = &bmi160_dev;
seyhmus.cacina 0:ac4dea3e2894 53 pbmi160->reset();
seyhmus.cacina 0:ac4dea3e2894 54 glbl_BMI160_QUEUE.reset();
seyhmus.cacina 0:ac4dea3e2894 55 wait_ms(20);
seyhmus.cacina 0:ac4dea3e2894 56 }
seyhmus.cacina 0:ac4dea3e2894 57
seyhmus.cacina 0:ac4dea3e2894 58
seyhmus.cacina 0:ac4dea3e2894 59 void CSTMR_SH_HostAccelerometerSetDefaults() {
seyhmus.cacina 0:ac4dea3e2894 60 pbmi160->BMI160_DefaultInitalize();
seyhmus.cacina 0:ac4dea3e2894 61 }
seyhmus.cacina 0:ac4dea3e2894 62
seyhmus.cacina 0:ac4dea3e2894 63 int CSTMR_SH_HostAccelerometerSetSampleRate(int sampleRate) {
seyhmus.cacina 0:ac4dea3e2894 64 return pbmi160->setSampleRate(sampleRate);
seyhmus.cacina 0:ac4dea3e2894 65 }
seyhmus.cacina 0:ac4dea3e2894 66
seyhmus.cacina 0:ac4dea3e2894 67 int CSTMR_SH_HostAccelerometerEnableDataReadyInterrupt() {
seyhmus.cacina 0:ac4dea3e2894 68 return pbmi160->enable_data_ready_interrupt();
seyhmus.cacina 0:ac4dea3e2894 69 }
seyhmus.cacina 0:ac4dea3e2894 70
seyhmus.cacina 0:ac4dea3e2894 71 int CSTMR_SH_HostAccelerometerGet_sensor_xyz(accel_data_t *accel_data) {
seyhmus.cacina 0:ac4dea3e2894 72 int ret = 0;
seyhmus.cacina 0:ac4dea3e2894 73 BMI160::SensorData stacc_data = {0};
seyhmus.cacina 0:ac4dea3e2894 74
seyhmus.cacina 0:ac4dea3e2894 75 if(pbmi160 == NULL)
seyhmus.cacina 0:ac4dea3e2894 76 return -1;
seyhmus.cacina 0:ac4dea3e2894 77
seyhmus.cacina 0:ac4dea3e2894 78 if (pbmi160) {
seyhmus.cacina 0:ac4dea3e2894 79 ret = pbmi160->getSensorXYZ(stacc_data, BMI160::SENS_2G);
seyhmus.cacina 0:ac4dea3e2894 80 if (ret < 0)
seyhmus.cacina 0:ac4dea3e2894 81 return ret;
seyhmus.cacina 0:ac4dea3e2894 82 }
seyhmus.cacina 0:ac4dea3e2894 83
seyhmus.cacina 0:ac4dea3e2894 84 accel_data->x = stacc_data.xAxis.scaled;
seyhmus.cacina 0:ac4dea3e2894 85 accel_data->y = stacc_data.yAxis.scaled;
seyhmus.cacina 0:ac4dea3e2894 86 accel_data->z = stacc_data.zAxis.scaled;
seyhmus.cacina 0:ac4dea3e2894 87 accel_data->x_raw = stacc_data.xAxis.raw;
seyhmus.cacina 0:ac4dea3e2894 88 accel_data->y_raw = stacc_data.yAxis.raw;
seyhmus.cacina 0:ac4dea3e2894 89 accel_data->z_raw = stacc_data.zAxis.raw;
seyhmus.cacina 0:ac4dea3e2894 90
seyhmus.cacina 0:ac4dea3e2894 91 return ret;
seyhmus.cacina 0:ac4dea3e2894 92 }
seyhmus.cacina 0:ac4dea3e2894 93
seyhmus.cacina 0:ac4dea3e2894 94
seyhmus.cacina 0:ac4dea3e2894 95 int CSTMR_SH_HostAccelerometerEnqueueData(accel_data_t *accel_data) {
seyhmus.cacina 0:ac4dea3e2894 96 int ret = 0;
seyhmus.cacina 0:ac4dea3e2894 97 if(glbl_BMI160_QUEUE.full())
seyhmus.cacina 0:ac4dea3e2894 98 ret = -1;
seyhmus.cacina 0:ac4dea3e2894 99 else {
seyhmus.cacina 0:ac4dea3e2894 100 glbl_BMI160_QUEUE.push(*accel_data);
seyhmus.cacina 0:ac4dea3e2894 101 }
seyhmus.cacina 0:ac4dea3e2894 102 return ret;
seyhmus.cacina 0:ac4dea3e2894 103 }
seyhmus.cacina 0:ac4dea3e2894 104
seyhmus.cacina 0:ac4dea3e2894 105 int CSTMR_SH_HostAccelerometerGetDataCount() {
seyhmus.cacina 0:ac4dea3e2894 106 return glbl_BMI160_QUEUE.size();
seyhmus.cacina 0:ac4dea3e2894 107 }
seyhmus.cacina 0:ac4dea3e2894 108
seyhmus.cacina 0:ac4dea3e2894 109 int CSTMR_SH_HostAccelerometerDequeuData(accel_data_t *accel_data) {
seyhmus.cacina 0:ac4dea3e2894 110 int ret = 0;
seyhmus.cacina 0:ac4dea3e2894 111
seyhmus.cacina 0:ac4dea3e2894 112 if(glbl_BMI160_QUEUE.empty()) {
seyhmus.cacina 0:ac4dea3e2894 113 ret = -1;
seyhmus.cacina 0:ac4dea3e2894 114 } else {
seyhmus.cacina 0:ac4dea3e2894 115 glbl_BMI160_QUEUE.pop(*accel_data);
seyhmus.cacina 0:ac4dea3e2894 116 }
seyhmus.cacina 0:ac4dea3e2894 117 return ret;
seyhmus.cacina 0:ac4dea3e2894 118 }
seyhmus.cacina 0:ac4dea3e2894 119
seyhmus.cacina 0:ac4dea3e2894 120
seyhmus.cacina 0:ac4dea3e2894 121