Line data Source code
1 : /* 2 : This program is free software: you can redistribute it and/or modify 3 : it under the terms of the GNU General Public License as published by 4 : the Free Software Foundation, either version 3 of the License, or 5 : (at your option) any later version. 6 : 7 : This program is distributed in the hope that it will be useful, 8 : but WITHOUT ANY WARRANTY; without even the implied warranty of 9 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 : GNU General Public License for more details. 11 : 12 : You should have received a copy of the GNU General Public License 13 : along with this program. If not, see <http://www.gnu.org/licenses/>. 14 : */ 15 : 16 : /* 17 : * I2C driver for Measurement Specialties MEAS TSYS01 digital temperature sensor 18 : */ 19 : 20 : #pragma once 21 : #include "AP_TemperatureSensor_Backend.h" 22 : 23 : #ifndef AP_TEMPERATURE_SENSOR_TSYS01_ENABLED 24 : #define AP_TEMPERATURE_SENSOR_TSYS01_ENABLED AP_TEMPERATURE_SENSOR_ENABLED 25 : #endif 26 : 27 : #if AP_TEMPERATURE_SENSOR_TSYS01_ENABLED 28 : 29 : #define TSYS01_ADDR_CSB0 0x77 30 : #define TSYS01_ADDR_CSB1 0x76 31 : 32 : class AP_TemperatureSensor_TSYS01 : public AP_TemperatureSensor_Backend { 33 : using AP_TemperatureSensor_Backend::AP_TemperatureSensor_Backend; 34 : 35 : public: 36 : __INITFUNC__ void init(void) override; 37 : 38 27101 : void update() override {}; 39 : 40 : 41 : private: 42 : uint16_t _k[5]; // internal calibration for temperature calculation 43 : 44 : // reset device 45 : bool reset(void) const; 46 : 47 : // read (relevant) internal calibration registers into _k 48 : bool read_prom(void); 49 : uint16_t read_prom_word(const uint8_t word) const; 50 : 51 : // begin an ADC conversion (min:7.40ms typ:8.22ms max:9.04ms) 52 : void start_next_sample(); 53 : uint32_t read_adc(void) const; 54 : 55 : // update the temperature, called at 20Hz 56 : void _timer(void); 57 : 58 : // calculate temperature using adc reading and internal calibration 59 : float calculate(const uint32_t adc) const; 60 : }; 61 : #endif // AP_TEMPERATURE_SENSOR_TSYS01_ENABLED