| 13 | namespace validation { |
| 14 | |
| 15 | bool testRxChannel( |
| 16 | fl::shared_ptr<fl::RxChannel> rx_channel, |
| 17 | int pin_tx, |
| 18 | int pin_rx, |
| 19 | u32 hz, |
| 20 | size_t buffer_size) { |
| 21 | |
| 22 | FL_WARN("[RX TEST] Testing RX channel with manual GPIO toggle on PIN " << pin_tx); |
| 23 | |
| 24 | // Configure PIN_TX as output using fl::pin functions (temporarily take ownership from FastLED) |
| 25 | fl::pinMode(pin_tx, fl::PinMode::Output); |
| 26 | fl::digitalWrite(pin_tx, fl::PinValue::Low); // Start LOW |
| 27 | |
| 28 | // Toggle parameters (generous timing works across all platforms) |
| 29 | const int num_toggles = 16; |
| 30 | const int toggle_delay_us = 1000; // 1ms per toggle |
| 31 | const u32 signal_range_max_ns = 2000000; // 2ms idle threshold |
| 32 | |
| 33 | // Initialize RX channel with signal range for fast GPIO toggles |
| 34 | fl::RxChannelConfig rx_config(pin_rx); |
| 35 | rx_config.edge_capacity = buffer_size; |
| 36 | rx_config.hz = hz; |
| 37 | rx_config.signal_range_min_ns = 100; // min=100ns |
| 38 | rx_config.signal_range_max_ns = signal_range_max_ns; |
| 39 | rx_config.start_low = true; |
| 40 | |
| 41 | if (!rx_channel->begin(rx_config)) { |
| 42 | FL_ERROR("[RX TEST]: Failed to begin RX channel"); |
| 43 | fl::pinMode(pin_tx, fl::PinMode::Input); // Release pin |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | fl::delayMicroseconds(50); // Let RX stabilize |
| 48 | |
| 49 | // Generate toggle pattern: HIGH -> LOW -> HIGH -> LOW ... |
| 50 | for (int i = 0; i < num_toggles; i++) { |
| 51 | fl::digitalWrite(pin_tx, fl::PinValue::High); |
| 52 | fl::delayMicroseconds(toggle_delay_us); |
| 53 | |
| 54 | fl::digitalWrite(pin_tx, fl::PinValue::Low); |
| 55 | fl::delayMicroseconds(toggle_delay_us); |
| 56 | } |
| 57 | |
| 58 | // Wait for RX to finish capturing (timeout = total toggle time + headroom) |
| 59 | u32 timeout_ms = 100; // 10 toggles * 200μs = 2ms, use 100ms for safety |
| 60 | fl::RxWaitResult wait_result = rx_channel->wait(timeout_ms); |
| 61 | |
| 62 | // Release PIN_TX for FastLED use using fl::pin functions |
| 63 | fl::pinMode(pin_tx, fl::PinMode::Input); |
| 64 | |
| 65 | // Check if we successfully captured data |
| 66 | if (wait_result != fl::RxWaitResult::SUCCESS) { |
| 67 | FL_ERROR("[RX TEST]: RX channel wait failed (result: " << static_cast<int>(wait_result) << ")"); |
| 68 | FL_ERROR("[RX TEST]: RX may not be working - check PIN_RX (" << pin_rx << ") and RMT peripheral"); |
| 69 | FL_ERROR("[RX TEST]: If using non-RMT TX, ensure physical jumper from PIN " << pin_tx << " to PIN " << pin_rx); |
| 70 | return false; |
| 71 | } |
| 72 |
nothing calls this directly
no test coverage detected