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 : MSP version 1 and 2 protocol library, based on betaflight/iNav implementations 17 : code by Alex Apostoli 18 : */ 19 : 20 : #pragma once 21 : 22 : #include "AP_MSP_config.h" 23 : 24 : #if HAL_MSP_ENABLED 25 : 26 : #include <AP_OSD/AP_OSD.h> 27 : #include "AP_MSP_Telem_Backend.h" 28 : 29 : #ifndef AP_MSP_INAV_FONTS_ENABLED 30 : #define AP_MSP_INAV_FONTS_ENABLED 1 31 : #endif 32 : 33 : #define MSP_MAX_INSTANCES 3 34 : #define MSP_OSD_START 2048 35 : #define MSP_OSD_STEP_X 1 36 : #define MSP_OSD_STEP_Y 32 37 : #define MSP_OSD_POS(osd_setting) (MSP_OSD_START + osd_setting->xpos*MSP_OSD_STEP_X + osd_setting->ypos*MSP_OSD_STEP_Y) 38 : 39 : class AP_MSP 40 : { 41 : friend class AP_MSP_Telem_Generic; 42 : friend class AP_MSP_Telem_DJI; 43 : friend class AP_MSP_Telem_Backend; 44 : #if HAL_WITH_MSP_DISPLAYPORT 45 : friend class AP_MSP_Telem_DisplayPort; 46 : friend class AP_OSD_MSP_DisplayPort; 47 : #endif 48 : public: 49 : AP_MSP(); 50 : 51 : /* Do not allow copies */ 52 : CLASS_NO_COPY(AP_MSP); 53 : 54 : // User settable parameters 55 : static const struct AP_Param::GroupInfo var_info[]; 56 : 57 : // init - perform required initialisation 58 : void init(); 59 : 60 : enum class Option : uint8_t { 61 : TELEMETRY_MODE = 1U<<0, 62 : TELEMETRY_DISABLE_DJI_WORKAROUNDS = 1U<<1, 63 : DISPLAYPORT_BTFL_SYMBOLS = 1U<<2, 64 : DISPLAYPORT_INAV_SYMBOLS = 1U<<3, 65 : VTX_HIGH_POWER = 1U<<4, 66 : }; 67 : 68 : bool is_option_enabled(const Option option) const; 69 : 70 60983 : static AP_MSP *get_singleton(void) 71 : { 72 60983 : return _singleton; 73 : } 74 : 75 : private: 76 : AP_MSP_Telem_Backend *_backends[MSP_MAX_INSTANCES]; 77 : 78 : AP_Int8 _options; 79 : AP_Int8 _cellcount; 80 : 81 : // these are the osd items we support for MSP OSD 82 : AP_OSD_Setting* _osd_item_settings[MSP::OSD_ITEM_COUNT]; 83 : MSP::osd_config_t _osd_config; 84 : 85 : struct { 86 : bool flashing_on; // OSD item flashing support @1.4Hz 87 : bool slow_flashing_on; // OSD item flashing support @0.5H 88 : uint8_t last_flight_mode = 255; 89 : uint32_t last_flight_mode_change_ms; 90 : bool flight_mode_focus; // do we need to steal focus from text messages 91 : bool osd_initialized; // for one time osd initialization 92 : uint8_t backend_count; // actual count of active bacends 93 : uint8_t current_screen; // defaults to screen 0 94 : } _msp_status; 95 : 96 : bool init_backend(uint8_t backend_idx, AP_HAL::UARTDriver *uart, AP_SerialManager::SerialProtocol protocol); 97 : void update_osd_item_settings(); 98 : void loop(void); 99 : AP_MSP_Telem_Backend* find_protocol(const AP_SerialManager::SerialProtocol protocol) const; 100 : 101 : static AP_MSP *_singleton; 102 : }; 103 : 104 : namespace AP 105 : { 106 : AP_MSP *msp(); 107 : }; 108 : 109 : #endif //HAL_MSP_ENABLED