actually adding BMA280 driver files, oops.

git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@417 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
timecop@gmail.com 2013-09-29 14:00:14 +00:00
parent 01eaf85510
commit 04ab548d2e
2 changed files with 57 additions and 0 deletions

54
src/drv_bma280.c Normal file
View File

@ -0,0 +1,54 @@
#include "board.h"
// BMA280, default I2C address mode 0x18
#define BMA280_ADDRESS 0x18
#define BMA280_ACC_X_LSB 0x02
#define BMA280_PMU_BW 0x10
#define BMA280_PMU_RANGE 0x0F
extern uint16_t acc_1G;
static void bma280Init(sensor_align_e align);
static void bma280Read(int16_t *accelData);
static sensor_align_e accAlign = CW0_DEG;
bool bma280Detect(sensor_t *acc)
{
bool ack = false;
uint8_t sig = 0;
ack = i2cRead(BMA280_ADDRESS, 0x00, 1, &sig);
if (!ack || sig != 0xFB)
return false;
acc->init = bma280Init;
acc->read = bma280Read;
return true;
}
static void bma280Init(sensor_align_e align)
{
i2cWrite(BMA280_ADDRESS, BMA280_PMU_RANGE, 0x08); // +-8g range
i2cWrite(BMA280_ADDRESS, BMA280_PMU_BW, 0x0E); // 500Hz BW
acc_1G = 512 * 8;
if (align > 0)
accAlign = align;
}
static void bma280Read(int16_t *accelData)
{
uint8_t buf[6];
int16_t data[3];
i2cRead(BMA280_ADDRESS, BMA280_ACC_X_LSB, 6, buf);
// Data format is lsb<5:0><crap><new_data_bit> | msb<13:6>
data[0] = (int16_t)((buf[0] >> 2) + (buf[1] << 8));
data[1] = (int16_t)((buf[2] >> 2) + (buf[3] << 8));
data[2] = (int16_t)((buf[4] >> 2) + (buf[5] << 8));
alignSensors(data, accelData, accAlign);
}

3
src/drv_bma280.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
bool bma280Detect(sensor_t *acc);