mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-18 08:54:15 +01:00
CC mag&baro for OSD, bmp needed some black magic hacking
This commit is contained in:
parent
44a3dad912
commit
79be7613b5
41
flight/Modules/Extensions/MagBaro/inc/magbaro.h
Normal file
41
flight/Modules/Extensions/MagBaro/inc/magbaro.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||||
|
* @{
|
||||||
|
* @addtogroup AltitudeModule Altitude Module
|
||||||
|
* @brief Communicate with BMP085 and update @ref AltitudeActual "AltitudeActual UAV Object"
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file altitude.h
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Altitude module, reads temperature and pressure from BMP085
|
||||||
|
*
|
||||||
|
* @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 MAGBARO_H
|
||||||
|
#define MAGBARO_H
|
||||||
|
|
||||||
|
int32_t MagBaroInitialize();
|
||||||
|
|
||||||
|
#endif // ALTITUDE_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
218
flight/Modules/Extensions/MagBaro/magbaro.c
Normal file
218
flight/Modules/Extensions/MagBaro/magbaro.c
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||||
|
* @{
|
||||||
|
* @addtogroup AltitudeModule Altitude Module
|
||||||
|
* @brief Communicate with BMP085 and update @ref BaroAltitude "BaroAltitude UAV Object"
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file altitude.c
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Altitude module, handles temperature and pressure readings from BMP085
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output object: BaroAltitude
|
||||||
|
*
|
||||||
|
* This module will periodically update the value of the BaroAltitude object.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "openpilot.h"
|
||||||
|
#include "hwsettings.h"
|
||||||
|
#include "magbaro.h"
|
||||||
|
#include "baroaltitude.h" // object that will be updated by the module
|
||||||
|
#include "magnetometer.h"
|
||||||
|
|
||||||
|
// Private constants
|
||||||
|
#define STACK_SIZE_BYTES 620
|
||||||
|
#define TASK_PRIORITY (tskIDLE_PRIORITY+1)
|
||||||
|
#define UPDATE_PERIOD 50
|
||||||
|
|
||||||
|
// Private types
|
||||||
|
|
||||||
|
// Private variables
|
||||||
|
static xTaskHandle taskHandle;
|
||||||
|
|
||||||
|
// down sampling variables
|
||||||
|
#define alt_ds_size 4
|
||||||
|
static int32_t alt_ds_temp = 0;
|
||||||
|
static int32_t alt_ds_pres = 0;
|
||||||
|
static int alt_ds_count = 0;
|
||||||
|
int32_t mag_test;
|
||||||
|
static bool magbaroEnabled;
|
||||||
|
static float mag_bias[3] = {0,0,0};
|
||||||
|
static float mag_scale[3] = {1,1,1};
|
||||||
|
|
||||||
|
// Private functions
|
||||||
|
static void magbaroTask(void *parameters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise the module, called on startup
|
||||||
|
* \returns 0 on success or -1 if initialisation failed
|
||||||
|
*/
|
||||||
|
int32_t MagBaroStart()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (magbaroEnabled) {
|
||||||
|
// Start main task
|
||||||
|
xTaskCreate(magbaroTask, (signed char *)"MagBaro", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle);
|
||||||
|
TaskMonitorAdd(TASKINFO_RUNNING_MAGBARO, taskHandle);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise the module, called on startup
|
||||||
|
* \returns 0 on success or -1 if initialisation failed
|
||||||
|
*/
|
||||||
|
int32_t MagBaroInitialize()
|
||||||
|
{
|
||||||
|
#ifdef MODULE_MagBaro_BUILTIN
|
||||||
|
magbaroEnabled = 1;
|
||||||
|
#else
|
||||||
|
HwSettingsInitialize();
|
||||||
|
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
|
||||||
|
HwSettingsOptionalModulesGet(optionalModules);
|
||||||
|
if (optionalModules[HWSETTINGS_OPTIONALMODULES_MAGBARO] == HWSETTINGS_OPTIONALMODULES_ENABLED) {
|
||||||
|
magbaroEnabled = 1;
|
||||||
|
} else {
|
||||||
|
magbaroEnabled = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(magbaroEnabled)
|
||||||
|
{
|
||||||
|
MagnetometerInitialize();
|
||||||
|
BaroAltitudeInitialize();
|
||||||
|
|
||||||
|
// init down-sampling data
|
||||||
|
alt_ds_temp = 0;
|
||||||
|
alt_ds_pres = 0;
|
||||||
|
alt_ds_count = 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
MODULE_INITCALL(MagBaroInitialize, MagBaroStart)
|
||||||
|
/**
|
||||||
|
* Module thread, should not return.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static const struct pios_hmc5883_cfg pios_hmc5883_cfg = {
|
||||||
|
#ifdef PIOS_HMC5883_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,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
static void magbaroTask(void *parameters)
|
||||||
|
{
|
||||||
|
BaroAltitudeData data;
|
||||||
|
portTickType lastSysTime;
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_BMP085)
|
||||||
|
PIOS_BMP085_Init();
|
||||||
|
#endif
|
||||||
|
#if defined(PIOS_INCLUDE_HMC5883)
|
||||||
|
PIOS_HMC5883_Init(&pios_hmc5883_cfg);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_HMC5883)
|
||||||
|
//mag_test = PIOS_HMC5883_Test();
|
||||||
|
#else
|
||||||
|
mag_test = 0;
|
||||||
|
#endif
|
||||||
|
// Main task loop
|
||||||
|
lastSysTime = xTaskGetTickCount();
|
||||||
|
uint32_t mag_update_time = PIOS_DELAY_GetRaw();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
#if defined(PIOS_INCLUDE_BMP085)
|
||||||
|
// Update the temperature data
|
||||||
|
PIOS_BMP085_StartADC(TemperatureConv);
|
||||||
|
#ifdef PIOS_BMP085_HAS_GPIOS
|
||||||
|
xSemaphoreTake(PIOS_BMP085_EOC, portMAX_DELAY);
|
||||||
|
#else
|
||||||
|
vTaskDelay(5 / portTICK_RATE_MS);
|
||||||
|
#endif
|
||||||
|
PIOS_BMP085_ReadADC();
|
||||||
|
alt_ds_temp += PIOS_BMP085_GetTemperature();
|
||||||
|
|
||||||
|
// Update the pressure data
|
||||||
|
PIOS_BMP085_StartADC(PressureConv);
|
||||||
|
#ifdef PIOS_BMP085_HAS_GPIOS
|
||||||
|
xSemaphoreTake(PIOS_BMP085_EOC, portMAX_DELAY);
|
||||||
|
#else
|
||||||
|
vTaskDelay(26 / portTICK_RATE_MS);
|
||||||
|
#endif
|
||||||
|
PIOS_BMP085_ReadADC();
|
||||||
|
alt_ds_pres += PIOS_BMP085_GetPressure();
|
||||||
|
|
||||||
|
if (++alt_ds_count >= alt_ds_size)
|
||||||
|
{
|
||||||
|
alt_ds_count = 0;
|
||||||
|
|
||||||
|
// Convert from 1/10ths of degC to degC
|
||||||
|
data.Temperature = alt_ds_temp / (10.0 * alt_ds_size);
|
||||||
|
alt_ds_temp = 0;
|
||||||
|
|
||||||
|
// Convert from Pa to kPa
|
||||||
|
data.Pressure = alt_ds_pres / (1000.0f * alt_ds_size);
|
||||||
|
alt_ds_pres = 0;
|
||||||
|
|
||||||
|
// Compute the current altitude (all pressures in kPa)
|
||||||
|
data.Altitude = 44330.0 * (1.0 - powf((data.Pressure / (BMP085_P0 / 1000.0)), (1.0 / 5.255)));
|
||||||
|
|
||||||
|
// Update the AltitudeActual UAVObject
|
||||||
|
BaroAltitudeSet(&data);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_HMC5883)
|
||||||
|
MagnetometerData mag;
|
||||||
|
if (PIOS_HMC5883_NewDataAvailable() || PIOS_DELAY_DiffuS(mag_update_time) > 100000) {
|
||||||
|
int16_t values[3];
|
||||||
|
PIOS_HMC5883_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]};
|
||||||
|
mag.x = mags[0];
|
||||||
|
mag.y = mags[1];
|
||||||
|
mag.z = mags[2];
|
||||||
|
MagnetometerSet(&mag);
|
||||||
|
mag_update_time = PIOS_DELAY_GetRaw();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Delay until it is time to read the next sample
|
||||||
|
vTaskDelayUntil(&lastSysTime, UPDATE_PERIOD / portTICK_RATE_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
@ -2313,7 +2313,7 @@ int32_t osdgenStart(void)
|
|||||||
// Start gps task
|
// Start gps task
|
||||||
vSemaphoreCreateBinary( osdSemaphore);
|
vSemaphoreCreateBinary( osdSemaphore);
|
||||||
xTaskCreate(osdgenTask, (signed char *)"OSDGEN", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &osdgenTaskHandle);
|
xTaskCreate(osdgenTask, (signed char *)"OSDGEN", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &osdgenTaskHandle);
|
||||||
TaskMonitorAdd(TASKINFO_RUNNING_GPS, osdgenTaskHandle);
|
//TaskMonitorAdd(TASKINFO_RUNNING_GPS, osdgenTaskHandle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ int32_t OpOsdStart(void)
|
|||||||
{
|
{
|
||||||
// Start gps task
|
// Start gps task
|
||||||
xTaskCreate(OpOsdTask, (signed char *)"OSD", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &OpOsdTaskHandle);
|
xTaskCreate(OpOsdTask, (signed char *)"OSD", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &OpOsdTaskHandle);
|
||||||
TaskMonitorAdd(TASKINFO_RUNNING_GPS, OpOsdTaskHandle);
|
//TaskMonitorAdd(TASKINFO_RUNNING_GPS, OpOsdTaskHandle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -48,10 +48,53 @@ endif
|
|||||||
|
|
||||||
FLASH_TOOL = OPENOCD
|
FLASH_TOOL = OPENOCD
|
||||||
|
|
||||||
# List of modules to include
|
# Optional module and driver defaults
|
||||||
MODULES = Osd/osdgen GPS
|
USE_CAMERASTAB ?= NO
|
||||||
|
USE_COMUSBBRIDGE ?= NO
|
||||||
|
USE_GPS ?= NO
|
||||||
|
USE_TXPID ?= NO
|
||||||
|
USE_I2C ?= NO
|
||||||
|
USE_ALTITUDE ?= NO
|
||||||
|
TEST_FAULTS ?= NO
|
||||||
|
USE_MAGBARO ?= NO
|
||||||
|
|
||||||
|
# List of optional modules to include
|
||||||
|
OPTMODULES =
|
||||||
|
ifeq ($(USE_CAMERASTAB), YES)
|
||||||
|
OPTMODULES += CameraStab
|
||||||
|
endif
|
||||||
|
ifeq ($(USE_COMUSBBRIDGE), YES)
|
||||||
|
OPTMODULES += ComUsbBridge
|
||||||
|
endif
|
||||||
|
ifeq ($(USE_GPS), YES)
|
||||||
|
OPTMODULES += GPS
|
||||||
|
endif
|
||||||
|
ifeq ($(USE_TXPID), YES)
|
||||||
|
OPTMODULES += TxPID
|
||||||
|
endif
|
||||||
|
ifeq ($(USE_ALTITUDE), YES)
|
||||||
|
ifeq ($(USE_I2C), YES)
|
||||||
|
OPTMODULES += Altitude
|
||||||
|
else
|
||||||
|
$(error "Altitude module (USE_ALTITUDE=YES) requires i2c (USE_I2C=YES)")
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifeq ($(TEST_FAULTS), YES)
|
||||||
|
OPTMODULES += Fault
|
||||||
|
endif
|
||||||
|
ifeq ($(USE_MAGBARO), YES)
|
||||||
|
ifeq ($(USE_I2C), YES)
|
||||||
|
OPTMODULES += Extensions/MagBaro
|
||||||
|
else
|
||||||
|
$(error "MagBaro module (USE_MAGBARO=YES) requires i2c (USE_I2C=YES)")
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# List of mandatory modules to include
|
||||||
|
MODULES = Osd/osdgen
|
||||||
|
MODULES += GPS
|
||||||
MODULES += Osd/osdinput
|
MODULES += Osd/osdinput
|
||||||
|
MODULES += Extensions/MagBaro
|
||||||
MODULES += Telemetry
|
MODULES += Telemetry
|
||||||
MODULES += FirmwareIAP
|
MODULES += FirmwareIAP
|
||||||
|
|
||||||
@ -94,6 +137,7 @@ OPUAVSYNTHDIR = $(OUTDIR)/../uavobject-synthetics/flight
|
|||||||
# use file-extension c for "c-only"-files
|
# use file-extension c for "c-only"-files
|
||||||
|
|
||||||
## MODULES
|
## MODULES
|
||||||
|
SRC += ${foreach MOD, ${OPTMODULES}, ${wildcard ${OPMODULEDIR}/${MOD}/*.c}}
|
||||||
SRC += ${foreach MOD, ${MODULES}, ${wildcard ${OPMODULEDIR}/${MOD}/*.c}}
|
SRC += ${foreach MOD, ${MODULES}, ${wildcard ${OPMODULEDIR}/${MOD}/*.c}}
|
||||||
## OPENPILOT CORE:
|
## OPENPILOT CORE:
|
||||||
SRC += ${OPMODULEDIR}/System/systemmod.c
|
SRC += ${OPMODULEDIR}/System/systemmod.c
|
||||||
@ -135,8 +179,8 @@ SRC += $(OPUAVSYNTHDIR)/systemsettings.c
|
|||||||
#SRC += $(OPUAVSYNTHDIR)/attituderaw.c
|
#SRC += $(OPUAVSYNTHDIR)/attituderaw.c
|
||||||
SRC += $(OPUAVSYNTHDIR)/attitudeactual.c
|
SRC += $(OPUAVSYNTHDIR)/attitudeactual.c
|
||||||
#SRC += $(OPUAVSYNTHDIR)/manualcontrolcommand.c
|
#SRC += $(OPUAVSYNTHDIR)/manualcontrolcommand.c
|
||||||
#SRC += $(OPUAVSYNTHDIR)/i2cstats.c
|
SRC += $(OPUAVSYNTHDIR)/i2cstats.c
|
||||||
#S#RC += $(OPUAVSYNTHDIR)/watchdogstatus.c
|
SRC += $(OPUAVSYNTHDIR)/watchdogstatus.c
|
||||||
#SRC += $(OPUAVSYNTHDIR)/telemetrysettings.c
|
#SRC += $(OPUAVSYNTHDIR)/telemetrysettings.c
|
||||||
#SRC += $(OPUAVSYNTHDIR)/manualcontrolsettings.c
|
#SRC += $(OPUAVSYNTHDIR)/manualcontrolsettings.c
|
||||||
#SRC += $(OPUAVSYNTHDIR)/mixersettings.c
|
#SRC += $(OPUAVSYNTHDIR)/mixersettings.c
|
||||||
@ -157,10 +201,13 @@ SRC += $(OPUAVSYNTHDIR)/gpssettings.c
|
|||||||
SRC += $(OPUAVSYNTHDIR)/gpsvelocity.c
|
SRC += $(OPUAVSYNTHDIR)/gpsvelocity.c
|
||||||
SRC += $(OPUAVSYNTHDIR)/gpstime.c
|
SRC += $(OPUAVSYNTHDIR)/gpstime.c
|
||||||
SRC += $(OPUAVSYNTHDIR)/osdsettings.c
|
SRC += $(OPUAVSYNTHDIR)/osdsettings.c
|
||||||
|
SRC += $(OPUAVSYNTHDIR)/baroaltitude.c
|
||||||
|
SRC += $(OPUAVSYNTHDIR)/magnetometer.c
|
||||||
|
|
||||||
## PIOS Hardware (Common)
|
## PIOS Hardware (Common)
|
||||||
SRC += $(PIOSCOMMON)/pios_com.c
|
SRC += $(PIOSCOMMON)/pios_com.c
|
||||||
#SRC += $(PIOSCOMMON)/pios_hmc5843.c
|
SRC += $(PIOSCOMMON)/pios_bmp085.c
|
||||||
|
SRC += $(PIOSCOMMON)/pios_hmc5883.c
|
||||||
#SRC += $(PIOSCOMMON)/printf-stdarg.c
|
#SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||||
SRC += $(PIOSCOMMON)/printf2.c
|
SRC += $(PIOSCOMMON)/printf2.c
|
||||||
SRC += $(PIOSCOMMON)/pios_crc.c
|
SRC += $(PIOSCOMMON)/pios_crc.c
|
||||||
@ -228,7 +275,7 @@ EXTRAINCDIRS += $(OPUAVSYNTHDIR)
|
|||||||
EXTRAINCDIRS += $(BOOTINC)
|
EXTRAINCDIRS += $(BOOTINC)
|
||||||
EXTRAINCDIRS += $(HWDEFSINC)
|
EXTRAINCDIRS += $(HWDEFSINC)
|
||||||
|
|
||||||
EXTRAINCDIRS += ${foreach MOD, ${MODULES}, ${OPMODULEDIR}/${MOD}/inc} ${OPMODULEDIR}/System/inc
|
EXTRAINCDIRS += ${foreach MOD, ${OPTMODULES} ${MODULES}, ${OPMODULEDIR}/${MOD}/inc} ${OPMODULEDIR}/System/inc
|
||||||
|
|
||||||
# List any extra directories to look for library files here.
|
# List any extra directories to look for library files here.
|
||||||
# Also add directories where the linker should search for
|
# Also add directories where the linker should search for
|
||||||
@ -266,8 +313,8 @@ endif
|
|||||||
CFLAGS += $(ARCHFLAGS)
|
CFLAGS += $(ARCHFLAGS)
|
||||||
|
|
||||||
|
|
||||||
#CFLAGS += -DDIAGNOSTICS
|
CFLAGS += -DDIAGNOSTICS
|
||||||
#CFLAGS += -DDIAG_TASKS
|
CFLAGS += -DDIAG_TASKS
|
||||||
|
|
||||||
# This is not the best place for these. Really should abstract out
|
# This is not the best place for these. Really should abstract out
|
||||||
# to the board file or something
|
# to the board file or something
|
||||||
@ -292,6 +339,9 @@ CDEFS += -DSYSCLK_FREQ=$(SYSCLK_FREQ)
|
|||||||
CDEFS += -DUSE_STDPERIPH_DRIVER
|
CDEFS += -DUSE_STDPERIPH_DRIVER
|
||||||
CDEFS += -DUSE_$(BOARD)
|
CDEFS += -DUSE_$(BOARD)
|
||||||
|
|
||||||
|
# Declare all non-optional modules as built-in to force inclusion
|
||||||
|
CDEFS += $(foreach MOD, $(notdir $(MODULES)), -DMODULE_$(MOD)_BUILTIN)
|
||||||
|
|
||||||
# Place project-specific -D and/or -U options for
|
# Place project-specific -D and/or -U options for
|
||||||
# Assembler with preprocessor here.
|
# Assembler with preprocessor here.
|
||||||
#ADEFS = -DUSE_IRQ_ASM_WRAPPER
|
#ADEFS = -DUSE_IRQ_ASM_WRAPPER
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
/* Enable/Disable PiOS Modules */
|
/* Enable/Disable PiOS Modules */
|
||||||
#define PIOS_INCLUDE_ADC
|
#define PIOS_INCLUDE_ADC
|
||||||
#define PIOS_INCLUDE_DELAY
|
#define PIOS_INCLUDE_DELAY
|
||||||
//#define PIOS_INCLUDE_I2C
|
#define PIOS_INCLUDE_I2C
|
||||||
#define PIOS_INCLUDE_IRQ
|
#define PIOS_INCLUDE_IRQ
|
||||||
#define PIOS_INCLUDE_LED
|
#define PIOS_INCLUDE_LED
|
||||||
#define PIOS_INCLUDE_IAP
|
#define PIOS_INCLUDE_IAP
|
||||||
@ -57,6 +57,8 @@
|
|||||||
#define PIOS_INCLUDE_COM_AUX
|
#define PIOS_INCLUDE_COM_AUX
|
||||||
#define PIOS_INCLUDE_GPS
|
#define PIOS_INCLUDE_GPS
|
||||||
//#define PIOS_OVERO_SPI
|
//#define PIOS_OVERO_SPI
|
||||||
|
#define PIOS_INCLUDE_BMP085
|
||||||
|
#define PIOS_INCLUDE_HMC5883
|
||||||
|
|
||||||
/* Supported receiver interfaces */
|
/* Supported receiver interfaces */
|
||||||
//#define PIOS_INCLUDE_RCVR
|
//#define PIOS_INCLUDE_RCVR
|
||||||
|
@ -247,6 +247,7 @@ void PIOS_Board_Init(void) {
|
|||||||
EventDispatcherInitialize();
|
EventDispatcherInitialize();
|
||||||
UAVObjInitialize();
|
UAVObjInitialize();
|
||||||
|
|
||||||
|
HwSettingsInitialize();
|
||||||
|
|
||||||
/* Initialize the alarms library */
|
/* Initialize the alarms library */
|
||||||
AlarmsInitialize();
|
AlarmsInitialize();
|
||||||
@ -459,6 +460,58 @@ void PIOS_Board_Init(void) {
|
|||||||
#endif /* PIOS_INCLUDE_COM */
|
#endif /* PIOS_INCLUDE_COM */
|
||||||
|
|
||||||
|
|
||||||
|
/* Configure FlexiPort */
|
||||||
|
|
||||||
|
/* uint8_t hwsettings_rv_flexiport;
|
||||||
|
HwSettingsRV_FlexiPortGet(&hwsettings_rv_flexiport);
|
||||||
|
|
||||||
|
switch (hwsettings_rv_flexiport) {
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_DISABLED:
|
||||||
|
break;
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_I2C:*/
|
||||||
|
#if defined(PIOS_INCLUDE_I2C)
|
||||||
|
{
|
||||||
|
if (PIOS_I2C_Init(&pios_i2c_flexiport_adapter_id, &pios_i2c_flexiport_adapter_cfg)) {
|
||||||
|
PIOS_Assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* PIOS_INCLUDE_I2C */
|
||||||
|
/* break;
|
||||||
|
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_DSM2:
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_DSMX10BIT:
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_DSMX11BIT:
|
||||||
|
{
|
||||||
|
enum pios_dsm_proto proto;
|
||||||
|
switch (hwsettings_rv_flexiport) {
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_DSM2:
|
||||||
|
proto = PIOS_DSM_PROTO_DSM2;
|
||||||
|
break;
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_DSMX10BIT:
|
||||||
|
proto = PIOS_DSM_PROTO_DSMX10BIT;
|
||||||
|
break;
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_DSMX11BIT:
|
||||||
|
proto = PIOS_DSM_PROTO_DSMX11BIT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
PIOS_Assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//TODO: Define the various Channelgroup for Revo dsm inputs and handle here
|
||||||
|
PIOS_Board_configure_dsm(&pios_usart_dsm_flexi_cfg, &pios_dsm_flexi_cfg,
|
||||||
|
&pios_usart_com_driver, &proto, MANUALCONTROLSETTINGS_CHANNELGROUPS_DSMMAINPORT,&hwsettings_DSMxBind);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_COMAUX:
|
||||||
|
PIOS_Board_configure_com(&pios_usart_flexi_cfg, PIOS_COM_AUX_RX_BUF_LEN, PIOS_COM_AUX_TX_BUF_LEN, &pios_usart_com_driver, &pios_com_aux_id);
|
||||||
|
break;
|
||||||
|
case HWSETTINGS_RV_FLEXIPORT_COMBRIDGE:
|
||||||
|
PIOS_Board_configure_com(&pios_usart_flexi_cfg, PIOS_COM_BRIDGE_RX_BUF_LEN, PIOS_COM_BRIDGE_TX_BUF_LEN, &pios_usart_com_driver, &pios_com_bridge_id);
|
||||||
|
break;
|
||||||
|
}*/
|
||||||
|
/* hwsettings_rv_flexiport */
|
||||||
|
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
/* Preconfiguration before using DAC----------------------------------------*/
|
/* Preconfiguration before using DAC----------------------------------------*/
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
|
@ -267,5 +267,19 @@ extern uint32_t pios_com_telem_usb_id;
|
|||||||
#define PIOS_USB_ENABLED 1 /* Should remove all references to this */
|
#define PIOS_USB_ENABLED 1 /* Should remove all references to this */
|
||||||
#define PIOS_USB_HID_MAX_DEVS 1
|
#define PIOS_USB_HID_MAX_DEVS 1
|
||||||
|
|
||||||
|
//------------------------
|
||||||
|
// PIOS_I2C
|
||||||
|
// See also pios_board.c
|
||||||
|
//------------------------
|
||||||
|
#define PIOS_I2C_MAX_DEVS 1
|
||||||
|
extern uint32_t pios_i2c_flexiport_adapter_id;
|
||||||
|
#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_flexiport_adapter_id)
|
||||||
|
#define PIOS_I2C_ESC_ADAPTER (pios_i2c_flexiport_adapter_id)
|
||||||
|
#define PIOS_I2C_BMP085_ADAPTER (pios_i2c_flexiport_adapter_id)
|
||||||
|
|
||||||
|
//------------------------
|
||||||
|
// PIOS_BMP085
|
||||||
|
//------------------------
|
||||||
|
#define PIOS_BMP085_OVERSAMPLING 3
|
||||||
|
|
||||||
#endif /* PIOS_BOARD_H */
|
#endif /* PIOS_BOARD_H */
|
||||||
|
@ -141,8 +141,8 @@ void PIOS_BMP085_Init(void)
|
|||||||
|
|
||||||
/* Read all 22 bytes of calibration data in one transfer, this is a very optimized way of doing things */
|
/* Read all 22 bytes of calibration data in one transfer, this is a very optimized way of doing things */
|
||||||
uint8_t Data[BMP085_CALIB_LEN];
|
uint8_t Data[BMP085_CALIB_LEN];
|
||||||
while (!PIOS_BMP085_Read(BMP085_CALIB_ADDR, Data, BMP085_CALIB_LEN))
|
PIOS_BMP085_Read(BMP085_CALIB_ADDR, Data, BMP085_CALIB_LEN);
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
/* Parameters AC1-AC6 */
|
/* Parameters AC1-AC6 */
|
||||||
CalibData.AC1 = (Data[0] << 8) | Data[1];
|
CalibData.AC1 = (Data[0] << 8) | Data[1];
|
||||||
@ -171,10 +171,10 @@ void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type)
|
|||||||
{
|
{
|
||||||
/* Start the conversion */
|
/* Start the conversion */
|
||||||
if (Type == TemperatureConv) {
|
if (Type == TemperatureConv) {
|
||||||
while (!PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_TEMP_ADDR))
|
while (PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_TEMP_ADDR) != 0)
|
||||||
continue;
|
continue;
|
||||||
} else if (Type == PressureConv) {
|
} else if (Type == PressureConv) {
|
||||||
while (!PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_PRES_ADDR))
|
while (PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_PRES_ADDR) != 0)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,8 +196,8 @@ void PIOS_BMP085_ReadADC(void)
|
|||||||
/* Read and store the 16bit result */
|
/* Read and store the 16bit result */
|
||||||
if (CurrentRead == TemperatureConv) {
|
if (CurrentRead == TemperatureConv) {
|
||||||
/* Read the temperature conversion */
|
/* Read the temperature conversion */
|
||||||
while (!PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 2))
|
PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 2);
|
||||||
continue;
|
// continue;
|
||||||
RawTemperature = ((Data[0] << 8) | Data[1]);
|
RawTemperature = ((Data[0] << 8) | Data[1]);
|
||||||
|
|
||||||
X1 = (RawTemperature - CalibData.AC6) * CalibData.AC5 >> 15;
|
X1 = (RawTemperature - CalibData.AC6) * CalibData.AC5 >> 15;
|
||||||
@ -206,8 +206,8 @@ void PIOS_BMP085_ReadADC(void)
|
|||||||
Temperature = (B5 + 8) >> 4;
|
Temperature = (B5 + 8) >> 4;
|
||||||
} else {
|
} else {
|
||||||
/* Read the pressure conversion */
|
/* Read the pressure conversion */
|
||||||
while (!PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 3))
|
PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 3);
|
||||||
continue;
|
// continue;
|
||||||
RawPressure = ((Data[0] << 16) | (Data[1] << 8) | Data[2]) >> (8 - BMP085_OVERSAMPLING);
|
RawPressure = ((Data[0] << 16) | (Data[1] << 8) | Data[2]) >> (8 - BMP085_OVERSAMPLING);
|
||||||
|
|
||||||
B6 = B5 - 4000;
|
B6 = B5 - 4000;
|
||||||
|
@ -54,8 +54,10 @@ void PIOS_HMC5883_Init(const struct pios_hmc5883_cfg * cfg)
|
|||||||
{
|
{
|
||||||
dev_cfg = cfg; // store config before enabling interrupt
|
dev_cfg = cfg; // store config before enabling interrupt
|
||||||
|
|
||||||
|
#ifdef PIOS_HMC5883_HAS_GPIOS
|
||||||
PIOS_EXTI_Init(cfg->exti_cfg);
|
PIOS_EXTI_Init(cfg->exti_cfg);
|
||||||
|
#endif
|
||||||
|
|
||||||
int32_t val = PIOS_HMC5883_Config(cfg);
|
int32_t val = PIOS_HMC5883_Config(cfg);
|
||||||
|
|
||||||
PIOS_Assert(val == 0);
|
PIOS_Assert(val == 0);
|
||||||
|
@ -93,7 +93,9 @@
|
|||||||
|
|
||||||
|
|
||||||
struct pios_hmc5883_cfg {
|
struct pios_hmc5883_cfg {
|
||||||
|
#ifdef PIOS_HMC5883_HAS_GPIOS
|
||||||
const struct pios_exti_cfg * exti_cfg; /* Pointer to the EXTI configuration */
|
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 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 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 Gain; /* Gain Configuration, select the full scale --> here below the relative define (See datasheet page 11 for more details) */
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
/* Select the sensors to include */
|
/* Select the sensors to include */
|
||||||
#define PIOS_INCLUDE_BMA180
|
#define PIOS_INCLUDE_BMA180
|
||||||
#define PIOS_INCLUDE_HMC5883
|
#define PIOS_INCLUDE_HMC5883
|
||||||
|
#define PIOS_HMC5883_HAS_GPIOS
|
||||||
#define PIOS_INCLUDE_MPU6000
|
#define PIOS_INCLUDE_MPU6000
|
||||||
#define PIOS_MPU6000_ACCEL
|
#define PIOS_MPU6000_ACCEL
|
||||||
#define PIOS_INCLUDE_L3GD20
|
#define PIOS_INCLUDE_L3GD20
|
||||||
|
@ -223,6 +223,83 @@ static const struct pios_usart_cfg pios_usart_telem_main_cfg = {
|
|||||||
|
|
||||||
#endif /* PIOS_INCLUDE_COM */
|
#endif /* PIOS_INCLUDE_COM */
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_I2C)
|
||||||
|
|
||||||
|
#include <pios_i2c_priv.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* I2C Adapters
|
||||||
|
*/
|
||||||
|
void PIOS_I2C_flexiport_adapter_ev_irq_handler(void);
|
||||||
|
void PIOS_I2C_flexiport_adapter_er_irq_handler(void);
|
||||||
|
void I2C2_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_flexiport_adapter_ev_irq_handler")));
|
||||||
|
void I2C2_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_flexiport_adapter_er_irq_handler")));
|
||||||
|
|
||||||
|
static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = {
|
||||||
|
.regs = I2C2,
|
||||||
|
.remap = GPIO_AF_I2C2,
|
||||||
|
.init = {
|
||||||
|
.I2C_Mode = I2C_Mode_I2C,
|
||||||
|
.I2C_OwnAddress1 = 0,
|
||||||
|
.I2C_Ack = I2C_Ack_Enable,
|
||||||
|
.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
|
||||||
|
.I2C_DutyCycle = I2C_DutyCycle_2,
|
||||||
|
.I2C_ClockSpeed = 400000, /* bits/s */
|
||||||
|
},
|
||||||
|
.transfer_timeout_ms = 50,
|
||||||
|
.scl = {
|
||||||
|
.gpio = GPIOB,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_10,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF,
|
||||||
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
|
.GPIO_OType = GPIO_OType_OD,
|
||||||
|
.GPIO_PuPd = GPIO_PuPd_NOPULL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.sda = {
|
||||||
|
.gpio = GPIOB,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_11,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF,
|
||||||
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
|
.GPIO_OType = GPIO_OType_OD,
|
||||||
|
.GPIO_PuPd = GPIO_PuPd_NOPULL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.event = {
|
||||||
|
.flags = 0, /* FIXME: check this */
|
||||||
|
.init = {
|
||||||
|
.NVIC_IRQChannel = I2C2_EV_IRQn,
|
||||||
|
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
|
||||||
|
.NVIC_IRQChannelSubPriority = 0,
|
||||||
|
.NVIC_IRQChannelCmd = ENABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.error = {
|
||||||
|
.flags = 0, /* FIXME: check this */
|
||||||
|
.init = {
|
||||||
|
.NVIC_IRQChannel = I2C2_ER_IRQn,
|
||||||
|
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
|
||||||
|
.NVIC_IRQChannelSubPriority = 0,
|
||||||
|
.NVIC_IRQChannelCmd = ENABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t pios_i2c_flexiport_adapter_id;
|
||||||
|
void PIOS_I2C_flexiport_adapter_ev_irq_handler(void)
|
||||||
|
{
|
||||||
|
/* Call into the generic code to handle the IRQ for this specific device */
|
||||||
|
PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexiport_adapter_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PIOS_I2C_flexiport_adapter_er_irq_handler(void)
|
||||||
|
{
|
||||||
|
/* Call into the generic code to handle the IRQ for this specific device */
|
||||||
|
PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexiport_adapter_id);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_RTC)
|
#if defined(PIOS_INCLUDE_RTC)
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user