Gavan Fantom
10 years ago
11 changed files with 327 additions and 9 deletions
@ -0,0 +1,129 @@
|
||||
/* hmc5883l.c */ |
||||
|
||||
#include "sensors.h" |
||||
#include "hmc5883l.h" |
||||
#include "i2c.h" |
||||
#include "event.h" |
||||
#include "log.h" |
||||
#include "uart.h" |
||||
|
||||
bool hmc5883l_state; |
||||
|
||||
i2c_result hmc5883l_result; |
||||
|
||||
unsigned char hmc5883l_sample_data[6]; |
||||
|
||||
#define LOG_SIGNATURE_MAGNETOMETER 0xDA7AAA75 |
||||
|
||||
unsigned char hmc5883l_init_command[] = {0x00, 0x70}; |
||||
unsigned char hmc5883l_init_command2[] = {0x01, 0xA0}; |
||||
|
||||
struct i2c_transaction hmc5883l_init_transaction2; |
||||
|
||||
struct i2c_transaction hmc5883l_init_transaction = { |
||||
(0x1E << 1) + 0, /* write */ |
||||
2, |
||||
hmc5883l_init_command, |
||||
&hmc5883l_result, |
||||
EVENT_HMC5883L_I2C_COMPLETE, |
||||
&hmc5883l_init_transaction2 |
||||
}; |
||||
|
||||
struct i2c_transaction hmc5883l_init_transaction2 = { |
||||
(0x1E << 1) + 0, /* write */ |
||||
2, |
||||
hmc5883l_init_command2, |
||||
&hmc5883l_result, |
||||
EVENT_HMC5883L_I2C_COMPLETE, |
||||
NULL |
||||
}; |
||||
|
||||
unsigned char hmc5883l_start_command[] = {0x02, 0x01}; |
||||
|
||||
struct i2c_transaction hmc5883l_start_transaction = { |
||||
(0x1E << 1) + 0, /* write */ |
||||
2, |
||||
hmc5883l_start_command, |
||||
&hmc5883l_result, |
||||
EVENT_HMC5883L_I2C_COMPLETE, |
||||
NULL |
||||
}; |
||||
|
||||
struct i2c_transaction hmc5883l_sample_transaction = { |
||||
(0x1E << 1) + 1, /* read */ |
||||
6, |
||||
hmc5883l_sample_data, |
||||
&hmc5883l_result, |
||||
EVENT_HMC5883L_I2C_COMPLETE, |
||||
NULL |
||||
}; |
||||
|
||||
void hmc5883l_event_handler(void); |
||||
|
||||
bool hmc5883l_init(void) |
||||
{ |
||||
event_register(EVENT_HMC5883L_I2C_COMPLETE, hmc5883l_event_handler); |
||||
|
||||
if (!i2c_start_transaction(&hmc5883l_init_transaction)) |
||||
return FALSE; |
||||
while (i2c_busy()) ; |
||||
|
||||
hmc5883l_state = 0; |
||||
|
||||
return (hmc5883l_result == I2C_SUCCESS); |
||||
} |
||||
|
||||
bool hmc5883l_start_sample(void) |
||||
{ |
||||
hmc5883l_state = !hmc5883l_state; |
||||
|
||||
if (hmc5883l_state) |
||||
return i2c_start_transaction(&hmc5883l_start_transaction); |
||||
else |
||||
return i2c_start_transaction(&hmc5883l_sample_transaction); |
||||
} |
||||
|
||||
void hmc5883l_event_handler(void) |
||||
{ |
||||
#if 0 |
||||
signed short int xi, yi, zi; |
||||
signed short int tempi; |
||||
signed short int rolli, pitchi, yawi; |
||||
|
||||
float x, y, z; |
||||
float temp; |
||||
float roll, pitch, yaw; |
||||
#endif |
||||
|
||||
if (hmc5883l_result != I2C_SUCCESS) |
||||
return; |
||||
|
||||
hmc5883l_result = I2C_IN_PROGRESS; |
||||
|
||||
sensors_sample_done(); |
||||
|
||||
/* If we just started a conversion, our job is done for now */ |
||||
if (hmc5883l_state) |
||||
return; |
||||
|
||||
#if 0 |
||||
xi = (hmc5883l_sample_data[0] << 8) + hmc5883l_sample_data[1]; |
||||
yi = (hmc5883l_sample_data[2] << 8) + hmc5883l_sample_data[3]; |
||||
zi = (hmc5883l_sample_data[4] << 8) + hmc5883l_sample_data[5]; |
||||
|
||||
tempi = (hmc5883l_sample_data[6] << 8) + hmc5883l_sample_data[7]; |
||||
|
||||
rolli = (hmc5883l_sample_data[ 8] << 8)+hmc5883l_sample_data[ 9]; |
||||
pitchi = (hmc5883l_sample_data[10] << 8)+hmc5883l_sample_data[11]; |
||||
yawi = (hmc5883l_sample_data[12] << 8)+hmc5883l_sample_data[13]; |
||||
|
||||
sensors_write_gyro_data(roll, pitch, yaw); |
||||
sensors_write_accel_data(x, y, z); |
||||
sensors_write_temp_data(temp); |
||||
|
||||
#endif |
||||
|
||||
log_put_uint(LOG_SIGNATURE_MAGNETOMETER); |
||||
log_put_array((char *)hmc5883l_sample_data, 6); |
||||
} |
||||
|
@ -0,0 +1,10 @@
|
||||
#ifndef __HMC5883L_H |
||||
#define __HMC5883L_H |
||||
|
||||
#include "types.h" |
||||
|
||||
bool hmc5883l_init(void); |
||||
bool hmc5883l_start_sample(void); |
||||
void hmc5883l_write_log(void); |
||||
|
||||
#endif /* __HMC5883L_H */ |
@ -0,0 +1,132 @@
|
||||
/* mpl3115a2.c */ |
||||
|
||||
#include "sensors.h" |
||||
#include "mpl3115a2.h" |
||||
#include "i2c.h" |
||||
#include "event.h" |
||||
#include "log.h" |
||||
#include "uart.h" |
||||
|
||||
bool mpl3115a2_state; |
||||
|
||||
i2c_result mpl3115a2_result; |
||||
|
||||
unsigned char mpl3115a2_sample_data[5]; |
||||
|
||||
#define LOG_SIGNATURE_ALTIMETER 0xDA7AAA70 |
||||
|
||||
unsigned char mpl3115a2_start_command[] = {0x26, 0x82}; |
||||
unsigned char mpl3115a2_read_address[] = {0x01}; |
||||
|
||||
struct i2c_transaction mpl3115a2_start_transaction = { |
||||
(0x60 << 1) + 0, /* write */ |
||||
sizeof(mpl3115a2_start_command), |
||||
mpl3115a2_start_command, |
||||
&mpl3115a2_result, |
||||
EVENT_MPL3115A2_I2C_COMPLETE, |
||||
NULL |
||||
}; |
||||
|
||||
struct i2c_transaction mpl3115a2_sample_transaction2; |
||||
|
||||
struct i2c_transaction mpl3115a2_sample_transaction = { |
||||
(0x60 << 1) + 0, /* write */ |
||||
sizeof(mpl3115a2_read_address), |
||||
mpl3115a2_read_address, |
||||
&mpl3115a2_result, |
||||
EVENT_MPL3115A2_I2C_COMPLETE, |
||||
&mpl3115a2_sample_transaction2 |
||||
}; |
||||
struct i2c_transaction mpl3115a2_sample_transaction2 = { |
||||
(0x60 << 1) + 1, /* read */ |
||||
5, |
||||
mpl3115a2_sample_data, |
||||
&mpl3115a2_result, |
||||
EVENT_MPL3115A2_I2C_COMPLETE, |
||||
NULL |
||||
}; |
||||
|
||||
void mpl3115a2_event_handler(void); |
||||
|
||||
bool mpl3115a2_init(void) |
||||
{ |
||||
event_register(EVENT_MPL3115A2_I2C_COMPLETE, mpl3115a2_event_handler); |
||||
|
||||
mpl3115a2_state = 0; |
||||
|
||||
return TRUE; |
||||
|
||||
#if 0 |
||||
if (!i2c_start_transaction(&mpl3115a2_init_transaction)) |
||||
return FALSE; |
||||
while (i2c_busy()) ; |
||||
|
||||
|
||||
return (mpl3115a2_result == I2C_SUCCESS); |
||||
#endif |
||||
} |
||||
|
||||
bool mpl3115a2_start_sample(void) |
||||
{ |
||||
mpl3115a2_state = !mpl3115a2_state; |
||||
|
||||
putstr("X"); |
||||
|
||||
if (mpl3115a2_state) |
||||
return i2c_start_transaction(&mpl3115a2_start_transaction); |
||||
else |
||||
return i2c_start_transaction(&mpl3115a2_sample_transaction); |
||||
} |
||||
|
||||
void mpl3115a2_event_handler(void) |
||||
{ |
||||
#if 0 |
||||
signed short int xi, yi, zi; |
||||
signed short int tempi; |
||||
signed short int rolli, pitchi, yawi; |
||||
|
||||
float x, y, z; |
||||
float temp; |
||||
float roll, pitch, yaw; |
||||
#endif |
||||
|
||||
if (mpl3115a2_result != I2C_SUCCESS) |
||||
return; |
||||
|
||||
mpl3115a2_result = I2C_IN_PROGRESS; |
||||
|
||||
sensors_sample_done(); |
||||
|
||||
/* If we just started a conversion, our job is done for now */ |
||||
if (mpl3115a2_state) |
||||
return; |
||||
|
||||
#if 0 |
||||
xi = (mpl3115a2_sample_data[0] << 8) + mpl3115a2_sample_data[1]; |
||||
yi = (mpl3115a2_sample_data[2] << 8) + mpl3115a2_sample_data[3]; |
||||
zi = (mpl3115a2_sample_data[4] << 8) + mpl3115a2_sample_data[5]; |
||||
|
||||
tempi = (mpl3115a2_sample_data[6] << 8) + mpl3115a2_sample_data[7]; |
||||
|
||||
rolli = (mpl3115a2_sample_data[ 8] << 8)+mpl3115a2_sample_data[ 9]; |
||||
pitchi = (mpl3115a2_sample_data[10] << 8)+mpl3115a2_sample_data[11]; |
||||
yawi = (mpl3115a2_sample_data[12] << 8)+mpl3115a2_sample_data[13]; |
||||
|
||||
sensors_write_gyro_data(roll, pitch, yaw); |
||||
sensors_write_accel_data(x, y, z); |
||||
sensors_write_temp_data(temp); |
||||
|
||||
#endif |
||||
|
||||
log_put_uint(LOG_SIGNATURE_ALTIMETER); |
||||
log_put_array((char *)mpl3115a2_sample_data, 5); |
||||
putstr("Y"); |
||||
|
||||
#if 0 |
||||
puthex(mpl3115a2_sample_data[0]); |
||||
puthex(mpl3115a2_sample_data[1]); |
||||
puthex(mpl3115a2_sample_data[2]); |
||||
putstr("\n"); |
||||
#endif |
||||
} |
||||
|
@ -0,0 +1,10 @@
|
||||
#ifndef __MPL3115A2_H |
||||
#define __MPL3115A2_H |
||||
|
||||
#include "types.h" |
||||
|
||||
bool mpl3115a2_init(void); |
||||
bool mpl3115a2_start_sample(void); |
||||
void mpl3115a2_write_log(void); |
||||
|
||||
#endif /* __MPL3115A2_H */ |
Loading…
Reference in new issue