MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/system/pin.cpp:11–766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "fl/test/fltest.h"
10
11FL_TEST_FILE(FL_FILEPATH) {
12
13// ============================================================================
14// PWM Frequency Tests
15// ============================================================================
16
17FL_TEST_CASE("pwm_basic_init_cleanup") {
18 FL_REQUIRE_EQ(fl::setPwmFrequency(5, 100), 0);
19 FL_REQUIRE_EQ(fl::getPwmFrequency(5), 100u);
20 fl::analogWrite(5, 128);
21 FL_REQUIRE_EQ(fl::pwmEnd(5), 0);
22 FL_REQUIRE_EQ(fl::getPwmFrequency(5), 0u);
23}
24
25FL_TEST_CASE("pwm_invalid_frequency") {
26 // Zero frequency invalid
27 FL_REQUIRE_LT(fl::setPwmFrequency(5, 0), 0);
28
29 // On stub platform (ISR fallback required), max is 500 Hz
30 FL_REQUIRE_LT(fl::setPwmFrequency(5, 1000), 0);
31 FL_REQUIRE_LT(fl::setPwmFrequency(5, 600), 0);
32
33 // Valid frequencies should work
34 FL_REQUIRE_EQ(fl::setPwmFrequency(5, 1), 0); // Min
35 FL_REQUIRE_EQ(fl::pwmEnd(5), 0);
36
37 FL_REQUIRE_EQ(fl::setPwmFrequency(5, 500), 0); // Max for ISR
38 FL_REQUIRE_EQ(fl::pwmEnd(5), 0);
39}
40
41FL_TEST_CASE("pwm_reconfigure") {
42 // First init
43 FL_REQUIRE_EQ(fl::setPwmFrequency(10, 100), 0);
44 FL_REQUIRE_EQ(fl::getPwmFrequency(10), 100u);
45 fl::analogWrite(10, 128);
46
47 // Reconfigure without explicit end (auto-releases and reconfigures)
48 FL_REQUIRE_EQ(fl::setPwmFrequency(10, 200), 0);
49 FL_REQUIRE_EQ(fl::getPwmFrequency(10), 200u);
50 fl::analogWrite(10, 200);
51
52 FL_REQUIRE_EQ(fl::pwmEnd(10), 0);
53}
54
55FL_TEST_CASE("pwm_channel_allocation") {
56 // Allocate all 8 channels
57 for (int i = 0; i < 8; i++) {
58 FL_REQUIRE_EQ(fl::setPwmFrequency(10 + i, 60 + i * 10), 0);
59 fl::analogWrite(10 + i, 128);
60 }
61
62 // 9th should fail (all channels in use)
63 FL_REQUIRE_LT(fl::setPwmFrequency(99, 60), 0);
64
65 // Release one channel
66 FL_REQUIRE_EQ(fl::pwmEnd(12), 0);
67
68 // Now 9th should succeed (reusing freed channel)

Callers

nothing calls this directly

Calls 15

setPwmFrequencyFunction · 0.85
getPwmFrequencyFunction · 0.85
pwmEndFunction · 0.85
digitalMultiWrite8Function · 0.85
digitalMultiWrite16Function · 0.85
pinToPortFunction · 0.85
pinMapFunction · 0.85
allSamePortMethod · 0.80
analogWriteFunction · 0.50
setPwm16Function · 0.50
pinModeFunction · 0.50
digitalReadFunction · 0.50

Tested by

no test coverage detected