2022-09-26 20:23:48 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-09-12 16:48:05 -03:00
|
|
|
/*
|
|
|
|
* I2C driver for Measurement Specialties MEAS TSYS01 digital temperature sensor
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "AP_TemperatureSensor_Backend.h"
|
|
|
|
|
2022-09-26 20:23:48 -03:00
|
|
|
#ifndef AP_TEMPERATURE_SENSOR_TSYS01_ENABLED
|
|
|
|
#define AP_TEMPERATURE_SENSOR_TSYS01_ENABLED AP_TEMPERATURE_SENSOR_ENABLED
|
2022-09-12 16:48:05 -03:00
|
|
|
#endif
|
|
|
|
|
2022-09-26 20:23:48 -03:00
|
|
|
#if AP_TEMPERATURE_SENSOR_TSYS01_ENABLED
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
#define TSYS01_ADDR_CSB0 0x77
|
|
|
|
#define TSYS01_ADDR_CSB1 0x76
|
|
|
|
|
|
|
|
class AP_TemperatureSensor_TSYS01 : public AP_TemperatureSensor_Backend {
|
|
|
|
using AP_TemperatureSensor_Backend::AP_TemperatureSensor_Backend;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void init(void) override;
|
|
|
|
|
|
|
|
void update() override {};
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint16_t _k[5]; // internal calibration for temperature calculation
|
|
|
|
|
|
|
|
// reset device
|
2022-09-26 20:23:48 -03:00
|
|
|
bool reset(void) const;
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
// read (relevant) internal calibration registers into _k
|
2022-09-26 20:23:48 -03:00
|
|
|
bool read_prom(void);
|
|
|
|
uint16_t read_prom_word(const uint8_t word) const;
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
// begin an ADC conversion (min:7.40ms typ:8.22ms max:9.04ms)
|
2022-09-26 20:23:48 -03:00
|
|
|
void start_next_sample();
|
|
|
|
uint32_t read_adc(void) const;
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
// update the temperature, called at 20Hz
|
|
|
|
void _timer(void);
|
|
|
|
|
|
|
|
// calculate temperature using adc reading and internal calibration
|
2022-09-26 20:23:48 -03:00
|
|
|
float calculate(const uint32_t adc) const;
|
2022-09-12 16:48:05 -03:00
|
|
|
};
|
2022-09-26 20:23:48 -03:00
|
|
|
#endif // AP_TEMPERATURE_SENSOR_TSYS01_ENABLED
|