diff --git a/flight/modules/Attitude/revolution/attitude.c b/flight/modules/Attitude/revolution/attitude.c index b49ac751b..2ee8901e0 100644 --- a/flight/modules/Attitude/revolution/attitude.c +++ b/flight/modules/Attitude/revolution/attitude.c @@ -352,7 +352,7 @@ static int32_t updateAttitudeComplementary(bool first_run) // During initialization and if (first_run) { -#if defined(PIOS_INCLUDE_HMC5883) +#if defined(PIOS_INCLUDE_HMC5X83) // To initialize we need a valid mag reading if (xQueueReceive(magQueue, &ev, 0 / portTICK_RATE_MS) != pdTRUE) { return -1; diff --git a/flight/modules/Extensions/MagBaro/magbaro.c b/flight/modules/Extensions/MagBaro/magbaro.c index 2b219ee16..aa956c57e 100644 --- a/flight/modules/Extensions/MagBaro/magbaro.c +++ b/flight/modules/Extensions/MagBaro/magbaro.c @@ -64,7 +64,7 @@ static int32_t alt_ds_pres = 0; static int alt_ds_count = 0; #endif -#if defined(PIOS_INCLUDE_HMC5883) +#if defined(PIOS_INCLUDE_HMC5X83) int32_t mag_test; static float mag_bias[3] = { 0, 0, 0 }; static float mag_scale[3] = { 1, 1, 1 }; @@ -108,7 +108,7 @@ int32_t MagBaroInitialize() #endif if (magbaroEnabled) { -#if defined(PIOS_INCLUDE_HMC5883) +#if defined(PIOS_INCLUDE_HMC5X83) MagSensorInitialize(); #endif @@ -127,15 +127,16 @@ MODULE_INITCALL(MagBaroInitialize, MagBaroStart); /** * Module thread, should not return. */ -#if defined(PIOS_INCLUDE_HMC5883) -static const struct pios_hmc5883_cfg pios_hmc5883_cfg = { -#ifdef PIOS_HMC5883_HAS_GPIOS +#if defined(PIOS_INCLUDE_HMC5X83) +static const struct pios_hmc5x83_cfg pios_hmc5x83_cfg = { +#ifdef PIOS_HMC5X83_HAS_GPIOS .exti_cfg = 0, #endif - .M_ODR = PIOS_HMC5883_ODR_15, - .Meas_Conf = PIOS_HMC5883_MEASCONF_NORMAL, - .Gain = PIOS_HMC5883_GAIN_1_9, - .Mode = PIOS_HMC5883_MODE_CONTINUOUS, + .M_ODR = PIOS_HMC5x83_ODR_15, + .Meas_Conf = PIOS_HMC5x83_MEASCONF_NORMAL, + .Gain = PIOS_HMC5x83_GAIN_1_9, + .Mode = PIOS_HMC5x83_MODE_CONTINUOUS, + .Driver = &PIOS_HMC5x83_I2C_DRIVER, }; #endif @@ -148,9 +149,9 @@ static void magbaroTask(__attribute__((unused)) void *parameters) PIOS_BMP085_Init(); #endif -#if defined(PIOS_INCLUDE_HMC5883) +#if defined(PIOS_INCLUDE_HMC5X83) MagSensorData mag; - PIOS_HMC5883_Init(&pios_hmc5883_cfg); + PIOS_HMC5x83_Init(&pios_hmc5x83_cfg, PIOS_I2C_MAIN_ADAPTER, 0); uint32_t mag_update_time = PIOS_DELAY_GetRaw(); #endif @@ -197,10 +198,10 @@ static void magbaroTask(__attribute__((unused)) void *parameters) } #endif /* if defined(PIOS_INCLUDE_BMP085) */ -#if defined(PIOS_INCLUDE_HMC5883) - if (PIOS_HMC5883_NewDataAvailable() || PIOS_DELAY_DiffuS(mag_update_time) > 100000) { +#if defined(PIOS_INCLUDE_HMC5X83) + if (PIOS_HMC5x83_NewDataAvailable() || PIOS_DELAY_DiffuS(mag_update_time) > 100000) { int16_t values[3]; - PIOS_HMC5883_ReadMag(values); + PIOS_HMC5x83_ReadMag(values); float mags[3] = { (float)values[1] * mag_scale[0] - mag_bias[0], (float)values[0] * mag_scale[1] - mag_bias[1], -(float)values[2] * mag_scale[2] - mag_bias[2] }; diff --git a/flight/modules/Sensors/sensors.c b/flight/modules/Sensors/sensors.c index e1d85b2f1..c93dc64f8 100644 --- a/flight/modules/Sensors/sensors.c +++ b/flight/modules/Sensors/sensors.c @@ -200,8 +200,8 @@ static void SensorsTask(__attribute__((unused)) void *parameters) PIOS_DEBUG_Assert(0); } -#if defined(PIOS_INCLUDE_HMC5883) - mag_test = PIOS_HMC5883_Test(); +#if defined(PIOS_INCLUDE_HMC5X83) + mag_test = PIOS_HMC5x83_Test(); #else mag_test = 0; #endif @@ -409,11 +409,11 @@ static void SensorsTask(__attribute__((unused)) void *parameters) // Because most crafts wont get enough information from gravity to zero yaw gyro, we try // and make it average zero (weakly) -#if defined(PIOS_INCLUDE_HMC5883) +#if defined(PIOS_INCLUDE_HMC5X83) MagSensorData mag; - if (PIOS_HMC5883_NewDataAvailable() || PIOS_DELAY_DiffuS(mag_update_time) > 150000) { + if (PIOS_HMC5x83_NewDataAvailable() || PIOS_DELAY_DiffuS(mag_update_time) > 150000) { int16_t values[3]; - PIOS_HMC5883_ReadMag(values); + PIOS_HMC5x83_ReadMag(values); float mags[3] = { (float)values[1] - mag_bias[0], (float)values[0] - mag_bias[1], -(float)values[2] - mag_bias[2] }; @@ -428,7 +428,7 @@ static void SensorsTask(__attribute__((unused)) void *parameters) MagSensorSet(&mag); mag_update_time = PIOS_DELAY_GetRaw(); } -#endif /* if defined(PIOS_INCLUDE_HMC5883) */ +#endif /* if defined(PIOS_INCLUDE_HMC5X83) */ #ifdef PIOS_INCLUDE_WDG PIOS_WDG_UpdateFlag(PIOS_WDG_SENSORS); diff --git a/flight/modules/StateEstimation/filtercf.c b/flight/modules/StateEstimation/filtercf.c index 15b61a665..d2e109655 100644 --- a/flight/modules/StateEstimation/filtercf.c +++ b/flight/modules/StateEstimation/filtercf.c @@ -221,7 +221,7 @@ static filterResult complementaryFilter(struct data *this, float gyro[3], float // During initialization and if (this->first_run) { -#if defined(PIOS_INCLUDE_HMC5883) +#if defined(PIOS_INCLUDE_HMC5X83) // wait until mags have been updated if (!this->magUpdated) { return FILTERRESULT_ERROR; diff --git a/flight/pios/common/pios_hmc5883.c b/flight/pios/common/pios_hmc5883.c deleted file mode 100644 index d425e16dc..000000000 --- a/flight/pios/common/pios_hmc5883.c +++ /dev/null @@ -1,425 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup PIOS PIOS Core hardware abstraction layer - * @{ - * @addtogroup PIOS_HMC5883 HMC5883 Functions - * @brief Deals with the hardware interface to the magnetometers - * @{ - * @file pios_hmc5883.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. - * @brief HMC5883 Magnetic Sensor Functions from AHRS - * @see The GNU Public License (GPL) Version 3 - * - ****************************************************************************** - */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "pios.h" - -#ifdef PIOS_INCLUDE_HMC5883 - -/* Global Variables */ - -/* Local Types */ - -/* Local Variables */ -volatile bool pios_hmc5883_data_ready; - -static int32_t PIOS_HMC5883_Config(const struct pios_hmc5883_cfg *cfg); -static int32_t PIOS_HMC5883_Read(uint8_t address, uint8_t *buffer, uint8_t len); -static int32_t PIOS_HMC5883_Write(uint8_t address, uint8_t buffer); - -static const struct pios_hmc5883_cfg *dev_cfg; - -/** - * @brief Initialize the HMC5883 magnetometer sensor. - * @return none - */ -void PIOS_HMC5883_Init(const struct pios_hmc5883_cfg *cfg) -{ - dev_cfg = cfg; // store config before enabling interrupt - -#ifdef PIOS_HMC5883_HAS_GPIOS - PIOS_EXTI_Init(cfg->exti_cfg); -#endif - - int32_t val = PIOS_HMC5883_Config(cfg); - - PIOS_Assert(val == 0); - - pios_hmc5883_data_ready = false; -} - -/** - * @brief Initialize the HMC5883 magnetometer sensor - * \return none - * \param[in] PIOS_HMC5883_ConfigTypeDef struct to be used to configure sensor. - * - * CTRL_REGA: Control Register A - * Read Write - * Default value: 0x10 - * 7:5 0 These bits must be cleared for correct operation. - * 4:2 DO2-DO0: Data Output Rate Bits - * DO2 | DO1 | DO0 | Minimum Data Output Rate (Hz) - * ------------------------------------------------------ - * 0 | 0 | 0 | 0.75 - * 0 | 0 | 1 | 1.5 - * 0 | 1 | 0 | 3 - * 0 | 1 | 1 | 7.5 - * 1 | 0 | 0 | 15 (default) - * 1 | 0 | 1 | 30 - * 1 | 1 | 0 | 75 - * 1 | 1 | 1 | Not Used - * 1:0 MS1-MS0: Measurement Configuration Bits - * MS1 | MS0 | MODE - * ------------------------------ - * 0 | 0 | Normal - * 0 | 1 | Positive Bias - * 1 | 0 | Negative Bias - * 1 | 1 | Not Used - * - * CTRL_REGB: Control RegisterB - * Read Write - * Default value: 0x20 - * 7:5 GN2-GN0: Gain Configuration Bits. - * GN2 | GN1 | GN0 | Mag Input | Gain | Output Range - * | | | Range[Ga] | [LSB/mGa] | - * ------------------------------------------------------ - * 0 | 0 | 0 | ±0.88Ga | 1370 | 0xF800–0x07FF (-2048:2047) - * 0 | 0 | 1 | ±1.3Ga (def) | 1090 | 0xF800–0x07FF (-2048:2047) - * 0 | 1 | 0 | ±1.9Ga | 820 | 0xF800–0x07FF (-2048:2047) - * 0 | 1 | 1 | ±2.5Ga | 660 | 0xF800–0x07FF (-2048:2047) - * 1 | 0 | 0 | ±4.0Ga | 440 | 0xF800–0x07FF (-2048:2047) - * 1 | 0 | 1 | ±4.7Ga | 390 | 0xF800–0x07FF (-2048:2047) - * 1 | 1 | 0 | ±5.6Ga | 330 | 0xF800–0x07FF (-2048:2047) - * 1 | 1 | 1 | ±8.1Ga | 230 | 0xF800–0x07FF (-2048:2047) - * |Not recommended| - * - * 4:0 CRB4-CRB: 0 This bit must be cleared for correct operation. - * - * _MODE_REG: Mode Register - * Read Write - * Default value: 0x02 - * 7:2 0 These bits must be cleared for correct operation. - * 1:0 MD1-MD0: Mode Select Bits - * MS1 | MS0 | MODE - * ------------------------------ - * 0 | 0 | Continuous-Conversion Mode. - * 0 | 1 | Single-Conversion Mode - * 1 | 0 | Negative Bias - * 1 | 1 | Sleep Mode - */ -static uint8_t CTRLB = 0x00; -static int32_t PIOS_HMC5883_Config(const struct pios_hmc5883_cfg *cfg) -{ - uint8_t CTRLA = 0x00; - uint8_t MODE = 0x00; - - CTRLB = 0; - - CTRLA |= (uint8_t)(cfg->M_ODR | cfg->Meas_Conf); - CTRLB |= (uint8_t)(cfg->Gain); - MODE |= (uint8_t)(cfg->Mode); - - // CRTL_REGA - if (PIOS_HMC5883_Write(PIOS_HMC5883_CONFIG_REG_A, CTRLA) != 0) { - return -1; - } - - // CRTL_REGB - if (PIOS_HMC5883_Write(PIOS_HMC5883_CONFIG_REG_B, CTRLB) != 0) { - return -1; - } - - // Mode register - if (PIOS_HMC5883_Write(PIOS_HMC5883_MODE_REG, MODE) != 0) { - return -1; - } - - return 0; -} - -/** - * @brief Read current X, Z, Y values (in that order) - * \param[out] int16_t array of size 3 to store X, Z, and Y magnetometer readings - * \return 0 for success or -1 for failure - */ -int32_t PIOS_HMC5883_ReadMag(int16_t out[3]) -{ - pios_hmc5883_data_ready = false; - uint8_t buffer[6]; - int32_t temp; - int32_t sensitivity; - - if (PIOS_HMC5883_Read(PIOS_HMC5883_DATAOUT_XMSB_REG, buffer, 6) != 0) { - return -1; - } - - switch (CTRLB & 0xE0) { - case 0x00: - sensitivity = PIOS_HMC5883_Sensitivity_0_88Ga; - break; - case 0x20: - sensitivity = PIOS_HMC5883_Sensitivity_1_3Ga; - break; - case 0x40: - sensitivity = PIOS_HMC5883_Sensitivity_1_9Ga; - break; - case 0x60: - sensitivity = PIOS_HMC5883_Sensitivity_2_5Ga; - break; - case 0x80: - sensitivity = PIOS_HMC5883_Sensitivity_4_0Ga; - break; - case 0xA0: - sensitivity = PIOS_HMC5883_Sensitivity_4_7Ga; - break; - case 0xC0: - sensitivity = PIOS_HMC5883_Sensitivity_5_6Ga; - break; - case 0xE0: - sensitivity = PIOS_HMC5883_Sensitivity_8_1Ga; - break; - default: - PIOS_Assert(0); - } - - for (int i = 0; i < 3; i++) { - temp = ((int16_t)((uint16_t)buffer[2 * i] << 8) - + buffer[2 * i + 1]) * 1000 / sensitivity; - out[i] = temp; - } - // Data reads out as X,Z,Y - temp = out[2]; - out[2] = out[1]; - out[1] = temp; - - // This should not be necessary but for some reason it is coming out of continuous conversion mode - PIOS_HMC5883_Write(PIOS_HMC5883_MODE_REG, PIOS_HMC5883_MODE_CONTINUOUS); - - return 0; -} - - -/** - * @brief Read the identification bytes from the HMC5883 sensor - * \param[out] uint8_t array of size 4 to store HMC5883 ID. - * \return 0 if successful, -1 if not - */ -uint8_t PIOS_HMC5883_ReadID(uint8_t out[4]) -{ - uint8_t retval = PIOS_HMC5883_Read(PIOS_HMC5883_DATAOUT_IDA_REG, out, 3); - - out[3] = '\0'; - return retval; -} - -/** - * @brief Tells whether new magnetometer readings are available - * \return true if new data is available - * \return false if new data is not available - */ -bool PIOS_HMC5883_NewDataAvailable(void) -{ - return pios_hmc5883_data_ready; -} - -/** - * @brief Reads one or more bytes into a buffer - * \param[in] address HMC5883 register address (depends on size) - * \param[out] buffer destination buffer - * \param[in] len number of bytes which should be read - * \return 0 if operation was successful - * \return -1 if error during I2C transfer - * \return -2 if unable to claim i2c device - */ -static int32_t PIOS_HMC5883_Read(uint8_t address, uint8_t *buffer, uint8_t len) -{ - uint8_t addr_buffer[] = { - address, - }; - - const struct pios_i2c_txn txn_list[] = { - { - .info = __func__, - .addr = PIOS_HMC5883_I2C_ADDR, - .rw = PIOS_I2C_TXN_WRITE, - .len = sizeof(addr_buffer), - .buf = addr_buffer, - } - , - { - .info = __func__, - .addr = PIOS_HMC5883_I2C_ADDR, - .rw = PIOS_I2C_TXN_READ, - .len = len, - .buf = buffer, - } - }; - - return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); -} - -/** - * @brief Writes one or more bytes to the HMC5883 - * \param[in] address Register address - * \param[in] buffer source buffer - * \return 0 if operation was successful - * \return -1 if error during I2C transfer - * \return -2 if unable to claim i2c device - */ -static int32_t PIOS_HMC5883_Write(uint8_t address, uint8_t buffer) -{ - uint8_t data[] = { - address, - buffer, - }; - - const struct pios_i2c_txn txn_list[] = { - { - .info = __func__, - .addr = PIOS_HMC5883_I2C_ADDR, - .rw = PIOS_I2C_TXN_WRITE, - .len = sizeof(data), - .buf = data, - } - , - }; - - ; - return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); -} - -/** - * @brief Run self-test operation. Do not call this during operational use!! - * \return 0 if success, -1 if test failed - */ -int32_t PIOS_HMC5883_Test(void) -{ - int32_t failed = 0; - uint8_t registers[3] = { 0, 0, 0 }; - uint8_t status; - uint8_t ctrl_a_read; - uint8_t ctrl_b_read; - uint8_t mode_read; - int16_t values[3]; - - - /* Verify that ID matches (HMC5883 ID is null-terminated ASCII string "H43") */ - char id[4]; - - PIOS_HMC5883_ReadID((uint8_t *)id); - if ((id[0] != 'H') || (id[1] != '4') || (id[2] != '3')) { // Expect H43 - return -1; - } - - /* Backup existing configuration */ - if (PIOS_HMC5883_Read(PIOS_HMC5883_CONFIG_REG_A, registers, 3) != 0) { - return -1; - } - - /* Stop the device and read out last value */ - PIOS_DELAY_WaitmS(10); - if (PIOS_HMC5883_Write(PIOS_HMC5883_MODE_REG, PIOS_HMC5883_MODE_IDLE) != 0) { - return -1; - } - if (PIOS_HMC5883_Read(PIOS_HMC5883_DATAOUT_STATUS_REG, &status, 1) != 0) { - return -1; - } - if (PIOS_HMC5883_ReadMag(values) != 0) { - return -1; - } - - /* - * Put HMC5883 into self test mode - * This is done by placing measurement config into positive (0x01) or negative (0x10) bias - * and then placing the mode register into single-measurement mode. This causes the HMC5883 - * to create an artificial magnetic field of ~1.1 Gauss. - * - * If gain were PIOS_HMC5883_GAIN_2_5, for example, X and Y will read around +766 LSB - * (1.16 Ga * 660 LSB/Ga) and Z would read around +713 LSB (1.08 Ga * 660 LSB/Ga) - * - * Changing measurement config back to PIOS_HMC5883_MEASCONF_NORMAL will leave self-test mode. - */ - PIOS_DELAY_WaitmS(10); - if (PIOS_HMC5883_Write(PIOS_HMC5883_CONFIG_REG_A, PIOS_HMC5883_MEASCONF_BIAS_POS | PIOS_HMC5883_ODR_15) != 0) { - return -1; - } - PIOS_DELAY_WaitmS(10); - if (PIOS_HMC5883_Write(PIOS_HMC5883_CONFIG_REG_B, PIOS_HMC5883_GAIN_8_1) != 0) { - return -1; - } - PIOS_DELAY_WaitmS(10); - if (PIOS_HMC5883_Write(PIOS_HMC5883_MODE_REG, PIOS_HMC5883_MODE_SINGLE) != 0) { - return -1; - } - - /* Must wait for value to be updated */ - PIOS_DELAY_WaitmS(200); - - if (PIOS_HMC5883_ReadMag(values) != 0) { - return -1; - } - - /* - if(abs(values[0] - 766) > 20) - failed |= 1; - if(abs(values[1] - 766) > 20) - failed |= 1; - if(abs(values[2] - 713) > 20) - failed |= 1; - */ - - PIOS_HMC5883_Read(PIOS_HMC5883_CONFIG_REG_A, &ctrl_a_read, 1); - PIOS_HMC5883_Read(PIOS_HMC5883_CONFIG_REG_B, &ctrl_b_read, 1); - PIOS_HMC5883_Read(PIOS_HMC5883_MODE_REG, &mode_read, 1); - PIOS_HMC5883_Read(PIOS_HMC5883_DATAOUT_STATUS_REG, &status, 1); - - - /* Restore backup configuration */ - PIOS_DELAY_WaitmS(10); - if (PIOS_HMC5883_Write(PIOS_HMC5883_CONFIG_REG_A, registers[0]) != 0) { - return -1; - } - PIOS_DELAY_WaitmS(10); - if (PIOS_HMC5883_Write(PIOS_HMC5883_CONFIG_REG_B, registers[1]) != 0) { - return -1; - } - PIOS_DELAY_WaitmS(10); - if (PIOS_HMC5883_Write(PIOS_HMC5883_MODE_REG, registers[2]) != 0) { - return -1; - } - - return failed; -} - -/** - * @brief IRQ Handler - */ -bool PIOS_HMC5883_IRQHandler(void) -{ - pios_hmc5883_data_ready = true; - - return false; -} - -#endif /* PIOS_INCLUDE_HMC5883 */ - -/** - * @} - * @} - */ diff --git a/flight/pios/inc/pios_hmc5883.h b/flight/pios/inc/pios_hmc5883.h deleted file mode 100644 index 6d34dae20..000000000 --- a/flight/pios/inc/pios_hmc5883.h +++ /dev/null @@ -1,116 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup PIOS PIOS Core hardware abstraction layer - * @{ - * @addtogroup PIOS_HMC5883 HMC5883 Functions - * @brief Deals with the hardware interface to the magnetometers - * @{ - * - * @file pios_hmc5883.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. - * @brief HMC5883 functions header. - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef PIOS_HMC5883_H -#define PIOS_HMC5883_H - -/* HMC5883 Addresses */ -#define PIOS_HMC5883_I2C_ADDR 0x1E -#define PIOS_HMC5883_I2C_READ_ADDR 0x3D -#define PIOS_HMC5883_I2C_WRITE_ADDR 0x3C -#define PIOS_HMC5883_CONFIG_REG_A (uint8_t)0x00 -#define PIOS_HMC5883_CONFIG_REG_B (uint8_t)0x01 -#define PIOS_HMC5883_MODE_REG (uint8_t)0x02 -#define PIOS_HMC5883_DATAOUT_XMSB_REG 0x03 -#define PIOS_HMC5883_DATAOUT_XLSB_REG 0x04 -#define PIOS_HMC5883_DATAOUT_ZMSB_REG 0x05 -#define PIOS_HMC5883_DATAOUT_ZLSB_REG 0x06 -#define PIOS_HMC5883_DATAOUT_YMSB_REG 0x07 -#define PIOS_HMC5883_DATAOUT_YLSB_REG 0x08 -#define PIOS_HMC5883_DATAOUT_STATUS_REG 0x09 -#define PIOS_HMC5883_DATAOUT_IDA_REG 0x0A -#define PIOS_HMC5883_DATAOUT_IDB_REG 0x0B -#define PIOS_HMC5883_DATAOUT_IDC_REG 0x0C - -/* Output Data Rate */ -#define PIOS_HMC5883_ODR_0_75 0x00 -#define PIOS_HMC5883_ODR_1_5 0x04 -#define PIOS_HMC5883_ODR_3 0x08 -#define PIOS_HMC5883_ODR_7_5 0x0C -#define PIOS_HMC5883_ODR_15 0x10 -#define PIOS_HMC5883_ODR_30 0x14 -#define PIOS_HMC5883_ODR_75 0x18 - -/* Measure configuration */ -#define PIOS_HMC5883_MEASCONF_NORMAL 0x00 -#define PIOS_HMC5883_MEASCONF_BIAS_POS 0x01 -#define PIOS_HMC5883_MEASCONF_BIAS_NEG 0x02 - -/* Gain settings */ -#define PIOS_HMC5883_GAIN_0_88 0x00 -#define PIOS_HMC5883_GAIN_1_3 0x20 -#define PIOS_HMC5883_GAIN_1_9 0x40 -#define PIOS_HMC5883_GAIN_2_5 0x60 -#define PIOS_HMC5883_GAIN_4_0 0x80 -#define PIOS_HMC5883_GAIN_4_7 0xA0 -#define PIOS_HMC5883_GAIN_5_6 0xC0 -#define PIOS_HMC5883_GAIN_8_1 0xE0 - -/* Modes */ -#define PIOS_HMC5883_MODE_CONTINUOUS 0x00 -#define PIOS_HMC5883_MODE_SINGLE 0x01 -#define PIOS_HMC5883_MODE_IDLE 0x02 -#define PIOS_HMC5883_MODE_SLEEP 0x03 - -/* Sensitivity Conversion Values */ -#define PIOS_HMC5883_Sensitivity_0_88Ga 1370 // LSB/Ga -#define PIOS_HMC5883_Sensitivity_1_3Ga 1090 // LSB/Ga -#define PIOS_HMC5883_Sensitivity_1_9Ga 820 // LSB/Ga -#define PIOS_HMC5883_Sensitivity_2_5Ga 660 // LSB/Ga -#define PIOS_HMC5883_Sensitivity_4_0Ga 440 // LSB/Ga -#define PIOS_HMC5883_Sensitivity_4_7Ga 390 // LSB/Ga -#define PIOS_HMC5883_Sensitivity_5_6Ga 330 // LSB/Ga -#define PIOS_HMC5883_Sensitivity_8_1Ga 230 // LSB/Ga --> NOT RECOMMENDED - - -struct pios_hmc5883_cfg { -#ifdef PIOS_HMC5883_HAS_GPIOS - const struct pios_exti_cfg *exti_cfg; /* Pointer to the EXTI configuration */ -#endif - uint8_t M_ODR; /* OUTPUT DATA RATE --> here below the relative define (See datasheet page 11 for more details) */ - uint8_t Meas_Conf; /* Measurement Configuration,: Normal, positive bias, or negative bias --> here below the relative define */ - uint8_t Gain; /* Gain Configuration, select the full scale --> here below the relative define (See datasheet page 11 for more details) */ - uint8_t Mode; -}; - -/* Public Functions */ -extern void PIOS_HMC5883_Init(const struct pios_hmc5883_cfg *cfg); -extern bool PIOS_HMC5883_NewDataAvailable(void); -extern int32_t PIOS_HMC5883_ReadMag(int16_t out[3]); -extern uint8_t PIOS_HMC5883_ReadID(uint8_t out[4]); -extern int32_t PIOS_HMC5883_Test(void); -extern bool PIOS_HMC5883_IRQHandler(); - -#endif /* PIOS_HMC5883_H */ - -/** - * @} - * @} - */ diff --git a/flight/pios/inc/pios_hmc5x83.h b/flight/pios/inc/pios_hmc5x83.h index 94f53b2f9..949966ef5 100644 --- a/flight/pios/inc/pios_hmc5x83.h +++ b/flight/pios/inc/pios_hmc5x83.h @@ -108,7 +108,7 @@ extern const struct pios_hmc5x83_io_driver PIOS_HMC5x83_I2C_DRIVER; #endif struct pios_hmc5x83_cfg { -#ifdef PIOS_HMC5x83_HAS_GPIOS +#ifdef PIOS_HMC5X83_HAS_GPIOS const struct pios_exti_cfg *exti_cfg; /* Pointer to the EXTI configuration */ #endif uint8_t M_ODR; // OUTPUT DATA RATE --> here below the relative define (See datasheet page 11 for more details) */ diff --git a/flight/pios/pios.h b/flight/pios/pios.h index 1bb1ea968..124dc1d8a 100644 --- a/flight/pios/pios.h +++ b/flight/pios/pios.h @@ -204,12 +204,6 @@ #include #endif -#ifdef PIOS_INCLUDE_HMC5883 -/* HMC5883 3-Axis Digital Compass */ -/* #define PIOS_HMC5883_HAS_GPIOS */ -#include -#endif - #ifdef PIOS_INCLUDE_HMC5X83 /* HMC5883/HMC5983 3-Axis Digital Compass */ /* #define PIOS_HMC5x83_HAS_GPIOS */ diff --git a/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h b/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h index e7da296e9..95332df45 100644 --- a/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h +++ b/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h @@ -84,7 +84,7 @@ #define PIOS_INCLUDE_MPU6000 #define PIOS_MPU6000_ACCEL /* #define PIOS_INCLUDE_HMC5843 */ -/* #define PIOS_INCLUDE_HMC5883 */ +/* #define PIOS_INCLUDE_HMC5X83 */ /* #define PIOS_HMC5883_HAS_GPIOS */ /* #define PIOS_INCLUDE_BMP085 */ /* #define PIOS_INCLUDE_MS5611 */ diff --git a/flight/targets/boards/discoveryf4bare/firmware/inc/pios_config.h b/flight/targets/boards/discoveryf4bare/firmware/inc/pios_config.h index a55d4cb09..44065be33 100644 --- a/flight/targets/boards/discoveryf4bare/firmware/inc/pios_config.h +++ b/flight/targets/boards/discoveryf4bare/firmware/inc/pios_config.h @@ -84,8 +84,8 @@ // #define PIOS_INCLUDE_MPU6000 // #define PIOS_MPU6000_ACCEL /* #define PIOS_INCLUDE_HMC5843 */ -// #define PIOS_INCLUDE_HMC5883 -// #define PIOS_HMC5883_HAS_GPIOS +// #define PIOS_INCLUDE_HMC5X83 +// #define PIOS_HMC5X83_HAS_GPIOS /* #define PIOS_INCLUDE_BMP085 */ // #define PIOS_INCLUDE_MS5611 // #define PIOS_INCLUDE_MPXV diff --git a/flight/targets/boards/discoveryf4bare/firmware/pios_board.c b/flight/targets/boards/discoveryf4bare/firmware/pios_board.c index 687f1c5f7..2e8971636 100644 --- a/flight/targets/boards/discoveryf4bare/firmware/pios_board.c +++ b/flight/targets/boards/discoveryf4bare/firmware/pios_board.c @@ -90,10 +90,10 @@ void PIOS_ADC_DMC_irq_handler(void) #endif /* if defined(PIOS_INCLUDE_ADC) */ -#if defined(PIOS_INCLUDE_HMC5883) -#include "pios_hmc5883.h" -static const struct pios_exti_cfg pios_exti_hmc5883_cfg __exti_config = { - .vector = PIOS_HMC5883_IRQHandler, +#if defined(PIOS_INCLUDE_HMC5X83) +#include "pios_hmc5x83.h" +static const struct pios_exti_cfg pios_exti_hmc5x83_cfg __exti_config = { + .vector = PIOS_HMC5x83_IRQHandler, .line = EXTI_Line7, .pin = { .gpio = GPIOB, @@ -123,14 +123,15 @@ static const struct pios_exti_cfg pios_exti_hmc5883_cfg __exti_config = { }, }; -static const struct pios_hmc5883_cfg pios_hmc5883_cfg = { - .exti_cfg = &pios_exti_hmc5883_cfg, - .M_ODR = PIOS_HMC5883_ODR_75, - .Meas_Conf = PIOS_HMC5883_MEASCONF_NORMAL, - .Gain = PIOS_HMC5883_GAIN_1_9, - .Mode = PIOS_HMC5883_MODE_CONTINUOUS, +static const struct pios_hmc5x83_cfg pios_hmc5x83_cfg = { + .exti_cfg = &pios_exti_hmc5x83_cfg, + .M_ODR = PIOS_HMC5x83_ODR_75, + .Meas_Conf = PIOS_HMC5x83_MEASCONF_NORMAL, + .Gain = PIOS_HMC5x83_GAIN_1_9, + .Mode = PIOS_HMC5x83_MODE_CONTINUOUS, + .Driver = &PIOS_HMC5x83_I2C_DRIVER, }; -#endif /* PIOS_INCLUDE_HMC5883 */ +#endif /* PIOS_INCLUDE_HMC5X83 */ /** * Configuration for the MS5611 chip @@ -929,8 +930,8 @@ void PIOS_Board_Init(void) PIOS_ADC_Init(&pios_adc_cfg); #endif -#if defined(PIOS_INCLUDE_HMC5883) - PIOS_HMC5883_Init(&pios_hmc5883_cfg); +#if defined(PIOS_INCLUDE_HMC5X83) + PIOS_HMC5x83_Init(&pios_hmc5x83_cfg, pios_i2c_mag_pressure_adapter_id, 0); #endif #if defined(PIOS_INCLUDE_MS5611) diff --git a/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h b/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h index 8dd30c0f3..7717beb52 100644 --- a/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h +++ b/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h @@ -81,7 +81,7 @@ /* #define PIOS_INCLUDE_MPU6000 */ /* #define PIOS_MPU6000_ACCEL */ /* #define PIOS_INCLUDE_HMC5843 */ -/* #define PIOS_INCLUDE_HMC5883 */ +/* #define PIOS_INCLUDE_HMC5X83 */ /* #define PIOS_HMC5883_HAS_GPIOS */ /* #define PIOS_INCLUDE_BMP085 */ /* #define PIOS_INCLUDE_MS5611 */ diff --git a/flight/targets/boards/osd/firmware/inc/pios_config.h b/flight/targets/boards/osd/firmware/inc/pios_config.h index 33542a953..66e178349 100644 --- a/flight/targets/boards/osd/firmware/inc/pios_config.h +++ b/flight/targets/boards/osd/firmware/inc/pios_config.h @@ -81,8 +81,8 @@ /* #define PIOS_INCLUDE_MPU6000 */ /* #define PIOS_MPU6000_ACCEL */ /* #define PIOS_INCLUDE_HMC5843 */ -#define PIOS_INCLUDE_HMC5883 -/* #define PIOS_HMC5883_HAS_GPIOS */ +#define PIOS_INCLUDE_HMC5X83 +/* #define PIOS_HMC5X83_HAS_GPIOS */ #define PIOS_INCLUDE_BMP085 /* #define PIOS_INCLUDE_MS5611 */ /* #define PIOS_INCLUDE_MPXV */ diff --git a/flight/targets/boards/revolution/firmware/inc/pios_config.h b/flight/targets/boards/revolution/firmware/inc/pios_config.h index 49cd0d8e6..5ee827783 100644 --- a/flight/targets/boards/revolution/firmware/inc/pios_config.h +++ b/flight/targets/boards/revolution/firmware/inc/pios_config.h @@ -84,8 +84,8 @@ #define PIOS_INCLUDE_MPU6000 #define PIOS_MPU6000_ACCEL /* #define PIOS_INCLUDE_HMC5843 */ -#define PIOS_INCLUDE_HMC5883 -#define PIOS_HMC5883_HAS_GPIOS +#define PIOS_INCLUDE_HMC5X83 +#define PIOS_HMC5X83_HAS_GPIOS /* #define PIOS_INCLUDE_BMP085 */ #define PIOS_INCLUDE_MS5611 #define PIOS_INCLUDE_MPXV diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index 4901cc432..b97adb07a 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -91,10 +91,10 @@ void PIOS_ADC_DMC_irq_handler(void) #endif /* if defined(PIOS_INCLUDE_ADC) */ -#if defined(PIOS_INCLUDE_HMC5883) -#include "pios_hmc5883.h" -static const struct pios_exti_cfg pios_exti_hmc5883_cfg __exti_config = { - .vector = PIOS_HMC5883_IRQHandler, +#if defined(PIOS_INCLUDE_HMC5X83) +#include "pios_hmc5x83.h" +static const struct pios_exti_cfg pios_exti_hmc5x83_cfg __exti_config = { + .vector = PIOS_HMC5x83_IRQHandler, .line = EXTI_Line7, .pin = { .gpio = GPIOB, @@ -124,14 +124,15 @@ static const struct pios_exti_cfg pios_exti_hmc5883_cfg __exti_config = { }, }; -static const struct pios_hmc5883_cfg pios_hmc5883_cfg = { - .exti_cfg = &pios_exti_hmc5883_cfg, - .M_ODR = PIOS_HMC5883_ODR_75, - .Meas_Conf = PIOS_HMC5883_MEASCONF_NORMAL, - .Gain = PIOS_HMC5883_GAIN_1_9, - .Mode = PIOS_HMC5883_MODE_CONTINUOUS, +static const struct pios_hmc5x83_cfg pios_hmc5x83_cfg = { + .exti_cfg = &pios_exti_hmc5x83_cfg, + .M_ODR = PIOS_HMC5x83_ODR_75, + .Meas_Conf = PIOS_HMC5x83_MEASCONF_NORMAL, + .Gain = PIOS_HMC5x83_GAIN_1_9, + .Mode = PIOS_HMC5x83_MODE_CONTINUOUS, + .Driver = &PIOS_HMC5x83_I2C_DRIVER, }; -#endif /* PIOS_INCLUDE_HMC5883 */ +#endif /* PIOS_INCLUDE_HMC5X83 */ /** * Configuration for the MS5611 chip @@ -944,8 +945,8 @@ void PIOS_Board_Init(void) PIOS_ADC_Init(&pios_adc_cfg); #endif -#if defined(PIOS_INCLUDE_HMC5883) - PIOS_HMC5883_Init(&pios_hmc5883_cfg); +#if defined(PIOS_INCLUDE_HMC5X83) + PIOS_HMC5x83_Init(&pios_hmc5x83_cfg, pios_i2c_mag_pressure_adapter_id, 0); #endif #if defined(PIOS_INCLUDE_MS5611) diff --git a/flight/targets/boards/revoproto/firmware/inc/pios_config.h b/flight/targets/boards/revoproto/firmware/inc/pios_config.h index 6077225aa..897f9b360 100644 --- a/flight/targets/boards/revoproto/firmware/inc/pios_config.h +++ b/flight/targets/boards/revoproto/firmware/inc/pios_config.h @@ -81,8 +81,8 @@ #define PIOS_INCLUDE_MPU6000 #define PIOS_MPU6000_ACCEL /* #define PIOS_INCLUDE_HMC5843 */ -#define PIOS_INCLUDE_HMC5883 -#define PIOS_HMC5883_HAS_GPIOS +#define PIOS_INCLUDE_HMC5X83 +#define PIOS_HMC5X83_HAS_GPIOS /* #define PIOS_INCLUDE_BMP085 */ #define PIOS_INCLUDE_MS5611 #define PIOS_INCLUDE_MPXV diff --git a/flight/targets/boards/revoproto/firmware/pios_board.c b/flight/targets/boards/revoproto/firmware/pios_board.c index e628d615e..de2c5982d 100644 --- a/flight/targets/boards/revoproto/firmware/pios_board.c +++ b/flight/targets/boards/revoproto/firmware/pios_board.c @@ -81,10 +81,10 @@ void PIOS_ADC_DMC_irq_handler(void) #endif /* if defined(PIOS_INCLUDE_ADC) */ -#if defined(PIOS_INCLUDE_HMC5883) -#include "pios_hmc5883.h" -static const struct pios_exti_cfg pios_exti_hmc5883_cfg __exti_config = { - .vector = PIOS_HMC5883_IRQHandler, +#if defined(PIOS_INCLUDE_HMC5X83) +#include "pios_hmc5x83.h" +static const struct pios_exti_cfg pios_exti_hmc5x83_cfg __exti_config = { + .vector = PIOS_HMC5x83_IRQHandler, .line = EXTI_Line5, .pin = { .gpio = GPIOB, @@ -114,14 +114,15 @@ static const struct pios_exti_cfg pios_exti_hmc5883_cfg __exti_config = { }, }; -static const struct pios_hmc5883_cfg pios_hmc5883_cfg = { - .exti_cfg = &pios_exti_hmc5883_cfg, - .M_ODR = PIOS_HMC5883_ODR_75, - .Meas_Conf = PIOS_HMC5883_MEASCONF_NORMAL, - .Gain = PIOS_HMC5883_GAIN_1_9, - .Mode = PIOS_HMC5883_MODE_CONTINUOUS, +static const struct pios_hmc5x83_cfg pios_hmc5x83_cfg = { + .exti_cfg = &pios_exti_hmc5x83_cfg, + .M_ODR = PIOS_HMC5x83_ODR_75, + .Meas_Conf = PIOS_HMC5x83_MEASCONF_NORMAL, + .Gain = PIOS_HMC5x83_GAIN_1_9, + .Mode = PIOS_HMC5x83_MODE_CONTINUOUS, + .Driver = &PIOS_HMC5x83_I2C_DRIVER, }; -#endif /* PIOS_INCLUDE_HMC5883 */ +#endif /* PIOS_INCLUDE_HMC5X83 */ /** * Configuration for the MS5611 chip @@ -938,8 +939,8 @@ void PIOS_Board_Init(void) PIOS_ADC_Init(&pios_adc_cfg); #endif -#if defined(PIOS_INCLUDE_HMC5883) - PIOS_HMC5883_Init(&pios_hmc5883_cfg); +#if defined(PIOS_INCLUDE_HMC5X83) + PIOS_HMC5x83_Init(&pios_hmc5x83_cfg, pios_i2c_pressure_adapter_id, 0); #endif #if defined(PIOS_INCLUDE_MS5611) diff --git a/flight/targets/boards/simposix/firmware/inc/pios_config.h b/flight/targets/boards/simposix/firmware/inc/pios_config.h index 9194e68b9..0dc6b7aaa 100644 --- a/flight/targets/boards/simposix/firmware/inc/pios_config.h +++ b/flight/targets/boards/simposix/firmware/inc/pios_config.h @@ -63,7 +63,7 @@ /* Select the sensors to include */ // #define PIOS_INCLUDE_BMA180 -// #define PIOS_INCLUDE_HMC5883 +// #define PIOS_INCLUDE_HMC5X83 // #define PIOS_INCLUDE_MPU6000 // #define PIOS_MPU6000_ACCEL // #define PIOS_INCLUDE_L3GD20 diff --git a/make/apps-defs.mk b/make/apps-defs.mk index a80fc6fc5..72381423e 100644 --- a/make/apps-defs.mk +++ b/make/apps-defs.mk @@ -64,7 +64,7 @@ SRC += $(PIOSCOMMON)/pios_etasv3.c SRC += $(PIOSCOMMON)/pios_gcsrcvr.c SRC += $(PIOSCOMMON)/pios_hcsr04.c SRC += $(PIOSCOMMON)/pios_hmc5843.c -SRC += $(PIOSCOMMON)/pios_hmc5883.c +SRC += $(PIOSCOMMON)/pios_hmc5x83.c SRC += $(PIOSCOMMON)/pios_i2c_esc.c SRC += $(PIOSCOMMON)/pios_l3gd20.c SRC += $(PIOSCOMMON)/pios_mpu6000.c