FastLED 3.10.8
Loading...
Searching...
No Matches
rx_test.cpp.hpp
Go to the documentation of this file.
1// src/fl/channels/detail/validation/rx_test.cpp.hpp
2//
3// RX channel testing implementation
4
7#include "fl/system/pin.h"
8#include "fl/log/log.h"
9#include "fl/system/delay.h"
10#include "fl/stl/vector.h"
11#include "fl/stl/noexcept.h"
12
13namespace fl {
14namespace validation {
15
18 int pin_tx,
19 int pin_rx,
20 u32 hz,
21 size_t buffer_size) FL_NO_EXCEPT {
22
23 FL_WARN("[RX TEST] Testing RX channel with manual GPIO toggle on PIN " << pin_tx);
24
25 // Configure PIN_TX as output using fl::pin functions (temporarily take ownership from FastLED)
27 fl::digitalWrite(pin_tx, fl::PinValue::Low); // Start LOW
28
29 // Toggle parameters (generous timing works across all platforms)
30 const int num_toggles = 16;
31 const int toggle_delay_us = 1000; // 1ms per toggle
32 const u32 signal_range_max_ns = 2000000; // 2ms idle threshold
33
34 // Initialize RX channel with signal range for fast GPIO toggles
35 fl::RxChannelConfig rx_config(pin_rx);
36 rx_config.edge_capacity = buffer_size;
37 rx_config.hz = hz;
38 rx_config.signal_range_min_ns = 100; // min=100ns
39 rx_config.signal_range_max_ns = signal_range_max_ns;
40 rx_config.start_low = true;
41
42 if (!rx_channel->begin(rx_config)) {
43 FL_ERROR("[RX TEST]: Failed to begin RX channel");
44 fl::pinMode(pin_tx, fl::PinMode::Input); // Release pin
45 return false;
46 }
47
48 fl::delayMicroseconds(50); // Let RX stabilize
49
50 // Generate toggle pattern: HIGH -> LOW -> HIGH -> LOW ...
51 for (int i = 0; i < num_toggles; i++) {
53 fl::delayMicroseconds(toggle_delay_us);
54
56 fl::delayMicroseconds(toggle_delay_us);
57 }
58
59 // Wait for RX to finish capturing (timeout = total toggle time + headroom)
60 u32 timeout_ms = 100; // 10 toggles * 200μs = 2ms, use 100ms for safety
61 fl::RxWaitResult wait_result = rx_channel->wait(timeout_ms);
62
63 // Release PIN_TX for FastLED use using fl::pin functions
65
66 // Check if we successfully captured data
67 if (wait_result != fl::RxWaitResult::SUCCESS) {
68 FL_ERROR("[RX TEST]: RX channel wait failed (result: " << (static_cast<int>(wait_result)) << ")");
69 FL_ERROR("[RX TEST]: RX may not be working - check PIN_RX (" << pin_rx << ") and RMT peripheral");
70 FL_ERROR("[RX TEST]: If using non-RMT TX, ensure physical jumper from PIN " << pin_tx << " to PIN " << pin_rx);
71 return false;
72 }
73
74 // Verify actual edge capture (wait() can succeed on timeout with 0 edges)
76 check_edges.resize(4);
77 size_t edge_count = rx_channel->getRawEdgeTimes(check_edges, 0);
78 if (edge_count == 0) {
79 FL_ERROR("[RX TEST]: wait() succeeded but 0 edges captured - DMA trigger may be misconfigured");
80 FL_ERROR("[RX TEST]: Check DMAMUX source number for PIN_RX (" << pin_rx << ")");
81 return false;
82 }
83
84 FL_WARN("[RX TEST] ✓ RX channel captured " << edge_count << " edges from " << num_toggles << " toggles");
85 FL_WARN("[RX TEST] ✓ RX channel is functioning correctly");
86
87 return true;
88}
89
90} // namespace validation
91} // namespace fl
void resize(fl::size n) FL_NO_EXCEPT
Definition vector.h:173
Delay utilities for FastLED Includes nanosecond-precision delays, cycle counting, and microsecond del...
#define FL_WARN(...)
Definition log.h:437
#define FL_ERROR(...)
Definition log.h:373
Centralized logging categories for FastLED hardware interfaces and subsystems.
bool testRxChannel(fl::shared_ptr< fl::RxChannel > rx_channel, int pin_tx, int pin_rx, u32 hz, size_t buffer_size) FL_NO_EXCEPT
Test RX channel with manual GPIO toggle pattern.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
@ Low
Logic low (0V / GND)
Definition pin.h:51
@ High
Logic high (3.3V / 5V, platform-dependent)
Definition pin.h:52
RxWaitResult
Result codes for RX wait() operations.
Definition rx.h:152
@ SUCCESS
Operation completed successfully.
Definition rx.h:153
void digitalWrite(int pin, PinValue val) FL_NO_EXCEPT
Write digital value to pin.
Definition pin.cpp.hpp:51
@ Output
Digital output (push-pull)
Definition pin.h:44
@ Input
Digital input (high impedance)
Definition pin.h:43
void pinMode(int pin, PinMode mode) FL_NO_EXCEPT
Set pin mode (input, output, pull-up, pull-down)
Definition pin.cpp.hpp:394
void delayMicroseconds(u32 us) FL_NO_EXCEPT
Delay for a given number of microseconds.
Base definition for an LED controller.
Definition crgb.hpp:179
fl::optional< u32 > hz
Definition config.h:19
u32 signal_range_max_ns
Definition config.h:21
size_t edge_capacity
Definition config.h:18
u32 signal_range_min_ns
Definition config.h:20