From e25f035863d5607d031978cde79ff1afb9df4401 Mon Sep 17 00:00:00 2001 From: William Clark Date: Thu, 21 Dec 2023 17:31:12 +0000 Subject: [PATCH] work on C implementation --- lis3dh.c | 9 +++++++++ lis3dh.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 lis3dh.c create mode 100644 lis3dh.h diff --git a/lis3dh.c b/lis3dh.c new file mode 100644 index 0000000..4f7f569 --- /dev/null +++ b/lis3dh.c @@ -0,0 +1,9 @@ +#include "lis3dh.h" + +int lis3dh_init(lis3dh_t *lis3dh) { + return 0; +} + +int lis3dh_deinit(lis3dh_t *lis3dh) { + return 0; +} \ No newline at end of file diff --git a/lis3dh.h b/lis3dh.h new file mode 100644 index 0000000..ab58c62 --- /dev/null +++ b/lis3dh.h @@ -0,0 +1,51 @@ +#ifndef LIS3DH_H +#define LIS3DH_H + +#include + +/* rats */ +#define LIS3DH_ODR_1_HZ 0b0001 +#define LIS3DH_ODR_10_HZ 0b0010 +#define LIS3DH_ODR_25_HZ 0b0011 +#define LIS3DH_ODR_50_HZ 0b0100 +#define LIS3DH_ODR_100_HZ 0b0101 +#define LIS3DH_ODR_200_HZ 0b0110 +#define LIS3DH_ODR_400_HZ 0b0111 +#define LIS3DH_ODR_10_HZ 0b0011 +#define LIS3DH_ODR_LP_1600_HZ 0b1000 +#define LIS3DH_ODR_NORM_1344_HZ 0b1001 +#define LIS3DH_ODR_LP_5376_HZ 0b1001 + +/* range/sens */ +#define LIS3DH_FS_2G = 0b00 +#define LIS3DH_FS_4G = 0b01 +#define LIS3DH_FS_8G = 0b10 +#define LIS3DH_FS_16G = 0b11 + + +struct lis3dh_device { + int (*init)(void); + int (*read)(uint8_t reg, uint8_t *dst, uint32_t size); + int (*write)(uint8_t reg, uint8_t value); + int (*sleep)(uint32_t dur_us); + int (*deinit)(void); +}; + +struct lis3dh_config { + uint8_t rate; /* ODR */ + uint8_t range; /* FS */ + uint8_t mode; /* LPen */ + uint8_t hr; /* high resolution */ +}; + +struct lis3dh { + struct lis3dh_device dev; + struct lis3dh_config cfg; +}; + +typedef struct lis3dh lis3dh_t; + +int lis3dh_init(lis3dh_t *lis3dh); +int lis3dh_deinit(lis3dh_t *lis3dh); + +#endif \ No newline at end of file