Skip to content

Commit 1100e3e

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 58a4842 commit 1100e3e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
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: 14 additions & 0 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_four = False
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_four = True
2231
else:
2332
print("Please add support for this test on this platform.")
2433
raise SystemExit
@@ -52,6 +61,7 @@ def rotate(self, pulses):
5261
def assertPosition(self, value):
5362
self.assertEqual(self.enc.value(), value)
5463

64+
@unittest.skipIf(sys.platform == "mimxrt", "cannot read back the pin")
5565
def test_connections(self):
5666
# Test the hardware connections are correct. If this test fails, all tests will fail.
5767
for ch, outp, inp in ((0, out0_pin, in0_pin), (1, out1_pin, in1_pin)):
@@ -60,6 +70,7 @@ def test_connections(self):
6070
self.assertEqual(1, inp())
6171
outp(0)
6272
self.assertEqual(0, inp())
73+
out1_pin(1)
6374

6475
def test_basics(self):
6576
self.assertPosition(0)
@@ -70,6 +81,9 @@ def test_basics(self):
7081

7182
def test_partial(self):
7283
# With phase=1 (default), need 4x pulses to count a rotation
84+
if start_four is True:
85+
self.assertPosition(0)
86+
self.rotate(1)
7387
self.assertPosition(0)
7488
self.rotate(1)
7589
self.assertPosition(0)

0 commit comments

Comments
 (0)