Split initialization from gyro.c for flash savings
[betaflight.git] / src / main / sensors / esc_sensor.h
blobbbee665f63dede251b87afd53ebb79198955935c
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "common/time.h"
25 typedef struct escSensorConfig_s {
26 uint8_t halfDuplex; // Set to false to listen on the TX pin for telemetry data
27 uint16_t offset; // offset consumed by the flight controller / VTX / cam / ... in milliampere
29 } escSensorConfig_t;
31 PG_DECLARE(escSensorConfig_t, escSensorConfig);
33 typedef struct {
34 uint8_t dataAge;
35 int8_t temperature; // C degrees
36 int16_t voltage; // 0.01V
37 int32_t current; // 0.01A
38 int32_t consumption; // mAh
39 int16_t rpm; // 0.01erpm
40 } escSensorData_t;
42 #define ESC_DATA_INVALID 255
44 #define ESC_BATTERY_AGE_MAX 10
46 bool escSensorInit(void);
47 void escSensorProcess(timeUs_t currentTime);
49 #define ESC_SENSOR_COMBINED 255
51 escSensorData_t *getEscSensorData(uint8_t motorNumber);
53 void startEscDataRead(uint8_t *frameBuffer, uint8_t frameLength);
54 uint8_t getNumberEscBytesRead(void);
56 uint8_t calculateCrc8(const uint8_t *Buf, const uint8_t BufLen);
58 int calcEscRpm(int erpm);