Minor updates the QMC5883L driver, implemented the softreset function for the BMP280 sensor and wrote the driver for the CST816D touch screen ic.

This commit is contained in:
anschrammh 2023-01-03 08:32:02 +01:00
parent facbd92bf5
commit 6187537a78
7 changed files with 101 additions and 23 deletions

View File

@ -4,7 +4,7 @@
#include "wm_osal.h"
#include "FreeRTOS.h"
typedef struct
typedef struct BMP280_calibration_data
{
uint16_t dig_T1;
int16_t dig_T2;
@ -19,9 +19,9 @@ typedef struct
int16_t dig_P8;
int16_t dig_P9;
} BMP280_calibration_data;
} BMP280_calibration_data_t;
static BMP280_calibration_data _calibration_data = {0};
static BMP280_calibration_data_t _calibration_data = {0};
static BMP280_Mode_e _mode;
static int32_t t_fine = 0;
@ -141,5 +141,5 @@ float BMP280_get_temperature(void)
bool BMP280_software_reset(void)
{
return false;
return i2c_write_reg(BMP280_I2C_ADDR, BMP280_RESET, BMP280_RESET_CODE);
}

View File

@ -7,6 +7,8 @@
/* Device ID */
#define BMP280_ID 0x58
#define BMP280_RESET_CODE 0xB6
/* Device registers list */
#define BMP280_TEMP_XLSB 0xFC
#define BMP280_TEMP_LSB 0xFB
@ -37,14 +39,14 @@
/* Field masks */
/* Configuration enumerations */
typedef enum
typedef enum BMP280_Mode
{
BMP280_Sleep = 0,
BMP280_Forced = 1,
BMP280_Normal = 3,
} BMP280_Mode_e;
typedef enum
typedef enum BMP280_Oversampling
{
BMP280_Oversampling_Skipped = 0,
BMP280_Oversampling_x1 = 1,
@ -54,7 +56,7 @@ typedef enum
BMP280_Oversampling_x16 = 5,
} BMP280_Oversampling_e;
typedef enum
typedef enum BMP280_Filter
{
BMP280_Filter_OFF = 0,
BMP280_Filter_x2 = 1,
@ -63,7 +65,7 @@ typedef enum
BMP280_Filter_x16 = 4,
} BMP280_Filter_e;
typedef enum
typedef enum BMP280_Standby_Duration
{
BMP280_Standby_0_5MS = 0,
BMP280_Standby_62_5MS = 1,
@ -75,8 +77,6 @@ typedef enum
BMP280_Standby_4000MS = 7,
} BMP280_Standby_Duration_e;
bool BMP280_init(void);
bool BMP280_configure(BMP280_Mode_e mode, BMP280_Oversampling_e temperature_oversampling, BMP280_Oversampling_e pressure_oversampling, BMP280_Filter_e filter, BMP280_Standby_Duration_e standby_duration);
@ -85,6 +85,8 @@ bool BMP280_trigger_measurement(void);
float BMP280_get_temperature(void);
float BMP280_get_pressure(void);
bool BMP280_software_reset(void);
#endif //BMP280_H

View File

@ -0,0 +1,24 @@
#include "i2c.h"
#include "CST816D.h"
bool CST816D_read_touch_event(CST816D_Touch_Data_t * const touch_data)
{
if(!touch_data) return false;
uint8_t data[7];
// Let's do an auto inc read of 7 bytes
if(i2c_read(CST816D_I2C_ADDR, CST816D_00, data, sizeof data))
{
touch_data->touch_x = ((data[3] & 0x0F) << 8) | data[4];
touch_data->touch_y = ((data[5] & 0x0F) << 8) | data[6];
touch_data->id = data[5] >> 4;
touch_data->touch_points = data[2] & 0x0F;
touch_data->gesture = data[1];
touch_data->event = data[3] >> 6;
touch_data->isValid = true;
return true;
}
touch_data->isValid = false;
return false;
}

View File

@ -0,0 +1,59 @@
#ifndef CST816D_H
#define CST816D_H
/* Device i2c address */
#define CST816D_I2C_ADDR 0x15
/* Device registers list */
#define CST816D_00 0x00
#define CST816D_GESTURE 0x01
#define CST816D_TOUCH_POINTS 0x02
#define CST816D_TOUCH_X_MSB 0x03
#define CST816D_TOUCH_X_LSB 0x04
#define CST816D_TOUCH_Y_MSB_AND_ID 0x05
#define CST816D_TOUCH_Y_LSB 0x06
typedef enum CST816D_Gesture
{
CST816D_Gesture_None = 0,
CST816D_Gesture_Swipe_Down,
CST816D_Gesture_Swipe_Up,
CST816D_Gesture_Swipe_Left,
CST816D_Gesture_Swipe_Right,
CST816D_Gesture_Tap,
CST816D_Gesture_Double_Tap = 11,
CST816D_Gesture_Long_Press,
} __attribute__((packed)) CST816D_Gesture_e;
typedef enum CST816D_Event
{
CST816D_Event_Touch_Down = 0,
CST816D_Event_Released,
CST816D_Event_Pressed,
} __attribute__((packed)) CST816D_Event_e;
typedef struct CST816D_Touch_Data
{
uint16_t touch_x;
uint16_t touch_y;
uint8_t id : 4;
uint8_t touch_points : 4;
CST816D_Gesture_e gesture;
bool isValid : 1;
CST816D_Event_e event : 2;
} CST816D_Touch_Data_t;
/**
* @brief Reads the incoming touch event data which contains the x and y
* position of the touch as well as various other information.
* /!\ This function has to be called in the IRQ ISR because
* the chip can only be read during a short time after the it triggered the interrupt !
*
* @param touch_data a pointer to a user allocated structure of type CST816D_Touch_Data_t
* @return true on success, ie successfully read the data from the chip
* @return false otherwise
*/
bool CST816D_read_touch_event(CST816D_Touch_Data_t * const touch_data);
#endif //CST816D_H

View File

@ -1,6 +0,0 @@
#ifndef CST816D_H
#define CST816D_H
#endif //CST816D_H

View File

@ -19,13 +19,13 @@
#define QMC5883L_DOR_BIT 0x04
/* Configuration enumerations */
typedef enum
typedef enum QMC5883L_Mode_Control
{
Standby = 0,
Continuous = 1,
} QMC5883L_Mode_Control_e;
typedef enum
typedef enum QMC5883L_Output_Data_Rate
{
ODR_10HZ = 0,
ODR_50HZ = 1,
@ -33,13 +33,13 @@ typedef enum
ODR_200HZ = 3,
} QMC5883L_Output_Data_Rate_e;
typedef enum
typedef enum QMC5883L_Full_Scale
{
FS_2G = 0,
FS_8G = 1,
} QMC5883L_Full_Scale_e;
typedef enum
typedef enum QMC5883L_Over_Sample_Ratio
{
OSR_512 = 0,
OSR_256 = 1,
@ -48,14 +48,14 @@ typedef enum
} QMC5883L_Over_Sample_Ratio_e;
typedef struct
typedef struct QMC5883L_MData
{
int16_t MFieldX;
int16_t MFieldY;
int16_t MFieldZ;
} QMC5883L_MData_t;
typedef struct
typedef struct QMC5883L_MData_calibrated
{
int16_t MFieldX;
int16_t MFieldY;