Skip to content

Commit b9672bc

Browse files
committed
tests/extmod: Add test for machine.time_pulse_us().
1 parent 2b7c4a1 commit b9672bc

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

tests/extmod/machine_pulse.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
try:
2+
import umachine as machine
3+
except ImportError:
4+
import machine
5+
try:
6+
machine.PinBase
7+
machine.time_pulse_us
8+
except AttributeError:
9+
print("SKIP")
10+
import sys
11+
sys.exit()
12+
13+
14+
class ConstPin(machine.PinBase):
15+
16+
def __init__(self, value):
17+
self.v = value
18+
19+
def value(self, v=None):
20+
if v is None:
21+
return self.v
22+
else:
23+
self.v = v
24+
25+
26+
class TogglePin(machine.PinBase):
27+
28+
def __init__(self):
29+
self.v = 0
30+
31+
def value(self, v=None):
32+
if v is None:
33+
self.v = 1 - self.v
34+
print("value:", self.v)
35+
return self.v
36+
37+
38+
p = TogglePin()
39+
40+
t = machine.time_pulse_us(p, 1)
41+
print(type(t))
42+
t = machine.time_pulse_us(p, 0)
43+
print(type(t))
44+
45+
p = ConstPin(0)
46+
try:
47+
machine.time_pulse_us(p, 1, 10)
48+
except OSError:
49+
print("OSError")
50+
51+
try:
52+
machine.time_pulse_us(p, 0, 10)
53+
except OSError:
54+
print("OSError")

tests/extmod/machine_pulse.py.exp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
value: 1
2+
value: 0
3+
<class 'int'>
4+
value: 1
5+
value: 0
6+
value: 1
7+
<class 'int'>
8+
OSError
9+
OSError

0 commit comments

Comments
 (0)