From ec6d5502252295db0881f17807d01b192fb23888 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 12 Nov 2011 21:34:47 -0500 Subject: [PATCH 1/8] i2c: allow i2c adapters to remap pin functions Allows us to support more complex pin configurations for i2c. --- flight/PiOS/STM32F10x/pios_i2c.c | 4 ++++ flight/PiOS/inc/pios_i2c_priv.h | 1 + 2 files changed, 5 insertions(+) diff --git a/flight/PiOS/STM32F10x/pios_i2c.c b/flight/PiOS/STM32F10x/pios_i2c.c index 90c208133..e1bdb44f8 100644 --- a/flight/PiOS/STM32F10x/pios_i2c.c +++ b/flight/PiOS/STM32F10x/pios_i2c.c @@ -891,6 +891,10 @@ int32_t PIOS_I2C_Init(uint32_t * i2c_id, const struct pios_i2c_adapter_cfg * cfg break; } + if (i2c_adapter->cfg->remap) { + GPIO_PinRemapConfig(i2c_adapter->cfg->remap, ENABLE); + } + /* Initialize the state machine */ i2c_adapter_fsm_init(i2c_adapter); diff --git a/flight/PiOS/inc/pios_i2c_priv.h b/flight/PiOS/inc/pios_i2c_priv.h index 5834fef34..a10fe0603 100644 --- a/flight/PiOS/inc/pios_i2c_priv.h +++ b/flight/PiOS/inc/pios_i2c_priv.h @@ -37,6 +37,7 @@ struct pios_i2c_adapter_cfg { uint32_t transfer_timeout_ms; struct stm32_gpio scl; struct stm32_gpio sda; + uint32_t remap; struct stm32_irq event; struct stm32_irq error; }; From feacec468d6b0127716fa23183977faa2fa4abad Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 12 Nov 2011 21:39:41 -0500 Subject: [PATCH 2/8] i2c: compile-time decoupling of i2c devices from adapters This allows each device to be moved (at compile time) to a different adapter. This is the first step to allowing devices to be attached to different i2c adapters. --- flight/PiOS/Boards/STM32103CB_CC_Rev1.h | 1 + flight/PiOS/Boards/STM3210E_OP.h | 1 + flight/PiOS/Common/pios_i2c_esc.c | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h index 437a49109..ff37debdc 100644 --- a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h @@ -112,6 +112,7 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1 #define PIOS_I2C_MAX_DEVS 1 extern uint32_t pios_i2c_main_adapter_id; #define PIOS_I2C_MAIN_ADAPTER (pios_i2c_main_adapter_id) +#define PIOS_I2C_ESC_ADAPTER (pios_i2c_main_adapter_id) //------------------------- // SPI diff --git a/flight/PiOS/Boards/STM3210E_OP.h b/flight/PiOS/Boards/STM3210E_OP.h index a7754c2ed..1cc4249f3 100644 --- a/flight/PiOS/Boards/STM3210E_OP.h +++ b/flight/PiOS/Boards/STM3210E_OP.h @@ -115,6 +115,7 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8 #define PIOS_I2C_MAX_DEVS 1 extern uint32_t pios_i2c_main_adapter_id; #define PIOS_I2C_MAIN_ADAPTER (pios_i2c_main_adapter_id) +#define PIOS_I2C_ESC_ADAPTER (pios_i2c_main_adapter_id) //------------------------ // PIOS_BMP085 diff --git a/flight/PiOS/Common/pios_i2c_esc.c b/flight/PiOS/Common/pios_i2c_esc.c index fdb58eba0..d440bfa48 100644 --- a/flight/PiOS/Common/pios_i2c_esc.c +++ b/flight/PiOS/Common/pios_i2c_esc.c @@ -93,7 +93,7 @@ bool PIOS_I2C_ESC_SetSpeed(uint8_t speed[4]) } }; - return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); + return PIOS_I2C_Transfer(PIOS_I2C_ESC_ADAPTER, txn_list, NELEMENTS(txn_list)); } bool PIOS_SetMKSpeed(uint8_t motornum, uint8_t speed) { @@ -115,7 +115,7 @@ bool PIOS_SetMKSpeed(uint8_t motornum, uint8_t speed) { } }; - return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); + return PIOS_I2C_Transfer(PIOS_I2C_ESC_ADAPTER, txn_list, NELEMENTS(txn_list)); } bool PIOS_SetAstec4Address(uint8_t new_address) { @@ -134,7 +134,7 @@ bool PIOS_SetAstec4Address(uint8_t new_address) { } }; - return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); + return PIOS_I2C_Transfer(PIOS_I2C_ESC_ADAPTER, txn_list, NELEMENTS(txn_list)); } bool PIOS_SetAstec4Speed(uint8_t motornum, uint8_t speed) { @@ -161,7 +161,7 @@ bool PIOS_SetAstec4Speed(uint8_t motornum, uint8_t speed) { } }; - return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); + return PIOS_I2C_Transfer(PIOS_I2C_ESC_ADAPTER, txn_list, NELEMENTS(txn_list)); } #endif From a0089f072a03d878403efdfe2f263e0379a1a0c7 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 12 Nov 2011 21:50:53 -0500 Subject: [PATCH 3/8] i2c: rename main adapter to flexi adapter on CC --- flight/CopterControl/System/pios_board.c | 20 ++++++++++---------- flight/PiOS/Boards/STM32103CB_CC_Rev1.h | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/flight/CopterControl/System/pios_board.c b/flight/CopterControl/System/pios_board.c index ffdde4759..4e0495776 100644 --- a/flight/CopterControl/System/pios_board.c +++ b/flight/CopterControl/System/pios_board.c @@ -903,12 +903,12 @@ const struct pios_pwm_cfg pios_pwm_cfg = { * I2C Adapters */ -void PIOS_I2C_main_adapter_ev_irq_handler(void); -void PIOS_I2C_main_adapter_er_irq_handler(void); -void I2C2_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_main_adapter_ev_irq_handler"))); -void I2C2_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_main_adapter_er_irq_handler"))); +void PIOS_I2C_flexi_adapter_ev_irq_handler(void); +void PIOS_I2C_flexi_adapter_er_irq_handler(void); +void I2C2_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_flexi_adapter_ev_irq_handler"))); +void I2C2_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_flexi_adapter_er_irq_handler"))); -static const struct pios_i2c_adapter_cfg pios_i2c_main_adapter_cfg = { +static const struct pios_i2c_adapter_cfg pios_i2c_flexi_adapter_cfg = { .regs = I2C2, .init = { .I2C_Mode = I2C_Mode_I2C, @@ -955,17 +955,17 @@ static const struct pios_i2c_adapter_cfg pios_i2c_main_adapter_cfg = { }, }; -uint32_t pios_i2c_main_adapter_id; -void PIOS_I2C_main_adapter_ev_irq_handler(void) +uint32_t pios_i2c_flexi_adapter_id; +void PIOS_I2C_flexi_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_main_adapter_id); + PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexi_adapter_id); } -void PIOS_I2C_main_adapter_er_irq_handler(void) +void PIOS_I2C_flexi_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_main_adapter_id); + PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexi_adapter_id); } #endif /* PIOS_INCLUDE_I2C */ diff --git a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h index ff37debdc..e908345b7 100644 --- a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h @@ -110,9 +110,9 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1 // See also pios_board.c //------------------------ #define PIOS_I2C_MAX_DEVS 1 -extern uint32_t pios_i2c_main_adapter_id; -#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_main_adapter_id) -#define PIOS_I2C_ESC_ADAPTER (pios_i2c_main_adapter_id) +extern uint32_t pios_i2c_flexi_adapter_id; +#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_flexi_adapter_id) +#define PIOS_I2C_ESC_ADAPTER (pios_i2c_flexi_adapter_id) //------------------------- // SPI From 4cb0c4133855742b00a1a35a1375c1019d0403e4 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Fri, 25 Nov 2011 19:38:16 -0500 Subject: [PATCH 4/8] bmp085: only use eoc and drdy gpios when available When the bmp085 chip is on an external board, we don't have access to the eoc and drdy gpio lines. Only use them when available. --- flight/Modules/Altitude/altitude.c | 8 ++++++++ flight/PiOS/Boards/STM3210E_INS.h | 1 + flight/PiOS/Boards/STM3210E_OP.h | 1 + flight/PiOS/Common/pios_bmp085.c | 10 ++++++++++ flight/PiOS/STM32F10x/pios_exti.c | 2 +- 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/flight/Modules/Altitude/altitude.c b/flight/Modules/Altitude/altitude.c index d1655aaa8..163258c1c 100644 --- a/flight/Modules/Altitude/altitude.c +++ b/flight/Modules/Altitude/altitude.c @@ -144,13 +144,21 @@ static void altitudeTask(void *parameters) #endif // 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(); diff --git a/flight/PiOS/Boards/STM3210E_INS.h b/flight/PiOS/Boards/STM3210E_INS.h index d661e8b96..5973bd168 100644 --- a/flight/PiOS/Boards/STM3210E_INS.h +++ b/flight/PiOS/Boards/STM3210E_INS.h @@ -106,6 +106,7 @@ extern uint32_t pios_i2c_gyro_adapter_id; //------------------------ // PIOS_BMP085 //------------------------ +#define PIOS_BMP085_HAS_GPIOS #define PIOS_BMP085_EOC_GPIO_PORT GPIOC #define PIOS_BMP085_EOC_GPIO_PIN GPIO_Pin_2 #define PIOS_BMP085_EOC_PORT_SOURCE GPIO_PortSourceGPIOC diff --git a/flight/PiOS/Boards/STM3210E_OP.h b/flight/PiOS/Boards/STM3210E_OP.h index 1cc4249f3..87d4ab4a0 100644 --- a/flight/PiOS/Boards/STM3210E_OP.h +++ b/flight/PiOS/Boards/STM3210E_OP.h @@ -120,6 +120,7 @@ extern uint32_t pios_i2c_main_adapter_id; //------------------------ // PIOS_BMP085 //------------------------ +#define PIOS_BMP085_HAS_GPIOS #define PIOS_BMP085_EOC_GPIO_PORT GPIOC #define PIOS_BMP085_EOC_GPIO_PIN GPIO_Pin_15 #define PIOS_BMP085_EOC_PORT_SOURCE GPIO_PortSourceGPIOC diff --git a/flight/PiOS/Common/pios_bmp085.c b/flight/PiOS/Common/pios_bmp085.c index 9a6a2310f..5d3668b2f 100644 --- a/flight/PiOS/Common/pios_bmp085.c +++ b/flight/PiOS/Common/pios_bmp085.c @@ -38,12 +38,17 @@ /* Glocal Variables */ ConversionTypeTypeDef CurrentRead; + +#ifdef PIOS_BMP085_HAS_GPIOS + #if defined(PIOS_INCLUDE_FREERTOS) xSemaphoreHandle PIOS_BMP085_EOC; #else int32_t PIOS_BMP085_EOC; #endif +#endif /* PIOS_BMP085_HAS_GPIOS */ + /* Local Variables */ static BMP085CalibDataTypeDef CalibData; @@ -60,6 +65,9 @@ static volatile uint16_t Temperature; */ void PIOS_BMP085_Init(void) { + +#ifdef PIOS_BMP085_HAS_GPIOS + GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; @@ -101,6 +109,8 @@ void PIOS_BMP085_Init(void) GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(PIOS_BMP085_XCLR_GPIO_PORT, &GPIO_InitStructure); +#endif /* PIOS_BMP085_HAS_GPIOS */ + /* 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]; while (!PIOS_BMP085_Read(BMP085_CALIB_ADDR, Data, BMP085_CALIB_LEN)) diff --git a/flight/PiOS/STM32F10x/pios_exti.c b/flight/PiOS/STM32F10x/pios_exti.c index 0b886666a..0b4a9a1ae 100644 --- a/flight/PiOS/STM32F10x/pios_exti.c +++ b/flight/PiOS/STM32F10x/pios_exti.c @@ -44,7 +44,7 @@ void EXTI15_10_IRQHandler(void) portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; #endif -#if defined(PIOS_INCLUDE_BMP085) +#if defined(PIOS_INCLUDE_BMP085) && defined(PIOS_BMP085_HAS_GPIOS) if (EXTI_GetITStatus(PIOS_BMP085_EOC_EXTI_LINE) != RESET) { /* Read the ADC Value */ #if defined(PIOS_INCLUDE_FREERTOS) From bae08fcad060712eb38fabdf11fe44a1972be3c9 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 10 Dec 2011 19:38:06 -0500 Subject: [PATCH 5/8] bmp085: decouple i2c adapter Let the bmp085 be attached to different adapters for different boards. --- flight/PiOS/Boards/STM3210E_INS.h | 1 + flight/PiOS/Boards/STM3210E_OP.h | 1 + flight/PiOS/Common/pios_bmp085.c | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/flight/PiOS/Boards/STM3210E_INS.h b/flight/PiOS/Boards/STM3210E_INS.h index 5973bd168..37ca4abe3 100644 --- a/flight/PiOS/Boards/STM3210E_INS.h +++ b/flight/PiOS/Boards/STM3210E_INS.h @@ -100,6 +100,7 @@ TIM8 | | | | #define PIOS_I2C_MAX_DEVS 3 extern uint32_t pios_i2c_pres_mag_adapter_id; #define PIOS_I2C_MAIN_ADAPTER (pios_i2c_pres_mag_adapter_id) +#define PIOS_I2C_BMP085_ADAPTER (pios_i2c_pres_mag_adapter_id) extern uint32_t pios_i2c_gyro_adapter_id; #define PIOS_I2C_GYRO_ADAPTER (pios_i2c_gyro_adapter_id) diff --git a/flight/PiOS/Boards/STM3210E_OP.h b/flight/PiOS/Boards/STM3210E_OP.h index 87d4ab4a0..7099234c6 100644 --- a/flight/PiOS/Boards/STM3210E_OP.h +++ b/flight/PiOS/Boards/STM3210E_OP.h @@ -116,6 +116,7 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8 extern uint32_t pios_i2c_main_adapter_id; #define PIOS_I2C_MAIN_ADAPTER (pios_i2c_main_adapter_id) #define PIOS_I2C_ESC_ADAPTER (pios_i2c_main_adapter_id) +#define PIOS_I2C_BMP085_ADAPTER (pios_i2c_main_adapter_id) //------------------------ // PIOS_BMP085 diff --git a/flight/PiOS/Common/pios_bmp085.c b/flight/PiOS/Common/pios_bmp085.c index 5d3668b2f..5a4b0cd94 100644 --- a/flight/PiOS/Common/pios_bmp085.c +++ b/flight/PiOS/Common/pios_bmp085.c @@ -245,7 +245,7 @@ bool PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len) } }; - return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); + return PIOS_I2C_Transfer(PIOS_I2C_BMP085_ADAPTER, txn_list, NELEMENTS(txn_list)); } /** @@ -274,7 +274,7 @@ bool PIOS_BMP085_Write(uint8_t address, uint8_t buffer) , }; - return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); + return PIOS_I2C_Transfer(PIOS_I2C_BMP085_ADAPTER, txn_list, NELEMENTS(txn_list)); } /** From 717c1311e62983889adc5fc34ac8a81bbb474f69 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 14 Jan 2012 15:04:49 -0500 Subject: [PATCH 6/8] altitude: allow altitude to be an optional module --- flight/Modules/Altitude/altitude.c | 66 ++++++++++++++--------- shared/uavobjectdefinition/hwsettings.xml | 2 +- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/flight/Modules/Altitude/altitude.c b/flight/Modules/Altitude/altitude.c index 163258c1c..9c0d5399f 100644 --- a/flight/Modules/Altitude/altitude.c +++ b/flight/Modules/Altitude/altitude.c @@ -37,6 +37,7 @@ */ #include "openpilot.h" +#include "hwsettings.h" #include "altitude.h" #include "baroaltitude.h" // object that will be updated by the module #if defined(PIOS_INCLUDE_HCSR04) @@ -60,6 +61,8 @@ static int32_t alt_ds_temp = 0; static int32_t alt_ds_pres = 0; static int alt_ds_count = 0; +static bool altitudeEnabled; + // Private functions static void altitudeTask(void *parameters); @@ -69,17 +72,19 @@ static void altitudeTask(void *parameters); */ int32_t AltitudeStart() { - - BaroAltitudeInitialize(); -#if defined(PIOS_INCLUDE_HCSR04) - SonarAltitudeInitialze(); -#endif - - // Start main task - xTaskCreate(altitudeTask, (signed char *)"Altitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle); - return 0; + if (altitudeEnabled) { + BaroAltitudeInitialize(); +#if defined(PIOS_INCLUDE_HCSR04) + SonarAltitudeInitialze(); +#endif + + // Start main task + xTaskCreate(altitudeTask, (signed char *)"Altitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); + TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle); + return 0; + } + return -1; } /** @@ -89,10 +94,19 @@ int32_t AltitudeStart() int32_t AltitudeInitialize() { + HwSettingsInitialize(); + uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; + HwSettingsOptionalModulesGet(optionalModules); + if (optionalModules[HWSETTINGS_OPTIONALMODULES_ALTITUDE] == HWSETTINGS_OPTIONALMODULES_ENABLED) { + altitudeEnabled = 1; + } else { + altitudeEnabled = 0; + } + // init down-sampling data - alt_ds_temp = 0; - alt_ds_pres = 0; - alt_ds_count = 0; + alt_ds_temp = 0; + alt_ds_pres = 0; + alt_ds_count = 0; return 0; } @@ -163,23 +177,23 @@ static void altitudeTask(void *parameters) alt_ds_pres += PIOS_BMP085_GetPressure(); if (++alt_ds_count >= alt_ds_size) - { - alt_ds_count = 0; + { + 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 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; + // 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))); + // 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); - } + // Update the AltitudeActual UAVObject + BaroAltitudeSet(&data); + } // Delay until it is time to read the next sample vTaskDelayUntil(&lastSysTime, UPDATE_PERIOD / portTICK_RATE_MS); diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index 24727a080..455e23cd7 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -16,7 +16,7 @@ - + From 53e9ef06b4261feed21e4e8fe3d0261d1560d416 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 14 Jan 2012 15:17:24 -0500 Subject: [PATCH 7/8] altitude: add optional altitude module --- flight/CopterControl/Makefile | 6 ++++-- flight/CopterControl/System/inc/pios_config.h | 2 ++ flight/CopterControl/System/pios_board.c | 2 +- flight/Modules/Altitude/altitude.c | 3 +-- flight/PiOS/Boards/STM32103CB_CC_Rev1.h | 6 ++++++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index 891e7f6c6..7a1653c0e 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -50,7 +50,7 @@ ENABLE_AUX_UART ?= NO USE_GPS ?= YES -USE_I2C ?= NO +USE_I2C ?= YES # Set to YES when using Code Sourcery toolchain CODE_SOURCERY ?= YES @@ -65,7 +65,7 @@ endif FLASH_TOOL = OPENOCD # List of modules to include -OPTMODULES = CameraStab ComUsbBridge +OPTMODULES = CameraStab ComUsbBridge Altitude ifeq ($(USE_GPS), YES) OPTMODULES += GPS endif @@ -182,6 +182,7 @@ SRC += $(OPUAVSYNTHDIR)/receiveractivity.c SRC += $(OPUAVSYNTHDIR)/taskinfo.c SRC += $(OPUAVSYNTHDIR)/mixerstatus.c SRC += $(OPUAVSYNTHDIR)/ratedesired.c +SRC += $(OPUAVSYNTHDIR)/baroaltitude.c endif @@ -225,6 +226,7 @@ SRC += $(PIOSCOMMON)/pios_flash_w25x.c SRC += $(PIOSCOMMON)/pios_adxl345.c SRC += $(PIOSCOMMON)/pios_com.c SRC += $(PIOSCOMMON)/pios_i2c_esc.c +SRC += $(PIOSCOMMON)/pios_bmp085.c SRC += $(PIOSCOMMON)/pios_iap.c SRC += $(PIOSCOMMON)/pios_bl_helper.c SRC += $(PIOSCOMMON)/pios_rcvr.c diff --git a/flight/CopterControl/System/inc/pios_config.h b/flight/CopterControl/System/inc/pios_config.h index 54c5b3b22..9be4387f0 100644 --- a/flight/CopterControl/System/inc/pios_config.h +++ b/flight/CopterControl/System/inc/pios_config.h @@ -76,6 +76,8 @@ #define PIOS_INCLUDE_ADXL345 #define PIOS_INCLUDE_FLASH +#define PIOS_INCLUDE_BMP085 + /* A really shitty setting saving implementation */ #define PIOS_INCLUDE_FLASH_SECTOR_SETTINGS diff --git a/flight/CopterControl/System/pios_board.c b/flight/CopterControl/System/pios_board.c index 4e0495776..a7197768d 100644 --- a/flight/CopterControl/System/pios_board.c +++ b/flight/CopterControl/System/pios_board.c @@ -1464,7 +1464,7 @@ void PIOS_Board_Init(void) { case HWSETTINGS_CC_FLEXIPORT_I2C: #if defined(PIOS_INCLUDE_I2C) { - if (PIOS_I2C_Init(&pios_i2c_main_adapter_id, &pios_i2c_main_adapter_cfg)) { + if (PIOS_I2C_Init(&pios_i2c_flexi_adapter_id, &pios_i2c_flexi_adapter_cfg)) { PIOS_Assert(0); } } diff --git a/flight/Modules/Altitude/altitude.c b/flight/Modules/Altitude/altitude.c index 9c0d5399f..da90b7f7c 100644 --- a/flight/Modules/Altitude/altitude.c +++ b/flight/Modules/Altitude/altitude.c @@ -47,8 +47,7 @@ // Private constants #define STACK_SIZE_BYTES 500 #define TASK_PRIORITY (tskIDLE_PRIORITY+1) -//#define UPDATE_PERIOD 100 -#define UPDATE_PERIOD 25 +#define UPDATE_PERIOD 50 // Private types diff --git a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h index e908345b7..7773b9092 100644 --- a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h @@ -113,6 +113,12 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1 extern uint32_t pios_i2c_flexi_adapter_id; #define PIOS_I2C_MAIN_ADAPTER (pios_i2c_flexi_adapter_id) #define PIOS_I2C_ESC_ADAPTER (pios_i2c_flexi_adapter_id) +#define PIOS_I2C_BMP085_ADAPTER (pios_i2c_flexi_adapter_id) + +//------------------------ +// PIOS_BMP085 +//------------------------ +#define PIOS_BMP085_OVERSAMPLING 3 //------------------------- // SPI From 27ceb7ea92c29f803ac5f3fd0cf12ae970727b96 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 14 Jan 2012 16:55:55 -0500 Subject: [PATCH 8/8] modules: Allow optional modules to be used as built-in Some modules are written such that they can be included or excluded at runtime. These are added to the OPTMODULES list in the makefile for a given board. This change provides a mechanism to allow a build to force a given module to be built-in (ie. always initialized) regardless of the configuration in hwsettings. The main use case for this is to handle a module being optional on one platform but essential on another. All modules added to the MODULES list in the Makefile will automatically result in a matching #define in the form MODULE_TheModuleName_BUILTIN being defined in the CFLAGS for all compiled source. Note that the capitalization of TheModuleName must match exactly the capitalization used in the MODULES list. --- flight/CopterControl/Makefile | 3 +++ flight/Modules/Altitude/altitude.c | 5 ++++- flight/Modules/CameraStab/camerastab.c | 5 +++++ flight/Modules/ComUsbBridge/ComUsbBridge.c | 4 ++++ flight/Modules/Fault/Fault.c | 4 ++++ flight/Modules/GPS/GPS.c | 4 ++++ flight/OpenPilot/Makefile | 3 +++ 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index 7a1653c0e..631a0e7c9 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -412,6 +412,9 @@ ifeq ($(USE_I2C), YES) CDEFS += -DUSE_I2C endif +# Declare all non-optional modules as built-in to force inclusion +CDEFS += ${foreach MOD, ${MODULES}, -DMODULE_$(MOD)_BUILTIN } + # Place project-specific -D and/or -U options for # Assembler with preprocessor here. #ADEFS = -DUSE_IRQ_ASM_WRAPPER diff --git a/flight/Modules/Altitude/altitude.c b/flight/Modules/Altitude/altitude.c index da90b7f7c..87a4240b6 100644 --- a/flight/Modules/Altitude/altitude.c +++ b/flight/Modules/Altitude/altitude.c @@ -92,7 +92,9 @@ int32_t AltitudeStart() */ int32_t AltitudeInitialize() { - +#ifdef MODULE_Altitude_BUILTIN + altitudeEnabled = 1; +#else HwSettingsInitialize(); uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; HwSettingsOptionalModulesGet(optionalModules); @@ -101,6 +103,7 @@ int32_t AltitudeInitialize() } else { altitudeEnabled = 0; } +#endif // init down-sampling data alt_ds_temp = 0; diff --git a/flight/Modules/CameraStab/camerastab.c b/flight/Modules/CameraStab/camerastab.c index 770ff7ab6..0c5b189d9 100644 --- a/flight/Modules/CameraStab/camerastab.c +++ b/flight/Modules/CameraStab/camerastab.c @@ -75,6 +75,10 @@ int32_t CameraStabInitialize(void) static UAVObjEvent ev; bool cameraStabEnabled; + +#ifdef MODULE_CameraStab_BUILTIN + cameraStabEnabled = true; +#else uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; HwSettingsInitialize(); @@ -84,6 +88,7 @@ int32_t CameraStabInitialize(void) cameraStabEnabled = true; else cameraStabEnabled = false; +#endif if (cameraStabEnabled) { diff --git a/flight/Modules/ComUsbBridge/ComUsbBridge.c b/flight/Modules/ComUsbBridge/ComUsbBridge.c index 984a53944..678e7039d 100644 --- a/flight/Modules/ComUsbBridge/ComUsbBridge.c +++ b/flight/Modules/ComUsbBridge/ComUsbBridge.c @@ -94,6 +94,9 @@ static int32_t comUsbBridgeInitialize(void) usart_port = PIOS_COM_BRIDGE; vcp_port = PIOS_COM_VCP; +#ifdef MODULE_ComUsbBridge_BUILTIN + bridge_enabled = true; +#else HwSettingsInitialize(); uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; @@ -104,6 +107,7 @@ static int32_t comUsbBridgeInitialize(void) bridge_enabled = true; else bridge_enabled = false; +#endif if (bridge_enabled) { com2usb_buf = pvPortMalloc(BRIDGE_BUF_LEN); diff --git a/flight/Modules/Fault/Fault.c b/flight/Modules/Fault/Fault.c index 0ac3748a6..868330739 100644 --- a/flight/Modules/Fault/Fault.c +++ b/flight/Modules/Fault/Fault.c @@ -40,6 +40,9 @@ static uint8_t active_fault; static int32_t fault_initialize(void) { +#ifdef MODULE_Fault_BUILTIN + module_enabled = true; +#else HwSettingsInitialize(); uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; @@ -50,6 +53,7 @@ static int32_t fault_initialize(void) } else { module_enabled = false; } +#endif /* Do this outside the module_enabled test so that it * can be changed even when the module has been disabled. diff --git a/flight/Modules/GPS/GPS.c b/flight/Modules/GPS/GPS.c index bc8f92c17..1f93d6dba 100644 --- a/flight/Modules/GPS/GPS.c +++ b/flight/Modules/GPS/GPS.c @@ -121,6 +121,9 @@ int32_t GPSInitialize(void) { gpsPort = PIOS_COM_GPS; +#ifdef MODULE_GPS_BUILTIN + gpsEnabled = true; +#else HwSettingsInitialize(); uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; @@ -130,6 +133,7 @@ int32_t GPSInitialize(void) gpsEnabled = true; else gpsEnabled = false; +#endif if (gpsPort && gpsEnabled) { GPSPositionInitialize(); diff --git a/flight/OpenPilot/Makefile b/flight/OpenPilot/Makefile index 940c1f117..2130bf283 100644 --- a/flight/OpenPilot/Makefile +++ b/flight/OpenPilot/Makefile @@ -369,6 +369,9 @@ ifeq ($(ENABLE_AUX_UART), YES) CDEFS += -DPIOS_ENABLE_AUX_UART endif +# Declare all non-optional modules as built-in to force inclusion +CDEFS += ${foreach MOD, ${MODULES}, -DMODULE_$(MOD)_BUILTIN } + # Place project-specific -D and/or -U options for # Assembler with preprocessor here. #ADEFS = -DUSE_IRQ_ASM_WRAPPER