Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Commit

Permalink
refs #17 Last changes for ADC demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoos committed Feb 10, 2015
1 parent 1841a39 commit 0125d5e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
8 changes: 0 additions & 8 deletions variants/platforms/aerial_v4/i2c_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

#include "hal.h"

// See ChibiOS/os/hal/platforms/STM32/I2Cv1
static const I2CConfig I2CD2_CONFIG = {
OPMODE_I2C,
400000,
FAST_DUTY_CYCLE_2
};

I2CPlatform::I2CPlatform() {
// I2C2
i2cStart(&I2CD2, &I2CD2_CONFIG);
palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(4)); // SCL
palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(4)); // SDA
}
18 changes: 18 additions & 0 deletions variants/platforms/aerial_v4/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "drivers/mpu9250.hpp"
#include "sensor/accelerometer.hpp"
#include "sensor/gyroscope.hpp"
#include "drivers/lsm303dlhc_mag.hpp"

#include "drivers/vishaytherm.hpp"
#include "sensor/thermistor.hpp"
Expand Down Expand Up @@ -47,6 +48,15 @@ static const SPIConfig H3LIS331DL_CONFIG {
SPI_CR1_BR_0 // 42000000/2^1 = 21000000
};

// See ChibiOS/os/hal/platforms/STM32/I2Cv1
static const I2CConfig I2CD2_CONFIG = {
OPMODE_I2C,
400000,
FAST_DUTY_CYCLE_2
};

static const i2caddr_t LSM303_I2C_MAG_ADDRESS = (0x3c >> 1);

const size_t ADC_GRP1_NUM_CHANNELS = 2;
const size_t ADC_GRP1_BUF_DEPTH = 4;

Expand Down Expand Up @@ -98,6 +108,12 @@ Accelerometer& Platform::get() {
return get<MPU9250>();
}

template <>
Magnetometer& Platform::get() {
static LSM303DLHCMag mag(&I2CD2, &I2CD2_CONFIG, LSM303_I2C_MAG_ADDRESS);
return mag;
}

template <>
VishayTherm& Platform::get() {
static VishayTherm therm(&ADCD1, &ADC_GRP1_CONFIG, &samples, &avg_ch);
Expand Down Expand Up @@ -160,6 +176,8 @@ void Platform::init() {
// Initialize IMU
get<MPU9250>().init();

get<Magnetometer>().init();

// Initialize thermistor
get<VishayTherm>().init();

Expand Down
3 changes: 2 additions & 1 deletion variants/units/helios/unit_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "input/offboard_input_source.hpp"
#include "sensor/gyroscope.hpp"
#include "sensor/accelerometer.hpp"
#include "sensor/magnetometer.hpp"
#include "sensor/gps.hpp"
#include "sensor/thermistor.hpp"
#include "system/multirotor_vehicle_system.hpp"
Expand Down Expand Up @@ -42,7 +43,7 @@ struct UnitData {
system(platform.get<Gyroscope>(),
platform.get<Accelerometer>(),
platform.get<GPS>(),
std::experimental::nullopt,
std::experimental::make_optional(&platform.get<Magnetometer>()),
std::experimental::make_optional(&platform.get<Thermistor>()),
world, attitude, inputSource, motorMapper, communicator) {
}
Expand Down

0 comments on commit 0125d5e

Please sign in to comment.