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..6514d7f --- /dev/null +++ b/embedded/Drivers/Sensor/Bosch-Sensortec/Driver_BMA2X2.c @@ -0,0 +1,326 @@ +/* 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. + */ +/*-------------------------------------------------------------------------------------------------*\ + | 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" + +/*-------------------------------------------------------------------------------------------------*\ + | 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 + +#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..65843ef --- /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) 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. + */ +/*-------------------------------------------------------------------------------------------------*\ + | 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..45a2c94 --- /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) 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. + */ +/*-------------------------------------------------------------------------------------------------*\ + | 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/include/Driver_Sensor.h b/embedded/include/Driver_Sensor.h new file mode 100644 index 0000000..61b72f2 --- /dev/null +++ b/embedded/include/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 (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 { + 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..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 @@ -1259,6 +1259,42 @@ 0 0 + + 11 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\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 + @@ -1269,7 +1305,7 @@ 0 12 - 36 + 39 1 0 0 @@ -1281,7 +1317,7 @@ 12 - 37 + 40 1 0 0 @@ -1293,7 +1329,7 @@ 12 - 38 + 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 c44dd66..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 @@ -743,6 +743,21 @@ 1 ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.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 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMM050.c + @@ -1532,6 +1547,21 @@ 1 ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.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 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMM050.c + @@ -2321,6 +2351,21 @@ 1 ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.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 + ..\..\..\..\embedded\Drivers\Sensor\Bosch-Sensortec\Driver_BMM050.c + @@ -2740,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 @@ -3110,6 +3155,21 @@ 1 ..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec\bmm050.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 + ..\..\..\..\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 28910b4..f8ace64 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_Accel; +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,1); /* 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,1); } 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,1); //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,1); //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_Accel.ReadData(&accelData,1); /* 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_Accel.ReadData(&accelData,1); } 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_Accel.Deactivate(); // 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.Deactivate(); #endif break; case GYRO_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Gyro_ConfigDataInt(false); + Driver_Gyro.Deactivate(); #endif break; @@ -252,19 +257,19 @@ void SensorControlCmdHandler(MsgSensorControlData *pData) case ACCEL_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Accel_ConfigDataInt(true); + Driver_Accel.Activate(SENSOR_FLAG_CONTINUOUS_DATA,NULL /* unused */,NULL /* unused */,NULL /* unused */); #endif break; case MAG_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Mag_ConfigDataInt(true); + Driver_Mag.Activate(SENSOR_FLAG_ONE_SHOT_MODE,NULL /* unused */,NULL /* unused */,NULL /* unused */); #endif break; case GYRO_INPUT_SENSOR: #ifdef SENSOR_CONTROL_ENABLE - Gyro_ConfigDataInt(true); + Driver_Gyro.Activate(SENSOR_FLAG_CONTINUOUS_DATA,NULL /* unused */,NULL /* unused */,NULL /* unused */); #endif break; @@ -346,28 +351,24 @@ 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); /* Setup interface for the accelerometers */ - Accel_HardwareSetup( true ); - Accel_Initialize( INIT_NORMAL ); + Driver_Accel.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 ); -# ifdef TRIGGERED_MAG_SAMPLING - Mag_SetLowPowerMode(); //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/external/CMSIS/Driver/Include/Driver_Common.h b/external/CMSIS/Driver/Include/Driver_Common.h new file mode 100644 index 0000000..396a11c --- /dev/null +++ b/external/CMSIS/Driver/Include/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 */