Merge branch 'master' into dev

This commit is contained in:
Felix Ruess
2011-11-16 17:30:51 +01:00
20 changed files with 444 additions and 98 deletions
+9 -3
View File
@@ -50,7 +50,6 @@ OBJCOPY = $(GCC_BIN_PREFIX)-objcopy
OBJDUMP = $(GCC_BIN_PREFIX)-objdump OBJDUMP = $(GCC_BIN_PREFIX)-objdump
NM = $(GCC_BIN_PREFIX)-nm NM = $(GCC_BIN_PREFIX)-nm
SIZE = $(GCC_BIN_PREFIX)-size SIZE = $(GCC_BIN_PREFIX)-size
OOCD = $(TOOLCHAIN_DIR)/bin/openocd
# #
# If we can't find the toolchain (in /opt/paparazzi/arm-multilib or ~/sat) then try picking up the compilers from the path # If we can't find the toolchain (in /opt/paparazzi/arm-multilib or ~/sat) then try picking up the compilers from the path
@@ -72,7 +71,15 @@ OBJCOPY = $(shell which $(GCC_PREFIX)-objcopy)
OBJDUMP = $(shell which $(GCC_PREFIX)-objdump) OBJDUMP = $(shell which $(GCC_PREFIX)-objdump)
NM = $(shell which $(GCC_PREFIX)-nm) NM = $(shell which $(GCC_PREFIX)-nm)
SIZE = $(shell which $(GCC_PREFIX)-size) SIZE = $(shell which $(GCC_PREFIX)-size)
OOCD = $(shell which openocd) endif
#first try to find OpenOCD in the path
OOCD = $(shell which openocd)
#if OpenOCD could not be found in the path, try the toolchain dir
ifeq ($(OOCD),)
ifneq ($(TOOLCHAIN),)
OOCD = $(shell if test -e $(TOOLCHAIN_DIR)/bin/openocd ; then echo $(TOOLCHAIN_DIR)/bin/openocd ; else echo "Warning: OpenOCD not found"; fi)
endif
endif endif
# Define some other programs and commands. # Define some other programs and commands.
@@ -182,7 +189,6 @@ LPC21IAP = $(PAPARAZZI_SRC)/sw/ground_segment/lpc21iap/lpc21iap
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Flash-Programming support using openocd # Flash-Programming support using openocd
OOCD = openocd
OOCD_INTERFACE = arm-usb-ocd OOCD_INTERFACE = arm-usb-ocd
OOCD_TARGET = csc OOCD_TARGET = csc
+10 -2
View File
@@ -53,7 +53,6 @@ DMP = $(GCC_BIN_PREFIX)-objdump
NM = $(GCC_BIN_PREFIX)-nm NM = $(GCC_BIN_PREFIX)-nm
SIZE = $(GCC_BIN_PREFIX)-size SIZE = $(GCC_BIN_PREFIX)-size
RM = rm RM = rm
OOCD = $(TOOLCHAIN_DIR)/bin/openocd
# If we can't find the toolchain then try picking up the compilers from the path # If we can't find the toolchain then try picking up the compilers from the path
else else
@@ -63,10 +62,19 @@ CP = $(shell which arm-none-eabi-objcopy)
DMP = $(shell which arm-none-eabi-objdump) DMP = $(shell which arm-none-eabi-objdump)
NM = $(shell which arm-none-eabi-nm) NM = $(shell which arm-none-eabi-nm)
SIZE = $(shell which arm-none-eabi-size) SIZE = $(shell which arm-none-eabi-size)
OOCD = $(shell which openocd)
GCC_LIB_DIR=$(shell dirname `which arm-none-eabi-gcc`)/../arm-none-eabi/lib GCC_LIB_DIR=$(shell dirname `which arm-none-eabi-gcc`)/../arm-none-eabi/lib
endif endif
#first try to find OpenOCD in the path
OOCD = $(shell which openocd)
#if OpenOCD could not be found in the path, try the toolchain dir
ifeq ($(OOCD),)
ifneq ($(TOOLCHAIN),)
OOCD = $(shell if test -e $(TOOLCHAIN_DIR)/bin/openocd ; then echo $(TOOLCHAIN_DIR)/bin/openocd ; else echo "Warning: OpenOCD not found"; fi)
endif
endif
LOADER=/home/poine/work/stm32/stm32loader-a3c51c26ad6c/stm32loader.py LOADER=/home/poine/work/stm32/stm32loader-a3c51c26ad6c/stm32loader.py
ifndef $(TARGET).OOCD_INTERFACE ifndef $(TARGET).OOCD_INTERFACE
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE airframe SYSTEM "airframe.dtd">
<!--
Connects a microSD card to the SPI port of the Paparazzi Tiny. Keep cables
short, microSD card can be directly soldered to Molex cable. For now only
non SDHC SD cards (<= 2GB) are supported. martinmm@pfump.org
microSD TinyV2 SPI J3
8 nc
7 DO 5 MISO
6 GND 1 GND
5 CLK 7 SCK
4 Vcc 2 +3V3
3 DI 4 MOSI
2 CS 3 SSEL
1 nc
Looking onto the gold plated connector side of the microSD card:
###############
I 8
I 7
I 6
I 5
I 4
I 3
I 2
I 1
###### ##
\ I \
## ##
-->
<airframe name="Logger">
<firmware name="logger">
<target name="ap" board="tiny_2.11" >
<configure name="SPI_CHANNEL" value="1" />
<configure name="UART0_BAUD" value="B9600" />
<configure name="UART1_BAUD" value="B9600" />
</target>
</firmware>
</airframe>
@@ -1,62 +1,54 @@
<!DOCTYPE airframe SYSTEM "airframe.dtd"> #
# setup.makefile
#
#
<!--
Connects a microSD card to the SPI port of the Paparazzi Tiny. Keep cables CFG_SHARED=$(PAPARAZZI_SRC)/conf/autopilot/subsystems/shared
short, microSD card can be directly soldered to Molex cable. For now only
non SDHC SD cards (<= 2GB) are supported. martinmm@pfump.org
microSD TinyV2 SPI J3 SRC_ARCH=arch/$(ARCH)
8 nc SRC_FIRMWARE=firmwares/logger
7 DO 5 MISO
6 GND 1 GND
5 CLK 7 SCK
4 Vcc 2 +3V3
3 DI 4 MOSI
2 CS 3 SSEL
1 nc
Looking onto the gold plated connector side of the microSD card: SETUP_INC = -I$(SRC_FIRMWARE)
############### $(TARGET).CFLAGS += -DBOARD_CONFIG=$(BOARD_CFG)
I 8
I 7
I 6
I 5
I 4
I 3
I 2
I 1
###### ##
\ I \
## ##
--> # default config
ifndef SPI_CHANNEL
SPI_CHANNEL = 1
endif
<airframe name="Logger"> ifndef UART0_BAUD
UART0_BAUD = B9600
endif
<makefile> ifndef UART1_BAUD
UART1_BAUD = B9600
endif
CONFIG = \"tiny_2_1_1_usb.h\"
include $(PAPARAZZI_SRC)/conf/autopilot/tiny.makefile # a configuration program to access both uart through usb
ifeq ($(ARCH), lpc21)
FLASH_MODE=IAP
ap.CFLAGS += -DBOARD_CONFIG=$(CONFIG) -DUSE_LED ap.CFLAGS += -DUSE_LED
ap.srcs = sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c main_logger.c ap.srcs = sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c $(SRC_FIRMWARE)/main_logger.c
#choose one #choose one
ap.CFLAGS += -DLOG_XBEE ap.CFLAGS += -DLOG_XBEE
#ap.CFLAGS += -DLOG_PPRZ #ap.CFLAGS += -DLOG_PPRZ
#set the speed #set the speed
ap.CFLAGS += -DUSE_UART0 -DUART0_BAUD=B9600 -DUSE_UART0_RX_ONLY ap.CFLAGS += -DUSE_UART0 -DUART0_BAUD=$(UART0_BAUD) -DUSE_UART0_RX_ONLY
ap.CFLAGS += -DUSE_UART1 -DUART1_BAUD=B9600 -DUSE_UART1_RX_ONLY ap.CFLAGS += -DUSE_UART1 -DUART1_BAUD=$(UART1_BAUD) -DUSE_UART1_RX_ONLY
ap.srcs += $(SRC_ARCH)/mcu_periph/uart_arch.c ap.srcs += $(SRC_ARCH)/mcu_periph/uart_arch.c
ap.srcs += mcu_periph/uart.c
ap.srcs += $(SRC_ARCH)/mcu_arch.c
ap.srcs += mcu.c
#set SPI interface for SD card (0 or 1) #set SPI interface for SD card (0 or 1)
ap.CFLAGS += -DHW_ENDPOINT_LPC2000_SPINUM=1 ap.CFLAGS += -DHW_ENDPOINT_LPC2000_SPINUM=$(SPI_CHANNEL)
#efsl #efsl
ap.CFLAGS += -I $(SRC_ARCH)/efsl/inc -I $(SRC_ARCH)/efsl/conf ap.CFLAGS += -I $(SRC_ARCH)/efsl/inc -I $(SRC_ARCH)/efsl/conf
@@ -84,7 +76,9 @@ ap.srcs += $(SRC_ARCH)/lpcusb/examples/msc_scsi.c
ap.srcs += $(SRC_ARCH)/lpcusb/examples/blockdev_sd.c ap.srcs += $(SRC_ARCH)/lpcusb/examples/blockdev_sd.c
ap.srcs += $(SRC_ARCH)/lpcusb/examples/lpc2000_spi.c ap.srcs += $(SRC_ARCH)/lpcusb/examples/lpc2000_spi.c
</makefile>
</airframe> else
$(error usb_tunnel currently only implemented for the lpc21)
endif
+43
View File
@@ -0,0 +1,43 @@
<!DOCTYPE module SYSTEM "./module.dtd">
<!--
// Use (parts of) the following section in airframe file to change
<section name="DIGITAL_CAMERA" prefix="DC_">
<configure name="PUSH" value"LED_ON" />
<configure name="RELEASE" value"LED_OFF" />
<configure name="AUTOSHOOT_QUARTERSEC_PERIOD" value="6" unit="quarter_second"/>
<configure name="AUTOSHOOT_METER_GRID" value="50" unit="meter"/>
</section>
# ap.CFLAGS += -DGPS_TRIGGERED_FUNCTION="dc_shoot_on_gps"
# ap.CFLAGS += -DDC_GPS_TRIGGER_START=1
# ap.CFLAGS += -DDC_GPS_TRIGGER_STOP=3
-->
<module name="digital_cam_servo" dir="digital_cam">
<header>
<file name="servo_cam_ctrl.h"/>
</header>
<init fun="servo_cam_ctrl_init()"/>
<periodic fun="servo_cam_ctrl_periodic()" freq="4" autorun="TRUE"/>
<makefile >
<define name="DIGITAL_CAM" />
<file name="servo_cam_ctrl.c"/>
<file name="dc.c"/>
<define name="SENSOR_SYNC_SEND" value="1" />
</makefile>
</module>
+7 -4
View File
@@ -74,13 +74,16 @@ void imu_impl_init(void)
void imu_periodic( void ) void imu_periodic( void )
{ {
// Start reading the latest gyroscope data // Start reading the latest gyroscope data
itg3200_periodic(); Itg3200Periodic();
// Start reading the latest accelerometer data // Start reading the latest accelerometer data
adxl345_periodic(); // Periodicity is automatically adapted
// 3200 is the maximum output freq corresponding to the parameter 0xF
// A factor 2 is applied to reduice the delay without overloading the i2c
RunOnceEvery((PERIODIC_FREQUENCY/(2*3200>>(0xf-ADXL345_BW_RATE))),Adxl345Periodic());
// Read HMC58XX at 50Hz (main loop for rotorcraft: 512Hz) // Read HMC58XX at 100Hz (main loop for rotorcraft: 512Hz)
RunOnceEvery(10,hmc58xx_periodic()); RunOnceEvery(5,Hmc58xxPeriodic());
//RunOnceEvery(20,imu_navgo_downlink_raw()); //RunOnceEvery(20,imu_navgo_downlink_raw());
} }
+11 -1
View File
@@ -51,6 +51,16 @@
#define DefaultVoltageOfAdc(adc) (0.01837*adc) #define DefaultVoltageOfAdc(adc) (0.01837*adc)
/* SPI (SSP) */
#define SPI_SELECT_SLAVE0_PORT 0
#define SPI_SELECT_SLAVE0_PIN 20
#define SPI1_DRDY_PINSEL PINSEL1
#define SPI1_DRDY_PINSEL_BIT 0
#define SPI1_DRDY_PINSEL_VAL 1
#define SPI1_DRDY_EINT 0
#define SPI1_DRDY_VIC_IT VIC_EINT0
/* PWM0 (internal PWM5) */ /* PWM0 (internal PWM5) */
/* P0.21 */ /* P0.21 */
#define PWM0_PINSEL PINSEL1 #define PWM0_PINSEL PINSEL1
@@ -65,4 +75,4 @@
#define BOARD_HAS_BARO #define BOARD_HAS_BARO
#endif /* CONFIG_UMARIM_V1_0_H */ #endif /* CONFIG_NAVGO_V1_0_H */
+2 -2
View File
@@ -69,10 +69,10 @@ void imu_impl_init(void)
void imu_periodic( void ) void imu_periodic( void )
{ {
// Start reading the latest gyroscope data // Start reading the latest gyroscope data
itg3200_periodic(); Itg3200Periodic();
// Start reading the latest accelerometer data // Start reading the latest accelerometer data
adxl345_periodic(); Adxl345Periodic();
//RunOnceEvery(10,imu_umarim_downlink_raw()); //RunOnceEvery(10,imu_umarim_downlink_raw());
} }
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2010 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi 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 2, or (at your option)
* any later version.
*
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "servo_cam_ctrl.h"
// Button Timer
uint8_t dc_timer;
@@ -0,0 +1,132 @@
/*
* Copyright (C) 2010 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi 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 2, or (at your option)
* any later version.
*
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/** \file servo_cam_ctrl.h
* \brief Digital Camera Control
*
* Provides the control of the shutter and the zoom of a digital camera
* through standard binary IOs of the board.
*
* Configuration:
* Since the API of led.h is used, connected pins must be defined as led
* numbers (usually in the airframe file):
* <define name="DC_SHUTTER_SERVO" value="6"/>
* <define name="DC_ZOOM_IN_SERVO" value="7"/>
* <define name="DC_ZOOM_OUT_SERVO" value="8"/>
* <define name="DC_POWER_SERVO" value="9"/>
* Related bank and pin must also be defined:
* <define name="LED_6_BANK" value="0"/>
* <define name="LED_6_PIN" value="2"/>
* The required initialization (dc_init()) and periodic (4Hz) process
*
*/
#ifndef servo_cam_ctrl_H
#define servo_cam_ctrl_H
// Include Standard Camera Control Interface
#include "dc.h"
// Include Servo and airframe servo channels
#include "std.h"
#include "commands.h"
#include "generated/airframe.h"
extern uint8_t dc_timer;
static inline void servo_cam_ctrl_init(void)
{
// Call common DC init
dc_init();
// Do LED specific DC init
dc_timer = 0;
}
#define DC_PUSH(X) commands[X] = -MAX_PPRZ;
#define DC_RELEASE(X) commands[X] = MAX_PPRZ;
#ifndef DC_SHUTTER_DELAY
#define DC_SHUTTER_DELAY 2 /* 4Hz -> 0.5s */
#endif
#ifndef DC_SHUTTER_SERVO
#error DC: Please specify at least a SHUTTER SERVO
#endif
/* Command The Camera */
static inline void dc_send_command(uint8_t cmd)
{
dc_timer = DC_SHUTTER_DELAY;
switch (cmd)
{
case DC_SHOOT:
DC_PUSH(DC_SHUTTER_SERVO);
dc_send_shot_position();
break;
#ifdef DC_ZOOM_IN_SERVO
case DC_TALLER:
DC_PUSH(DC_ZOOM_IN_SERVO);
break;
#endif
#ifdef DC_ZOOM_OUT_SERVO
case DC_WIDER:
DC_PUSH(DC_ZOOM_OUT_SERVO);
break;
#endif
#ifdef DC_POWER_SERVO
case DC_POWER:
DC_PUSH(DC_POWER_SERVO);
break;
#endif
}
}
/* 4Hz Periodic */
static inline void servo_cam_ctrl_periodic( void )
{
if (dc_timer) {
dc_timer--;
} else {
DC_RELEASE(DC_SHUTTER_SERVO);
#ifdef DC_ZOOM_IN_SERVO
DC_RELEASE(DC_ZOOM_IN_SERVO);
#endif
#ifdef DC_ZOOM_OUT_SERVO
DC_RELEASE(DC_ZOOM_OUT_SERVO);
#endif
#ifdef DC_POWER_SERVO
DC_RELEASE(DC_POWER_SERVO);
#endif
}
// Common DC Periodic task
dc_periodic_4Hz();
}
#endif // DC_H
+10 -1
View File
@@ -67,6 +67,8 @@
#define ADXL345_I2C_DEVICE i2c1 #define ADXL345_I2C_DEVICE i2c1
#endif #endif
// Config done flag
extern bool_t adxl345_initialized;
// Data ready flag // Data ready flag
extern volatile bool_t adxl345_data_available; extern volatile bool_t adxl345_data_available;
// Data vector // Data vector
@@ -78,9 +80,16 @@ extern struct i2c_transaction adxl345_trans;
// Functions // Functions
extern void adxl345_init(void); extern void adxl345_init(void);
extern void adxl345_periodic(void); extern void adxl345_configure(void);
extern void adxl345_read(void);
extern void adxl345_event(void); extern void adxl345_event(void);
// Macro for using ADXL345 in periodic function
#define Adxl345Periodic() { \
if (adxl345_initialized) adxl345_read(); \
else adxl345_configure(); \
}
#define AccelEvent(_handler) { \ #define AccelEvent(_handler) { \
adxl345_event(); \ adxl345_event(); \
if (adxl345_data_available) { \ if (adxl345_data_available) { \
+27 -13
View File
@@ -62,21 +62,25 @@ static void adxl345_send_config(void)
adxl345_i2c_trans.buf[0] = ADXL345_REG_BW_RATE; adxl345_i2c_trans.buf[0] = ADXL345_REG_BW_RATE;
adxl345_i2c_trans.buf[1] = ADXL345_BW_RATE; adxl345_i2c_trans.buf[1] = ADXL345_BW_RATE;
I2CTransmit(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 2); I2CTransmit(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 2);
adxl345_init_status++;
break; break;
case ADXL_CONF_POWER: case ADXL_CONF_POWER:
adxl345_i2c_trans.buf[0] = ADXL345_REG_POWER_CTL; adxl345_i2c_trans.buf[0] = ADXL345_REG_POWER_CTL;
adxl345_i2c_trans.buf[1] = ADXL345_POWER_CTL; adxl345_i2c_trans.buf[1] = ADXL345_POWER_CTL;
I2CTransmit(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 2); I2CTransmit(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 2);
adxl345_init_status++;
break; break;
case ADXL_CONF_INT: case ADXL_CONF_INT:
adxl345_i2c_trans.buf[0] = ADXL345_REG_INT_ENABLE; adxl345_i2c_trans.buf[0] = ADXL345_REG_INT_ENABLE;
adxl345_i2c_trans.buf[1] = ADXL345_INT_ENABLE; adxl345_i2c_trans.buf[1] = ADXL345_INT_ENABLE;
I2CTransmit(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 2); I2CTransmit(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 2);
adxl345_init_status++;
break; break;
case ADXL_CONF_FORMAT: case ADXL_CONF_FORMAT:
adxl345_i2c_trans.buf[0] = ADXL345_REG_DATA_FORMAT; adxl345_i2c_trans.buf[0] = ADXL345_REG_DATA_FORMAT;
adxl345_i2c_trans.buf[1] = ADXL345_DATA_FORMAT; adxl345_i2c_trans.buf[1] = ADXL345_DATA_FORMAT;
I2CTransmit(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 2); I2CTransmit(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 2);
adxl345_init_status++;
break; break;
case ADXL_CONF_DONE: case ADXL_CONF_DONE:
adxl345_initialized = TRUE; adxl345_initialized = TRUE;
@@ -87,24 +91,23 @@ static void adxl345_send_config(void)
} }
} }
void adxl345_periodic(void) // Configure
void adxl345_configure(void)
{ {
if (!adxl345_initialized) { if (adxl345_init_status == ADXL_CONF_UNINIT) {
// Configure adxl345_init_status++;
if (adxl345_i2c_trans.status == I2CTransSuccess || adxl345_i2c_trans.status == I2CTransDone) { if (adxl345_i2c_trans.status == I2CTransSuccess || adxl345_i2c_trans.status == I2CTransDone) {
adxl345_init_status++;
adxl345_send_config(); adxl345_send_config();
} }
if (adxl345_i2c_trans.status == I2CTransFailed) {
adxl345_send_config(); // Retry config
}
} }
else { }
// Normal reading
if (adxl345_i2c_trans.status == I2CTransDone){ // Normal reading
adxl345_i2c_trans.buf[0] = ADXL345_REG_DATA_X0; void adxl345_read(void)
I2CTransceive(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 1, 6); {
} if (adxl345_initialized && adxl345_i2c_trans.status == I2CTransDone) {
adxl345_i2c_trans.buf[0] = ADXL345_REG_DATA_X0;
I2CTransceive(ADXL345_I2C_DEVICE, adxl345_i2c_trans, ADXL345_I2C_ADDR, 1, 6);
} }
} }
@@ -125,6 +128,17 @@ void adxl345_event(void)
adxl345_i2c_trans.status = I2CTransDone; adxl345_i2c_trans.status = I2CTransDone;
} }
} }
else if (!adxl345_initialized && adxl345_init_status != ADXL_CONF_UNINIT) { // Configuring
if (adxl345_i2c_trans.status == I2CTransSuccess || adxl345_i2c_trans.status == I2CTransDone) {
adxl345_i2c_trans.status = I2CTransDone;
adxl345_send_config();
}
if (adxl345_i2c_trans.status == I2CTransFailed) {
adxl345_init_status--;
adxl345_i2c_trans.status = I2CTransDone;
adxl345_send_config(); // Retry config (TODO max retry)
}
}
} }
+26 -13
View File
@@ -61,16 +61,19 @@ static void hmc58xx_send_config(void)
hmc58xx_i2c_trans.buf[0] = HMC58XX_REG_CFGA; hmc58xx_i2c_trans.buf[0] = HMC58XX_REG_CFGA;
hmc58xx_i2c_trans.buf[1] = HMC58XX_CRA; hmc58xx_i2c_trans.buf[1] = HMC58XX_CRA;
I2CTransmit(HMC58XX_I2C_DEVICE, hmc58xx_i2c_trans, HMC58XX_ADDR, 2); I2CTransmit(HMC58XX_I2C_DEVICE, hmc58xx_i2c_trans, HMC58XX_ADDR, 2);
hmc58xx_init_status++;
break; break;
case HMC_CONF_CRB: case HMC_CONF_CRB:
hmc58xx_i2c_trans.buf[0] = HMC58XX_REG_CFGB; hmc58xx_i2c_trans.buf[0] = HMC58XX_REG_CFGB;
hmc58xx_i2c_trans.buf[1] = HMC58XX_CRB; hmc58xx_i2c_trans.buf[1] = HMC58XX_CRB;
I2CTransmit(HMC58XX_I2C_DEVICE, hmc58xx_i2c_trans, HMC58XX_ADDR, 2); I2CTransmit(HMC58XX_I2C_DEVICE, hmc58xx_i2c_trans, HMC58XX_ADDR, 2);
hmc58xx_init_status++;
break; break;
case HMC_CONF_MODE: case HMC_CONF_MODE:
hmc58xx_i2c_trans.buf[0] = HMC58XX_REG_MODE; hmc58xx_i2c_trans.buf[0] = HMC58XX_REG_MODE;
hmc58xx_i2c_trans.buf[1] = HMC58XX_MD; hmc58xx_i2c_trans.buf[1] = HMC58XX_MD;
I2CTransmit(HMC58XX_I2C_DEVICE, hmc58xx_i2c_trans, HMC58XX_ADDR, 2); I2CTransmit(HMC58XX_I2C_DEVICE, hmc58xx_i2c_trans, HMC58XX_ADDR, 2);
hmc58xx_init_status++;
break; break;
case HMC_CONF_DONE: case HMC_CONF_DONE:
hmc58xx_initialized = TRUE; hmc58xx_initialized = TRUE;
@@ -81,24 +84,23 @@ static void hmc58xx_send_config(void)
} }
} }
void hmc58xx_periodic(void) // Configure
void hmc58xx_configure(void)
{ {
if (!hmc58xx_initialized) { if (hmc58xx_init_status == HMC_CONF_UNINIT) {
// Configure hmc58xx_init_status++;
if (hmc58xx_i2c_trans.status == I2CTransSuccess || hmc58xx_i2c_trans.status == I2CTransDone) { if (hmc58xx_i2c_trans.status == I2CTransSuccess || hmc58xx_i2c_trans.status == I2CTransDone) {
hmc58xx_init_status++;
hmc58xx_send_config(); hmc58xx_send_config();
} }
if (hmc58xx_i2c_trans.status == I2CTransFailed) {
hmc58xx_send_config(); // Retry config
}
} }
else { }
// Normal reading
if (hmc58xx_i2c_trans.status == I2CTransDone){ // Normal reading
hmc58xx_i2c_trans.buf[0] = HMC58XX_REG_DATXM; void hmc58xx_read(void)
I2CTransceive(HMC58XX_I2C_DEVICE, hmc58xx_i2c_trans, HMC58XX_ADDR, 1, 6); {
} if (hmc58xx_initialized && hmc58xx_i2c_trans.status == I2CTransDone){
hmc58xx_i2c_trans.buf[0] = HMC58XX_REG_DATXM;
I2CTransceive(HMC58XX_I2C_DEVICE, hmc58xx_i2c_trans, HMC58XX_ADDR, 1, 6);
} }
} }
@@ -118,5 +120,16 @@ void hmc58xx_event(void)
hmc58xx_i2c_trans.status = I2CTransDone; hmc58xx_i2c_trans.status = I2CTransDone;
} }
} }
else if (!hmc58xx_initialized && hmc58xx_init_status != HMC_CONF_UNINIT) { // Configuring
if (hmc58xx_i2c_trans.status == I2CTransSuccess || hmc58xx_i2c_trans.status == I2CTransDone) {
hmc58xx_i2c_trans.status = I2CTransDone;
hmc58xx_send_config();
}
if (hmc58xx_i2c_trans.status == I2CTransFailed) {
hmc58xx_init_status--;
hmc58xx_i2c_trans.status = I2CTransDone;
hmc58xx_send_config(); // Retry config (TODO max retry)
}
}
} }
+10 -1
View File
@@ -70,6 +70,8 @@
#define HMC58XX_I2C_DEVICE i2c2 #define HMC58XX_I2C_DEVICE i2c2
#endif #endif
// Config done flag
extern bool_t hmc58xx_initialized;
// Data ready flag // Data ready flag
extern volatile bool_t hmc58xx_data_available; extern volatile bool_t hmc58xx_data_available;
// Data vector // Data vector
@@ -81,9 +83,16 @@ extern struct i2c_transaction hmc58xx_i2c_trans;
// Functions // Functions
extern void hmc58xx_init(void); extern void hmc58xx_init(void);
extern void hmc58xx_periodic(void); extern void hmc58xx_configure(void);
extern void hmc58xx_read(void);
extern void hmc58xx_event(void); extern void hmc58xx_event(void);
// Macro for using HMC58XX in periodic function
#define Hmc58xxPeriodic() { \
if (hmc58xx_initialized) hmc58xx_read(); \
else hmc58xx_configure(); \
}
#define MagEvent(_m_handler) { \ #define MagEvent(_m_handler) { \
hmc58xx_event(); \ hmc58xx_event(); \
if (hmc58xx_data_available) { \ if (hmc58xx_data_available) { \
+27 -13
View File
@@ -62,21 +62,25 @@ static void itg3200_send_config(void)
itg3200_i2c_trans.buf[0] = ITG3200_REG_SMPLRT_DIV; itg3200_i2c_trans.buf[0] = ITG3200_REG_SMPLRT_DIV;
itg3200_i2c_trans.buf[1] = ITG3200_SMPLRT_DIV; itg3200_i2c_trans.buf[1] = ITG3200_SMPLRT_DIV;
I2CTransmit(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 2); I2CTransmit(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 2);
itg3200_init_status++;
break; break;
case ITG_CONF_DF: case ITG_CONF_DF:
itg3200_i2c_trans.buf[0] = ITG3200_REG_DLPF_FS; itg3200_i2c_trans.buf[0] = ITG3200_REG_DLPF_FS;
itg3200_i2c_trans.buf[1] = ITG3200_DLPF_FS; itg3200_i2c_trans.buf[1] = ITG3200_DLPF_FS;
I2CTransmit(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 2); I2CTransmit(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 2);
itg3200_init_status++;
break; break;
case ITG_CONF_INT: case ITG_CONF_INT:
itg3200_i2c_trans.buf[0] = ITG3200_REG_INT_CFG; itg3200_i2c_trans.buf[0] = ITG3200_REG_INT_CFG;
itg3200_i2c_trans.buf[1] = ITG3200_INT_CFG; itg3200_i2c_trans.buf[1] = ITG3200_INT_CFG;
I2CTransmit(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 2); I2CTransmit(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 2);
itg3200_init_status++;
break; break;
case ITG_CONF_PWR: case ITG_CONF_PWR:
itg3200_i2c_trans.buf[0] = ITG3200_REG_PWR_MGM; itg3200_i2c_trans.buf[0] = ITG3200_REG_PWR_MGM;
itg3200_i2c_trans.buf[1] = ITG3200_PWR_MGM; itg3200_i2c_trans.buf[1] = ITG3200_PWR_MGM;
I2CTransmit(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 2); I2CTransmit(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 2);
itg3200_init_status++;
break; break;
case ITG_CONF_DONE: case ITG_CONF_DONE:
itg3200_initialized = TRUE; itg3200_initialized = TRUE;
@@ -87,24 +91,23 @@ static void itg3200_send_config(void)
} }
} }
void itg3200_periodic(void) // Configure
void itg3200_configure(void)
{ {
if (!itg3200_initialized) { if (itg3200_init_status == ITG_CONF_UNINIT) {
// Configure itg3200_init_status++;
if (itg3200_i2c_trans.status == I2CTransSuccess || itg3200_i2c_trans.status == I2CTransDone) { if (itg3200_i2c_trans.status == I2CTransSuccess || itg3200_i2c_trans.status == I2CTransDone) {
itg3200_init_status++;
itg3200_send_config(); itg3200_send_config();
} }
if (itg3200_i2c_trans.status == I2CTransFailed) {
itg3200_send_config(); // Retry config
}
} }
else { }
// Normal reading
if (itg3200_i2c_trans.status == I2CTransDone) { // Normal reading
itg3200_i2c_trans.buf[0] = ITG3200_REG_INT_STATUS; void itg3200_read(void)
I2CTransceive(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 1, 9); {
} if (itg3200_initialized && itg3200_i2c_trans.status == I2CTransDone) {
itg3200_i2c_trans.buf[0] = ITG3200_REG_INT_STATUS;
I2CTransceive(ITG3200_I2C_DEVICE, itg3200_i2c_trans, ITG3200_I2C_ADDR, 1, 9);
} }
} }
@@ -128,5 +131,16 @@ void itg3200_event(void)
itg3200_i2c_trans.status = I2CTransDone; itg3200_i2c_trans.status = I2CTransDone;
} }
} }
else if (!itg3200_initialized && itg3200_init_status != ITG_CONF_UNINIT) { // Configuring
if (itg3200_i2c_trans.status == I2CTransSuccess || itg3200_i2c_trans.status == I2CTransDone) {
itg3200_i2c_trans.status = I2CTransDone;
itg3200_send_config();
}
if (itg3200_i2c_trans.status == I2CTransFailed) {
itg3200_init_status--;
itg3200_i2c_trans.status = I2CTransDone;
itg3200_send_config(); // Retry config (TODO max retry)
}
}
} }
+10 -1
View File
@@ -64,6 +64,8 @@
#define ITG3200_I2C_DEVICE i2c1 #define ITG3200_I2C_DEVICE i2c1
#endif #endif
// Config done flag
extern bool_t itg3200_initialized;
// Data ready flag // Data ready flag
extern volatile bool_t itg3200_data_available; extern volatile bool_t itg3200_data_available;
// Data vector // Data vector
@@ -75,9 +77,16 @@ extern struct i2c_transaction itg3200_trans;
// Functions // Functions
extern void itg3200_init(void); extern void itg3200_init(void);
extern void itg3200_periodic(void); extern void itg3200_configure(void);
extern void itg3200_read(void);
extern void itg3200_event(void); extern void itg3200_event(void);
// Macro for using ITG3200 in periodic function
#define Itg3200Periodic() { \
if (itg3200_initialized) itg3200_read(); \
else itg3200_configure(); \
}
#define GyroEvent(_handler) { \ #define GyroEvent(_handler) { \
itg3200_event(); \ itg3200_event(); \
if (itg3200_data_available) { \ if (itg3200_data_available) { \
+5 -1
View File
@@ -359,6 +359,7 @@ let options =
"-no_google_http", Arg.Unit (fun () -> Gm.set_policy Gm.NoHttp), "Switch off Google Maps downloading"; "-no_google_http", Arg.Unit (fun () -> Gm.set_policy Gm.NoHttp), "Switch off Google Maps downloading";
"-ortho", Arg.Set_string get_bdortho, "IGN tiles path"; "-ortho", Arg.Set_string get_bdortho, "IGN tiles path";
"-osm", Arg.Unit (fun () -> Gm.set_maps_source Gm.OSM), "Use OpenStreetMap database (default is Google)"; "-osm", Arg.Unit (fun () -> Gm.set_maps_source Gm.OSM), "Use OpenStreetMap database (default is Google)";
"-ms", Arg.Unit (fun () -> Gm.set_maps_source Gm.MS), "Use Microsoft maps database (default is Google)";
"-particules", Arg.Set display_particules, "Display particules"; "-particules", Arg.Set display_particules, "Display particules";
"-plugin", Arg.Set_string plugin_window, "External X application (launched with the id of the plugin window as argument)"; "-plugin", Arg.Set_string plugin_window, "External X application (launched with the id of the plugin window as argument)";
"-ref", Arg.Set_string geo_ref, "Geographic ref (e.g. 'WGS84 43.605 1.443')"; "-ref", Arg.Set_string geo_ref, "Geographic ref (e.g. 'WGS84 43.605 1.443')";
@@ -404,10 +405,13 @@ let create_geomap = fun switch_fullscreen editor_frame ->
let maps_source_menu = map_menu_fact#add_submenu "Maps Source" in let maps_source_menu = map_menu_fact#add_submenu "Maps Source" in
let maps_source_fact = new GMenu.factory maps_source_menu in let maps_source_fact = new GMenu.factory maps_source_menu in
let group = ref None in let group = ref None in
(* Determine a decent default selected item *)
let active_maps_source = Gm.get_maps_source () in
List.iter List.iter
(fun maps_source -> (fun maps_source ->
let callback = fun b -> if b then Gm.set_maps_source maps_source in let callback = fun b -> if b then Gm.set_maps_source maps_source in
let menu_item = maps_source_fact#add_radio_item ~group: !group ~callback (Gm.string_of_maps_source maps_source) in let active = (maps_source = active_maps_source) in
let menu_item = maps_source_fact#add_radio_item ~group: !group ~active ~callback (Gm.string_of_maps_source maps_source) in
group := menu_item#group) group := menu_item#group)
Gm.maps_sources; Gm.maps_sources;
+1
View File
@@ -48,6 +48,7 @@ let string_of_maps_source = function
let maps_source = ref Google let maps_source = ref Google
let set_maps_source = fun s -> maps_source := s let set_maps_source = fun s -> maps_source := s
let get_maps_source = fun () -> !maps_source
let mkdir = fun d -> let mkdir = fun d ->
if not (Sys.file_exists d) then if not (Sys.file_exists d) then
+3 -3
View File
@@ -38,6 +38,9 @@ type tile_t = {
type maps_source = Google | OSM | MS type maps_source = Google | OSM | MS
val string_of_maps_source : maps_source -> string val string_of_maps_source : maps_source -> string
val maps_sources : maps_source list val maps_sources : maps_source list
val set_maps_source : maps_source -> unit
val get_maps_source : unit -> maps_source
(** Initialized to Google *)
val tile_of_geo : Latlong.geographic -> int -> tile_t val tile_of_geo : Latlong.geographic -> int -> tile_t
(** [tile_string geo zoom] Returns the tile description containing a (** [tile_string geo zoom] Returns the tile description containing a
@@ -56,9 +59,6 @@ val set_policy : policy -> unit
val get_policy : unit -> policy val get_policy : unit -> policy
(** Initialized to CacheOrHttp using cache and http access *) (** Initialized to CacheOrHttp using cache and http access *)
val set_maps_source : maps_source -> unit
(** Initialized to Google *)
exception Not_available exception Not_available
val get_image : string -> tile_t * string val get_image : string -> tile_t * string