PWM outputs on P9_28 and P9_42 are part of the ECAP hardware block. This causes 'ecap' to be in the path instead of 'pwm'. For example:
`/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0/pwm0`
is one character longer than:
`/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip4/pwm0`
Thus the index in pwm_path must be adjusted for the ecap_path_udev path. This fixes issue #342
Debian 10 (Buster) has gcc 8.2 which warns about:
source/c_pwm.c:459:65: error: argument to ‘sizeof’ in ‘strncpy’ call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
source/c_pwm.c:396:43: error: ‘%s’ directive output may be truncated writing up to 199 bytes into a region of size 100 [-Werror=format-truncation=]
Issue #197: JesseMcL raised the issue that running
PWM.start() and PWM.start() in a loop will eventually
exhaust the number of open file descriptors and
PWM.start() will raise the error:
RuntimeError: problem with sysfs file.
The file descriptor for the enable file should
be closed in pwm_disable() to avoid the leak
Signed-off-by: Drew Fustini <drew@pdp7.com>
sleep 100 ms after export to avoid race condition as udev
needs the opportunity to set group ownership and permission
Test instructions:
==================
reboot, log back in, wait for udev to set group ownership and permission:
$ ls -la /sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip6/export
-rw-rw---- 1 root pwm 4096 Nov 2 04:02 /sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip6/export
run test program:
python ~/issue185.py
contents of test program:
import Adafruit_BBIO.PWM as PWM
PWM.start("P8_13", 50, 1000, 0)
PWM.stop("P8_13")
PWM.cleanup()
Example of pwm and ecap paths for pwm outputs in the 4.14 kernel:
/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0/pwm-0:0/duty_cycle
/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip1/pwm-1:0/duty_cycle
/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip1/pwm-1:1/duty_cycle
/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip3/pwm-3:0/duty_cycle
/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip3/pwm-3:1/duty_cycle
/sys/devices/platform/ocp/48304000.epwmss/48304100.ecap/pwm/pwmchip5/pwm-5:0/duty_cycle
Note that the ecap path is longer than pwm path by 1 character