93 lines
2.0 KiB
C
93 lines
2.0 KiB
C
/*
|
|
* sps30.h
|
|
*
|
|
* Created on: Jul 18, 2021
|
|
* Author: mrs
|
|
*/
|
|
|
|
#ifndef INC_SPS30_H_
|
|
#define INC_SPS30_H_
|
|
|
|
#include "stdint.h"
|
|
#include "stm32l0xx_ll_i2c.h"
|
|
#include "stm32l0xx_ll_utils.h"
|
|
#include "i2c.h"
|
|
#include "crc8.h"
|
|
|
|
/*
|
|
* Defines & macros
|
|
*/
|
|
|
|
#define SPS30_I2C_ADDRESS 0x69
|
|
#define SPS30_MEASURED_VALUES_COUNT 10
|
|
|
|
/*
|
|
* Return values
|
|
*/
|
|
|
|
#define SPS30_OK 0
|
|
#define SPS30_ERROR -1 // generic error
|
|
#define SPS30_CRC8_ERROR -2 // checksum failed
|
|
|
|
/*
|
|
* Data types
|
|
*/
|
|
|
|
typedef enum {
|
|
SPS30_START_MEASUREMENT = 0x0010,
|
|
SPS30_STOP_MEASUREMENT = 0x0104,
|
|
SPS30_READ_DATA_READY_FLAG = 0x0202,
|
|
SPS30_READ_MEASURED_VALUES = 0x0300,
|
|
SPS30_SLEEP = 0x1001,
|
|
SPS30_WAKE_UP = 0x1103,
|
|
SPS30_START_FAN_CLEANING = 0x5607,
|
|
SPS30_READ_AUTO_CLEANING_INTERVAL = 0x8004,
|
|
SPS30_WRITE_AUTO_CLEANING_INTERVAL = 0x8004,
|
|
SPS30_READ_PRODUCT_TYPE = 0xD002,
|
|
SPS30_READ_SERIAL_NUMBER = 0xD033,
|
|
SPS30_READ_VERSION = 0xD100,
|
|
SPS30_READ_DEVICE_STATUS_REGISTER = 0xD206,
|
|
SPS30_CLEAR_DEVICE_STATUS_REGISTER = 0xD210,
|
|
SPS30_RESET = 0xD304
|
|
} sps30_cmd_t;
|
|
|
|
typedef enum {
|
|
SPS30_FLOAT_FORMAT = 0x03,
|
|
SPS30_UINT16_FORMAT = 0x05
|
|
} sps30_data_format_t;
|
|
|
|
typedef enum {
|
|
PM0_5 = 0, /* this category is used only for number concentration */
|
|
PM1_0,
|
|
PM2_5,
|
|
PM4_0,
|
|
PM10_0,
|
|
SPS30_PM_CATEGORIES_COUNT
|
|
} sps30_pm_categories_t;
|
|
|
|
typedef struct {
|
|
/* PM0.5 is skipped for mass concentration */
|
|
uint16_t mass_concentration[SPS30_PM_CATEGORIES_COUNT]; /* ug / m^3 */
|
|
uint16_t number_concentration[SPS30_PM_CATEGORIES_COUNT]; /* 1 / cm^3 */
|
|
uint16_t typical_particle_size; /* nm */
|
|
} sps30_data_t;
|
|
|
|
int8_t sps30_send_cmd(sps30_cmd_t cmd);
|
|
|
|
int8_t sps30_start_measurement( void );
|
|
int8_t sps30_stop_measurement( void );
|
|
int8_t sps30_read_measured_values(sps30_data_t *measured_data);
|
|
|
|
int8_t sps30_sleep( void );
|
|
int8_t sps30_wake_up( void );
|
|
|
|
int8_t sps30_start_fan_cleaning( void );
|
|
|
|
int8_t sps30_reset( void );
|
|
|
|
int8_t sps30_read_status_register ( void );
|
|
|
|
int8_t sps30_read_firmware_version ( uint8_t * fw_ver_hi, uint8_t * fw_ver_lo );
|
|
|
|
#endif /* INC_SPS30_H_ */
|