updated and added some basic tests for the driver
This commit is contained in:
parent
7ae112a7ce
commit
06310475df
|
@ -1,4 +1,5 @@
|
|||
add_subdirectory(led_driver)
|
||||
add_subdirectory(gy521_driver)
|
||||
|
||||
|
||||
add_executable(main
|
||||
|
@ -7,4 +8,5 @@ add_executable(main
|
|||
|
||||
target_link_libraries(main
|
||||
led_driver
|
||||
gy521_driver
|
||||
)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
add_library(gy521_driver STATIC
|
||||
gy521_driver.c
|
||||
)
|
||||
|
||||
target_include_directories(gy521_driver PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Author: Jake Goodwin
|
||||
* Date: 2023
|
||||
* Description:
|
||||
*/
|
||||
#include "gy521_driver.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
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;
|
||||
|
||||
typedef struct{
|
||||
_Bool (*init)(uint8_t slv_addr);
|
||||
}methods_struct;
|
||||
|
||||
typedef struct{
|
||||
uint8_t slave_address;
|
||||
gyro_values_struct gyro;
|
||||
accel_values_struct accel;
|
||||
methods_struct methods;
|
||||
}gy521_module_struct;
|
||||
|
||||
|
||||
_Bool init_gy521(uint8_t slave_address) {
|
||||
if(slave_address != TWI_GY521_ADDR1 && slave_address != TWI_GY521_ADDR2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
_Bool module_test(gy521_module_struct *m)
|
||||
{
|
||||
_Bool ret = m->methods.init(TWI_GY521_ADDR1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* returns 1 */
|
||||
uint8_t test_function(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Author: Jake Goodwin
|
||||
* Date: 2023
|
||||
* Description:
|
||||
*/
|
||||
|
||||
#ifndef GY521_DRIVER_H
|
||||
#define GY521_DRIVER_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
|
||||
|
||||
/*
|
||||
* ############################
|
||||
* Types/Structures
|
||||
* ############################
|
||||
*/
|
||||
//typedef struct gy521_module_struct *gy521_module;
|
||||
typedef struct gy521_module_struct *gy521_module;
|
||||
|
||||
/*
|
||||
* ############################
|
||||
* Function Prototypes
|
||||
* ############################
|
||||
*/
|
||||
|
||||
/*Function pointers for the TX and RX fuctionality*/
|
||||
extern void twi_tx(uint8_t *data, uint8_t size);
|
||||
extern void twi_rx(uint8_t *data, uint8_t size);
|
||||
|
||||
_Bool init_gy521(uint8_t slave_address);
|
||||
|
||||
|
||||
|
||||
_Bool module_test(struct gy521_module_struct *m);
|
||||
uint8_t test_function(void);
|
||||
|
||||
|
||||
|
||||
#endif /* GY521_DRIVER_H */
|
Loading…
Reference in New Issue