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
381 NUM_SWITCHES_POSITIONS
384 #if defined(PCBXLITES)
385 #define NUM_SWITCHES 6
386 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
387 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_2POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
388 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 2) + (POT_WITHOUT_DETENT << 0)
389 #elif defined(PCBXLITE)
390 #define NUM_SWITCHES 4
391 #define STORAGE_NUM_SWITCHES 6
392 #define DEFAULT_SWITCH_CONFIG (SWITCH_2POS << 6) + (SWITCH_2POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
393 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 2) + (POT_WITHOUT_DETENT << 0)
394 #elif defined(RADIO_T12)
395 #define NUM_SWITCHES 8
396 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
397 #define DEFAULT_SWITCH_CONFIG (SWITCH_2POS << 10) + (SWITCH_2POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
398 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITHOUT_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
400 #define NUM_SWITCHES 8
401 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
402 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 10) + (SWITCH_2POS << 8) + (SWITCH_3POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0)
403 #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
404 #elif defined(PCBX9LITES)
405 #define NUM_SWITCHES 7
406 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
407 #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);
408 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0); // S1 = pot with detent
409 #elif defined(PCBX9LITE)
410 #define NUM_SWITCHES 5
411 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
412 #define DEFAULT_SWITCH_CONFIG (SWITCH_TOGGLE << 8) + (SWITCH_2POS << 6) + (SWITCH_3POS << 4) + (SWITCH_3POS << 2) + (SWITCH_3POS << 0);
413 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0); // S1 = pot with detent
414 #elif defined(PCBX9E)
415 #define NUM_SWITCHES 18 // yes, it's perfect like that !
416 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
417 #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)
418 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
419 #define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 3) + (SLIDER_WITH_DETENT << 2) + (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
420 #elif defined(PCBX9DP) && PCBREV >= 2019
421 #define NUM_SWITCHES 9
422 #define STORAGE_NUM_SWITCHES NUM_SWITCHES
423 #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);
424 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
425 #define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
426 #elif defined(PCBX9D) || defined(PCBX9DP)
427 #define NUM_SWITCHES 8
428 #define STORAGE_NUM_SWITCHES 9
429 #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)
430 #define DEFAULT_POTS_CONFIG (POT_WITH_DETENT << 0) + (POT_WITH_DETENT << 2); // S1 = pot without detent, S2 = pot with detent
431 #define DEFAULT_SLIDERS_CONFIG (SLIDER_WITH_DETENT << 1) + (SLIDER_WITH_DETENT << 0)
434 #define STORAGE_NUM_SWITCHES_POSITIONS (STORAGE_NUM_SWITCHES * 3)
437 uint32_t switchState(uint8_t index
);
439 uint32_t readTrims();
440 #define TRIMS_PRESSED() (readTrims())
441 #define KEYS_PRESSED() (readKeys())
444 #define WDG_DURATION 500 /*ms*/
445 #if !defined(WATCHDOG) || defined(SIMU)
446 #define WDG_ENABLE(x)
449 #define WDG_ENABLE(x) watchdogInit(x)
450 #define WDG_RESET() IWDG->KR = 0xAAAA
452 void watchdogInit(unsigned int duration
);
453 #define WAS_RESET_BY_SOFTWARE() (RCC->CSR & RCC_CSR_SFTRSTF)
454 #define WAS_RESET_BY_WATCHDOG() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF))
455 #define WAS_RESET_BY_WATCHDOG_OR_SOFTWARE() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_SFTRSTF))
465 #if defined(PCBX9LITE)
467 #elif defined(PCBXLITE) || defined(PCBX7)
470 #elif defined(PCBX9E)
491 #if defined(PCBX9LITE)
493 #define NUM_SLIDERS 0
494 #define STORAGE_NUM_POTS 1
495 #define STORAGE_NUM_SLIDERS 0
496 #elif defined(PCBXLITE) || defined(PCBX7)
498 #define NUM_SLIDERS 0
499 #define STORAGE_NUM_POTS 2
500 #define STORAGE_NUM_SLIDERS 0
501 #elif defined(PCBX9E)
503 #define NUM_SLIDERS 4
504 #define STORAGE_NUM_POTS 4
505 #define STORAGE_NUM_SLIDERS 4
506 #elif defined(PCBX9DP)
508 #define NUM_SLIDERS 2
509 #define STORAGE_NUM_POTS 3
510 #define STORAGE_NUM_SLIDERS 2
512 #define NUM_POTS 3 // TODO X9D has only 2 pots
513 #define NUM_SLIDERS 2
514 #define STORAGE_NUM_POTS 3
515 #define STORAGE_NUM_SLIDERS 2
518 #define NUM_XPOTS STORAGE_NUM_POTS
520 #define NUM_MOUSE_ANALOGS 0
521 #define STORAGE_NUM_MOUSE_ANALOGS 0
523 #if defined(STICKS_PWM)
524 #define NUM_PWMSTICKS 4
525 #define STICKS_PWM_ENABLED() (!hardwareOptions.sticksPwmDisabled)
526 void sticksPwmInit();
527 void sticksPwmRead(uint16_t * values
);
528 extern volatile uint32_t pwm_interrupt_count
; // TODO => reusable buffer (boot section)
529 #define NUM_TRIMS_KEYS 4
531 #define NUM_TRIMS_KEYS 8
532 #define STICKS_PWM_ENABLED() false
535 #if NUM_PWMSTICKS > 0
536 PACK(typedef struct {
537 uint8_t sticksPwmDisabled
:1;
538 uint8_t pxx2Enabled
:1;
541 PACK(typedef struct {
542 uint8_t pxx2Enabled
:1;
546 extern HardwareOptions hardwareOptions
;
549 #define IS_PXX2_INTERNAL_ENABLED() (false)
550 #define IS_PXX1_INTERNAL_ENABLED() (true)
551 #elif !defined(PXX1) || defined(PCBXLITES) || defined(PCBX9LITE)
552 #define IS_PXX2_INTERNAL_ENABLED() (true)
553 #define IS_PXX1_INTERNAL_ENABLED() (false)
554 #elif defined(INTERNAL_MODULE_PXX1)
555 #define IS_PXX2_INTERNAL_ENABLED() (false)
556 #define IS_PXX1_INTERNAL_ENABLED() (true)
558 // TODO #define PXX2_PROBE
559 // TODO #define IS_PXX2_INTERNAL_ENABLED() (hardwareOptions.pxx2Enabled)
560 #define IS_PXX2_INTERNAL_ENABLED() (true)
561 #define IS_PXX1_INTERNAL_ENABLED() (true)
564 enum CalibratedAnalogs
{
569 CALIBRATED_POT_FIRST
,
570 CALIBRATED_POT_LAST
= CALIBRATED_POT_FIRST
+ NUM_POTS
- 1,
571 CALIBRATED_SLIDER_FIRST
,
572 CALIBRATED_SLIDER_LAST
= CALIBRATED_SLIDER_FIRST
+ NUM_SLIDERS
- 1,
573 NUM_CALIBRATED_ANALOGS
577 #define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT2) // POT3 is only defined in software
579 #define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT_LAST)
582 #define IS_SLIDER(x) ((x)>POT_LAST && (x)<TX_VOLTAGE)
584 extern uint16_t adcValues
[NUM_ANALOGS
];
589 #define BATTERY_WARN 87 // 8.7V
590 #define BATTERY_MIN 85 // 8.5V
591 #define BATTERY_MAX 115 // 11.5V
592 #elif defined(PCBXLITE)
594 #define BATTERY_WARN 66 // 6.6V
595 #define BATTERY_MIN 67 // 6.7V
596 #define BATTERY_MAX 83 // 8.3V
599 #define BATTERY_WARN 65 // 6.5V
600 #define BATTERY_MIN 60 // 6.0V
601 #define BATTERY_MAX 80 // 8.0V
604 #if defined(PCBXLITE)
605 #define BATT_SCALE 131
607 #define BATT_SCALE 123
608 #elif defined(PCBX9LITE)
609 #define BATT_SCALE 117
610 #elif defined(PCBX9DP) && PCBREV >= 2019
611 #define BATT_SCALE 117
613 #define BATT_SCALE 150
616 #if defined(__cplusplus) && !defined(SIMU)
621 #define SOFT_PWR_CTRL
627 #if defined(PWR_BUTTON_PRESS)
628 #define STARTUP_ANIMATION
629 uint32_t pwrPressedDuration();
631 void pwrResetHandler();
634 #define UNEXPECTED_SHUTDOWN() false
636 #define UNEXPECTED_SHUTDOWN() (WAS_RESET_BY_WATCHDOG() || g_eeGeneral.unexpectedShutdown)
640 void backlightInit();
641 void backlightDisable();
642 #define BACKLIGHT_DISABLE() backlightDisable()
643 uint8_t isBacklightEnabled();
644 #if !defined(__cplusplus)
645 #define backlightEnable(...)
646 #elif defined(PCBX9E) || defined(PCBX9DP)
647 void backlightEnable(uint8_t level
= 0, uint8_t color
= 0);
648 #define BACKLIGHT_ENABLE() backlightEnable(g_eeGeneral.backlightBright, g_eeGeneral.backlightColor)
650 void backlightEnable(uint8_t level
= 0);
651 #define BACKLIGHT_ENABLE() backlightEnable(g_eeGeneral.backlightBright)
655 void usbJoystickUpdate();
657 #define USB_NAME "FrSky Taranis"
658 #define USB_MANUFACTURER 'F', 'r', 'S', 'k', 'y', ' ', ' ', ' ' /* 8 bytes */
659 #define USB_PRODUCT 'T', 'a', 'r', 'a', 'n', 'i', 's', ' ' /* 8 Bytes */
661 #if defined(__cplusplus) && !defined(SIMU)
665 // I2C driver: EEPROM + Audio Volume
666 #define EEPROM_SIZE (32*1024)
669 void eepromReadBlock(uint8_t * buffer
, size_t address
, size_t size
);
670 void eepromStartWrite(uint8_t * buffer
, size_t address
, size_t size
);
671 uint8_t eepromIsTransferComplete();
674 void debugPutc(const char c
);
677 void telemetryPortInit(uint32_t baudrate
, uint8_t mode
);
678 void telemetryPortSetDirectionInput();
679 void telemetryPortSetDirectionOutput();
680 void sportSendByte(uint8_t byte
);
681 void sportSendByteLoop(uint8_t byte
);
682 void sportStopSendByteLoop();
683 void sportSendBuffer(const uint8_t * buffer
, uint32_t count
);
684 bool telemetryGetByte(uint8_t * byte
);
685 void telemetryClearFifo();
686 extern uint32_t telemetryErrors
;
689 void telemetryPortInvertedInit(uint32_t baudrate
);
693 #define IS_PCBREV_40() (GPIO_ReadInputDataBit(PCBREV_GPIO, PCBREV_GPIO_PIN) == Bit_SET)
694 #define HAS_SPORT_UPDATE_CONNECTOR() IS_PCBREV_40()
695 #elif defined(SPORT_UPDATE_PWR_GPIO)
696 #define HAS_SPORT_UPDATE_CONNECTOR() true
698 #define HAS_SPORT_UPDATE_CONNECTOR() false
701 // Sport update driver
702 #if defined(SPORT_UPDATE_PWR_GPIO)
703 void sportUpdateInit();
704 void sportUpdatePowerOn();
705 void sportUpdatePowerOff();
706 #define SPORT_UPDATE_POWER_ON() sportUpdatePowerOn()
707 #define SPORT_UPDATE_POWER_OFF() sportUpdatePowerOff()
709 #define sportUpdateInit()
710 #define SPORT_UPDATE_POWER_ON()
711 #define SPORT_UPDATE_POWER_OFF()
719 void setSampleRate(uint32_t frequency
);
720 #define VOLUME_LEVEL_MAX 23
721 #define VOLUME_LEVEL_DEF 12
722 #if !defined(SOFTWARE_VOLUME)
723 void setScaledVolume(uint8_t volume
);
724 void setVolume(uint8_t volume
);
727 #if defined(AUDIO_SPEAKER_ENABLE_GPIO)
728 void initSpeakerEnable();
729 void enableSpeaker();
730 void disableSpeaker();
732 static inline void initSpeakerEnable() { }
733 static inline void enableSpeaker() { }
734 static inline void disableSpeaker() { }
736 #if defined(HEADPHONE_TRAINER_SWITCH_GPIO)
737 void initHeadphoneTrainerSwitch();
738 void enableHeadphone();
739 void enableTrainer();
741 static inline void initHeadphoneTrainerSwitch() { }
742 static inline void enableHeadphone() { }
743 static inline void enableTrainer() { }
745 #if defined(JACK_DETECT_GPIO)
746 void initJackDetect();
747 bool isJackPlugged();
749 void audioConsumeCurrentBuffer();
750 #define audioDisableIrq() __disable_irq()
751 #define audioEnableIrq() __enable_irq()
756 #if defined(HAPTIC_PWM)
757 void hapticOn(uint32_t pwmPercent
);
762 // Second serial port driver
763 #if defined(AUX_SERIAL_GPIO)
764 #define DEBUG_BAUDRATE 115200
766 extern uint8_t auxSerialMode
;
767 void auxSerialInit(unsigned int mode
, unsigned int protocol
);
768 void auxSerialPutc(char c
);
769 #define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol)
770 void auxSerialSbusInit();
771 void auxSerialStop();
775 #define BLUETOOTH_BOOTLOADER_BAUDRATE 230400
776 #define BLUETOOTH_DEFAULT_BAUDRATE 115200
778 #define BLUETOOTH_FACTORY_BAUDRATE 9600
780 #define BLUETOOTH_FACTORY_BAUDRATE 57600
782 #define BT_TX_FIFO_SIZE 64
783 #define BT_RX_FIFO_SIZE 128
784 void bluetoothInit(uint32_t baudrate
, bool enable
);
785 void bluetoothWriteWakeup();
786 uint8_t bluetoothIsWriting();
787 void bluetoothDisable();
788 #if defined(PCBX9LITES)
789 #define IS_BLUETOOTH_CHIP_PRESENT() (true)
790 #elif defined(PCBX9LITE)
791 #define IS_BLUETOOTH_CHIP_PRESENT() (false)
792 #elif (defined(PCBX7) || defined(PCBXLITE)) && !defined(SIMU)
793 extern volatile uint8_t btChipPresent
;
794 #define IS_BLUETOOTH_CHIP_PRESENT() (btChipPresent)
796 #define IS_BLUETOOTH_CHIP_PRESENT() (true)
807 #if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E)
811 #define LCD_CONTRAST_MIN 0
812 #define LCD_CONTRAST_MAX 45
813 #define LCD_CONTRAST_DEFAULT 25
818 #define IS_LCD_RESET_NEEDED() true
819 #define LCD_CONTRAST_MIN 10
820 #define LCD_CONTRAST_MAX 30
821 #define LCD_CONTRAST_DEFAULT 20
824 #if defined(PCBX9D) || defined(PCBX9E) || (defined(PCBX9DP) && PCBREV < 2019)
825 #define IS_LCD_RESET_NEEDED() (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE())
827 #define IS_LCD_RESET_NEEDED() true
831 void lcdInitFinish();
834 // TODO lcdRefreshWait() stub in simpgmspace and remove LCD_DUAL_BUFFER
835 #if defined(LCD_DMA) && !defined(LCD_DUAL_BUFFER) && !defined(SIMU)
836 void lcdRefreshWait();
838 #define lcdRefreshWait()
840 #if defined(PCBX9D) || defined(SIMU) || !defined(__cplusplus)
843 void lcdRefresh(bool wait
=true); // TODO uint8_t wait to simplify this
845 void lcdSetRefVolt(unsigned char val
);
846 void lcdSetContrast();
849 #if defined(TOPLCD_GPIO)
852 void toplcdRefreshStart();
853 void toplcdRefreshEnd();
854 void setTopFirstTimer(int32_t value
);
855 void setTopSecondTimer(uint32_t value
);
856 void setTopRssi(uint32_t rssi
);
857 void setTopBatteryState(int state
, uint8_t blinking
);
858 void setTopBatteryValue(uint32_t volts
);
861 #define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
863 #if defined(__cplusplus)
867 #if defined(CROSSFIRE)
868 #define TELEMETRY_FIFO_SIZE 128
870 #define TELEMETRY_FIFO_SIZE 64
873 extern Fifo
<uint8_t, TELEMETRY_FIFO_SIZE
> telemetryFifo
;
874 typedef DMAFifo
<32> AuxSerialRxFifo
;
875 extern AuxSerialRxFifo auxSerialRxFifo
;
879 #define GYRO_VALUES_COUNT 6
880 #define GYRO_BUFFER_LENGTH (GYRO_VALUES_COUNT * sizeof(int16_t))
882 int gyroRead(uint8_t buffer
[GYRO_BUFFER_LENGTH
]);
883 #define GYRO_MAX_DEFAULT 30
884 #define GYRO_MAX_RANGE 60
885 #define GYRO_OFFSET_MIN -30
886 #define GYRO_OFFSET_MAX 10