FastLED 3.9.15
Loading...
Searching...
No Matches

◆ testRxChannel()

bool fl::validation::testRxChannel ( fl::shared_ptr< fl::RxChannel > rx_channel,
int pin_tx,
int pin_rx,
u32 hz,
size_t buffer_size )

Test RX channel with manual GPIO toggle pattern.

Parameters
rx_channelRX channel to test
pin_txGPIO pin to toggle
pin_rxGPIO pin for RX
hzSampling frequency in Hz
buffer_sizeSize of RX buffer in symbols
Returns
true if test passes, false otherwise
Note
Generates 10 fast toggles (100μs pulses = 5kHz square wave)
Uses fl::pin API for platform-independent pin control

Definition at line 15 of file rx_test.cpp.hpp.

20 {
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)
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++) {
52 fl::delayMicroseconds(toggle_delay_us);
53
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
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
73 // Verify actual edge capture (wait() can succeed on timeout with 0 edges)
74 fl::FixedVector<fl::EdgeTime, 4> check_edges;
75 check_edges.resize(4);
76 size_t edge_count = rx_channel->getRawEdgeTimes(check_edges, 0);
77 if (edge_count == 0) {
78 FL_ERROR("[RX TEST]: wait() succeeded but 0 edges captured - DMA trigger may be misconfigured");
79 FL_ERROR("[RX TEST]: Check DMAMUX source number for PIN_RX (" << pin_rx << ")");
80 return false;
81 }
82
83 FL_WARN("[RX TEST] ✓ RX channel captured " << edge_count << " edges from " << num_toggles << " toggles");
84 FL_WARN("[RX TEST] ✓ RX channel is functioning correctly");
85
86 return true;
87}
void resize(fl::size n) FL_NOEXCEPT
Definition vector.h:173
bool begin(const RxChannelConfig &config) FL_NOEXCEPT
size_t getRawEdgeTimes(fl::span< EdgeTime > out, size_t offset=0) FL_NOEXCEPT
RxWaitResult wait(u32 timeout_ms) FL_NOEXCEPT
#define FL_WARN(X)
Definition log.h:276
#define FL_ERROR(X)
Definition log.h:219
@ Low
Logic low (0V / GND)
Definition pin.h:50
@ High
Logic high (3.3V / 5V, platform-dependent)
Definition pin.h:51
void pinMode(int pin, PinMode mode)
Set pin mode (input, output, pull-up, pull-down)
Definition pin.cpp.hpp:378
void digitalWrite(int pin, PinValue val)
Write digital value to pin.
Definition pin.cpp.hpp:51
RxWaitResult
Result codes for RX wait() operations.
Definition rx.h:151
@ SUCCESS
Operation completed successfully.
Definition rx.h:152
void delayMicroseconds(u32 us)
Delay for a given number of microseconds.
@ Output
Digital output (push-pull)
Definition pin.h:43
@ Input
Digital input (high impedance)
Definition pin.h:42

References fl::delayMicroseconds(), fl::digitalWrite(), fl::RxChannelConfig::edge_capacity, FL_ERROR, FL_WARN, fl::High, fl::RxChannelConfig::hz, fl::Input, fl::Low, fl::Output, fl::pinMode(), fl::FixedVector< T, N >::resize(), fl::RxChannelConfig::signal_range_max_ns, fl::RxChannelConfig::signal_range_min_ns, fl::RxChannelConfig::start_low, and fl::SUCCESS.

Referenced by testRxChannel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: