| 28 | #include "platforms/shared/mock/esp/32/drivers/uart_peripheral_mock.h" |
| 29 | |
| 30 | FL_TEST_FILE(FL_FILEPATH) { |
| 31 | |
| 32 | using namespace fl; |
| 33 | |
| 34 | namespace { |
| 35 | |
| 36 | /// UART bit duration at 4.0 Mbps = 250ns |
| 37 | constexpr uint32_t UART_BIT_NS = 250; |
| 38 | |
| 39 | /// WS2812 timing constants for channel driver tests |
| 40 | constexpr uint32_t WS2812_T0H = 400; |
| 41 | constexpr uint32_t WS2812_T0L = 850; |
| 42 | constexpr uint32_t WS2812_T1H = 800; |
| 43 | constexpr uint32_t WS2812_T1L = 450; |
| 44 | |
| 45 | /// Create a default UART test configuration at 4.0 Mbps |
| 46 | UartPeripheralConfig defaultConfig() { |
| 47 | return UartPeripheralConfig(4000000, 17, -1, 4096, 0, 1, 1); |
| 48 | } |
| 49 | |
| 50 | /// Convert UART waveform bits (from mock) into EdgeTime entries. |
| 51 | fl::vector<EdgeTime> waveformToEdges(const fl::vector<bool>& waveform, uint32_t bit_ns) { |
| 52 | fl::vector<EdgeTime> edges; |
| 53 | if (waveform.empty()) return edges; |
| 54 | |
| 55 | // Prepend idle HIGH period (UART idle = mark = HIGH) |
| 56 | EdgeTime idle; |
| 57 | idle.ns = bit_ns * 2; |
| 58 | idle.high = 1; |
| 59 | edges.push_back(idle); |
| 60 | |
| 61 | bool current_level = waveform[0]; |
| 62 | uint32_t run_length = 1; |
| 63 | |
| 64 | for (size_t i = 1; i < waveform.size(); i++) { |
| 65 | if (waveform[i] == current_level) { |
| 66 | run_length++; |
| 67 | } else { |
| 68 | EdgeTime edge; |
| 69 | edge.ns = run_length * bit_ns; |
| 70 | edge.high = current_level ? 1 : 0; |
| 71 | edges.push_back(edge); |
| 72 | current_level = waveform[i]; |
| 73 | run_length = 1; |
| 74 | } |
| 75 | } |
| 76 | EdgeTime edge; |
| 77 | edge.ns = run_length * bit_ns; |
| 78 | edge.high = current_level ? 1 : 0; |
| 79 | edges.push_back(edge); |
| 80 | |
| 81 | return edges; |
| 82 | } |
| 83 | |
| 84 | /// Decode UART wave8 edges back to LED bytes using forward-only edge cursor. |
| 85 | size_t decodeUartWave8FromEdges(fl::span<const EdgeTime> edges, fl::span<uint8_t> out) { |
| 86 | const uint32_t BIT_NS = UART_BIT_NS; |
| 87 | const uint32_t HALF_BIT_NS = BIT_NS / 2; |
nothing calls this directly
no test coverage detected