Commit graph

56 commits

Author SHA1 Message Date
Drew Fustini
7fb13f9f3d Fix warnings on format truncation and sizeof in strncpy #308
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=]
2019-12-11 09:03:44 +00:00
Drew Fustini
1f7c20e899 remove debug logging 2018-10-17 14:59:09 -05:00
Drew Fustini
c09ab8ee43 fix pwm on pocketbeagle and beaglebone blue #286
pocketbeagle and beaglebone blue have complete dtb file
and do not need overlays
2018-10-17 14:56:11 -05:00
Aaron Marburg
e061d1358e Added usleep after successfully enabling PWM via udev. 2018-04-12 22:46:49 +00:00
Drew Fustini
503e8397e6
Fix leak of pwm enable file descriptor (#197)
Make sure that the file descriptor for pwm enable
is closed along with the other pwm file descriptors

Signed-off-by: Drew Fustini <drew@pdp7.com>
2017-11-24 00:29:04 -06:00
Drew Fustini
f82ba3a1ec
close enable_fd when stopping PWM output (#197)
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>
2017-11-22 04:38:14 -06:00
Drew Fustini
794d7136b4 Change log level from INFO to DEBUG #188
Signed-off-by: Drew Fustini <drew@pdp7.com>
2017-11-08 03:16:47 -06:00
Drew Fustini
b65cbf8e41 sleep to avoid udev race condition #185
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()
2017-11-02 04:08:48 +00:00
Drew Fustini
f267ec01b1 minor change to pwm debug logging 2017-11-01 09:11:44 +00:00
Drew Fustini
58eb54679c Attempt to use udev ecap path for pwm path
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
2017-11-01 09:05:12 +00:00
Drew Fustini
705368d91e only check kernel overlays if u-boot overlays are not being used 2017-11-01 04:15:08 +00:00
Drew Fustini
5af654ca14 change fprintf() to syslog() 2017-10-31 07:19:53 +00:00
Drew Fustini
8e08a40f14 move pwm_set_polarity() after period is set 2017-10-31 06:39:20 +00:00
Drew Fustini
73ea172d21 remove polarity "hack" for PWM #170 2017-10-31 05:37:14 +00:00
Drew Fustini
1b3dab6950 add "Adafruit_BBIO" to syslog() 2017-10-31 03:53:02 +00:00
Robert Nelson
c35e4cb98a source/c_pwm.c: disable pwm_set_polarity (broken in v4.9.x/v4.14.x)
Signed-off-by: Robert Nelson <robertcnelson@gmail.com>
2017-10-12 16:33:43 -05:00
Robert Nelson
02c6ca5924 source/c_pwm.c: pwm: add support for pwmchipX/pwm-X:Y syntax
Signed-off-by: Robert Nelson <robertcnelson@gmail.com>
2017-10-12 16:31:20 -05:00
Robert Nelson
2d5a88aee9 source/c_pwm.c: debug pwm_path/pwm_path_udev
Signed-off-by: Robert Nelson <robertcnelson@gmail.com>
2017-10-12 16:05:23 -05:00
Robert Nelson
d201c910ec source/c_pwm.c: HACK: PocketBeagle: v4.14.x
Signed-off-by: Robert Nelson <robertcnelson@gmail.com>
2017-10-12 16:00:43 -05:00
Robert Nelson
4e180c54cf source/c_pwm.c: HACK: U-Boot pre-setup everything, dont search for specific overlay
Signed-off-by: Robert Nelson <robertcnelson@gmail.com>
2017-10-12 15:04:17 -05:00
cocasema
6c489fce8e Add syslog and debugging messages 2017-03-31 02:16:21 -07:00
Drew Fustini
6d78f9db06 Fix gcc warnings about comparing signed and unsigned values
warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
2017-01-11 09:14:38 +00:00
Drew Fustini
b1ad088164 Fix unused parameter warning [-Werror=unused-parameter] 2017-01-10 10:52:01 +00:00
Drew Fustini
67e0f61f9c add PWM test for ecap0 (P9_42) and ecap2 (P9_28) 2016-12-20 10:26:19 +00:00
Drew Fustini
f58cabef1d Use pin mode "pwm2" for P9_28 2016-12-20 09:46:50 +00:00
cocasema
efc0a25f65 Treat warnings as errors 2016-10-18 21:59:24 -07:00
Jesse McLachlan
207526e91d Move BBBVERSION41 pwm disable logic into pwm list iterator.
Outside the list iteration loop it causes a seg fault from writing to a closed/invalid handle if PWM.stop is called when the PWM is not open
2016-10-10 14:58:52 +11:00
Matthew West
0620b43818 Bugfix: add missing read call 2016-08-30 09:46:56 -06:00
Matthew West
6759d58b91 Remove some trailing whitespace 2016-08-29 21:21:50 -07:00
Matthew West
f48e60d501 When setting up a PWM pin, read period_ns & duty_ns 2016-08-29 21:20:40 -07:00
Matthew West
ddbf6c354f Fix initialization weirdness with pwm_set_frequency 2016-08-10 15:29:51 -07:00
Matthew West
99e27ad39e Add a safeguard if we didn't start 2016-08-10 15:29:29 -07:00
Matthew West
f4fcd12c2f Move a common variable out of #ifdef and #else 2016-08-10 15:29:11 -07:00
Matthew West
149129c3f5 Initialize ocp_dir before use 2016-08-10 15:09:14 -07:00
Matthew West
0b8def4cb5 Bugfixes based on CircleCI (regressions introduced on 3.8) 2016-08-08 15:26:38 -07:00
Matthew West
b6cf76fa0b Small bugfix to setting frequency 2016-08-08 11:26:42 -07:00
Matthew West
ac1104c55b Fix bug with setting frequency, fix stopping 2016-08-08 11:18:27 -07:00
Matthew West
8fe1336b0a Bug fixes almost to stability 2016-08-08 10:51:15 -07:00
Matthew West
298334a814 Bug fixes to 4.1+ PWM code 2016-08-05 13:27:42 -07:00
Matthew West
6b2aa7aabc Change return value convention for errors
Replace 1 for success and 0/-1 for failure with an enum type.
2016-08-05 13:19:54 -07:00
Matthew West
599ec57f4c Fix PWM in Linux 4.1+ 2016-08-05 10:16:34 -07:00
Matthew West
a2a88fb21a Move PWM exporting to its own function 2016-08-05 09:58:04 -07:00
Tony DiCola
5c8db6b80d Fix #67 and fix compiler warnings. 2014-10-03 23:24:10 +00:00
Justin Cooper
25e654a982 fix for SPI not loading spidevX.X correctly based on load order 2014-05-23 03:22:48 +00:00
Justin Cooper
a0902d971f further pwm cleanup 2013-08-19 21:52:16 +00:00
bit-hacker
fc4df3fdf1 Update c_pwm.c
In definition of struct pwm_exp, extended length of key by 1 to ensure room for a terminating byte.  Currently, the code doesn't check this, expecting strncpy in pwm_start to trim and NUL-terminate the string. 

In lookup_exported_pwm, return "not-found" condition as NULL, not 0, per general pointer usage recommendations.

In pwm_start, added code to ensure NUL-termination of the key.

In pwm_disable, there's a path that doesn't set prev_pwm and can leave it NULL.  It being NULL seems to indicate a "first-time" flag, for when the first item in the list is matched. If the search should be terminated after finding device "key", should break be used?  Reasonably, a device named "key" should only be found once in the tree, but as coded, it seems that this search loop might find it more than once.  

In pwm_set_polarity, the original length of the buffer as 5 will cover positive 16-bit integers, but not room for a trailing NUL byte.  If accidently negative, a size of 7 will include room for the sign without breaking.
2013-08-16 09:54:26 -07:00
Justin Cooper
a322ddc2c0 fix for polarity not getting set properly, add polarity as optional parameter in start 2013-08-15 03:55:08 +00:00
Justin Cooper
5f865a1b6c remove unused variables 2013-08-12 21:28:46 +00:00
Justin Cooper
b9c2b3d6d7 Fix PWM duty cycle so 0 is off and 100 is on. Set polarity to 0 by default. 2013-08-12 21:25:51 +00:00
Justin Cooper
670bfcbf1c better error handling of load_device_tree through adc, pwm, and uart 2013-07-30 19:34:24 +00:00