1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-11 19:24:10 +01:00
LibrePilot/flight/PiOS/inc/pios_hmc5843.h

115 lines
4.3 KiB
C
Raw Normal View History

/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_HMC5843 HMC5843 Functions
* @brief Deals with the hardware interface to the magnetometers
* @{
*
* @file pios_hmc5843.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief HMC5843 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_HMC5843_H
#define PIOS_HMC5843_H
/* BMP085 Addresses */
#define PIOS_HMC5843_I2C_ADDR 0x1E
#define PIOS_HMC5843_CONFIG_REG_A (uint8_t)0x00
#define PIOS_HMC5843_CONFIG_REG_B (uint8_t)0x01
#define PIOS_HMC5843_MODE_REG (uint8_t)0x02
#define PIOS_HMC5843_DATAOUT_XMSB_REG 0x03
#define PIOS_HMC5843_DATAOUT_XLSB_REG 0x04
#define PIOS_HMC5843_DATAOUT_YMSB_REG 0x05
#define PIOS_HMC5843_DATAOUT_YLSB_REG 0x06
#define PIOS_HMC5843_DATAOUT_ZMSB_REG 0x07
#define PIOS_HMC5843_DATAOUT_ZLSB_REG 0x08
#define PIOS_HMC5843_DATAOUT_STATUS_REG 0x09
#define PIOS_HMC5843_DATAOUT_IDA_REG 0x0A
#define PIOS_HMC5843_DATAOUT_IDB_REG 0x0B
#define PIOS_HMC5843_DATAOUT_IDC_REG 0x0C
/* Output Data Rate */
#define PIOS_HMC5843_ODR_05 0x00
#define PIOS_HMC5843_ODR_1 0x04
#define PIOS_HMC5843_ODR_2 0x08
#define PIOS_HMC5843_ODR_5 0x0C
#define PIOS_HMC5843_ODR_10 0x10
#define PIOS_HMC5843_ODR_20 0x14
#define PIOS_HMC5843_ODR_50 0x18
/* Measure configuration */
#define PIOS_HMC5843_MEASCONF_NORMAL 0x00
#define PIOS_HMC5843_MEASCONF_BIAS_POS 0x01
#define PIOS_HMC5843_MEASCONF_BIAS_NEG 0x02
/* Gain settings */
#define PIOS_HMC5843_GAIN_0_7 0x00
#define PIOS_HMC5843_GAIN_1 0x20
#define PIOS_HMC5843_GAIN_1_5 0x40
#define PIOS_HMC5843_GAIN_2 0x60
#define PIOS_HMC5843_GAIN_3_2 0x80
#define PIOS_HMC5843_GAIN_3_8 0xA0
#define PIOS_HMC5843_GAIN_4_5 0xC0
#define PIOS_HMC5843_GAIN_6_5 0xE0
/* Modes */
#define PIOS_HMC5843_MODE_CONTINUOUS 0x00
#define PIOS_HMC5843_MODE_SINGLE 0x01
#define PIOS_HMC5843_MODE_IDLE 0x02
#define PIOS_HMC5843_MODE_SLEEP 0x02
/* Sensitivity Conversion Values */
#define PIOS_HMC5843_Sensitivity_0_7Ga 1602 // LSB/Ga
#define PIOS_HMC5843_Sensitivity_1Ga 1300 // LSB/Ga
#define PIOS_HMC5843_Sensitivity_1_5Ga 970 // LSB/Ga
#define PIOS_HMC5843_Sensitivity_2Ga 780 // LSB/Ga
#define PIOS_HMC5843_Sensitivity_3_2Ga 530 // LSB/Ga
#define PIOS_HMC5843_Sensitivity_3_8Ga 460 // LSB/Ga
#define PIOS_HMC5843_Sensitivity_4_5Ga 390 // LSB/Ga
#define PIOS_HMC5843_Sensitivity_6_5Ga 280 // LSB/Ga --> NOT RECOMMENDED
/* Global Types */
typedef struct {
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;
} PIOS_HMC5843_ConfigTypeDef;
/* Global Variables */
/* Public Functions */
extern void PIOS_HMC5843_Init(void);
extern void PIOS_HMC5843_Config(PIOS_HMC5843_ConfigTypeDef *HMC5843_Config_Struct);
extern void PIOS_HMC5843_ReadMag(int16_t out[3]);
extern void PIOS_HMC5843_ReadID(uint8_t out[4]);
i2c: rewrite i2c layer The STM32 I2C block has a number of errata associated with it. These errata are primarily related to timing sensitivities between the peripheral and the interrupt handler. In particular, the correct generation of the stop bit relies on the I2C IRQ running immediately and not being held off for any reason. NOTE: The I2C interrupts must be the highest priority IRQs in the system to ensure correct operation. I2C protocol is now implemented as a formal state machine. See: stm32_i2c_fsm.{dot,jpg} for FSM description. I2C init is now expressed by const initializers in pios_board.c for both OP and AHRS boards. I2C device drivers (ie. bmp085/hmc5843) now pass in const arrays of an unlimited number of bus transfers to be done atomically. The I2C adapter driver now handles all bus-level locking across the list of transactions. Generation of start/restart/stop conditions are handled automatically over the list of transactions. Timeouts have been removed from the API for now. May be added back later. This driver has run error free on both the OP and AHRS boards for up to 48hrs but it still sometimes fails earlier than that on the OP board. There is another possible set of improvements to the driver that could employ the DMA engine for transfers of >= 2bytes. This change would reduce the timing sensitivities between the peripheral and the driver but unfortunately, both the SPI and I2C interfaces share the DMA1 engine. That means only one of these two peripherals can use the DMA engine and right now, SPI between OP and AHRS is already using it. Failures are currently fatal and will lock up the CPU. This allows useful information to be obtained in the failure cases. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1241 ebee16cc-31ac-478f-84a7-5cbb03baadba
2010-08-08 06:15:08 +02:00
extern bool PIOS_HMC5843_Read(uint8_t address, uint8_t *buffer, uint8_t len);
extern bool PIOS_HMC5843_Write(uint8_t address, uint8_t buffer);
#endif /* PIOS_HMC5843_H */
/**
* @}
* @}
i2c: rewrite i2c layer The STM32 I2C block has a number of errata associated with it. These errata are primarily related to timing sensitivities between the peripheral and the interrupt handler. In particular, the correct generation of the stop bit relies on the I2C IRQ running immediately and not being held off for any reason. NOTE: The I2C interrupts must be the highest priority IRQs in the system to ensure correct operation. I2C protocol is now implemented as a formal state machine. See: stm32_i2c_fsm.{dot,jpg} for FSM description. I2C init is now expressed by const initializers in pios_board.c for both OP and AHRS boards. I2C device drivers (ie. bmp085/hmc5843) now pass in const arrays of an unlimited number of bus transfers to be done atomically. The I2C adapter driver now handles all bus-level locking across the list of transactions. Generation of start/restart/stop conditions are handled automatically over the list of transactions. Timeouts have been removed from the API for now. May be added back later. This driver has run error free on both the OP and AHRS boards for up to 48hrs but it still sometimes fails earlier than that on the OP board. There is another possible set of improvements to the driver that could employ the DMA engine for transfers of >= 2bytes. This change would reduce the timing sensitivities between the peripheral and the driver but unfortunately, both the SPI and I2C interfaces share the DMA1 engine. That means only one of these two peripherals can use the DMA engine and right now, SPI between OP and AHRS is already using it. Failures are currently fatal and will lock up the CPU. This allows useful information to be obtained in the failure cases. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1241 ebee16cc-31ac-478f-84a7-5cbb03baadba
2010-08-08 06:15:08 +02:00
*/