@@ -112,7 +112,7 @@ void ICACHE_RAM_ATTR getRFlinkInfo()
112112
113113 crsf.PackedRCdataOut .ch15 = UINT10_to_CRSF (map (rssiDBM, -100 , -50 , 0 , 1023 ));
114114 crsf.PackedRCdataOut .ch14 = UINT10_to_CRSF (fmap (uplinkLQ, 0 , 100 , 0 , 1023 ));
115-
115+
116116 // our rssiDBM is currently in the range -128 to 98, but BF wants a value in the range
117117 // 0 to 255 that maps to -1 * the negative part of the rssiDBM, so cap at 0.
118118 if (rssiDBM > 0 )
@@ -278,14 +278,17 @@ void LostConnection()
278278 prevOffset = 0 ;
279279 LPF_Offset.init (0 );
280280
281- digitalWrite (GPIO_PIN_LED, 0 ); // turn off led
282281 Radio.SetFrequency (GetInitialFreq ()); // in conn lost state we always want to listen on freq index 0
283282 hwTimer.stop ();
284283 Serial.println (" lost conn" );
285284
286- #ifdef PLATFORM_STM32
285+ #ifdef GPIO_PIN_LED_GREEN
287286 digitalWrite (GPIO_PIN_LED_GREEN, LOW);
288287#endif
288+
289+ #ifdef GPIO_PIN_LED
290+ digitalWrite (GPIO_PIN_LED, 0 ); // turn off led
291+ #endif
289292}
290293
291294void ICACHE_RAM_ATTR TentativeConnection ()
@@ -319,13 +322,16 @@ void GotConnection()
319322 RXtimerState = tim_tentative;
320323 GotConnectionMillis = millis ();
321324
322- RFmodeLastCycled = millis (); // give another 3 sec for loc to occur.
323- digitalWrite (GPIO_PIN_LED, 1 ); // turn on led
325+ RFmodeLastCycled = millis (); // give another 3 sec for loc to occur.
324326 Serial.println (" got conn" );
325327
326- #ifdef PLATFORM_STM32
328+ #ifdef GPIO_PIN_LED_GREEN
327329 digitalWrite (GPIO_PIN_LED_GREEN, HIGH);
328330#endif
331+
332+ #ifdef GPIO_PIN_LED
333+ digitalWrite (GPIO_PIN_LED, HIGH); // turn on led
334+ #endif
329335}
330336
331337void ICACHE_RAM_ATTR UnpackChannelData_11bit ()
@@ -492,7 +498,7 @@ void ICACHE_RAM_ATTR ProcessRFPacket()
492498 Radio.SetPPMoffsetReg (FreqCorrection); // as above but corrects a different PPM offset based on freq error
493499 #endif
494500 }
495-
501+
496502 doneProcessing = micros ();
497503
498504#ifndef DEBUG_SUPPRESS
@@ -518,6 +524,7 @@ void beginWebsever()
518524
519525void sampleButton ()
520526{
527+ #ifdef GPIO_PIN_BUTTON
521528 bool buttonValue = digitalRead (GPIO_PIN_BUTTON);
522529
523530 if (buttonValue == false && buttonPrevValue == true )
@@ -550,6 +557,7 @@ void sampleButton()
550557 }
551558
552559 buttonPrevValue = buttonValue;
560+ #endif
553561}
554562
555563void ICACHE_RAM_ATTR RXdoneISR ()
@@ -568,30 +576,43 @@ void ICACHE_RAM_ATTR TXdoneISR()
568576void setup ()
569577{
570578 delay (100 );
571- Serial.println (" ExpressLRS Module Booting..." );
572579
573580#ifdef PLATFORM_STM32
581+ #if defined(TARGET_R9SLIMPLUS_RX)
582+ CRSF_RX_SERIAL.setRx (GPIO_PIN_RCSIGNAL_RX);
583+ CRSF_RX_SERIAL.begin (CRSF_RX_BAUDRATE);
584+
585+ Serial.setTx (GPIO_PIN_RCSIGNAL_TX);
586+ #else /* !TARGET_R9SLIMPLUS_RX */
574587 #ifdef USE_R9MM_R9MINI_SBUS
575- HardwareSerial (USART2);
588+ // HardwareSerial(USART2); // This is useless call
576589 #endif
577590 Serial.setTx (GPIO_PIN_RCSIGNAL_TX);
578591 Serial.setRx (GPIO_PIN_RCSIGNAL_RX);
579- pinMode (GPIO_PIN_LED_GREEN, OUTPUT);
580- pinMode (GPIO_PIN_LED_RED, OUTPUT);
581- pinMode (GPIO_PIN_LED, OUTPUT);
582- pinMode (GPIO_PIN_BUTTON, INPUT);
583- #endif
592+ #endif /* TARGET_R9SLIMPLUS_RX */
593+ #endif /* PLATFORM_STM32 */
594+
595+ Serial.begin (CRSF_RX_BAUDRATE);
596+
597+ Serial.println (" ExpressLRS Module Booting..." );
584598
585599#ifdef PLATFORM_ESP8266
586600 WiFi.mode (WIFI_OFF);
587601 WiFi.forceSleepBegin ();
588- pinMode (GPIO_PIN_LED, OUTPUT);
589- #endif
602+ #endif /* PLATFORM_ESP8266 */
590603
591- #ifdef PLATFORM_STM32
604+ #ifdef GPIO_PIN_LED_GREEN
592605 pinMode (GPIO_PIN_LED_GREEN, OUTPUT);
593- #endif
606+ #endif /* GPIO_PIN_LED_GREEN */
607+ #ifdef GPIO_PIN_LED_RED
608+ pinMode (GPIO_PIN_LED_RED, OUTPUT);
609+ #endif /* GPIO_PIN_LED_RED */
610+ #if defined(GPIO_PIN_LED)
611+ pinMode (GPIO_PIN_LED, OUTPUT);
612+ #endif /* GPIO_PIN_LED */
613+ #ifdef GPIO_PIN_BUTTON
594614 pinMode (GPIO_PIN_BUTTON, INPUT);
615+ #endif /* GPIO_PIN_BUTTON */
595616
596617#ifdef Regulatory_Domain_AU_915
597618 Serial.println (" Setting 915MHz Mode" );
@@ -603,9 +624,6 @@ void setup()
603624 Serial.println (" Setting 433MHz Mode" );
604625#endif
605626
606- // Serial.begin(230400); // for linux debugging
607- Serial.begin (420000 );
608-
609627 FHSSrandomiseFHSSsequence ();
610628
611629 Radio.currFreq = GetInitialFreq ();
@@ -615,7 +633,9 @@ void setup()
615633 bool init_success = Radio.Begin ();
616634 while (!init_success)
617635 {
636+ #ifdef GPIO_PIN_LED
618637 digitalWrite (GPIO_PIN_LED, LED);
638+ #endif
619639 LED = !LED;
620640 delay (200 );
621641 Serial.println (" Failed to detect RF chipset!!!" );
@@ -682,7 +702,9 @@ void loop()
682702 HandleWebUpdate ();
683703 if (millis () > WEB_UPDATE_LED_FLASH_INTERVAL + webUpdateLedFlashIntervalLast)
684704 {
705+ #ifdef GPIO_PIN_LED
685706 digitalWrite (GPIO_PIN_LED, LED);
707+ #endif
686708 LED = !LED;
687709 webUpdateLedFlashIntervalLast = millis ();
688710 }
@@ -722,7 +744,9 @@ void loop()
722744 SetRFLinkRate (scanIndex % CURR_RATE_MAX); // switch between rates
723745 SendLinkStatstoFCintervalLastSent = millis ();
724746 LQCALC.reset ();
747+ #ifdef GPIO_PIN_LED
725748 digitalWrite (GPIO_PIN_LED, LED);
749+ #endif
726750 LED = !LED;
727751 Serial.println (ExpressLRS_currAirRate_Modparams->interval );
728752 scanIndex++;
@@ -769,7 +793,7 @@ void loop()
769793 #endif
770794 }
771795
772- #ifdef PLATFORM_STM32
796+ #ifdef PLATFORM_STM32
773797 STM32_RX_HandleUARTin ();
774- #endif
798+ #endif
775799}
0 commit comments