From f4bf6c744402f5eb23156c318c4d3a76c58e9ace Mon Sep 17 00:00:00 2001 From: Pankaj Goenka Date: Fri, 4 Dec 2015 01:54:53 +0530 Subject: [PATCH 1/3] Added Sensor HAL for Acc, Mag and Gyr. Modified the SH-Xpresso-LPC54102 project to include HAL files Signed-off-by: Pankaj Goenka --- .../modules/sensor-drivers/Driver_Common.h | 72 ++ .../modules/sensor-drivers/Driver_Sensor.h | 98 +++ .../keil-mdk-build/SH-Xpresso-LPC54102.uvoptx | 18 +- .../SH-Xpresso-LPC54102.uvprojx | 20 + .../sources/app/sensoracq_t.c | 54 +- .../Sensor/Bosch-Sensortec/Driver_Sensor.c | 824 ++++++++++++++++++ 6 files changed, 1057 insertions(+), 29 deletions(-) create mode 100644 embedded/common/modules/sensor-drivers/Driver_Common.h create mode 100644 embedded/common/modules/sensor-drivers/Driver_Sensor.h create mode 100644 external/Drivers/Sensor/Bosch-Sensortec/Driver_Sensor.c diff --git a/embedded/common/modules/sensor-drivers/Driver_Common.h b/embedded/common/modules/sensor-drivers/Driver_Common.h new file mode 100644 index 0000000..8870881 --- /dev/null +++ b/embedded/common/modules/sensor-drivers/Driver_Common.h @@ -0,0 +1,72 @@ +/* ----------------------------------------------------------------------------- + * Copyright (c) 2013-2014 ARM Ltd. + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. Permission is granted to anyone to use this + * software for any purpose, including commercial applications, and to alter + * it and redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + * + * + * $Date: 2. Jan 2014 + * $Revision: V2.00 + * + * Project: Common Driver definitions + * -------------------------------------------------------------------------- */ + +/* History: + * Version 2.00 + * Changed prefix ARM_DRV -> ARM_DRIVER + * Added General return codes definitions + * Version 1.10 + * Namespace prefix ARM_ added + * Version 1.00 + * Initial release + */ + +#ifndef __DRIVER_COMMON_H +#define __DRIVER_COMMON_H + +#include +#include +#include + +#define ARM_DRIVER_VERSION_MAJOR_MINOR(major,minor) (((major) << 8) | (minor)) + +/** +\brief Driver Version +*/ +typedef struct _ARM_DRIVER_VERSION { + uint16_t api; ///< API version + uint16_t drv; ///< Driver version +} ARM_DRIVER_VERSION; + +/* General return codes */ +#define ARM_DRIVER_OK 0 ///< Operation succeeded +#define ARM_DRIVER_ERROR -1 ///< Unspecified error +#define ARM_DRIVER_ERROR_BUSY -2 ///< Driver is busy +#define ARM_DRIVER_ERROR_TIMEOUT -3 ///< Timeout occurred +#define ARM_DRIVER_ERROR_UNSUPPORTED -4 ///< Operation not supported +#define ARM_DRIVER_ERROR_PARAMETER -5 ///< Parameter error +#define ARM_DRIVER_ERROR_SPECIFIC -6 ///< Start of driver specific errors + +/** +\brief General power states +*/ +typedef enum _ARM_POWER_STATE { + ARM_POWER_OFF, ///< Power off: no operation possible + ARM_POWER_LOW, ///< Low Power mode: retain state, detect and signal wake-up events + ARM_POWER_FULL ///< Power on: full operation at maximum performance +} ARM_POWER_STATE; + +#endif /* __DRIVER_COMMON_H */ diff --git a/embedded/common/modules/sensor-drivers/Driver_Sensor.h b/embedded/common/modules/sensor-drivers/Driver_Sensor.h new file mode 100644 index 0000000..38bcdc5 --- /dev/null +++ b/embedded/common/modules/sensor-drivers/Driver_Sensor.h @@ -0,0 +1,98 @@ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2015 Audience Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __DRIVER_SENSOR_H +#define __DRIVER_SENSOR_H + +#include "Driver_Common.h" + +#define OSP_SENSOR_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,00) + +typedef void (*OSP_Sensor_SignalEvent_t) (uint32_t sensor_flags); + +typedef struct _OSP_SENSOR_DETAILS { + const char* name; ///< + const char* part_num; ///< + uint32_t sensor_type; ///< conforms to Android IDs + uint32_t unit_scaling_8Q24; ///< fixed point factor to convert raw data to physical units + uint32_t max_range_12Q20; ///< + uint16_t num_data_elems; ///< + uint16_t supported_flags; ///< use with SENSOR_FLAG_* +} OSP_SENSOR_DETAILS; + + +#define SENSOR_FLAG_CONTINUOUS_DATA ( 0) ///< +#define SENSOR_FLAG_WAKE_UP (1U << 0) ///< +#define SENSOR_FLAG_ON_CHANGE_MODE (1U << 1) ///< +#define SENSOR_FLAG_ONE_SHOT_MODE (1U << 2) ///< +#define SENSOR_FLAG_MOTION_WAKEUP (1U << 3) ///< +#define SENSOR_FLAG_DATA_INJECTION (1U << 4) ///< + + +typedef struct _OSP_DRIVER_SENSOR { + ARM_DRIVER_VERSION (*GetVersion) (void); + int32_t (*Initialize) (OSP_Sensor_SignalEvent_t cb, void *data); + int32_t (*Uninitialize) (void); + int32_t (*PowerControl) (ARM_POWER_STATE state); + int32_t (*Activate) (uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency); + int32_t (*ReadData) (void *data, uint16_t num_samples); + int32_t (*Deactivate) (void); + int32_t (*GetDetails) (void *data); + int32_t (*InjectData) (void *data); +} const OSP_DRIVER_SENSOR; + +#define OSP_BUILD_DRIVER_SENSOR(pre1, pre2, priv) \ + static ARM_DRIVER_VERSION pre1##_GetVersion (void) { \ + return pre2##_GetVersion (priv); \ + } \ + static int32_t pre1##_Initialize (OSP_Sensor_SignalEvent_t cb, void *data) { \ + return pre2##_Initialize (cb, data, priv); \ + } \ + static int32_t pre1##_Uninitialize (void) { \ + return pre2##_Uninitialize (priv); \ + } \ + static int32_t pre1##_PowerControl (ARM_POWER_STATE state) { \ + return pre2##_PowerControl (state, priv); \ + } \ + static int32_t pre1##_Activate (uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency) { \ + return pre2##_Activate (flags, us_delay, fifo_num_samples, max_report_latency, priv); \ + } \ + static int32_t pre1##_ReadData (void *data, uint16_t num_samples) { \ + return pre2##_ReadData (data, num_samples, priv); \ + } \ + static int32_t pre1##_Deactivate (void) { \ + return pre2##_Deactivate (priv); \ + } \ + static int32_t pre1##_GetDetails (void *data) { \ + return pre2##_GetDetails (data, priv); \ + } \ + static int32_t pre1##_InjectData (void *data) { \ + return pre2##_InjectData (data, priv); \ + } \ + OSP_DRIVER_SENSOR Driver_##pre1 = { \ + pre1##_GetVersion, \ + pre1##_Initialize, \ + pre1##_Uninitialize, \ + pre1##_PowerControl, \ + pre1##_Activate, \ + pre1##_ReadData, \ + pre1##_Deactivate, \ + pre1##_GetDetails, \ + pre1##_InjectData, \ + }; + +#endif /* __DRIVER_SENSOR_H */ diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx index 625f4ec..1bc179c 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx @@ -1259,6 +1259,18 @@ 0 0 + + 11 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + Driver_Sensor.c + 0 + 0 + @@ -1269,7 +1281,7 @@ 0 12 - 36 + 37 1 0 0 @@ -1281,7 +1293,7 @@ 12 - 37 + 38 1 0 0 @@ -1293,7 +1305,7 @@ 12 - 38 + 39 1 0 0 diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx index c44dd66..d01e6b2 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx @@ -743,6 +743,11 @@ 1 ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.c + + Driver_Sensor.c + 1 + ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + @@ -1532,6 +1537,11 @@ 1 ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.c + + Driver_Sensor.c + 1 + ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + @@ -2321,6 +2331,11 @@ 1 ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.c + + Driver_Sensor.c + 1 + ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + @@ -3110,6 +3125,11 @@ 1 ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.c + + Driver_Sensor.c + 1 + ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/app/sensoracq_t.c b/embedded/projects/SH-Xpresso-LPC54102/sources/app/sensoracq_t.c index 28910b4..23265fa 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/app/sensoracq_t.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/app/sensoracq_t.c @@ -19,15 +19,16 @@ | I N C L U D E F I L E S \*-------------------------------------------------------------------------------------------------*/ #include "common.h" -#include "acc_common.h" -#include "mag_common.h" -#include "gyro_common.h" +#include "Driver_Sensor.h" #include "osp-api.h" /*-------------------------------------------------------------------------------------------------*\ | E X T E R N A L V A R I A B L E S & F U N C T I O N S \*-------------------------------------------------------------------------------------------------*/ void WaitForHostSync( void ); +extern OSP_DRIVER_SENSOR Driver_Acc; +extern OSP_DRIVER_SENSOR Driver_Mag; +extern OSP_DRIVER_SENSOR Driver_Gyro; /*-------------------------------------------------------------------------------------------------*\ | P U B L I C V A R I A B L E S D E F I N I T I O N S @@ -129,7 +130,7 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) if ((sMagDecimateCount++ % MAG_DECIMATE_FACTOR) == 0 ) { /* Read mag Data - reading would clear interrupt also */ - Mag_ReadData( &magData ); + Driver_Mag.ReadData(&magData,0); /* Replace time stamp with that captured by interrupt handler */ magData.timeStamp = timeStamp; #ifdef ALGORITHM_TASK @@ -140,7 +141,8 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) } else { - Mag_ClearDataInt(); + /* Reading would clear interrupt also */ + Driver_Mag.ReadData(&magData,0); } break; @@ -148,7 +150,7 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) if ((gyroSampleCount++ % GYRO_SAMPLE_DECIMATE) == 0) { /* Read Gyro Data - reading typically clears interrupt as well */ - Gyro_ReadData( &gyroData ); //Reads also clears DRDY interrupt + Driver_Gyro.ReadData(&gyroData,0); //Reads also clears DRDY interrupt /* Replace time stamp with that captured by interrupt handler */ gyroData.timeStamp = timeStamp; #ifdef ALGORITHM_TASK @@ -159,7 +161,8 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) } else { - Gyro_ClearDataInt(); + /* Reading would clear interrupt also */ + Driver_Gyro.ReadData(&gyroData,0); //Reads also clears DRDY interrupt } break; @@ -167,13 +170,14 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) #if defined TRIGGERED_MAG_SAMPLING if (accSampleCount % MAG_TRIGGER_RATE_DECIMATE == 0) { + /* PG: No analogous function in sensor HAL. Need to find a workaround. TBD */ Mag_TriggerDataAcq(); //Mag is triggered relative to Accel to avoid running separate timer } #endif if (accSampleCount++ % ACCEL_SAMPLE_DECIMATE == 0) { /* Read Accel Data - reading typically clears interrupt as well */ - Accel_ReadData( &accelData ); + Driver_Acc.ReadData(&accelData,0); /* Replace time stamp with that captured by interrupt handler */ accelData.timeStamp = timeStamp; #ifdef ALGORITHM_TASK @@ -185,7 +189,8 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) } else { - Accel_ClearDataInt(); + /* Reading would clear interrupt also */ + Driver_Acc.ReadData(&accelData,0); } break; @@ -219,19 +224,19 @@ void SensorControlCmdHandler(MsgSensorControlData *pData) #ifdef SENSOR_CONTROL_ENABLE // Maybe add a user configurable 'powerMode' setting and here we // configure the sensor hardware according to its value. - Accel_ConfigDataInt(false); // do not disable accel so watch window input will work + Driver_Acc.Activate(false,0,0,0); // do not disable accel so watch window input will work #endif break; case MAG_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Mag_ConfigDataInt(false); + Driver_Mag.Activate(false,0,0,0); #endif break; case GYRO_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Gyro_ConfigDataInt(false); + Driver_Gyro.Activate(false,0,0,0); #endif break; @@ -252,19 +257,19 @@ void SensorControlCmdHandler(MsgSensorControlData *pData) case ACCEL_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Accel_ConfigDataInt(true); + Driver_Acc.Activate(true,0,0,0); #endif break; case MAG_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Mag_ConfigDataInt(true); + Driver_Mag.Activate(true,0,0,0); #endif break; case GYRO_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Gyro_ConfigDataInt(true); + Driver_Gyro.Activate(true,0,0,0); #endif break; @@ -346,28 +351,25 @@ ASF_TASK void SensorAcqTask( ASF_TASK_ARG ) #endif /* Setup interface for the Magnetometer */ - Mag_HardwareSetup( true ); - Mag_Initialize(); - Mag_ClearDataInt(); /* Clear interrupt from previous run that maynot have been acknowledged */ + Driver_Mag.Initialize(NULL, NULL); + Driver_Mag.Deactivate(); /* Clear interrupt from previous run that maynot have been acknowledged */ /* Setup interface for the accelerometers */ - Accel_HardwareSetup( true ); - Accel_Initialize( INIT_NORMAL ); + Driver_Acc.Initialize(NULL, NULL); /* Setup Gyro */ - Gyro_HardwareSetup( true ); - Gyro_Initialize(); + Driver_Gyro.Initialize(NULL, NULL); #ifndef INTERRUPT_BASED_SAMPLING /* Start sample period timer */ ASFTimerStart( SENSOR_ACQ_TASK_ID, TIMER_REF_SENSOR_READ, SENSOR_SAMPLE_PERIOD, &sSensorTimer ); #else /* Enable Sensor interrupts */ - Mag_ConfigDataInt( true ); - Accel_ConfigDataInt( true ); - Gyro_ConfigDataInt( true ); + Driver_Mag.Activate(true,0,0,0); + Driver_Acc.Activate(true,0,0,0); + Driver_Gyro.Activate(true,0,0,0); # ifdef TRIGGERED_MAG_SAMPLING - Mag_SetLowPowerMode(); //Low power mode until triggered + Driver_Gyro.PowerControl(ARM_POWER_LOW); //Low power mode until triggered # endif #endif diff --git a/external/Drivers/Sensor/Bosch-Sensortec/Driver_Sensor.c b/external/Drivers/Sensor/Bosch-Sensortec/Driver_Sensor.c new file mode 100644 index 0000000..b96b5b4 --- /dev/null +++ b/external/Drivers/Sensor/Bosch-Sensortec/Driver_Sensor.c @@ -0,0 +1,824 @@ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2015 Audience Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common.h" +#include "Driver_Sensor.h" +#include "bma2x2.h" +#include "bmm050.h" +#include "bmg160.h" +#include "bosch_i2c_adapter.h" +#include "chip.h" + +#ifndef I2C_DRIVER +# error Needs I2C_DRIVER to be defined. Check Common.h +#endif + +#define OSP_SENSOR_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,0) + +#define ACTIVE_HIGH 1 +#define ACTIVE_LOW 0 + +/* Driver Version */ +static const ARM_DRIVER_VERSION DriverVersion = { + OSP_SENSOR_API_VERSION, + OSP_SENSOR_DRV_VERSION +}; + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +static bma2x2_t bma2x2; +static struct bmm050 bmc150mag; +static struct bmg160_t bmg160; + +/*************************************************************************************************** + * ACCEL HAL APIs * + ***************************************************************************************************/ + +/**************************************************************************************************** + * @fn Accx_GetVersion + * Get driver version. + * + * @param data Private Argument (Unused) + * + * @return Driver Version + * + ***************************************************************************************************/ +static ARM_DRIVER_VERSION Accx_GetVersion (void *data) +{ + return DriverVersion; +} + +/**************************************************************************************************** + * @fn _Accel_DumpRegisters + * Dumps the registers of the chosen Accelerometer device + * + ***************************************************************************************************/ +static void _Accel_DumpRegisters( void ) +{ + //TODO + return; +} + +/**************************************************************************************************** + * @fn _Accel_ResetDevice + * Soft resets the Accelerometer. + * + ***************************************************************************************************/ +static void _Accel_ResetDevice( void ) +{ + /* Soft Reset device */ + bma2x2_soft_reset(); // Problem with I2C at 1.8V + bma2x2.delay_msec(1); +} + +/**************************************************************************************************** + * @fn _Accel_HardwareSetup + * Configures the interrupt GPIO and regulators (if any) for the Accelerometer. + * + * @param enable - Enables or disables the GPIOs / Communications interface + * + * @return none + * + ***************************************************************************************************/ +static void _Accel_HardwareSetup( osp_bool_t enable ) +{ + if (enable == true) + { + /* Initialize the Sensor interface HW (typically I2C or SPI) */ + Board_SensorIfInit( ACCEL_INPUT_SENSOR ); + } + else + { + /* Disable interrupts and free GPIOs */ + Board_SensorIfDeinit( ACCEL_INPUT_SENSOR ); + } +} + +/**************************************************************************************************** + * @fn Accx_Initialize + * Initialization function for Accel + * + * @param cb Event Handler + * @param data Data required for initialization + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Accx_Initialize(OSP_Sensor_SignalEvent_t cb, void *data, void *priv) +{ + _Accel_HardwareSetup(true); + + /* Init the Bosch Driver for accel */ + bma2x2.bus_write = dev_i2c_write; + bma2x2.bus_read = dev_i2c_read; + bma2x2.delay_msec = dev_i2c_delay; + bma2x2_init(&bma2x2); + + /* Register state before changes */ + _Accel_DumpRegisters(); + + /* Set key registers to default on startup */ + _Accel_ResetDevice(); + + /* Clear any existing interrupts */ + /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, + we don't need to do data read to clear any pending interrupts */ + + bma2x2_set_mode(BMA2x2_MODE_NORMAL); // Normal power + bma2x2_set_range(BMA2x2_RANGE_4G); // set range 4g for grange + bma2x2_set_bandwidth(BMA2x2_BW_31_25HZ ); // BW set to 31.25Hz, ODR = BW*2 (62.5Hz) + + /* Setup interrupt selections */ + bma2x2_set_newdata( BMA2x2_INT1_NDATA, 1 ); //DRDY interrupt on INT1 pad + /* Latched with 250uS duration */ + bma2x2_set_latch_int(BMA2x2_LATCH_DUR_250US); + + /* Registers after initialization */ + _Accel_DumpRegisters(); + + /* Set to suspend mode till application requests data by enabling interrupt */ + //bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); --> This requires additional setup in IntEnable call + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Accx_Uninitialize + * Uninitialize the Accel + * + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Accx_Uninitialize(void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn Accx_Activate + * Activate the sensor + * + * @param flags Enable/Disable flag + * @param us_delay Delay before actual activation + * @param fifo_num_samples Fifo size + * @param max_report_latency Maximum latency for reporting the data + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Accx_Activate (uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv) +{ + /* Enables/Disables the New Data interrupt on the Accelerometer. + Note: If device is set in low power/suspend mode then additional device needs to be + reinitialized to the last operating mode */ + if (flags) + { + bma2x2_set_Int_Enable( BMA2x2_DATA_EN, 1 ); + + NVIC_ClearPendingIRQ(ACCEL_PINT_IRQn); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(ACCEL_PINT_IRQn); + } + else + { + bma2x2_set_Int_Enable( BMA2x2_DATA_EN, 0 ); + + NVIC_DisableIRQ(ACCEL_PINT_IRQn); + /* Set to suspend mode till application requests data by enabling interrupt */ + //bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); --> This requires additional setup in enable + } + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Accx_ReadData + * Reads data from Accelerometer's X, Y, Z data registers + * + * @param *data Data pointer + * @param num_samples Number of samples to be read + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Accx_ReadData (void *data, uint16_t num_samples, void *priv) +{ + MsgAccelData *pxyzData = data; + + bma2x2acc_t acc; //create object of type bma250acc_t + + bma2x2_read_accel_xyz(&acc); //get acceleration data from sensor + + pxyzData->X = acc.x; + pxyzData->Y = acc.y; + pxyzData->Z = acc.z; + + //add timestamp here! + pxyzData->timeStamp = RTC_GetCounter(); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Accx_Deactivate + * Deactivate Accelerometer + * + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Accx_Deactivate (void *priv) +{ + bma2x2_set_Int_Enable( BMA2x2_DATA_EN, 0 ); + NVIC_DisableIRQ(ACCEL_PINT_IRQn); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Accx_PowerControl + * Control the power state of the sensor + * + * @param state Power state + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Accx_PowerControl(ARM_POWER_STATE state, void *priv) +{ + switch (state) + { + case ARM_POWER_OFF: + Accx_Deactivate(NULL); + break; + + case ARM_POWER_LOW: + bma2x2_set_mode(BMA2x2_MODE_STANDBY); + break; + + case ARM_POWER_FULL: + Accx_Activate(true,0,0,0,NULL); + break; + + default: + return ARM_DRIVER_ERROR_PARAMETER; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Accx_GetDetails + * Get sensor details + * + * @param data Pointer to the sensor details + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Accx_GetDetails (void *data, void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn Accx_InjectData + * Feed dummy data + * + * @param data Simulated data + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Accx_InjectData (void *data, void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing +} + +/* Accel Driver Definition */ +OSP_BUILD_DRIVER_SENSOR(Acc, Accx, NULL); + +/*************************************************************************************************** + * MAG HAL APIs * + ***************************************************************************************************/ + +/**************************************************************************************************** + * @fn Magx_GetVersion + * Get driver version. + * + * @param data Private Argument (Unused) + * + * @return Driver Version + * + ***************************************************************************************************/ +static ARM_DRIVER_VERSION Magx_GetVersion (void *data) +{ + return DriverVersion; +} + +/**************************************************************************************************** + * @fn _Mag_DumpRegisters + * Dumps the registers of the chosen Magnetometer device + * + ***************************************************************************************************/ +static void _Mag_DumpRegisters( void ) +{ + //TODO + return; +} + + +/**************************************************************************************************** + * @fn _Mag_HardwareSetup + * Configures the interrupt GPIO and regulators (if any) for the Magnetometer. + * + * @param enable - Enables or disables the GPIOs / Communications interface + * + * @return none + * + ***************************************************************************************************/ +static void _Mag_HardwareSetup( osp_bool_t enable ) +{ + if (enable == true) + { + /* Initialize the Sensor interface HW (typically I2C or SPI) */ + Board_SensorIfInit( MAG_INPUT_SENSOR ); + } + else + { + /* Disable interrupts and free GPIOs */ + Board_SensorIfDeinit( MAG_INPUT_SENSOR ); + } +} + +/**************************************************************************************************** + * @fn Magx_Initialize + * Initialization function for Mag + * + * @param cb Event Handler + * @param data Data required for initialization + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Magx_Initialize(OSP_Sensor_SignalEvent_t cb, void *data, void *priv) +{ + uint8_t value; + + _Mag_HardwareSetup(true); + + /* Init the Bosch Driver for mag */ + bmc150mag.bus_write = dev_i2c_write; + bmc150mag.bus_read = dev_i2c_read; + bmc150mag.delay_msec = dev_i2c_delay; + + /* Initialize and set key registers to default on startup */ + bmm050_init(&bmc150mag); + + /* Register state before changes */ + _Mag_DumpRegisters(); + + /* Clear any existing interrupts */ + /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, + we don't need to do data read to clear any pending interrupts */ + + /* Enable all axis & Set DR Polarity to active high */ + value = 0x04; + bmm050_write_register(BMM050_SENS_CNTL, &value, 1); + + /* Set data rate */ + bmm050_set_datarate(BMM050_DR_25HZ); + + bmm050_set_functional_state(BMM050_NORMAL_MODE); + bmc150mag.delay_msec(1); + + /* Registers after initialization */ + _Mag_DumpRegisters(); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Magx_Uninitialize + * Uninitialize the Mag + * + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Magx_Uninitialize(void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn Magx_Activate + * Activate the sensor + * + * @param flags Enable/Disable flag + * @param us_delay Delay before actual activation + * @param fifo_num_samples Fifo size + * @param max_report_latency Maximum latency for reporting the data + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Magx_Activate (uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv) +{ + if (flags) + { + bmm050_set_mag_drdy_interrupt( true, ACTIVE_HIGH ); + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(MAG_PINT_IRQn); + } + else + { + bmm050_set_mag_drdy_interrupt( false, ACTIVE_HIGH ); + NVIC_DisableIRQ(MAG_PINT_IRQn); + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Magx_ReadData + * Read data from Mag + * + * @param *data Data pointer + * @param num_samples Number of samples to be read + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Magx_ReadData (void *data, uint16_t num_samples, void *priv) +{ + MsgMagData *pxyzData = data; + struct bmm050_mdata_s32 mdata; + + bmm050_read_mdataXYZ_s32(&mdata); + + pxyzData->X = mdata.datax; + pxyzData->Y = mdata.datay; + pxyzData->Z = mdata.dataz; + + //add timestamp here! + pxyzData->timeStamp = RTC_GetCounter(); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Magx_Deactivate + * Deactivate Mag + * + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Magx_Deactivate (void *priv) +{ + bmm050_set_mag_drdy_interrupt( false, ACTIVE_HIGH ); + NVIC_DisableIRQ(MAG_PINT_IRQn); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Magx_PowerControl + * Control the power state of the sensor + * + * @param state Power state + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Magx_PowerControl(ARM_POWER_STATE state, void *priv) +{ + switch (state) + { + case ARM_POWER_OFF: + Magx_Deactivate(NULL); + break; + + case ARM_POWER_LOW: + bmm050_set_functional_state(BMM050_SUSPEND_MODE); + break; + + case ARM_POWER_FULL: + Magx_Activate(true,0,0,0, NULL); + break; + + default: + return ARM_DRIVER_ERROR_PARAMETER; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Magx_GetDetails + * Get sensor details + * + * @param data Pointer to the sensor details + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Magx_GetDetails (void *data, void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn Magx_InjectData + * Feed dummy data + * + * @param data Simulated data + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Magx_InjectData (void *data, void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing +} + +/* Mag Driver Definition */ +OSP_BUILD_DRIVER_SENSOR(Mag, Magx, NULL); + +/*************************************************************************************************** + * GYRO HAL APIs * + ***************************************************************************************************/ + +/**************************************************************************************************** + * @fn Gyrox_GetVersion + * Get driver version. + * + * @param data Private Argument (Unused) + * + * @return Driver Version + * + ***************************************************************************************************/ +static ARM_DRIVER_VERSION Gyrox_GetVersion (void *data) +{ + return DriverVersion; +} + +/**************************************************************************************************** + * @fn _Gyro_DumpRegisters + * Dumps the registers of the chosen Gyroscope device + * + ***************************************************************************************************/ +static void _Gyro_DumpRegisters( void ) +{ + //TODO + return; +} + +/**************************************************************************************************** + * @fn _Gyro_HardwareSetup + * Configures the interrupt GPIO and regulators (if any) for the Gyroscope. + * + * @param enable - Enables or disables the GPIOs / Communications interface + * + * @return none + * + ***************************************************************************************************/ +static void _Gyro_HardwareSetup( osp_bool_t enable ) +{ + if (enable == true) + { + /* Initialize the Sensor interface HW (typically I2C or SPI) */ + Board_SensorIfInit( GYRO_INPUT_SENSOR ); + } + else + { + /* Disable interrupts and free GPIOs */ + Board_SensorIfDeinit( GYRO_INPUT_SENSOR ); + } +} + +/**************************************************************************************************** + * @fn Gyrox_Initialize + * Initialization function for Gyro + * + * @param cb Event Handler + * @param data Data required for initialization + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Gyrox_Initialize(OSP_Sensor_SignalEvent_t cb, void *data, void *priv) +{ + + /* Configure the interrupt GPIO and regulators (if any) for the Gyroscope */ + _Gyro_HardwareSetup(true); + + /* Init the Bosch Driver for Gyro */ + bmg160.bus_write = dev_i2c_write; + bmg160.bus_read = dev_i2c_read; + bmg160.delay_msec = dev_i2c_delay; + bmg160_init(&bmg160); + + /* Register state before changes */ + _Gyro_DumpRegisters(); + + /* Clear any existing interrupts */ + /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, + we don't need to do data read to clear any pending interrupts */ + + bmg160_set_mode(BMG160_MODE_NORMAL); + bmg160_set_bw(C_BMG160_BW_32Hz_U8X); //ODR = 100Hz + bmg160_set_range_reg(C_BMG160_Zero_U8X); //Zero = 2000dps + + /* Interrupt setup */ + bmg160_set_int_data( BMG160_INT1_DATA, 1 ); //DRDY interrupt on INT1 pad + /* Latched with 250uS duration */ + bmg160_set_latch_int(BMG160_LATCH_DUR_250US); + + /* Registers after initialization */ + _Gyro_DumpRegisters(); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Gyrox_Uninitialize + * Uninitialize the Gyro + * + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Gyrox_Uninitialize(void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn Gyrox_Activate + * Activate the sensor + * + * @param flags Enable/Disable flag + * @param us_delay Delay before actual activation + * @param fifo_num_samples Fifo size + * @param max_report_latency Maximum latency for reporting the data + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Gyrox_Activate (uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv) +{ + /* Enables/Disables the New Data interrupt on the Gyroscope */ + if (flags) + { + bmg160_set_data_en(1); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(GYRO_PINT_IRQn); + } + else + { + NVIC_DisableIRQ(GYRO_PINT_IRQn); + bmg160_set_data_en(0); + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Gyrox_ReadData + * Reads data from Gyroscope's X, Y, Z data registers + * + * @param *data Data pointer + * @param num_samples Number of samples to be read + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Gyrox_ReadData (void *data, uint16_t num_samples, void *priv) +{ + MsgGyroData *pxyzData = data; + struct bmg160_data_t gyro_raw; + + bmg160_get_dataXYZ(&gyro_raw); + pxyzData->X = gyro_raw.datax; + pxyzData->Y = gyro_raw.datay; + pxyzData->Z = gyro_raw.dataz; + //add timestamp here! + pxyzData->timeStamp = RTC_GetCounter(); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Gyrox_Deactivate + * Deactivate Gyro Interrupt + * + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Gyrox_Deactivate (void *priv) +{ + NVIC_DisableIRQ(GYRO_PINT_IRQn); + bmg160_set_data_en(0); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Gyrox_PowerControl + * Control the power state of the sensor + * + * @param state Power state + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t Gyrox_PowerControl(ARM_POWER_STATE state, void *priv) +{ + switch (state) + { + case ARM_POWER_OFF: + Gyrox_Deactivate(NULL); + break; + + case ARM_POWER_LOW: + bmg160_set_mode(BMG160_MODE_SUSPEND); + break; + + case ARM_POWER_FULL: + Gyrox_Activate(true,0,0,0,NULL); + break; + + default: + return ARM_DRIVER_ERROR_PARAMETER; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn Gyrox_GetDetails + * Get sensor details + * + * @param data Pointer to the sensor details + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Gyrox_GetDetails (void *data, void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn Gyrox_InjectData + * Feed dummy data + * + * @param data Simulated data + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t Gyrox_InjectData (void *data, void *priv) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing +} + +/* Gyro Driver Definition */ +OSP_BUILD_DRIVER_SENSOR(Gyro, Gyrox, NULL); From 921a33fa81fbe26f7c6d89f0a45a2f069d164b15 Mon Sep 17 00:00:00 2001 From: Pankaj Goenka Date: Thu, 10 Dec 2015 19:38:28 +0530 Subject: [PATCH 2/3] Split Driver_Sensor.c into individual files for Accel, Mag and Gyro Moved Driver_Common.h and Driver_Sensor.h into embedded folder Moved Driver_Sensor.h higher up in the directory structure Moved sensor pin initialization to Board_SensorIfInit and removed double initialization of I2C pins Details of other changes are in the pull request #7 Signed-off-by: Pankaj Goenka --- .../Sensor/Bosch-Sensortec/Driver_BMA2X2.c | 323 +++++++ .../Sensor/Bosch-Sensortec/Driver_BMG160.c | 299 +++++++ .../Sensor/Bosch-Sensortec/Driver_BMM050.c | 302 +++++++ .../Driver_Sensor.h | 12 +- .../keil-mdk-build/SH-Xpresso-LPC54102.uvoptx | 34 +- .../SH-Xpresso-LPC54102.uvprojx | 58 +- .../sources/app/sensoracq_t.c | 39 +- .../sources/boardsupport/hw_setup.c | 24 +- .../boardsupport/hw_setup_xpresso_lpc54102.h | 10 + .../CMSIS/Driver/Include}/Driver_Common.h | 144 +-- .../Sensor/Bosch-Sensortec/Driver_Sensor.c | 824 ------------------ 11 files changed, 1115 insertions(+), 954 deletions(-) create mode 100644 embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c create mode 100644 embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c create mode 100644 embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c rename embedded/{common/modules/sensor-drivers => include}/Driver_Sensor.h (90%) rename {embedded/common/modules/sensor-drivers => external/CMSIS/Driver/Include}/Driver_Common.h (96%) delete mode 100644 external/Drivers/Sensor/Bosch-Sensortec/Driver_Sensor.c diff --git a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c new file mode 100644 index 0000000..40459e1 --- /dev/null +++ b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c @@ -0,0 +1,323 @@ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "common.h" +#include "Driver_Sensor.h" +#include "bma2x2.h" +#include "bosch_i2c_adapter.h" +#include "chip.h" + +#ifndef I2C_DRIVER +# error Needs I2C_DRIVER to be defined. Check Common.h +#endif + +#define OSP_SENSOR_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR( 1,0 ) + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Driver Version */ +static const ARM_DRIVER_VERSION DriverVersion = { + OSP_SENSOR_API_VERSION, + OSP_SENSOR_DRV_VERSION +}; + +static bma2x2_t bma2x2; + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/**************************************************************************************************** + * @fn OSP_Accel_GetVersion + * Get driver version + * + * @param data Private Argument (Unused) + * + * @return Driver Version + * + ***************************************************************************************************/ +static ARM_DRIVER_VERSION OSP_Accel_GetVersion( void *data ) +{ + return DriverVersion; +} + +/**************************************************************************************************** + * @fn _Accel_DumpRegisters + * Dumps the registers of the chosen Accelerometer device + * + * @param None + * + * @return None + * + ***************************************************************************************************/ +static void _Accel_DumpRegisters( void ) +{ + //TODO + return; +} + +/**************************************************************************************************** + * @fn _Accel_ResetDevice + * Soft resets the Accelerometer + * + * @param None + * + * @return None + * + ***************************************************************************************************/ +static void _Accel_ResetDevice( void ) +{ + /* Soft Reset device */ + bma2x2_soft_reset(); // Problem with I2C at 1.8V + bma2x2.delay_msec( 1 ); +} + +/**************************************************************************************************** + * @fn _Accel_HardwareSetup + * Configures the interrupt GPIO and regulators (if any) for the Accelerometer + * + * @param enable - Enables or disables the GPIOs / Communications interface + * + * @return none + * + ***************************************************************************************************/ +static void _Accel_HardwareSetup( osp_bool_t enable ) +{ + if (enable == true) + { + /* Initialize the Sensor interface HW (typically I2C or SPI) */ + Board_SensorIfInit( ACCEL_INPUT_SENSOR ); + } + else + { + /* Disable interrupts and free GPIOs */ + Board_SensorIfDeinit( ACCEL_INPUT_SENSOR ); + } +} + +/**************************************************************************************************** + * @fn OSP_Accel_Initialize + * Initialization function for Accel + * + * @param cb Event Handler + * @param data Data required for initialization + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Accel_Initialize( OSP_Sensor_SignalEvent_t cb, void *data, void *priv ) +{ + _Accel_HardwareSetup( true ); + + /* Init the Bosch Driver for accel */ + bma2x2.bus_write = dev_i2c_write; + bma2x2.bus_read = dev_i2c_read; + bma2x2.delay_msec = dev_i2c_delay; + bma2x2_init( &bma2x2 ); + + /* Register state before changes */ + _Accel_DumpRegisters(); + + /* Set key registers to default on startup */ + _Accel_ResetDevice(); + + /* Clear any existing interrupts */ + /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, + we don't need to do data read to clear any pending interrupts */ + + bma2x2_set_mode( BMA2x2_MODE_NORMAL ); // Normal power + bma2x2_set_range( BMA2x2_RANGE_4G ); // set range 4g for grange + bma2x2_set_bandwidth( BMA2x2_BW_31_25HZ ); // BW set to 31.25Hz, ODR = BW*2 (62.5Hz) + + /* Setup interrupt selections */ + bma2x2_set_newdata( BMA2x2_INT1_NDATA, 1 ); //DRDY interrupt on INT1 pad + /* Latched with 250uS duration */ + bma2x2_set_latch_int( BMA2x2_LATCH_DUR_250US ); + + /* Registers after initialization */ + _Accel_DumpRegisters(); + + /* Set to suspend mode till application requests data by enabling interrupt */ + //bma2x2_set_mode( BMA2x2_MODE_DEEP_SUSPEND ); --> This requires additional setup in IntEnable call + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Accel_Uninitialize + * Uninitialize the Accel + * + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Accel_Uninitialize( void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn OSP_Accel_Activate + * Activate the sensor + * + * @param flags Sensor Flag - SENSOR_FLAG* (Unused) + * @param us_delay Delay before actual activation + * @param fifo_num_samples Fifo size + * @param max_report_latency Maximum latency for reporting the data + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Accel_Activate( uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv ) +{ + /* Enables/Disables the New Data interrupt on the Accelerometer. + Note: If device is set in low power/suspend mode then additional device needs to be + reinitialized to the last operating mode */ + bma2x2_set_Int_Enable( BMA2x2_DATA_EN, 1 ); + + NVIC_ClearPendingIRQ( ACCEL_PINT_IRQn ); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ( ACCEL_PINT_IRQn ); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Accel_ReadData + * Reads data from Accelerometer's X, Y, Z data registers + * + * @param *data Data pointer + * @param num_samples Number of samples to be read + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Accel_ReadData( void *data, uint16_t num_samples, void *priv ) +{ + MsgAccelData *pxyzData = data; + uint16_t i = 0; + + bma2x2acc_t acc; //create object of type bma250acc_t + + for (; iX = acc.x; + pxyzData->Y = acc.y; + pxyzData->Z = acc.z; + + //add timestamp here! + pxyzData->timeStamp = RTC_GetCounter(); + pxyzData++; + } + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Accel_Deactivate + * Deactivate Accelerometer + * + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Accel_Deactivate( void *priv ) +{ + bma2x2_set_Int_Enable( BMA2x2_DATA_EN, 0 ); + NVIC_DisableIRQ( ACCEL_PINT_IRQn ); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Accel_PowerControl + * Control the power state of the sensor + * + * @param state Power state + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Accel_PowerControl( ARM_POWER_STATE state, void *priv ) +{ + switch (state) + { + case ARM_POWER_OFF: + OSP_Accel_Deactivate( NULL ); + break; + + case ARM_POWER_LOW: + bma2x2_set_mode( BMA2x2_MODE_STANDBY ); + break; + + case ARM_POWER_FULL: + OSP_Accel_Activate( SENSOR_FLAG_CONTINUOUS_DATA,NULL /* unused */,NULL /* unused */,NULL /* unused */,NULL ); + break; + + default: + return ARM_DRIVER_ERROR_PARAMETER; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Accel_GetDetails + * Get sensor details + * + * @param data Pointer to the sensor details + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Accel_GetDetails( void *data, void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn OSP_Accel_InjectData + * Feed dummy data + * + * @param data Simulated data + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Accel_InjectData( void *data, void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing +} + +/* Accel Driver Definition */ +OSP_BUILD_DRIVER_SENSOR( Accel, OSP_Accel, NULL ); + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c new file mode 100644 index 0000000..fafaa09 --- /dev/null +++ b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c @@ -0,0 +1,299 @@ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "common.h" +#include "Driver_Sensor.h" +#include "bmg160.h" +#include "bosch_i2c_adapter.h" +#include "chip.h" + +#ifndef I2C_DRIVER +# error Needs I2C_DRIVER to be defined. Check Common.h +#endif + +#define OSP_SENSOR_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR( 1,0 ) + +#define ACTIVE_HIGH 1 +#define ACTIVE_LOW 0 + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Driver Version */ +static const ARM_DRIVER_VERSION DriverVersion = { + OSP_SENSOR_API_VERSION, + OSP_SENSOR_DRV_VERSION +}; + +static struct bmg160_t bmg160; + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/**************************************************************************************************** + * @fn OSP_Gyro_GetVersion + * Get driver version. + * + * @param data Private Argument (Unused) + * + * @return Driver Version + * + ***************************************************************************************************/ +static ARM_DRIVER_VERSION OSP_Gyro_GetVersion( void *data ) +{ + return DriverVersion; +} + +/**************************************************************************************************** + * @fn _Gyro_DumpRegisters + * Dumps the registers of the chosen Gyroscope device + * + * @param None + * + * @return None + * + ***************************************************************************************************/ +static void _Gyro_DumpRegisters( void ) +{ + //TODO + return; +} + +/**************************************************************************************************** + * @fn _Gyro_HardwareSetup + * Configures the interrupt GPIO and regulators (if any) for the Gyroscope. + * + * @param enable - Enables or disables the GPIOs / Communications interface + * + * @return none + * + ***************************************************************************************************/ +static void _Gyro_HardwareSetup( osp_bool_t enable ) +{ + if (enable == true) + { + /* Initialize the Sensor interface HW (typically I2C or SPI) */ + Board_SensorIfInit( GYRO_INPUT_SENSOR ); + } + else + { + /* Disable interrupts and free GPIOs */ + Board_SensorIfDeinit( GYRO_INPUT_SENSOR ); + } +} + +/**************************************************************************************************** + * @fn OSP_Gyro_Initialize + * Initialization function for Gyro + * + * @param cb Event Handler + * @param data Data required for initialization + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Gyro_Initialize( OSP_Sensor_SignalEvent_t cb, void *data, void *priv ) +{ + + /* Configure the interrupt GPIO and regulators (if any) for the Gyroscope */ + _Gyro_HardwareSetup( true ); + + /* Init the Bosch Driver for Gyro */ + bmg160.bus_write = dev_i2c_write; + bmg160.bus_read = dev_i2c_read; + bmg160.delay_msec = dev_i2c_delay; + bmg160_init( &bmg160 ); + + /* Register state before changes */ + _Gyro_DumpRegisters(); + + /* Clear any existing interrupts */ + /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, + we don't need to do data read to clear any pending interrupts */ + + bmg160_set_mode( BMG160_MODE_NORMAL ); + bmg160_set_bw( C_BMG160_BW_32Hz_U8X ); //ODR = 100Hz + bmg160_set_range_reg( C_BMG160_Zero_U8X ); //Zero = 2000dps + + /* Interrupt setup */ + bmg160_set_int_data( BMG160_INT1_DATA, 1 ); //DRDY interrupt on INT1 pad + /* Latched with 250uS duration */ + bmg160_set_latch_int( BMG160_LATCH_DUR_250US ); + + /* Registers after initialization */ + _Gyro_DumpRegisters(); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Gyro_Uninitialize + * Uninitialize the Gyro + * + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Gyro_Uninitialize( void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn OSP_Gyro_Activate + * Activate the sensor + * + * @param flags Sensor Flag - SENSOR_FLAG* (Unused) + * @param us_delay Delay before actual activation + * @param fifo_num_samples Fifo size + * @param max_report_latency Maximum latency for reporting the data + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Gyro_Activate( uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv ) +{ + /* Enables the New Data interrupt on the Gyroscope */ + bmg160_set_data_en( 1 ); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ( GYRO_PINT_IRQn ); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Gyro_ReadData + * Reads data from Gyroscope's X, Y, Z data registers + * + * @param *data Data pointer + * @param num_samples Number of samples to be read + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Gyro_ReadData( void *data, uint16_t num_samples, void *priv ) +{ + MsgGyroData *pxyzData = data; + struct bmg160_data_t gyro_raw; + uint16_t i = 0; + + for (; iX = gyro_raw.datax; + pxyzData->Y = gyro_raw.datay; + pxyzData->Z = gyro_raw.dataz; + //add timestamp here! + pxyzData->timeStamp = RTC_GetCounter(); + pxyzData++; + } + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Gyro_Deactivate + * Deactivate Gyro Interrupt + * + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Gyro_Deactivate( void *priv ) +{ + NVIC_DisableIRQ( GYRO_PINT_IRQn ); + bmg160_set_data_en( 0 ); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Gyro_PowerControl + * Control the power state of the sensor + * + * @param state Power state + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Gyro_PowerControl( ARM_POWER_STATE state, void *priv ) +{ + switch (state) + { + case ARM_POWER_OFF: + OSP_Gyro_Deactivate( NULL ); + break; + + case ARM_POWER_LOW: + bmg160_set_mode( BMG160_MODE_SUSPEND ); + break; + + case ARM_POWER_FULL: + OSP_Gyro_Activate( SENSOR_FLAG_CONTINUOUS_DATA,NULL /* unused */,NULL /* unused */, NULL /* unused */,NULL ); + break; + + default: + return ARM_DRIVER_ERROR_PARAMETER; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Gyro_GetDetails + * Get sensor details + * + * @param data Pointer to the sensor details + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Gyro_GetDetails( void *data, void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn OSP_Gyro_InjectData + * Feed dummy data + * + * @param data Simulated data + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Gyro_InjectData( void *data, void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing +} + +/* Gyro Driver Definition */ +OSP_BUILD_DRIVER_SENSOR( Gyro, OSP_Gyro, NULL ); + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c new file mode 100644 index 0000000..24d32cc --- /dev/null +++ b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c @@ -0,0 +1,302 @@ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "common.h" +#include "Driver_Sensor.h" +#include "bmm050.h" +#include "bosch_i2c_adapter.h" +#include "chip.h" + +#ifndef I2C_DRIVER +# error Needs I2C_DRIVER to be defined. Check Common.h +#endif + +#define OSP_SENSOR_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR( 1,0 ) + +#define ACTIVE_HIGH 1 +#define ACTIVE_LOW 0 + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Driver Version */ +static const ARM_DRIVER_VERSION DriverVersion = { + OSP_SENSOR_API_VERSION, + OSP_SENSOR_DRV_VERSION +}; + +static struct bmm050 bmc150mag; + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/**************************************************************************************************** + * @fn OSP_Mag_GetVersion + * Get driver version + * + * @param data Private Argument (Unused) + * + * @return Driver Version + * + ***************************************************************************************************/ +static ARM_DRIVER_VERSION OSP_Mag_GetVersion( void *data ) +{ + return DriverVersion; +} + +/**************************************************************************************************** + * @fn _Mag_DumpRegisters + * Dumps the registers of the chosen Magnetometer device + * + * @param None + * + * @return None + * + ***************************************************************************************************/ +static void _Mag_DumpRegisters( void ) +{ + //TODO + return; +} + +/**************************************************************************************************** + * @fn _Mag_HardwareSetup + * Configures the interrupt GPIO and regulators (if any) for the Magnetometer. + * + * @param enable - Enables or disables the GPIOs / Communications interface + * + * @return none + * + ***************************************************************************************************/ +static void _Mag_HardwareSetup( osp_bool_t enable ) +{ + if (enable == true) + { + /* Initialize the Sensor interface HW (typically I2C or SPI) */ + Board_SensorIfInit( MAG_INPUT_SENSOR ); + } + else + { + /* Disable interrupts and free GPIOs */ + Board_SensorIfDeinit( MAG_INPUT_SENSOR ); + } +} + +/**************************************************************************************************** + * @fn OSP_Mag_Initialize + * Initialization function for Mag + * + * @param cb Event Handler + * @param data Data required for initialization + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Mag_Initialize( OSP_Sensor_SignalEvent_t cb, void *data, void *priv ) +{ + uint8_t value; + + _Mag_HardwareSetup( true ); + + /* Init the Bosch Driver for mag */ + bmc150mag.bus_write = dev_i2c_write; + bmc150mag.bus_read = dev_i2c_read; + bmc150mag.delay_msec = dev_i2c_delay; + + /* Initialize and set key registers to default on startup */ + bmm050_init( &bmc150mag ); + + /* Register state before changes */ + _Mag_DumpRegisters(); + + /* Clear any existing interrupts */ + /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, + we don't need to do data read to clear any pending interrupts */ + + /* Enable all axis & Set DR Polarity to active high */ + value = 0x04; + bmm050_write_register( BMM050_SENS_CNTL, &value, 1 ); + + /* Set data rate */ + bmm050_set_datarate( BMM050_DR_25HZ ); + + bmm050_set_functional_state( BMM050_NORMAL_MODE ); + bmc150mag.delay_msec( 1 ); + + /* Registers after initialization */ + _Mag_DumpRegisters(); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Mag_Uninitialize + * Uninitialize the Mag + * + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Mag_Uninitialize( void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn OSP_Mag_Activate + * Activate the sensor + * + * @param flags Sensor Flag - SENSOR_FLAG* (Unused) + * @param us_delay Delay before actual activation + * @param fifo_num_samples Fifo size + * @param max_report_latency Maximum latency for reporting the data + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Mag_Activate( uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv ) +{ + bmm050_set_mag_drdy_interrupt( true, ACTIVE_HIGH ); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ( MAG_PINT_IRQn ); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Mag_ReadData + * Read data from Mag + * + * @param *data Data pointer + * @param num_samples Number of samples to be read + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Mag_ReadData( void *data, uint16_t num_samples, void *priv ) +{ + MsgMagData *pxyzData = data; + struct bmm050_mdata_s32 mdata; + uint16_t i = 0; + + for (; iX = mdata.datax; + pxyzData->Y = mdata.datay; + pxyzData->Z = mdata.dataz; + + //add timestamp here! + pxyzData->timeStamp = RTC_GetCounter(); + pxyzData++; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Mag_Deactivate + * Deactivate Mag + * + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Mag_Deactivate( void *priv ) +{ + bmm050_set_mag_drdy_interrupt( false, ACTIVE_HIGH ); + NVIC_DisableIRQ( MAG_PINT_IRQn ); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Mag_PowerControl + * Control the power state of the sensor + * + * @param state Power state + * @param priv Private Argument (Unused) + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_Mag_PowerControl( ARM_POWER_STATE state, void *priv ) +{ + switch ( state ) + { + case ARM_POWER_OFF: + OSP_Mag_Deactivate( NULL ); + break; + + case ARM_POWER_LOW: + bmm050_set_functional_state( BMM050_SUSPEND_MODE ); + break; + + case ARM_POWER_FULL: + OSP_Mag_Activate( SENSOR_FLAG_ONE_SHOT_MODE,NULL /* unused */,NULL /* unused */,NULL /* unused */, NULL ); + break; + + default: + return ARM_DRIVER_ERROR_PARAMETER; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_Mag_GetDetails + * Get sensor details + * + * @param data Pointer to the sensor details + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Mag_GetDetails( void *data, void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; +} + +/**************************************************************************************************** + * @fn OSP_Mag_InjectData + * Feed dummy data + * + * @param data Simulated data + * @param priv Private Argument (Unused) + * + * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported + * + ***************************************************************************************************/ +static int32_t OSP_Mag_InjectData( void *data, void *priv ) +{ + return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing +} + +/* Mag Driver Definition */ +OSP_BUILD_DRIVER_SENSOR( Mag, OSP_Mag, NULL ); + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/modules/sensor-drivers/Driver_Sensor.h b/embedded/include/Driver_Sensor.h similarity index 90% rename from embedded/common/modules/sensor-drivers/Driver_Sensor.h rename to embedded/include/Driver_Sensor.h index 38bcdc5..61b72f2 100644 --- a/embedded/common/modules/sensor-drivers/Driver_Sensor.h +++ b/embedded/include/Driver_Sensor.h @@ -35,12 +35,12 @@ typedef struct _OSP_SENSOR_DETAILS { } OSP_SENSOR_DETAILS; -#define SENSOR_FLAG_CONTINUOUS_DATA ( 0) ///< -#define SENSOR_FLAG_WAKE_UP (1U << 0) ///< -#define SENSOR_FLAG_ON_CHANGE_MODE (1U << 1) ///< -#define SENSOR_FLAG_ONE_SHOT_MODE (1U << 2) ///< -#define SENSOR_FLAG_MOTION_WAKEUP (1U << 3) ///< -#define SENSOR_FLAG_DATA_INJECTION (1U << 4) ///< +#define SENSOR_FLAG_CONTINUOUS_DATA (1U << 0) ///< +#define SENSOR_FLAG_WAKE_UP (1U << 1) ///< +#define SENSOR_FLAG_ON_CHANGE_MODE (1U << 2) ///< +#define SENSOR_FLAG_ONE_SHOT_MODE (1U << 3) ///< +#define SENSOR_FLAG_MOTION_WAKEUP (1U << 4) ///< +#define SENSOR_FLAG_DATA_INJECTION (1U << 5) ///< typedef struct _OSP_DRIVER_SENSOR { diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx index 1bc179c..8cf541d 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx @@ -1266,8 +1266,32 @@ 0 0 0 - ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c - Driver_Sensor.c + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMA2X2.c + Driver_BMA2X2.c + 0 + 0 + + + 11 + 37 + 1 + 0 + 0 + 0 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMG160.c + Driver_BMG160.c + 0 + 0 + + + 11 + 38 + 1 + 0 + 0 + 0 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMM050.c + Driver_BMM050.c 0 0 @@ -1281,7 +1305,7 @@ 0 12 - 37 + 39 1 0 0 @@ -1293,7 +1317,7 @@ 12 - 38 + 40 1 0 0 @@ -1305,7 +1329,7 @@ 12 - 39 + 41 1 0 0 diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx index d01e6b2..e1782a7 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx @@ -744,9 +744,19 @@ ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.c - Driver_Sensor.c + Driver_BMA2X2.c 1 - ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMA2X2.c + + + Driver_BMG160.c + 1 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMG160.c + + + Driver_BMM050.c + 1 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMM050.c @@ -1538,9 +1548,19 @@ ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.c - Driver_Sensor.c + Driver_BMA2X2.c 1 - ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMA2X2.c + + + Driver_BMG160.c + 1 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMG160.c + + + Driver_BMM050.c + 1 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMM050.c @@ -2332,9 +2352,19 @@ ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.c - Driver_Sensor.c + Driver_BMA2X2.c 1 - ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMA2X2.c + + + Driver_BMG160.c + 1 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMG160.c + + + Driver_BMM050.c + 1 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMM050.c @@ -2755,7 +2785,7 @@ SYSTEM_CLOCK_FREQ=96000000, __FPU_PRESENT=1, CHIP_LPC5410X, CORE_M4, DEBUG_BUILD, XPRESSO_LPC54102_BOARD, UART_DMA_ENABLE, ANDROID_DEMO, ASF_PROFILING, ON_DEMAND_PROFILING - ..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\..\..\..\external\MCU\NXP-5410x\CSLib\inc;..\..\..\common\modules\bus-drivers;..\..\..\common\modules\sensor-drivers;..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec;..\..\..\common\hostinterface + ..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\..\..\..\external\MCU\NXP-5410x\CSLib\inc;..\..\..\common\modules\bus-drivers;..\..\..\common\modules\sensor-drivers;..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec;..\..\..\common\hostinterface;..\..\..\..\external\CMSIS\Driver\Include;..\..\..\..\embedded\include @@ -3126,9 +3156,19 @@ ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.c - Driver_Sensor.c + Driver_BMA2X2.c + 1 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMA2X2.c + + + Driver_BMG160.c + 1 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMG160.c + + + Driver_BMM050.c 1 - ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\Driver_Sensor.c + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMM050.c diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/app/sensoracq_t.c b/embedded/projects/SH-Xpresso-LPC54102/sources/app/sensoracq_t.c index 23265fa..f8ace64 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/app/sensoracq_t.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/app/sensoracq_t.c @@ -26,7 +26,7 @@ | E X T E R N A L V A R I A B L E S & F U N C T I O N S \*-------------------------------------------------------------------------------------------------*/ void WaitForHostSync( void ); -extern OSP_DRIVER_SENSOR Driver_Acc; +extern OSP_DRIVER_SENSOR Driver_Accel; extern OSP_DRIVER_SENSOR Driver_Mag; extern OSP_DRIVER_SENSOR Driver_Gyro; @@ -130,7 +130,7 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) if ((sMagDecimateCount++ % MAG_DECIMATE_FACTOR) == 0 ) { /* Read mag Data - reading would clear interrupt also */ - Driver_Mag.ReadData(&magData,0); + Driver_Mag.ReadData(&magData,1); /* Replace time stamp with that captured by interrupt handler */ magData.timeStamp = timeStamp; #ifdef ALGORITHM_TASK @@ -142,7 +142,7 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) else { /* Reading would clear interrupt also */ - Driver_Mag.ReadData(&magData,0); + Driver_Mag.ReadData(&magData,1); } break; @@ -150,7 +150,7 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) if ((gyroSampleCount++ % GYRO_SAMPLE_DECIMATE) == 0) { /* Read Gyro Data - reading typically clears interrupt as well */ - Driver_Gyro.ReadData(&gyroData,0); //Reads also clears DRDY interrupt + Driver_Gyro.ReadData(&gyroData,1); //Reads also clears DRDY interrupt /* Replace time stamp with that captured by interrupt handler */ gyroData.timeStamp = timeStamp; #ifdef ALGORITHM_TASK @@ -162,7 +162,7 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) else { /* Reading would clear interrupt also */ - Driver_Gyro.ReadData(&gyroData,0); //Reads also clears DRDY interrupt + Driver_Gyro.ReadData(&gyroData,1); //Reads also clears DRDY interrupt } break; @@ -177,7 +177,7 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) if (accSampleCount++ % ACCEL_SAMPLE_DECIMATE == 0) { /* Read Accel Data - reading typically clears interrupt as well */ - Driver_Acc.ReadData(&accelData,0); + Driver_Accel.ReadData(&accelData,1); /* Replace time stamp with that captured by interrupt handler */ accelData.timeStamp = timeStamp; #ifdef ALGORITHM_TASK @@ -190,7 +190,7 @@ static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp) else { /* Reading would clear interrupt also */ - Driver_Acc.ReadData(&accelData,0); + Driver_Accel.ReadData(&accelData,1); } break; @@ -224,19 +224,19 @@ void SensorControlCmdHandler(MsgSensorControlData *pData) #ifdef SENSOR_CONTROL_ENABLE // Maybe add a user configurable 'powerMode' setting and here we // configure the sensor hardware according to its value. - Driver_Acc.Activate(false,0,0,0); // do not disable accel so watch window input will work + Driver_Accel.Deactivate(); // do not disable accel so watch window input will work #endif break; case MAG_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Driver_Mag.Activate(false,0,0,0); + Driver_Mag.Deactivate(); #endif break; case GYRO_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Driver_Gyro.Activate(false,0,0,0); + Driver_Gyro.Deactivate(); #endif break; @@ -257,19 +257,19 @@ void SensorControlCmdHandler(MsgSensorControlData *pData) case ACCEL_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Driver_Acc.Activate(true,0,0,0); + Driver_Accel.Activate(SENSOR_FLAG_CONTINUOUS_DATA,NULL /* unused */,NULL /* unused */,NULL /* unused */); #endif break; case MAG_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Driver_Mag.Activate(true,0,0,0); + Driver_Mag.Activate(SENSOR_FLAG_ONE_SHOT_MODE,NULL /* unused */,NULL /* unused */,NULL /* unused */); #endif break; case GYRO_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Driver_Gyro.Activate(true,0,0,0); + Driver_Gyro.Activate(SENSOR_FLAG_CONTINUOUS_DATA,NULL /* unused */,NULL /* unused */,NULL /* unused */); #endif break; @@ -352,10 +352,9 @@ ASF_TASK void SensorAcqTask( ASF_TASK_ARG ) /* Setup interface for the Magnetometer */ Driver_Mag.Initialize(NULL, NULL); - Driver_Mag.Deactivate(); /* Clear interrupt from previous run that maynot have been acknowledged */ /* Setup interface for the accelerometers */ - Driver_Acc.Initialize(NULL, NULL); + Driver_Accel.Initialize(NULL, NULL); /* Setup Gyro */ Driver_Gyro.Initialize(NULL, NULL); @@ -365,11 +364,11 @@ ASF_TASK void SensorAcqTask( ASF_TASK_ARG ) ASFTimerStart( SENSOR_ACQ_TASK_ID, TIMER_REF_SENSOR_READ, SENSOR_SAMPLE_PERIOD, &sSensorTimer ); #else /* Enable Sensor interrupts */ - Driver_Mag.Activate(true,0,0,0); - Driver_Acc.Activate(true,0,0,0); - Driver_Gyro.Activate(true,0,0,0); -# ifdef TRIGGERED_MAG_SAMPLING - Driver_Gyro.PowerControl(ARM_POWER_LOW); //Low power mode until triggered + Driver_Mag.Activate(SENSOR_FLAG_ONE_SHOT_MODE,NULL /* unused */,NULL /* unused */,NULL /* unused */); + Driver_Accel.Activate(SENSOR_FLAG_CONTINUOUS_DATA,NULL /* unused */,NULL /* unused */,NULL /* unused */); + Driver_Gyro.Activate(SENSOR_FLAG_CONTINUOUS_DATA,NULL /* unused */,NULL /* unused */,NULL /* unused */); +#ifdef TRIGGERED_MAG_SAMPLING + Driver_Mag.PowerControl(ARM_POWER_LOW); //Low power mode until triggered # endif #endif diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c index d8ec16d..5161aae 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c @@ -43,21 +43,6 @@ const GpioInfo_t DiagLEDs[NUM_LEDS] = {PINS_LEDS}; /*-------------------------------------------------------------------------------------------------*\ | S T A T I C V A R I A B L E S D E F I N I T I O N S \*-------------------------------------------------------------------------------------------------*/ -/* Pin muxing table, only items that need changing from their default pin - state are in this table. Not every pin is mapped. */ -//TODO Pin init should be moved to respective modules handling the pin function -STATIC const PINMUX_GRP_T pinmuxing[] = { - - /* I2C1 standard/fast (bridge) */ - {0, 27, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_STDI2C_EN)}, /* BRIDGE_SCL (SCL) */ - {0, 28, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_STDI2C_EN)}, /* BRIDGE_SDA (SDA) */ - - /* Sensor related */ - {0, 4, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)}, /* GYR_INT1 (GPIO input) */ - {0, 18, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)}, /* CT32B0_MAT0-ACCL_INT1 */ - {0, 22, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)}, /* MAG_DRDY_INT (GPIO input) */ - -}; /*-------------------------------------------------------------------------------------------------*\ | F O R W A R D F U N C T I O N D E C L A R A T I O N S @@ -173,9 +158,6 @@ void SystemGPIOConfig( void ) //Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, SH_INT_GPIO_GRP, SH_INT_GPIO_PIN); //SensorHubIntLow(); //Deassert on startup - /* TODO: Catch ALL for uninitialized pins... should be moved to respective modules */ - Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); - /* Setup DMA Common here since its not specific to any peripheral */ Chip_DMA_Init(LPC_DMA); //Chip_SYSCON_PeriphReset(RESET_DMA); @@ -344,6 +326,8 @@ void Board_SensorIfInit( InputSensor_t ifID ) switch (ifID) { case ACCEL_INPUT_SENSOR: + /* Initialize the pinmux pin */ + Chip_IOCON_PinMuxSet(LPC_IOCON, PIN_ACCEL); /* ACCEL INT1 irq setup */ NVIC_DisableIRQ(ACCEL_PINT_IRQn); NVIC_SetPriority(ACCEL_PINT_IRQn, ACCEL_INT_IRQ_PRIORITY); @@ -363,6 +347,8 @@ void Board_SensorIfInit( InputSensor_t ifID ) break; case MAG_INPUT_SENSOR: + /* Initialize the pinmux pin */ + Chip_IOCON_PinMuxSet(LPC_IOCON, PIN_MAG); NVIC_DisableIRQ(MAG_PINT_IRQn); NVIC_SetPriority(MAG_PINT_IRQn, MAG_INT_IRQ_PRIORITY); @@ -381,6 +367,8 @@ void Board_SensorIfInit( InputSensor_t ifID ) break; case GYRO_INPUT_SENSOR: + /* Initialize the pinmux pin */ + Chip_IOCON_PinMuxSet(LPC_IOCON, PIN_GYRO); NVIC_DisableIRQ(GYRO_PINT_IRQn); NVIC_SetPriority(GYRO_PINT_IRQn, GYRO_INT_IRQ_PRIORITY); diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h index f183077..d0b7144 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h @@ -164,6 +164,9 @@ extern const GpioInfo_t DiagLEDs[NUM_LEDS]; #define ACCEL_INT2_PORT 0 #define ACCEL_INT2_PIN 7 +/* CT32B0_MAT0-ACCL_INT1 */ +#define PIN_ACCEL 0, 18, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGITAL_EN) + /* IMPORTANT! - Sensor interrupts are shared by multiple sensor devices on the * LPCXpresso Sensor Shield board. Particularly when Accel on BMI055 is used, * INT1 is connected to P0_18 via R16 (220ohm) and fights with the INT1 of BMC150 @@ -186,6 +189,10 @@ extern const GpioInfo_t DiagLEDs[NUM_LEDS]; #define MAG_INT3_PORT 0 #define MAG_INT3_PIN 10 +/* MAG_DRDY_INT (GPIO input) */ +#define PIN_MAG 0, 22, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN) + + /* ########################################################################## */ /* # G Y R O S C O P E I N T E R F A C E # */ /* ########################################################################## */ @@ -198,6 +205,9 @@ extern const GpioInfo_t DiagLEDs[NUM_LEDS]; #define GYRO_WAKE SYSCON_STARTER_PINT1 #define GYRO_IRQHandler PIN_INT1_IRQHandler +/* GYR_INT1 (GPIO input) */ +#define PIN_GYRO 0, 4, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN) + /* ########################################################################## */ /* # B A R O M E T E R I N T E R F A C E # */ /* ########################################################################## */ diff --git a/embedded/common/modules/sensor-drivers/Driver_Common.h b/external/CMSIS/Driver/Include/Driver_Common.h similarity index 96% rename from embedded/common/modules/sensor-drivers/Driver_Common.h rename to external/CMSIS/Driver/Include/Driver_Common.h index 8870881..396a11c 100644 --- a/embedded/common/modules/sensor-drivers/Driver_Common.h +++ b/external/CMSIS/Driver/Include/Driver_Common.h @@ -1,72 +1,72 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2013-2014 ARM Ltd. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from - * the use of this software. Permission is granted to anyone to use this - * software for any purpose, including commercial applications, and to alter - * it and redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - * - * - * $Date: 2. Jan 2014 - * $Revision: V2.00 - * - * Project: Common Driver definitions - * -------------------------------------------------------------------------- */ - -/* History: - * Version 2.00 - * Changed prefix ARM_DRV -> ARM_DRIVER - * Added General return codes definitions - * Version 1.10 - * Namespace prefix ARM_ added - * Version 1.00 - * Initial release - */ - -#ifndef __DRIVER_COMMON_H -#define __DRIVER_COMMON_H - -#include -#include -#include - -#define ARM_DRIVER_VERSION_MAJOR_MINOR(major,minor) (((major) << 8) | (minor)) - -/** -\brief Driver Version -*/ -typedef struct _ARM_DRIVER_VERSION { - uint16_t api; ///< API version - uint16_t drv; ///< Driver version -} ARM_DRIVER_VERSION; - -/* General return codes */ -#define ARM_DRIVER_OK 0 ///< Operation succeeded -#define ARM_DRIVER_ERROR -1 ///< Unspecified error -#define ARM_DRIVER_ERROR_BUSY -2 ///< Driver is busy -#define ARM_DRIVER_ERROR_TIMEOUT -3 ///< Timeout occurred -#define ARM_DRIVER_ERROR_UNSUPPORTED -4 ///< Operation not supported -#define ARM_DRIVER_ERROR_PARAMETER -5 ///< Parameter error -#define ARM_DRIVER_ERROR_SPECIFIC -6 ///< Start of driver specific errors - -/** -\brief General power states -*/ -typedef enum _ARM_POWER_STATE { - ARM_POWER_OFF, ///< Power off: no operation possible - ARM_POWER_LOW, ///< Low Power mode: retain state, detect and signal wake-up events - ARM_POWER_FULL ///< Power on: full operation at maximum performance -} ARM_POWER_STATE; - -#endif /* __DRIVER_COMMON_H */ +/* ----------------------------------------------------------------------------- + * Copyright (c) 2013-2014 ARM Ltd. + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. Permission is granted to anyone to use this + * software for any purpose, including commercial applications, and to alter + * it and redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + * + * + * $Date: 2. Jan 2014 + * $Revision: V2.00 + * + * Project: Common Driver definitions + * -------------------------------------------------------------------------- */ + +/* History: + * Version 2.00 + * Changed prefix ARM_DRV -> ARM_DRIVER + * Added General return codes definitions + * Version 1.10 + * Namespace prefix ARM_ added + * Version 1.00 + * Initial release + */ + +#ifndef __DRIVER_COMMON_H +#define __DRIVER_COMMON_H + +#include +#include +#include + +#define ARM_DRIVER_VERSION_MAJOR_MINOR(major,minor) (((major) << 8) | (minor)) + +/** +\brief Driver Version +*/ +typedef struct _ARM_DRIVER_VERSION { + uint16_t api; ///< API version + uint16_t drv; ///< Driver version +} ARM_DRIVER_VERSION; + +/* General return codes */ +#define ARM_DRIVER_OK 0 ///< Operation succeeded +#define ARM_DRIVER_ERROR -1 ///< Unspecified error +#define ARM_DRIVER_ERROR_BUSY -2 ///< Driver is busy +#define ARM_DRIVER_ERROR_TIMEOUT -3 ///< Timeout occurred +#define ARM_DRIVER_ERROR_UNSUPPORTED -4 ///< Operation not supported +#define ARM_DRIVER_ERROR_PARAMETER -5 ///< Parameter error +#define ARM_DRIVER_ERROR_SPECIFIC -6 ///< Start of driver specific errors + +/** +\brief General power states +*/ +typedef enum _ARM_POWER_STATE { + ARM_POWER_OFF, ///< Power off: no operation possible + ARM_POWER_LOW, ///< Low Power mode: retain state, detect and signal wake-up events + ARM_POWER_FULL ///< Power on: full operation at maximum performance +} ARM_POWER_STATE; + +#endif /* __DRIVER_COMMON_H */ diff --git a/external/Drivers/Sensor/Bosch-Sensortec/Driver_Sensor.c b/external/Drivers/Sensor/Bosch-Sensortec/Driver_Sensor.c deleted file mode 100644 index b96b5b4..0000000 --- a/external/Drivers/Sensor/Bosch-Sensortec/Driver_Sensor.c +++ /dev/null @@ -1,824 +0,0 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2015 Audience Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "common.h" -#include "Driver_Sensor.h" -#include "bma2x2.h" -#include "bmm050.h" -#include "bmg160.h" -#include "bosch_i2c_adapter.h" -#include "chip.h" - -#ifndef I2C_DRIVER -# error Needs I2C_DRIVER to be defined. Check Common.h -#endif - -#define OSP_SENSOR_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,0) - -#define ACTIVE_HIGH 1 -#define ACTIVE_LOW 0 - -/* Driver Version */ -static const ARM_DRIVER_VERSION DriverVersion = { - OSP_SENSOR_API_VERSION, - OSP_SENSOR_DRV_VERSION -}; - -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -static bma2x2_t bma2x2; -static struct bmm050 bmc150mag; -static struct bmg160_t bmg160; - -/*************************************************************************************************** - * ACCEL HAL APIs * - ***************************************************************************************************/ - -/**************************************************************************************************** - * @fn Accx_GetVersion - * Get driver version. - * - * @param data Private Argument (Unused) - * - * @return Driver Version - * - ***************************************************************************************************/ -static ARM_DRIVER_VERSION Accx_GetVersion (void *data) -{ - return DriverVersion; -} - -/**************************************************************************************************** - * @fn _Accel_DumpRegisters - * Dumps the registers of the chosen Accelerometer device - * - ***************************************************************************************************/ -static void _Accel_DumpRegisters( void ) -{ - //TODO - return; -} - -/**************************************************************************************************** - * @fn _Accel_ResetDevice - * Soft resets the Accelerometer. - * - ***************************************************************************************************/ -static void _Accel_ResetDevice( void ) -{ - /* Soft Reset device */ - bma2x2_soft_reset(); // Problem with I2C at 1.8V - bma2x2.delay_msec(1); -} - -/**************************************************************************************************** - * @fn _Accel_HardwareSetup - * Configures the interrupt GPIO and regulators (if any) for the Accelerometer. - * - * @param enable - Enables or disables the GPIOs / Communications interface - * - * @return none - * - ***************************************************************************************************/ -static void _Accel_HardwareSetup( osp_bool_t enable ) -{ - if (enable == true) - { - /* Initialize the Sensor interface HW (typically I2C or SPI) */ - Board_SensorIfInit( ACCEL_INPUT_SENSOR ); - } - else - { - /* Disable interrupts and free GPIOs */ - Board_SensorIfDeinit( ACCEL_INPUT_SENSOR ); - } -} - -/**************************************************************************************************** - * @fn Accx_Initialize - * Initialization function for Accel - * - * @param cb Event Handler - * @param data Data required for initialization - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Accx_Initialize(OSP_Sensor_SignalEvent_t cb, void *data, void *priv) -{ - _Accel_HardwareSetup(true); - - /* Init the Bosch Driver for accel */ - bma2x2.bus_write = dev_i2c_write; - bma2x2.bus_read = dev_i2c_read; - bma2x2.delay_msec = dev_i2c_delay; - bma2x2_init(&bma2x2); - - /* Register state before changes */ - _Accel_DumpRegisters(); - - /* Set key registers to default on startup */ - _Accel_ResetDevice(); - - /* Clear any existing interrupts */ - /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, - we don't need to do data read to clear any pending interrupts */ - - bma2x2_set_mode(BMA2x2_MODE_NORMAL); // Normal power - bma2x2_set_range(BMA2x2_RANGE_4G); // set range 4g for grange - bma2x2_set_bandwidth(BMA2x2_BW_31_25HZ ); // BW set to 31.25Hz, ODR = BW*2 (62.5Hz) - - /* Setup interrupt selections */ - bma2x2_set_newdata( BMA2x2_INT1_NDATA, 1 ); //DRDY interrupt on INT1 pad - /* Latched with 250uS duration */ - bma2x2_set_latch_int(BMA2x2_LATCH_DUR_250US); - - /* Registers after initialization */ - _Accel_DumpRegisters(); - - /* Set to suspend mode till application requests data by enabling interrupt */ - //bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); --> This requires additional setup in IntEnable call - - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Accx_Uninitialize - * Uninitialize the Accel - * - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Accx_Uninitialize(void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; -} - -/**************************************************************************************************** - * @fn Accx_Activate - * Activate the sensor - * - * @param flags Enable/Disable flag - * @param us_delay Delay before actual activation - * @param fifo_num_samples Fifo size - * @param max_report_latency Maximum latency for reporting the data - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Accx_Activate (uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv) -{ - /* Enables/Disables the New Data interrupt on the Accelerometer. - Note: If device is set in low power/suspend mode then additional device needs to be - reinitialized to the last operating mode */ - if (flags) - { - bma2x2_set_Int_Enable( BMA2x2_DATA_EN, 1 ); - - NVIC_ClearPendingIRQ(ACCEL_PINT_IRQn); - - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(ACCEL_PINT_IRQn); - } - else - { - bma2x2_set_Int_Enable( BMA2x2_DATA_EN, 0 ); - - NVIC_DisableIRQ(ACCEL_PINT_IRQn); - /* Set to suspend mode till application requests data by enabling interrupt */ - //bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); --> This requires additional setup in enable - } - - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Accx_ReadData - * Reads data from Accelerometer's X, Y, Z data registers - * - * @param *data Data pointer - * @param num_samples Number of samples to be read - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Accx_ReadData (void *data, uint16_t num_samples, void *priv) -{ - MsgAccelData *pxyzData = data; - - bma2x2acc_t acc; //create object of type bma250acc_t - - bma2x2_read_accel_xyz(&acc); //get acceleration data from sensor - - pxyzData->X = acc.x; - pxyzData->Y = acc.y; - pxyzData->Z = acc.z; - - //add timestamp here! - pxyzData->timeStamp = RTC_GetCounter(); - - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Accx_Deactivate - * Deactivate Accelerometer - * - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Accx_Deactivate (void *priv) -{ - bma2x2_set_Int_Enable( BMA2x2_DATA_EN, 0 ); - NVIC_DisableIRQ(ACCEL_PINT_IRQn); - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Accx_PowerControl - * Control the power state of the sensor - * - * @param state Power state - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Accx_PowerControl(ARM_POWER_STATE state, void *priv) -{ - switch (state) - { - case ARM_POWER_OFF: - Accx_Deactivate(NULL); - break; - - case ARM_POWER_LOW: - bma2x2_set_mode(BMA2x2_MODE_STANDBY); - break; - - case ARM_POWER_FULL: - Accx_Activate(true,0,0,0,NULL); - break; - - default: - return ARM_DRIVER_ERROR_PARAMETER; - } - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Accx_GetDetails - * Get sensor details - * - * @param data Pointer to the sensor details - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Accx_GetDetails (void *data, void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; -} - -/**************************************************************************************************** - * @fn Accx_InjectData - * Feed dummy data - * - * @param data Simulated data - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Accx_InjectData (void *data, void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing -} - -/* Accel Driver Definition */ -OSP_BUILD_DRIVER_SENSOR(Acc, Accx, NULL); - -/*************************************************************************************************** - * MAG HAL APIs * - ***************************************************************************************************/ - -/**************************************************************************************************** - * @fn Magx_GetVersion - * Get driver version. - * - * @param data Private Argument (Unused) - * - * @return Driver Version - * - ***************************************************************************************************/ -static ARM_DRIVER_VERSION Magx_GetVersion (void *data) -{ - return DriverVersion; -} - -/**************************************************************************************************** - * @fn _Mag_DumpRegisters - * Dumps the registers of the chosen Magnetometer device - * - ***************************************************************************************************/ -static void _Mag_DumpRegisters( void ) -{ - //TODO - return; -} - - -/**************************************************************************************************** - * @fn _Mag_HardwareSetup - * Configures the interrupt GPIO and regulators (if any) for the Magnetometer. - * - * @param enable - Enables or disables the GPIOs / Communications interface - * - * @return none - * - ***************************************************************************************************/ -static void _Mag_HardwareSetup( osp_bool_t enable ) -{ - if (enable == true) - { - /* Initialize the Sensor interface HW (typically I2C or SPI) */ - Board_SensorIfInit( MAG_INPUT_SENSOR ); - } - else - { - /* Disable interrupts and free GPIOs */ - Board_SensorIfDeinit( MAG_INPUT_SENSOR ); - } -} - -/**************************************************************************************************** - * @fn Magx_Initialize - * Initialization function for Mag - * - * @param cb Event Handler - * @param data Data required for initialization - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Magx_Initialize(OSP_Sensor_SignalEvent_t cb, void *data, void *priv) -{ - uint8_t value; - - _Mag_HardwareSetup(true); - - /* Init the Bosch Driver for mag */ - bmc150mag.bus_write = dev_i2c_write; - bmc150mag.bus_read = dev_i2c_read; - bmc150mag.delay_msec = dev_i2c_delay; - - /* Initialize and set key registers to default on startup */ - bmm050_init(&bmc150mag); - - /* Register state before changes */ - _Mag_DumpRegisters(); - - /* Clear any existing interrupts */ - /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, - we don't need to do data read to clear any pending interrupts */ - - /* Enable all axis & Set DR Polarity to active high */ - value = 0x04; - bmm050_write_register(BMM050_SENS_CNTL, &value, 1); - - /* Set data rate */ - bmm050_set_datarate(BMM050_DR_25HZ); - - bmm050_set_functional_state(BMM050_NORMAL_MODE); - bmc150mag.delay_msec(1); - - /* Registers after initialization */ - _Mag_DumpRegisters(); - - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Magx_Uninitialize - * Uninitialize the Mag - * - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Magx_Uninitialize(void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; -} - -/**************************************************************************************************** - * @fn Magx_Activate - * Activate the sensor - * - * @param flags Enable/Disable flag - * @param us_delay Delay before actual activation - * @param fifo_num_samples Fifo size - * @param max_report_latency Maximum latency for reporting the data - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Magx_Activate (uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv) -{ - if (flags) - { - bmm050_set_mag_drdy_interrupt( true, ACTIVE_HIGH ); - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(MAG_PINT_IRQn); - } - else - { - bmm050_set_mag_drdy_interrupt( false, ACTIVE_HIGH ); - NVIC_DisableIRQ(MAG_PINT_IRQn); - } - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Magx_ReadData - * Read data from Mag - * - * @param *data Data pointer - * @param num_samples Number of samples to be read - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Magx_ReadData (void *data, uint16_t num_samples, void *priv) -{ - MsgMagData *pxyzData = data; - struct bmm050_mdata_s32 mdata; - - bmm050_read_mdataXYZ_s32(&mdata); - - pxyzData->X = mdata.datax; - pxyzData->Y = mdata.datay; - pxyzData->Z = mdata.dataz; - - //add timestamp here! - pxyzData->timeStamp = RTC_GetCounter(); - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Magx_Deactivate - * Deactivate Mag - * - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Magx_Deactivate (void *priv) -{ - bmm050_set_mag_drdy_interrupt( false, ACTIVE_HIGH ); - NVIC_DisableIRQ(MAG_PINT_IRQn); - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Magx_PowerControl - * Control the power state of the sensor - * - * @param state Power state - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Magx_PowerControl(ARM_POWER_STATE state, void *priv) -{ - switch (state) - { - case ARM_POWER_OFF: - Magx_Deactivate(NULL); - break; - - case ARM_POWER_LOW: - bmm050_set_functional_state(BMM050_SUSPEND_MODE); - break; - - case ARM_POWER_FULL: - Magx_Activate(true,0,0,0, NULL); - break; - - default: - return ARM_DRIVER_ERROR_PARAMETER; - } - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Magx_GetDetails - * Get sensor details - * - * @param data Pointer to the sensor details - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Magx_GetDetails (void *data, void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; -} - -/**************************************************************************************************** - * @fn Magx_InjectData - * Feed dummy data - * - * @param data Simulated data - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Magx_InjectData (void *data, void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing -} - -/* Mag Driver Definition */ -OSP_BUILD_DRIVER_SENSOR(Mag, Magx, NULL); - -/*************************************************************************************************** - * GYRO HAL APIs * - ***************************************************************************************************/ - -/**************************************************************************************************** - * @fn Gyrox_GetVersion - * Get driver version. - * - * @param data Private Argument (Unused) - * - * @return Driver Version - * - ***************************************************************************************************/ -static ARM_DRIVER_VERSION Gyrox_GetVersion (void *data) -{ - return DriverVersion; -} - -/**************************************************************************************************** - * @fn _Gyro_DumpRegisters - * Dumps the registers of the chosen Gyroscope device - * - ***************************************************************************************************/ -static void _Gyro_DumpRegisters( void ) -{ - //TODO - return; -} - -/**************************************************************************************************** - * @fn _Gyro_HardwareSetup - * Configures the interrupt GPIO and regulators (if any) for the Gyroscope. - * - * @param enable - Enables or disables the GPIOs / Communications interface - * - * @return none - * - ***************************************************************************************************/ -static void _Gyro_HardwareSetup( osp_bool_t enable ) -{ - if (enable == true) - { - /* Initialize the Sensor interface HW (typically I2C or SPI) */ - Board_SensorIfInit( GYRO_INPUT_SENSOR ); - } - else - { - /* Disable interrupts and free GPIOs */ - Board_SensorIfDeinit( GYRO_INPUT_SENSOR ); - } -} - -/**************************************************************************************************** - * @fn Gyrox_Initialize - * Initialization function for Gyro - * - * @param cb Event Handler - * @param data Data required for initialization - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Gyrox_Initialize(OSP_Sensor_SignalEvent_t cb, void *data, void *priv) -{ - - /* Configure the interrupt GPIO and regulators (if any) for the Gyroscope */ - _Gyro_HardwareSetup(true); - - /* Init the Bosch Driver for Gyro */ - bmg160.bus_write = dev_i2c_write; - bmg160.bus_read = dev_i2c_read; - bmg160.delay_msec = dev_i2c_delay; - bmg160_init(&bmg160); - - /* Register state before changes */ - _Gyro_DumpRegisters(); - - /* Clear any existing interrupts */ - /* Note: DRDY is normally cleared on Data read but otherwise since we don't latch DRDY interrupt, - we don't need to do data read to clear any pending interrupts */ - - bmg160_set_mode(BMG160_MODE_NORMAL); - bmg160_set_bw(C_BMG160_BW_32Hz_U8X); //ODR = 100Hz - bmg160_set_range_reg(C_BMG160_Zero_U8X); //Zero = 2000dps - - /* Interrupt setup */ - bmg160_set_int_data( BMG160_INT1_DATA, 1 ); //DRDY interrupt on INT1 pad - /* Latched with 250uS duration */ - bmg160_set_latch_int(BMG160_LATCH_DUR_250US); - - /* Registers after initialization */ - _Gyro_DumpRegisters(); - - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Gyrox_Uninitialize - * Uninitialize the Gyro - * - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Gyrox_Uninitialize(void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; -} - -/**************************************************************************************************** - * @fn Gyrox_Activate - * Activate the sensor - * - * @param flags Enable/Disable flag - * @param us_delay Delay before actual activation - * @param fifo_num_samples Fifo size - * @param max_report_latency Maximum latency for reporting the data - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Gyrox_Activate (uint16_t flags, uint32_t us_delay, uint16_t fifo_num_samples, uint32_t max_report_latency, void *priv) -{ - /* Enables/Disables the New Data interrupt on the Gyroscope */ - if (flags) - { - bmg160_set_data_en(1); - - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(GYRO_PINT_IRQn); - } - else - { - NVIC_DisableIRQ(GYRO_PINT_IRQn); - bmg160_set_data_en(0); - } - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Gyrox_ReadData - * Reads data from Gyroscope's X, Y, Z data registers - * - * @param *data Data pointer - * @param num_samples Number of samples to be read - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Gyrox_ReadData (void *data, uint16_t num_samples, void *priv) -{ - MsgGyroData *pxyzData = data; - struct bmg160_data_t gyro_raw; - - bmg160_get_dataXYZ(&gyro_raw); - pxyzData->X = gyro_raw.datax; - pxyzData->Y = gyro_raw.datay; - pxyzData->Z = gyro_raw.dataz; - //add timestamp here! - pxyzData->timeStamp = RTC_GetCounter(); - - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Gyrox_Deactivate - * Deactivate Gyro Interrupt - * - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Gyrox_Deactivate (void *priv) -{ - NVIC_DisableIRQ(GYRO_PINT_IRQn); - bmg160_set_data_en(0); - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Gyrox_PowerControl - * Control the power state of the sensor - * - * @param state Power state - * @param priv Private Argument (Unused) - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t Gyrox_PowerControl(ARM_POWER_STATE state, void *priv) -{ - switch (state) - { - case ARM_POWER_OFF: - Gyrox_Deactivate(NULL); - break; - - case ARM_POWER_LOW: - bmg160_set_mode(BMG160_MODE_SUSPEND); - break; - - case ARM_POWER_FULL: - Gyrox_Activate(true,0,0,0,NULL); - break; - - default: - return ARM_DRIVER_ERROR_PARAMETER; - } - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn Gyrox_GetDetails - * Get sensor details - * - * @param data Pointer to the sensor details - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Gyrox_GetDetails (void *data, void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; -} - -/**************************************************************************************************** - * @fn Gyrox_InjectData - * Feed dummy data - * - * @param data Simulated data - * @param priv Private Argument (Unused) - * - * @return Returns ARM_DRIVER_ERROR_UNSUPPORTED since function is currently not supported - * - ***************************************************************************************************/ -static int32_t Gyrox_InjectData (void *data, void *priv) -{ - return ARM_DRIVER_ERROR_UNSUPPORTED; //Do nothing -} - -/* Gyro Driver Definition */ -OSP_BUILD_DRIVER_SENSOR(Gyro, Gyrox, NULL); From b7b67f0fefd0cecbb19ff71045d532834e7b263a Mon Sep 17 00:00:00 2001 From: Pankaj Goenka Date: Fri, 11 Dec 2015 14:15:34 +0530 Subject: [PATCH 3/3] Corrected the copyright message --- embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c | 5 ++++- embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c | 2 +- embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c index 40459e1..6514d7f 100644 --- a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c +++ b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c @@ -1,7 +1,7 @@ /* Open Sensor Platform Project * https://github.com/sensorplatforms/open-sensor-platform * - * Copyright (C) 2013 Sensor Platforms Inc. + * Copyright (C) 2015 Audience Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,9 @@ #include "bosch_i2c_adapter.h" #include "chip.h" +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ #ifndef I2C_DRIVER # error Needs I2C_DRIVER to be defined. Check Common.h #endif diff --git a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c index fafaa09..65843ef 100644 --- a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c +++ b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMG160.c @@ -1,7 +1,7 @@ /* Open Sensor Platform Project * https://github.com/sensorplatforms/open-sensor-platform * - * Copyright (C) 2013 Sensor Platforms Inc. + * Copyright (C) 2015 Audience Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c index 24d32cc..45a2c94 100644 --- a/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c +++ b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMM050.c @@ -1,7 +1,7 @@ /* Open Sensor Platform Project * https://github.com/sensorplatforms/open-sensor-platform * - * Copyright (C) 2013 Sensor Platforms Inc. + * Copyright (C) 2015 Audience Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.