5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
25 #include "../definitions.h"
26 #include "../opentx_constants.h"
27 #include "board_common.h"
31 #if defined(ROTARY_ENCODER_NAVIGATION)
32 // Rotary Encoder driver
33 void rotaryEncoderInit();
34 void rotaryEncoderCheck();
37 #define FLASHSIZE 0x80000
38 #define BOOTLOADER_SIZE 0x8000
39 #define FIRMWARE_ADDRESS 0x08000000
41 #define LUA_MEM_MAX (0) // max allowed memory usage for complete Lua (in bytes), 0 means unlimited
44 #define PERI1_FREQUENCY 42000000
45 #define PERI2_FREQUENCY 84000000
47 #define PERI1_FREQUENCY 30000000
48 #define PERI2_FREQUENCY 60000000
51 #define TIMER_MULT_APB1 2
52 #define TIMER_MULT_APB2 2
54 extern uint16_t sessionTimer
;
65 #define BLOCK_SIZE 512 /* Block Size in Bytes */
66 #if !defined(SIMU) || defined(SIMU_DISKIO)
68 uint32_t sdGetSpeed();
69 #define SD_IS_HC() (sdIsHC())
70 #define SD_GET_SPEED() (sdGetSpeed())
71 #define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
73 #define SD_IS_HC() (0)
74 #define SD_GET_SPEED() (0)
76 #define __disk_read disk_read
77 #define __disk_write disk_write
79 #if !defined(SIMU_DISKIO)
84 #define SD_CARD_PRESENT() true
91 #define SD_CARD_PRESENT() ((SD_GPIO_PRESENT_GPIO->IDR & SD_GPIO_PRESENT_GPIO_PIN) == 0)
95 #define FLASH_PAGESIZE 256
98 void flashWrite(uint32_t * address
, const uint32_t * buffer
);
99 uint32_t isFirmwareStart(const uint8_t * buffer
);
100 uint32_t isBootloaderStart(const uint8_t * buffer
);
103 #define INTERNAL_MODULE_ON() GPIO_SetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN)
104 #if defined(INTMODULE_USART)
105 #define INTERNAL_MODULE_OFF() intmoduleStop()
107 #define INTERNAL_MODULE_OFF() GPIO_ResetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN)
110 #define EXTERNAL_MODULE_ON() EXTERNAL_MODULE_PWR_ON()
112 #if defined(EXTMODULE_USART)
113 #define EXTERNAL_MODULE_OFF() extmoduleStop()
115 #define EXTERNAL_MODULE_OFF() EXTERNAL_MODULE_PWR_OFF()
118 #if defined(RADIO_T12)
119 #define IS_INTERNAL_MODULE_ON() false
121 #define IS_INTERNAL_MODULE_ON() (GPIO_ReadInputDataBit(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) == Bit_SET)
124 void intmoduleSerialStart(uint32_t baudrate
, uint8_t rxEnable
, uint16_t parity
, uint16_t stopBits
, uint16_t wordLength
);
125 #if defined(INTERNAL_MODULE_MULTI)
126 void intmoduleTimerStart(uint32_t periodMs
);
128 void intmoduleSendByte(uint8_t byte
);
129 void intmoduleSendBuffer(const uint8_t * data
, uint8_t size
);
130 void intmoduleSendNextFrame();
132 void extmoduleSerialStart(uint32_t baudrate
, uint32_t period_half_us
, bool inverted
);
133 void extmoduleInvertedSerialStart(uint32_t baudrate
);
134 void extmoduleSendBuffer(const uint8_t * data
, uint8_t size
);
135 void extmoduleSendNextFrame();
136 void extmoduleSendInvertedByte(uint8_t byte
);
139 #define SLAVE_MODE() (g_model.trainerData.mode == TRAINER_MODE_SLAVE)
141 #if defined(PCBX9D) || (defined(PCBX9DP) && PCBREV < 2019)
142 // Trainer detect is a switch on the jack
143 #define TRAINER_CONNECTED() (GPIO_ReadInputDataBit(TRAINER_DETECT_GPIO, TRAINER_DETECT_GPIO_PIN) == Bit_RESET)
144 #elif defined(PCBXLITES)
145 // Trainer is on the same connector than Headphones
152 extern uint8_t jackState
;
153 #define TRAINER_CONNECTED() (jackState == TRAINER_ACTIVE)
154 #elif defined(PCBXLITE)
155 // No Tainer jack on Taranis X-Lite
156 #define TRAINER_CONNECTED() false
158 // Trainer detect catches PPM, detection would use more CPU
159 #define TRAINER_CONNECTED() true
162 #if defined(TRAINER_GPIO)
163 void init_trainer_ppm();
164 void stop_trainer_ppm();
165 void init_trainer_capture();
166 void stop_trainer_capture();
168 #define init_trainer_ppm()
169 #define stop_trainer_ppm()
170 #define init_trainer_capture()
171 #define stop_trainer_capture()
173 #if defined(TRAINER_MODULE_CPPM)
174 void init_trainer_module_cppm();
175 void stop_trainer_module_cppm();
177 #define init_trainer_module_cppm()
178 #define stop_trainer_module_cppm()
180 #if defined(TRAINER_MODULE_SBUS)
181 void init_trainer_module_sbus();
182 void stop_trainer_module_sbus();
184 #define init_trainer_module_sbus()
185 #define stop_trainer_module_sbus()
188 #if defined(INTMODULE_HEARTBEAT_GPIO)
189 void init_intmodule_heartbeat();
190 void stop_intmodule_heartbeat();
191 void check_intmodule_heartbeat();
193 #define init_intmodule_heartbeat()
194 #define stop_intmodule_heartbeat()
195 #define check_intmodule_heartbeat()
198 void check_telemetry_exti();
201 int sbusGetByte(uint8_t * byte
);
206 #if defined(KEYS_GPIO_REG_SHIFT)
210 #if defined(KEYS_GPIO_REG_MENU)
217 #if defined(KEYS_GPIO_REG_DOWN)
222 #if defined(KEYS_GPIO_REG_RIGHT)
227 #if defined(KEYS_GPIO_REG_PAGE)
231 #if defined(KEYS_GPIO_REG_PLUS)
237 KEY_MAX
= KEY_COUNT
- 1,
239 #if defined(ROTARY_ENCODER_NAVIGATION)
245 TRM_LH_DWN
= TRM_BASE
,
253 TRM_LAST
= TRM_RH_UP
,
258 #if defined(PCBX9E) && !defined(SIMU)
259 #define KEY_UP KEY_MINUS
260 #define KEY_DOWN KEY_PLUS
261 #define KEY_RIGHT KEY_PLUS
262 #define KEY_LEFT KEY_MINUS
263 #elif defined(NAVIGATION_XLITE)
264 #define KEY_PLUS KEY_RIGHT
265 #define KEY_MINUS KEY_LEFT
266 #elif defined(NAVIGATION_9X)
267 #define KEY_MENU KEY_ENTER
268 #define KEY_MINUS KEY_DOWN
269 #define KEY_PLUS KEY_UP
271 #define KEY_UP KEY_PLUS
272 #define KEY_DOWN KEY_MINUS
273 #define KEY_RIGHT KEY_MINUS
274 #define KEY_LEFT KEY_PLUS
277 #if defined(KEYS_GPIO_PIN_SHIFT)
278 #define IS_SHIFT_KEY(index) (index == KEY_SHIFT)
280 #define IS_SHIFT_PRESSED() (readKeys() & (1 << KEY_SHIFT))
282 #define IS_SHIFT_PRESSED() (~KEYS_GPIO_REG_SHIFT & KEYS_GPIO_PIN_SHIFT)
285 #define IS_SHIFT_KEY(index) (false)
286 #define IS_SHIFT_PRESSED() (false)
300 #define IS_3POS(x) ((x) != SW_SF && (x) != SW_SH)
302 enum EnumSwitchesPositions
316 #if defined(PCBX9) || defined(PCBXLITES) || defined(PCBX9LITES)
321 #if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E) || defined(PCBX7) || defined(PCBXLITES) || defined(PCBX9LITES)
326 #if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E) || defined(PCBX9LITES)
331 #if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E) || defined(PCBX7)
336 #if defined(PCBX9DP) && PCBREV >= 2019
341 #if defined(PCBX7ACCESS)
385 NUM_SWITCHES_POSITIONS
388 #if defined(PCBXLITES)
389 #define NUM_SWITCHES 6
390 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
391 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_2POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
392 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 2) + (POT_WITHOUT_DETENT << 0)
393 #elif defined(PCBXLITE)
394 #define NUM_SWITCHES 4
395 #define STORAGE_NUM_SWITCHES 6
396 #define DEFAULT_SWITCH_CONFIG (SWITCH_2POS << 6) + (SWITCH_2POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
397 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 2) + (POT_WITHOUT_DETENT << 0)
398 #elif defined(RADIO_T12)
399 #define NUM_SWITCHES 8
400 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
401 #define DEFAULT_SWITCH_CONFIG (SWITCH_2POS << 10) + (SWITCH_2POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
402 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITHOUT_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
403 #elif defined(PCBX7ACCESS)
404 #define NUM_SWITCHES 7
405 #define STORAGE_NUM_SWITCHES 8
406 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_2POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
407 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
409 #define NUM_SWITCHES 8
410 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
411 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_2POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
412 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
413 #elif defined(PCBX9LITES)
414 #define NUM_SWITCHES 7
415 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
416 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 12) + (SWITCH_TOGGLE << 10) + (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
417 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0); // S1 = pot with detent
418 #elif defined(PCBX9LITE)
419 #define NUM_SWITCHES 5
420 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
421 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
422 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0); // S1 = pot with detent
423 #elif defined(PCBX9E)
424 #define NUM_SWITCHES 18 // yes, it's perfect like that !
425 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
426 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 14) + (SWITCH_3POS << 12) + (SWITCH_2POS << 10) + (SWITCH_3POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
427 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
428 #define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 3) + (SLIDER_WITH_DETENT << 2) + (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
429 #elif defined(PCBX9DP) && PCBREV >= 2019
430 #define NUM_SWITCHES 9
431 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
432 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 16) + (SWITCH_TOGGLE << 14) + (SWITCH_3POS << 12) + (SWITCH_2POS << 10) + (SWITCH_3POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
433 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
434 #define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
435 #elif defined(PCBX9D) || defined(PCBX9DP)
436 #define NUM_SWITCHES 8
437 #define STORAGE_NUM_SWITCHES 9
438 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 14) + (SWITCH_3POS << 12) + (SWITCH_2POS << 10) + (SWITCH_3POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
439 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
440 #define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
443 #define STORAGE_NUM_SWITCHES_POSITIONS (STORAGE_NUM_SWITCHES * 3)
446 uint32_t switchState(uint8_t index
);
448 uint32_t readTrims();
449 #define TRIMS_PRESSED() (readTrims())
450 #define KEYS_PRESSED() (readKeys())
453 #define WDG_DURATION 500 /*ms*/
454 #if !defined(WATCHDOG) || defined(SIMU)
455 #define WDG_ENABLE(x)
458 #define WDG_ENABLE(x) watchdogInit(x)
459 #define WDG_RESET() IWDG->KR = 0xAAAA
461 void watchdogInit(unsigned int duration
);
462 #define WAS_RESET_BY_SOFTWARE() (RCC->CSR & RCC_CSR_SFTRSTF)
463 #define WAS_RESET_BY_WATCHDOG() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF))
464 #define WAS_RESET_BY_WATCHDOG_OR_SOFTWARE() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_SFTRSTF))
474 #if defined(PCBX9LITE)
476 #elif defined(PCBXLITE) || defined(PCBX7)
479 #elif defined(PCBX9E)
500 #if defined(PCBX9LITE)
502 #define NUM_SLIDERS 0
503 #define STORAGE_NUM_POTS 1
504 #define STORAGE_NUM_SLIDERS 0
505 #elif defined(PCBXLITE) || defined(PCBX7)
507 #define NUM_SLIDERS 0
508 #define STORAGE_NUM_POTS 2
509 #define STORAGE_NUM_SLIDERS 0
510 #elif defined(PCBX9E)
512 #define NUM_SLIDERS 4
513 #define STORAGE_NUM_POTS 4
514 #define STORAGE_NUM_SLIDERS 4
515 #elif defined(PCBX9DP)
517 #define NUM_SLIDERS 2
518 #define STORAGE_NUM_POTS 3
519 #define STORAGE_NUM_SLIDERS 2
521 #define NUM_POTS 3 // TODO X9D has only 2 pots
522 #define NUM_SLIDERS 2
523 #define STORAGE_NUM_POTS 3
524 #define STORAGE_NUM_SLIDERS 2
527 #define NUM_XPOTS STORAGE_NUM_POTS
529 #define NUM_MOUSE_ANALOGS 0
530 #define STORAGE_NUM_MOUSE_ANALOGS 0
532 #if defined(STICKS_PWM)
533 #define NUM_PWMSTICKS 4
534 #define STICKS_PWM_ENABLED() (!hardwareOptions.sticksPwmDisabled)
535 void sticksPwmInit();
536 void sticksPwmRead(uint16_t * values
);
537 extern volatile uint32_t pwm_interrupt_count
; // TODO => reusable buffer (boot section)
538 #define NUM_TRIMS_KEYS 4
540 #define NUM_TRIMS_KEYS 8
541 #define STICKS_PWM_ENABLED() false
544 #if NUM_PWMSTICKS > 0
545 PACK(typedef struct {
546 uint8_t sticksPwmDisabled
:1;
547 uint8_t pxx2Enabled
:1;
550 PACK(typedef struct {
551 uint8_t pxx2Enabled
:1;
555 extern HardwareOptions hardwareOptions
;
558 #define IS_PXX2_INTERNAL_ENABLED() (false)
559 #define IS_PXX1_INTERNAL_ENABLED() (true)
560 #elif !defined(PXX1) || defined(PCBXLITES) || defined(PCBX9LITE)
561 #define IS_PXX2_INTERNAL_ENABLED() (true)
562 #define IS_PXX1_INTERNAL_ENABLED() (false)
563 #elif defined(INTERNAL_MODULE_PXX1)
564 #define IS_PXX2_INTERNAL_ENABLED() (false)
565 #define IS_PXX1_INTERNAL_ENABLED() (true)
567 // TODO #define PXX2_PROBE
568 // TODO #define IS_PXX2_INTERNAL_ENABLED() (hardwareOptions.pxx2Enabled)
569 #define IS_PXX2_INTERNAL_ENABLED() (true)
570 #define IS_PXX1_INTERNAL_ENABLED() (true)
573 enum CalibratedAnalogs
{
578 CALIBRATED_POT_FIRST
,
579 CALIBRATED_POT_LAST
= CALIBRATED_POT_FIRST
+ NUM_POTS
- 1,
580 CALIBRATED_SLIDER_FIRST
,
581 CALIBRATED_SLIDER_LAST
= CALIBRATED_SLIDER_FIRST
+ NUM_SLIDERS
- 1,
582 NUM_CALIBRATED_ANALOGS
586 #define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT2) // POT3 is only defined in software
588 #define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT_LAST)
591 #define IS_SLIDER(x) ((x)>POT_LAST && (x)<TX_VOLTAGE)
593 extern uint16_t adcValues
[NUM_ANALOGS
];
598 #define BATTERY_WARN 87 // 8.7V
599 #define BATTERY_MIN 85 // 8.5V
600 #define BATTERY_MAX 115 // 11.5V
601 #elif defined(PCBXLITE)
603 #define BATTERY_WARN 66 // 6.6V
604 #define BATTERY_MIN 67 // 6.7V
605 #define BATTERY_MAX 83 // 8.3V
608 #define BATTERY_WARN 65 // 6.5V
609 #define BATTERY_MIN 60 // 6.0V
610 #define BATTERY_MAX 80 // 8.0V
613 #if defined(PCBXLITE)
614 #define BATT_SCALE 131
616 #define BATT_SCALE 123
617 #elif defined(PCBX9LITE)
618 #define BATT_SCALE 117
619 #elif defined(PCBX9DP) && PCBREV >= 2019
620 #define BATT_SCALE 117
622 #define BATT_SCALE 150
625 #if defined(__cplusplus) && !defined(SIMU)
630 #define SOFT_PWR_CTRL
636 #if defined(PWR_BUTTON_PRESS)
637 #define STARTUP_ANIMATION
638 uint32_t pwrPressedDuration();
640 void pwrResetHandler();
643 #define UNEXPECTED_SHUTDOWN() false
645 #define UNEXPECTED_SHUTDOWN() (WAS_RESET_BY_WATCHDOG() || g_eeGeneral.unexpectedShutdown)
649 void backlightInit();
650 void backlightDisable();
651 #define BACKLIGHT_DISABLE() backlightDisable()
652 uint8_t isBacklightEnabled();
653 #if !defined(__cplusplus)
654 #define backlightEnable(...)
655 #elif defined(PCBX9E) || defined(PCBX9DP)
656 void backlightEnable(uint8_t level
= 0, uint8_t color
= 0);
657 #define BACKLIGHT_ENABLE() backlightEnable(g_eeGeneral.backlightBright, g_eeGeneral.backlightColor)
659 void backlightEnable(uint8_t level
= 0);
660 #define BACKLIGHT_ENABLE() backlightEnable(g_eeGeneral.backlightBright)
664 void usbJoystickUpdate();
666 #define USB_NAME "FrSky Taranis"
667 #define USB_MANUFACTURER 'F', 'r', 'S', 'k', 'y', ' ', ' ', ' ' /* 8 bytes */
668 #define USB_PRODUCT 'T', 'a', 'r', 'a', 'n', 'i', 's', ' ' /* 8 Bytes */
670 #if defined(__cplusplus) && !defined(SIMU)
674 // I2C driver: EEPROM + Audio Volume
675 #define EEPROM_SIZE (32*1024)
678 void eepromReadBlock(uint8_t * buffer
, size_t address
, size_t size
);
679 void eepromStartWrite(uint8_t * buffer
, size_t address
, size_t size
);
680 uint8_t eepromIsTransferComplete();
683 void debugPutc(const char c
);
686 void telemetryPortInit(uint32_t baudrate
, uint8_t mode
);
687 void telemetryPortSetDirectionInput();
688 void telemetryPortSetDirectionOutput();
689 void sportSendByte(uint8_t byte
);
690 void sportSendByteLoop(uint8_t byte
);
691 void sportStopSendByteLoop();
692 void sportSendBuffer(const uint8_t * buffer
, uint32_t count
);
693 bool telemetryGetByte(uint8_t * byte
);
694 void telemetryClearFifo();
695 extern uint32_t telemetryErrors
;
698 void telemetryPortInvertedInit(uint32_t baudrate
);
701 #if defined(PCBX7ACCESS)
702 #define HAS_SPORT_UPDATE_CONNECTOR() true
704 #define IS_PCBREV_40() (GPIO_ReadInputDataBit(PCBREV_GPIO, PCBREV_GPIO_PIN) == Bit_SET)
705 #define HAS_SPORT_UPDATE_CONNECTOR() IS_PCBREV_40()
706 #elif defined(SPORT_UPDATE_PWR_GPIO)
707 #define HAS_SPORT_UPDATE_CONNECTOR() true
709 #define HAS_SPORT_UPDATE_CONNECTOR() false
712 // Sport update driver
713 #if defined(SPORT_UPDATE_PWR_GPIO)
714 void sportUpdateInit();
715 void sportUpdatePowerOn();
716 void sportUpdatePowerOff();
717 #define SPORT_UPDATE_POWER_ON() sportUpdatePowerOn()
718 #define SPORT_UPDATE_POWER_OFF() sportUpdatePowerOff()
720 #define sportUpdateInit()
721 #define SPORT_UPDATE_POWER_ON()
722 #define SPORT_UPDATE_POWER_OFF()
730 void setSampleRate(uint32_t frequency
);
731 #define VOLUME_LEVEL_MAX 23
732 #define VOLUME_LEVEL_DEF 12
733 #if !defined(SOFTWARE_VOLUME)
734 void setScaledVolume(uint8_t volume
);
735 void setVolume(uint8_t volume
);
738 #if defined(AUDIO_SPEAKER_ENABLE_GPIO)
739 void initSpeakerEnable();
740 void enableSpeaker();
741 void disableSpeaker();
743 static inline void initSpeakerEnable() { }
744 static inline void enableSpeaker() { }
745 static inline void disableSpeaker() { }
747 #if defined(HEADPHONE_TRAINER_SWITCH_GPIO)
748 void initHeadphoneTrainerSwitch();
749 void enableHeadphone();
750 void enableTrainer();
752 static inline void initHeadphoneTrainerSwitch() { }
753 static inline void enableHeadphone() { }
754 static inline void enableTrainer() { }
756 #if defined(JACK_DETECT_GPIO)
757 void initJackDetect();
758 bool isJackPlugged();
760 void audioConsumeCurrentBuffer();
761 #define audioDisableIrq() __disable_irq()
762 #define audioEnableIrq() __enable_irq()
767 #if defined(HAPTIC_PWM)
768 void hapticOn(uint32_t pwmPercent
);
773 // Second serial port driver
774 #if defined(AUX_SERIAL_GPIO)
775 #define DEBUG_BAUDRATE 115200
777 extern uint8_t auxSerialMode
;
778 void auxSerialInit(unsigned int mode
, unsigned int protocol
);
779 void auxSerialPutc(char c
);
780 #define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol)
781 void auxSerialSbusInit();
782 void auxSerialStop();
786 #define BLUETOOTH_BOOTLOADER_BAUDRATE 230400
787 #define BLUETOOTH_DEFAULT_BAUDRATE 115200
789 #define BLUETOOTH_FACTORY_BAUDRATE 9600
791 #define BLUETOOTH_FACTORY_BAUDRATE 57600
793 #define BT_TX_FIFO_SIZE 64
794 #define BT_RX_FIFO_SIZE 128
795 void bluetoothInit(uint32_t baudrate
, bool enable
);
796 void bluetoothWriteWakeup();
797 uint8_t bluetoothIsWriting();
798 void bluetoothDisable();
799 #if defined(PCBX9LITES) || defined(PCBX7ACCESS)
800 #define IS_BLUETOOTH_CHIP_PRESENT() (true)
801 #elif defined(PCBX9LITE)
802 #define IS_BLUETOOTH_CHIP_PRESENT() (false)
803 #elif (defined(PCBX7) || defined(PCBXLITE)) && !defined(SIMU)
804 extern volatile uint8_t btChipPresent
;
805 #define IS_BLUETOOTH_CHIP_PRESENT() (btChipPresent)
807 #define IS_BLUETOOTH_CHIP_PRESENT() (true)
818 #if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E)
822 #define LCD_CONTRAST_MIN 0
823 #define LCD_CONTRAST_MAX 45
824 #define LCD_CONTRAST_DEFAULT 25
829 #define IS_LCD_RESET_NEEDED() true
830 #define LCD_CONTRAST_MIN 10
831 #define LCD_CONTRAST_MAX 30
832 #define LCD_CONTRAST_DEFAULT 20
835 #if defined(PCBX9D) || defined(PCBX9E) || (defined(PCBX9DP) && PCBREV < 2019)
836 #define IS_LCD_RESET_NEEDED() (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE())
838 #define IS_LCD_RESET_NEEDED() true
842 void lcdInitFinish();
845 // TODO lcdRefreshWait() stub in simpgmspace and remove LCD_DUAL_BUFFER
846 #if defined(LCD_DMA) && !defined(LCD_DUAL_BUFFER) && !defined(SIMU)
847 void lcdRefreshWait();
849 #define lcdRefreshWait()
851 #if defined(PCBX9D) || defined(SIMU) || !defined(__cplusplus)
854 void lcdRefresh(bool wait
=true); // TODO uint8_t wait to simplify this
856 void lcdSetRefVolt(unsigned char val
);
857 void lcdSetContrast();
860 #if defined(TOPLCD_GPIO)
863 void toplcdRefreshStart();
864 void toplcdRefreshEnd();
865 void setTopFirstTimer(int32_t value
);
866 void setTopSecondTimer(uint32_t value
);
867 void setTopRssi(uint32_t rssi
);
868 void setTopBatteryState(int state
, uint8_t blinking
);
869 void setTopBatteryValue(uint32_t volts
);
872 #define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
874 #if defined(__cplusplus)
878 #if defined(CROSSFIRE)
879 #define TELEMETRY_FIFO_SIZE 128
881 #define TELEMETRY_FIFO_SIZE 64
884 extern Fifo
<uint8_t, TELEMETRY_FIFO_SIZE
> telemetryFifo
;
885 typedef DMAFifo
<32> AuxSerialRxFifo
;
886 extern AuxSerialRxFifo auxSerialRxFifo
;
890 #define GYRO_VALUES_COUNT 6
891 #define GYRO_BUFFER_LENGTH (GYRO_VALUES_COUNT * sizeof(int16_t))
893 int gyroRead(uint8_t buffer
[GYRO_BUFFER_LENGTH
]);
894 #define GYRO_MAX_DEFAULT 30
895 #define GYRO_MAX_RANGE 60
896 #define GYRO_OFFSET_MIN -30
897 #define GYRO_OFFSET_MAX 10