diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e89dd68..d0d28d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(led_driver) +add_subdirectory(gy521_driver) add_executable(main @@ -6,5 +7,6 @@ add_executable(main ) target_link_libraries(main - led_driver + led_driver + gy521_driver ) diff --git a/src/gy521_driver/CMakeLists.txt b/src/gy521_driver/CMakeLists.txt new file mode 100644 index 0000000..cbcf02c --- /dev/null +++ b/src/gy521_driver/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(gy521_driver STATIC + gy521_driver.c +) + +target_include_directories(gy521_driver PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) diff --git a/src/gy521_driver/gy521_driver.c b/src/gy521_driver/gy521_driver.c new file mode 100644 index 0000000..2bd095c --- /dev/null +++ b/src/gy521_driver/gy521_driver.c @@ -0,0 +1,53 @@ +/* + * Author: Jake Goodwin + * Date: 2023 + * Description: + */ +#include "gy521_driver.h" +#include + + +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; +} diff --git a/src/gy521_driver/gy521_driver.h b/src/gy521_driver/gy521_driver.h new file mode 100644 index 0000000..fde1227 --- /dev/null +++ b/src/gy521_driver/gy521_driver.h @@ -0,0 +1,49 @@ +/* + * Author: Jake Goodwin + * Date: 2023 + * Description: + */ + +#ifndef GY521_DRIVER_H +#define GY521_DRIVER_H + +#include + +/* + * ############################ + * 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 */