1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

OP-1477 - Fix mag exti config, set correct rate, set correct SPI speed for hmc5x83. Note: GPIO is disabled as it seems there is some issues with Exti on PB0

This commit is contained in:
Alessio Morale 2014-10-01 02:07:46 +02:00
parent 0ffb99f228
commit ae9f30c729
4 changed files with 15 additions and 6 deletions

View File

@ -29,14 +29,22 @@
#include <ubx_utils.h> #include <ubx_utils.h>
#include <pios_hmc5x83.h> #include <pios_hmc5x83.h>
#include "inc/gps9protocol.h" #include "inc/gps9protocol.h"
#define MAG_RATE_HZ 30
extern pios_hmc5x83_dev_t onboard_mag; extern pios_hmc5x83_dev_t onboard_mag;
void handleMag() void handleMag()
{ {
#ifdef PIOS_HMC5X83_HAS_GPIOS
if (!PIOS_HMC5x83_NewDataAvailable(onboard_mag)) { if (!PIOS_HMC5x83_NewDataAvailable(onboard_mag)) {
return; return;
} }
#else
static uint32_t lastUpdate = 0;
if(PIOS_DELAY_DiffuS(lastUpdate) < (1000000 / MAG_RATE_HZ)){
return;
}
lastUpdate = PIOS_DELAY_GetRaw();
#endif
static int16_t mag[3]; static int16_t mag[3];
if (PIOS_HMC5x83_ReadMag(onboard_mag, mag) == 0) { if (PIOS_HMC5x83_ReadMag(onboard_mag, mag) == 0) {

View File

@ -401,6 +401,7 @@ static int32_t pios_hmc5x83_spi_claim_bus(pios_hmc5x83_dev_data_t *dev)
if (PIOS_SPI_ClaimBus(dev->port_id) < 0) { if (PIOS_SPI_ClaimBus(dev->port_id) < 0) {
return -1; return -1;
} }
PIOS_SPI_SetClockSpeed(dev->port_id, SPI_BaudRatePrescaler_16);
PIOS_SPI_RC_PinSet(dev->port_id, dev->slave_num, 0); PIOS_SPI_RC_PinSet(dev->port_id, dev->slave_num, 0);
return 0; return 0;
} }

View File

@ -214,11 +214,11 @@ bool pios_board_mag_handler()
} }
static const struct pios_exti_cfg pios_exti_mag_cfg __exti_config = { static const struct pios_exti_cfg pios_exti_mag_cfg __exti_config = {
.vector = pios_board_mag_handler, .vector = pios_board_mag_handler,
.line = EXTI_Line7, .line = EXTI_Line0,
.pin = { .pin = {
.gpio = GPIOB, .gpio = GPIOB,
.init = { .init = {
.GPIO_Pin = GPIO_Pin_7, .GPIO_Pin = GPIO_Pin_0,
.GPIO_Speed = GPIO_Speed_Level_3, .GPIO_Speed = GPIO_Speed_Level_3,
.GPIO_Mode = GPIO_Mode_IN, .GPIO_Mode = GPIO_Mode_IN,
.GPIO_OType = GPIO_OType_OD, .GPIO_OType = GPIO_OType_OD,
@ -227,14 +227,14 @@ static const struct pios_exti_cfg pios_exti_mag_cfg __exti_config = {
}, },
.irq = { .irq = {
.init = { .init = {
.NVIC_IRQChannel = EXTI4_15_IRQn, .NVIC_IRQChannel = EXTI0_1_IRQn,
.NVIC_IRQChannelPriority = PIOS_IRQ_PRIO_LOW, .NVIC_IRQChannelPriority = PIOS_IRQ_PRIO_LOW,
.NVIC_IRQChannelCmd = ENABLE, .NVIC_IRQChannelCmd = ENABLE,
}, },
}, },
.exti = { .exti = {
.init = { .init = {
.EXTI_Line = EXTI_Line7, // matches above GPIO pin .EXTI_Line = EXTI_Line0, // matches above GPIO pin
.EXTI_Mode = EXTI_Mode_Interrupt, .EXTI_Mode = EXTI_Mode_Interrupt,
.EXTI_Trigger = EXTI_Trigger_Rising, .EXTI_Trigger = EXTI_Trigger_Rising,
.EXTI_LineCmd = ENABLE, .EXTI_LineCmd = ENABLE,

View File

@ -83,7 +83,7 @@
// #define PIOS_MPU6000_ACCEL // #define PIOS_MPU6000_ACCEL
/* #define PIOS_INCLUDE_HMC5843 */ /* #define PIOS_INCLUDE_HMC5843 */
#define PIOS_INCLUDE_HMC5X83 #define PIOS_INCLUDE_HMC5X83
#define PIOS_HMC5X83_HAS_GPIOS //#define PIOS_HMC5X83_HAS_GPIOS
/* #define PIOS_INCLUDE_BMP085 */ /* #define PIOS_INCLUDE_BMP085 */
/* #define PIOS_INCLUDE_MS5611 */ /* #define PIOS_INCLUDE_MS5611 */
/* #define PIOS_INCLUDE_MPXV */ /* #define PIOS_INCLUDE_MPXV */