Skip to content

Commit 5e8bac1

Browse files
committed
tests/extmod_hardware/machine_encoder: Add a MIMXRT configuration.
For Teensy 4.x. The connectivity tests and the falling edge of the counter test are skipped. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent 6f817d3 commit 5e8bac1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tests/extmod_hardware/machine_counter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
id = 0
1717
out_pin = 4
1818
in_pin = 5
19+
elif sys.platform == "mimxrt":
20+
if "Teensy" in sys.implementation._machine:
21+
id = 0
22+
out_pin = "D2"
23+
in_pin = "D3"
1924
else:
2025
print("Please add support for this test on this platform.")
2126
raise SystemExit
@@ -43,6 +48,7 @@ def tearDown(self):
4348
def assertCounter(self, value):
4449
self.assertEqual(self.counter.value(), value)
4550

51+
@unittest.skipIf(sys.platform == "mimxrt", "cannot read back the pin")
4652
def test_connections(self):
4753
# Test the hardware connections are correct. If this test fails, all tests will fail.
4854
out_pin(1)
@@ -73,6 +79,7 @@ def test_change_directions(self):
7379
toggle(25)
7480
self.assertCounter(75)
7581

82+
@unittest.skipIf(sys.platform == "mimxrt", "FALLING edge not supported")
7683
def test_count_falling(self):
7784
self.counter.init(in_pin, direction=Counter.UP, edge=Counter.FALLING)
7885
toggle(20)

tests/extmod_hardware/machine_encoder.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
in0_pin = 5
2020
out1_pin = 12
2121
in1_pin = 13
22+
start_value = -1
23+
elif sys.platform == "mimxrt":
24+
if "Teensy" in sys.implementation._machine:
25+
id = 0
26+
out0_pin = "D2"
27+
in0_pin = "D3"
28+
out1_pin = "D5"
29+
in1_pin = "D4"
30+
start_value = 0
2231
else:
2332
print("Please add support for this test on this platform.")
2433
raise SystemExit
@@ -35,8 +44,9 @@ class TestEncoder(unittest.TestCase):
3544
def setUp(self):
3645
out0_pin(0)
3746
out1_pin(0)
38-
self.enc = Encoder(id, in0_pin, in1_pin)
47+
self.enc = Encoder(id, in0_pin, in1_pin, phases=1)
3948
self.pulses = 0 # track the expected encoder position in software
49+
self.pulses = start_value # track the expected encoder position in software
4050

4151
def tearDown(self):
4252
self.enc.deinit()
@@ -52,6 +62,7 @@ def rotate(self, pulses):
5262
def assertPosition(self, value):
5363
self.assertEqual(self.enc.value(), value)
5464

65+
@unittest.skipIf(sys.platform == "mimxrt", "cannot read back the pin")
5566
def test_connections(self):
5667
# Test the hardware connections are correct. If this test fails, all tests will fail.
5768
for ch, outp, inp in ((0, out0_pin, in0_pin), (1, out1_pin, in1_pin)):
@@ -76,7 +87,9 @@ def test_partial(self):
7687
self.rotate(1)
7788
self.assertPosition(0)
7889
self.rotate(1)
79-
self.assertPosition(1) # only 3 pulses to count first rotation?
90+
self.assertPosition(0)
91+
self.rotate(1)
92+
self.assertPosition(1) # 4 pulses to count first rotation?
8093
self.rotate(1)
8194
self.assertPosition(1)
8295
self.rotate(1)

0 commit comments

Comments
 (0)