dev #1
|
@ -18,6 +18,8 @@ extern void _test_free(void* const ptr, const char* file, const int line);
|
||||||
#define free(ptr) _test_free(ptr, __FILE__, __LINE__)
|
#define free(ptr) _test_free(ptr, __FILE__, __LINE__)
|
||||||
#endif // UNIT_TESTING
|
#endif // UNIT_TESTING
|
||||||
|
|
||||||
|
#define NUM_ACCEL_REGS 6
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ############################
|
* ############################
|
||||||
* REGISTER MAP
|
* REGISTER MAP
|
||||||
|
@ -25,6 +27,20 @@ extern void _test_free(void* const ptr, const char* file, const int line);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum gy521_map {
|
enum gy521_map {
|
||||||
|
accel_xouth = 0x3B,
|
||||||
|
accel_xoutl,
|
||||||
|
accel_youth,
|
||||||
|
accel_youtl,
|
||||||
|
accel_zouth,
|
||||||
|
accel_zoutl,
|
||||||
|
temp_outh,
|
||||||
|
temp_outl,
|
||||||
|
gyro_xouth,
|
||||||
|
gyro_xoutl,
|
||||||
|
gyro_youth,
|
||||||
|
gyro_youtl,
|
||||||
|
gyro_zouth,
|
||||||
|
gyro_zoutl,
|
||||||
fifo_couth = 0x72,
|
fifo_couth = 0x72,
|
||||||
fifo_contl,
|
fifo_contl,
|
||||||
fifo_r_w,
|
fifo_r_w,
|
||||||
|
@ -55,6 +71,23 @@ struct gy521_module{
|
||||||
accel_values_struct accel;
|
accel_values_struct accel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ############################
|
||||||
|
* Helper/Private Functions
|
||||||
|
* ############################
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t read_register(enum gy521_map reg)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t write_register(enum gy521_map reg)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ############################
|
* ############################
|
||||||
* Function Definitions
|
* Function Definitions
|
||||||
|
@ -75,6 +108,7 @@ void gy521_free(gy521_module *m)
|
||||||
free(m);
|
free(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_Bool gy521_init(gy521_module *m, uint8_t slave_address) {
|
_Bool gy521_init(gy521_module *m, uint8_t slave_address) {
|
||||||
if((slave_address != TWI_GY521_ADDR1) && (slave_address != TWI_GY521_ADDR2)) {
|
if((slave_address != TWI_GY521_ADDR1) && (slave_address != TWI_GY521_ADDR2)) {
|
||||||
m->slave_address = 0x0;
|
m->slave_address = 0x0;
|
||||||
|
@ -97,12 +131,25 @@ _Bool gy521_init(gy521_module *m, uint8_t slave_address) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_Bool gy521_update_gyro(gy521_module *m)
|
void gy521_update_gyro(gy521_module *m)
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_Bool gy521_update_accel(gy521_module *m)
|
void gy521_update_accel(gy521_module *m)
|
||||||
{
|
{
|
||||||
return 0;
|
uint8_t read_regs[NUM_ACCEL_REGS] = {accel_xouth, accel_xoutl,
|
||||||
|
accel_youth, accel_youth,
|
||||||
|
accel_zouth, accel_zoutl};
|
||||||
|
|
||||||
|
/*update individually the structure by communicating with the device.*/
|
||||||
|
gy521_twi_rx(m->slave_address, read_regs, NUM_ACCEL_REGS);
|
||||||
|
|
||||||
|
/*bitshift to reassembly the high/low regs into a single 16bit*/
|
||||||
|
m->accel.x = (read_regs[0] << 8) | read_regs[1];
|
||||||
|
m->accel.y = (read_regs[2] << 8) | read_regs[3];
|
||||||
|
m->accel.z = (read_regs[4] << 8) | read_regs[5];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@ extern void (*gy521_twi_rx)(uint8_t, uint8_t*, uint8_t);
|
||||||
|
|
||||||
struct gy521_module* gy521_new(void);
|
struct gy521_module* gy521_new(void);
|
||||||
_Bool gy521_init(struct gy521_module *m, uint8_t slave_address);
|
_Bool gy521_init(struct gy521_module *m, uint8_t slave_address);
|
||||||
_Bool gy521_update_gyro(struct gy521_module* m);
|
void gy521_update_gyro(struct gy521_module* m);
|
||||||
_Bool gy521_update_accel(struct gy521_module* m);
|
void gy521_update_accel(struct gy521_module* m);
|
||||||
void gy521_free(struct gy521_module *m);
|
void gy521_free(struct gy521_module *m);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue