Compare commits
No commits in common. "604dc1ad6051a58a6bb6c6e73b84de122101b2b6" and "1bc91feed8dfcd054fc7d99a135cb95fc8dd23da" have entirely different histories.
604dc1ad60
...
1bc91feed8
4 changed files with 119 additions and 178 deletions
|
@ -4,12 +4,7 @@
|
||||||
* Description: The implimentation file for the gy521 module, assumes TWI/I2c
|
* Description: The implimentation file for the gy521 module, assumes TWI/I2c
|
||||||
*/
|
*/
|
||||||
#include "gy521_driver.h"
|
#include "gy521_driver.h"
|
||||||
|
#include <stdint.h>
|
||||||
/*
|
|
||||||
* ############################
|
|
||||||
* MACROS
|
|
||||||
* ############################
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*DEBUG macro*/
|
/*DEBUG macro*/
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
@ -37,12 +32,6 @@ extern void mock_assert(const int result, const char* const expression,
|
||||||
|
|
||||||
#endif // UNIT_TESTING
|
#endif // UNIT_TESTING
|
||||||
|
|
||||||
/*
|
|
||||||
* ############################
|
|
||||||
* Defines and consts
|
|
||||||
* ############################
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define NUM_ACCEL_REGS 6
|
#define NUM_ACCEL_REGS 6
|
||||||
#define NUM_GYRO_REGS 6
|
#define NUM_GYRO_REGS 6
|
||||||
|
|
||||||
|
@ -63,6 +52,100 @@ extern void mock_assert(const int result, const char* const expression,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ############################
|
||||||
|
* REGISTER MAP
|
||||||
|
* ############################
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*This thing is fairly huge, but it's got pretty much all the registers
|
||||||
|
* on it.*/
|
||||||
|
|
||||||
|
enum gy521_map {
|
||||||
|
self_test_x = 0x0D,
|
||||||
|
self_test_y,
|
||||||
|
self_test_z,
|
||||||
|
self_test_a,
|
||||||
|
smplrt_div = 0x19,
|
||||||
|
config,
|
||||||
|
gyro_config,
|
||||||
|
accel_config,
|
||||||
|
fifo_en = 0x23,
|
||||||
|
i2c_mst_ctrl,
|
||||||
|
i2c_slv0_addr,
|
||||||
|
i2c_slv0_reg,
|
||||||
|
i2c_slv0_ctrl,
|
||||||
|
i2c_slv1_addr,
|
||||||
|
i2c_slv1_reg,
|
||||||
|
i2c_slv1_ctrl,
|
||||||
|
i2c_slv2_addr,
|
||||||
|
i2c_slv2_reg,
|
||||||
|
i2c_slv2_ctrl,
|
||||||
|
i2c_slv3_addr,
|
||||||
|
i2c_slv3_reg,
|
||||||
|
i2c_slv3_ctrl,
|
||||||
|
i2c_slv4_addr,
|
||||||
|
i2c_slv4_reg,
|
||||||
|
i2c_slv4_do,
|
||||||
|
i2c_slv4_ctrl,
|
||||||
|
i2c_slv4_di,
|
||||||
|
i2c_mst_status,
|
||||||
|
int_pin_cfg,
|
||||||
|
int_enable,
|
||||||
|
int_status,
|
||||||
|
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,
|
||||||
|
ext_sens_data_00,
|
||||||
|
ext_sens_data_01,
|
||||||
|
ext_sens_data_02,
|
||||||
|
ext_sens_data_03,
|
||||||
|
ext_sens_data_04,
|
||||||
|
ext_sens_data_05,
|
||||||
|
ext_sens_data_06,
|
||||||
|
ext_sens_data_07,
|
||||||
|
ext_sens_data_08,
|
||||||
|
ext_sens_data_09,
|
||||||
|
ext_sens_data_10,
|
||||||
|
ext_sens_data_11,
|
||||||
|
ext_sens_data_12,
|
||||||
|
ext_sens_data_13,
|
||||||
|
ext_sens_data_14,
|
||||||
|
ext_sens_data_15,
|
||||||
|
ext_sens_data_16,
|
||||||
|
ext_sens_data_17,
|
||||||
|
ext_sens_data_18,
|
||||||
|
ext_sens_data_19,
|
||||||
|
ext_sens_data_20,
|
||||||
|
ext_sens_data_21,
|
||||||
|
ext_sens_data_22,
|
||||||
|
ext_sens_data_23,
|
||||||
|
i2c_slv0_do,
|
||||||
|
i2c_slv1_do,
|
||||||
|
i2c_slv2_do,
|
||||||
|
i2c_slv3_do,
|
||||||
|
i2c_mst_delay_ctrl,
|
||||||
|
signal_path_reset,
|
||||||
|
user_ctrl,
|
||||||
|
pwr_mgmt_1,
|
||||||
|
pwr_mgmt_2,
|
||||||
|
fifo_couth = 0x72,
|
||||||
|
fifo_contl,
|
||||||
|
fifo_r_w,
|
||||||
|
who_am_i,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ############################
|
* ############################
|
||||||
* Structures
|
* Structures
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
#ifndef GY521_DRIVER_H
|
#ifndef GY521_DRIVER_H
|
||||||
#define GY521_DRIVER_H
|
#define GY521_DRIVER_H
|
||||||
#include "gy521_interface.h"
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -15,6 +16,10 @@
|
||||||
* ############################
|
* ############################
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define STARTUP_DELAY 30 //in ms
|
||||||
|
#define TWI_GY521_ADDR1 0x68 //ADO Logic Low
|
||||||
|
#define TWI_GY521_ADDR2 0x69 //ADO Logic High
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ############################
|
* ############################
|
||||||
* Types/Structures
|
* Types/Structures
|
||||||
|
@ -33,101 +38,13 @@ typedef struct accel_values{
|
||||||
uint16_t z;
|
uint16_t z;
|
||||||
}accel_values_struct;
|
}accel_values_struct;
|
||||||
|
|
||||||
/*
|
typedef struct gy521_module gy521_module;
|
||||||
* ############################
|
|
||||||
* REGISTER MAP
|
|
||||||
* ############################
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*This thing is fairly huge, but it's got pretty much all the registers
|
|
||||||
* on it.*/
|
|
||||||
|
|
||||||
enum gy521_map {
|
|
||||||
self_test_x = 0x0D,
|
|
||||||
self_test_y,
|
|
||||||
self_test_z,
|
|
||||||
self_test_a,
|
|
||||||
smplrt_div = 0x19,
|
|
||||||
config,
|
|
||||||
gyro_config,
|
|
||||||
accel_config,
|
|
||||||
fifo_en = 0x23,
|
|
||||||
i2c_mst_ctrl,
|
|
||||||
i2c_slv0_addr,
|
|
||||||
i2c_slv0_reg,
|
|
||||||
i2c_slv0_ctrl,
|
|
||||||
i2c_slv1_addr,
|
|
||||||
i2c_slv1_reg,
|
|
||||||
i2c_slv1_ctrl,
|
|
||||||
i2c_slv2_addr,
|
|
||||||
i2c_slv2_reg,
|
|
||||||
i2c_slv2_ctrl,
|
|
||||||
i2c_slv3_addr,
|
|
||||||
i2c_slv3_reg,
|
|
||||||
i2c_slv3_ctrl,
|
|
||||||
i2c_slv4_addr,
|
|
||||||
i2c_slv4_reg,
|
|
||||||
i2c_slv4_do,
|
|
||||||
i2c_slv4_ctrl,
|
|
||||||
i2c_slv4_di,
|
|
||||||
i2c_mst_status,
|
|
||||||
int_pin_cfg,
|
|
||||||
int_enable,
|
|
||||||
int_status,
|
|
||||||
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,
|
|
||||||
ext_sens_data_00,
|
|
||||||
ext_sens_data_01,
|
|
||||||
ext_sens_data_02,
|
|
||||||
ext_sens_data_03,
|
|
||||||
ext_sens_data_04,
|
|
||||||
ext_sens_data_05,
|
|
||||||
ext_sens_data_06,
|
|
||||||
ext_sens_data_07,
|
|
||||||
ext_sens_data_08,
|
|
||||||
ext_sens_data_09,
|
|
||||||
ext_sens_data_10,
|
|
||||||
ext_sens_data_11,
|
|
||||||
ext_sens_data_12,
|
|
||||||
ext_sens_data_13,
|
|
||||||
ext_sens_data_14,
|
|
||||||
ext_sens_data_15,
|
|
||||||
ext_sens_data_16,
|
|
||||||
ext_sens_data_17,
|
|
||||||
ext_sens_data_18,
|
|
||||||
ext_sens_data_19,
|
|
||||||
ext_sens_data_20,
|
|
||||||
ext_sens_data_21,
|
|
||||||
ext_sens_data_22,
|
|
||||||
ext_sens_data_23,
|
|
||||||
i2c_slv0_do,
|
|
||||||
i2c_slv1_do,
|
|
||||||
i2c_slv2_do,
|
|
||||||
i2c_slv3_do,
|
|
||||||
i2c_mst_delay_ctrl,
|
|
||||||
signal_path_reset,
|
|
||||||
user_ctrl,
|
|
||||||
pwr_mgmt_1,
|
|
||||||
pwr_mgmt_2,
|
|
||||||
fifo_couth = 0x72,
|
|
||||||
fifo_contl,
|
|
||||||
fifo_r_w,
|
|
||||||
who_am_i,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
passed = 0,
|
||||||
|
gyro_failed,
|
||||||
|
accel_failed,
|
||||||
|
}self_test_results;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ############################
|
* ############################
|
||||||
|
@ -135,22 +52,25 @@ enum gy521_map {
|
||||||
* ############################
|
* ############################
|
||||||
*/
|
*/
|
||||||
|
|
||||||
gy521_module* gy521_new(void);
|
|
||||||
|
|
||||||
void disable_self_test_gyro(struct gy521_module* m);
|
/*Function pointers for the TX and RX fuctionality*/
|
||||||
void enable_self_test_gyro(struct gy521_module* m);
|
|
||||||
struct ft_vals self_test_ft_calculation(struct gy521_module* m);
|
|
||||||
self_test_results gy521_self_test(struct gy521_module* m);
|
|
||||||
|
|
||||||
uint8_t read_register(gy521_module *m, enum gy521_map reg);
|
extern void (*gy521_twi_tx)(uint8_t, uint8_t*, uint8_t);
|
||||||
void write_register(gy521_module *m, enum gy521_map reg, uint8_t data);
|
extern void (*gy521_twi_rx)(uint8_t, uint8_t*, uint8_t);
|
||||||
|
|
||||||
|
|
||||||
|
struct gy521_module* gy521_new(void);
|
||||||
|
_Bool gy521_init(struct gy521_module *m, uint8_t slave_address);
|
||||||
|
void gy521_update_gyro(struct gy521_module* m);
|
||||||
|
void gy521_update_accel(struct gy521_module* m);
|
||||||
|
void gy521_free(struct gy521_module *m);
|
||||||
|
|
||||||
/*These are used instead of direct access; assuming interrupt driven*/
|
/*These are used instead of direct access; assuming interrupt driven*/
|
||||||
/*updates to the gy521 then it protects the user from using volatile values*/
|
/*updates to the gy521 then it protects the user from using volatile values*/
|
||||||
struct accel_values gy521_get_accel(struct gy521_module* m);
|
struct accel_values gy521_get_accel(struct gy521_module* m);
|
||||||
struct gyro_values gy521_get_gyro(struct gy521_module* m);
|
struct gyro_values gy521_get_gyro(struct gy521_module* m);
|
||||||
|
|
||||||
|
self_test_results gy521_self_test(struct gy521_module* m);
|
||||||
|
|
||||||
|
|
||||||
#endif /* GY521_DRIVER_H */
|
#endif /* GY521_DRIVER_H */
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
* Author: Jake Goodwin
|
|
||||||
* Filename: interface.h
|
|
||||||
* Description: The file you should include for normal use.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*Function pointers for the TX and RX fuctionality*/
|
|
||||||
|
|
||||||
#ifndef _GY521_INTERFACE_H
|
|
||||||
#define _GY521_INTERFACE_H
|
|
||||||
|
|
||||||
#include "stdint.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ############################
|
|
||||||
* DEFINES
|
|
||||||
* ############################
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define STARTUP_DELAY 30 //in ms
|
|
||||||
#define TWI_GY521_ADDR1 0x68 //ADO Logic Low
|
|
||||||
#define TWI_GY521_ADDR2 0x69 //ADO Logic High
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ############################
|
|
||||||
* Structures & Typedefs
|
|
||||||
* ############################
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct gy521_module gy521_module;
|
|
||||||
|
|
||||||
typedef enum{
|
|
||||||
passed = 0,
|
|
||||||
gyro_failed,
|
|
||||||
accel_failed,
|
|
||||||
}self_test_results;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ############################
|
|
||||||
* Fuction Prototypes
|
|
||||||
* ############################
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern void (*gy521_twi_tx)(uint8_t, uint8_t*, uint8_t);
|
|
||||||
extern void (*gy521_twi_rx)(uint8_t, uint8_t*, uint8_t);
|
|
||||||
|
|
||||||
|
|
||||||
struct gy521_module* gy521_new(void);
|
|
||||||
_Bool gy521_init(struct gy521_module *m, uint8_t slave_address);
|
|
||||||
void gy521_update_gyro(struct gy521_module* m);
|
|
||||||
void gy521_update_accel(struct gy521_module* m);
|
|
||||||
void gy521_free(struct gy521_module *m);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -341,17 +341,11 @@ static void test_gy521_self_test_accel(void **sate)
|
||||||
/*Mock Object/function for TWI RX*/
|
/*Mock Object/function for TWI RX*/
|
||||||
|
|
||||||
|
|
||||||
static void test_gy521_testing(void **state)
|
static void test_gy521_testing(void **sate)
|
||||||
{
|
{
|
||||||
assert_false(1);
|
assert_false(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_gyro_update(void **state)
|
|
||||||
{
|
|
||||||
assert_true(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -359,7 +353,7 @@ int main(void)
|
||||||
/*For testing TWI/I2C related stuff*/
|
/*For testing TWI/I2C related stuff*/
|
||||||
const struct CMUnitTest twi_group[] = {
|
const struct CMUnitTest twi_group[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_gy521_testing, setup_gy521_instance, teardown_gy521_instance),
|
cmocka_unit_test_setup_teardown(test_gy521_testing, setup_gy521_instance, teardown_gy521_instance),
|
||||||
cmocka_unit_test_setup_teardown(test_gyro_update, setup_gy521_instance, teardown_gy521_instance),
|
//cmocka_unit_test(test_gy521_testing),
|
||||||
};
|
};
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test(test_gy521_init),
|
cmocka_unit_test(test_gy521_init),
|
||||||
|
|
Loading…
Add table
Reference in a new issue