/* * File: sps30.h * Description: Sensirion SPS30 sensor communication library * Author: David Zaitlik * Date: 2021-07-18 * * * Copyright (c) 2024 Veles Labs s.r.o. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ #ifndef INC_SPS30_H_ #define INC_SPS30_H_ #include "stdint.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_ */