Skip to content

Commit 7c6b045

Browse files
committed
Fixed pwm on pcduino v3b
1 parent 27833d4 commit 7c6b045

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎pcduino/pwm.py‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os.path
22

3-
from pinmap import PinMap
3+
#from pinmap import PinMap
44

55

6-
pins = PinMap('/sys/class/leds', 'pwm', 5)
6+
#pins = PinMap('/sys/devices/virtual/misc/pwmtimer/', 'pwm', 12)
7+
8+
#pinMap broken beyond repair for new sysfs-pwm
79

810
MAX_PWM_LEVEL = 255
911

@@ -13,14 +15,26 @@ def analog_write(pin, value):
1315
value can be an number between 0 and 255.
1416
1517
"""
16-
path = pins.get_path(pin)
18+
path = '/sys/class/misc/pwmtimer/'
19+
20+
ending = 'pwm' + str(pin)
1721

18-
with open(os.path.join(path, 'max_brightness')) as f:
22+
with open(os.path.join(path, 'max_level',ending )) as f:
1923
max_value = int(f.read())
2024

2125
if value < 0 or value > MAX_PWM_LEVEL:
2226
raise ValueError("value must be between 0 and %s" % MAX_PWM_LEVEL)
2327

24-
map_level = (max_value * value) / MAX_PWM_LEVEL
25-
with open(os.path.join(path, 'brightness'), 'w+') as f:
28+
map_level = (max_value * value) // MAX_PWM_LEVEL
29+
#// because python 3 compatibility
30+
#for some reason 255 becomes 0 (overflow?)
31+
32+
#disable -> change level -> enable , as requested by documentation
33+
with open(os.path.join(path, 'enable', ending), 'w+') as f:
34+
f.write("0\n")
35+
36+
with open(os.path.join(path, 'level', ending), 'w+') as f:
2637
f.write("%d\n" % map_level)
38+
39+
with open(os.path.join(path, 'enable', ending), 'w+') as f:
40+
f.write("1\n")

‎pcduino/testSkriptPwm.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from pwm import analog_write
2+
3+
analog_write(1,100)
4+

0 commit comments

Comments
 (0)