dev #1

Merged
jakegoodwin merged 11 commits from dev into main 2023-09-01 01:22:30 +00:00
2 changed files with 35 additions and 12 deletions
Showing only changes of commit 75a28027f5 - Show all commits

View File

@ -54,17 +54,7 @@ enum gy521_map {
* ############################ * ############################
*/ */
typedef struct{
uint16_t x;
uint16_t y;
uint16_t z;
}gyro_values_struct;
typedef struct{
uint16_t x;
uint16_t y;
uint16_t z;
}accel_values_struct;
struct gy521_module{ struct gy521_module{
uint8_t slave_address; uint8_t slave_address;
@ -139,6 +129,7 @@ _Bool gy521_init(gy521_module *m, uint8_t slave_address) {
void gy521_update_accel(gy521_module *m) void gy521_update_accel(gy521_module *m)
{ {
/*We shift the High byte over by 8 for a u16*/
m->accel.x = read_register(m, accel_xouth) <<8; m->accel.x = read_register(m, accel_xouth) <<8;
m->accel.x |= read_register(m, accel_xoutl); m->accel.x |= read_register(m, accel_xoutl);
m->accel.y = read_register(m, accel_youth) <<8; m->accel.y = read_register(m, accel_youth) <<8;
@ -149,6 +140,7 @@ void gy521_update_accel(gy521_module *m)
void gy521_update_gyro(gy521_module *m) void gy521_update_gyro(gy521_module *m)
{ {
/*We shift the High byte over by 8 for a u16*/
m->gyro.x = read_register(m, gyro_xouth) <<8; m->gyro.x = read_register(m, gyro_xouth) <<8;
m->gyro.x |= read_register(m, gyro_xoutl); m->gyro.x |= read_register(m, gyro_xoutl);
m->gyro.y = read_register(m, gyro_youth) <<8; m->gyro.y = read_register(m, gyro_youth) <<8;
@ -158,3 +150,21 @@ void gy521_update_gyro(gy521_module *m)
} }
struct accel_values gy521_get_accel(struct gy521_module* m)
{
struct accel_values s;
s.x = m->accel.x;
s.y = m->accel.y;
s.z = m->accel.z;
return s;
}
struct gyro_values gy521_get_gyro(struct gy521_module* m)
{
struct gyro_values s;
s.x = m->gyro.x;
s.y = m->gyro.y;
s.z = m->gyro.z;
return s;
}

View File

@ -25,6 +25,18 @@
* Types/Structures * Types/Structures
* ############################ * ############################
*/ */
typedef struct gyro_values{
uint16_t x;
uint16_t y;
uint16_t z;
}gyro_values_struct;
typedef struct accel_values{
uint16_t x;
uint16_t y;
uint16_t z;
}accel_values_struct;
typedef struct gy521_module gy521_module; typedef struct gy521_module gy521_module;
/* /*
@ -45,6 +57,7 @@ _Bool gy521_init(struct gy521_module *m, uint8_t slave_address);
void gy521_update_gyro(struct gy521_module* m); void gy521_update_gyro(struct gy521_module* m);
void 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);
struct accel_values gy521_get_accel(struct gy521_module* m);
struct gyro_values gy521_get_gyro(struct gy521_module* m);
#endif /* GY521_DRIVER_H */ #endif /* GY521_DRIVER_H */