diff --git a/docs/pwm.md b/docs/pwm.md index 1bfd97c..8da29ad 100644 --- a/docs/pwm.md +++ b/docs/pwm.md @@ -5,6 +5,10 @@ Import the PWM module as follows import CHIP_IO.PWM as PWM ``` +For the CHIP, this requires the PWM0 DTBO loaded via the OverlayManager or other means. +For the CHIP, PWM1 is unavaiable +For the CHIP Pro, PWM0 and PWM1 are setup in the base DTB by default + ### toggle_debug() Enable/Disable the Debug @@ -18,6 +22,151 @@ Enable/Disable the Debug PWM.toggle_debug() ``` +### is_chip_pro() +Function to report to the calling script if the SBC is a CHIP or a CHIP Pro +* Parameters + + None + +* Returns + + int - 1 for CHIP Pro, 0 for CHIP + +* Examples + + ```python + is_chip_pro = PWM.is_chip_pro() + ``` + +### start(channel, duty_cycle=0.0, frequency=2000.0, polarity=0) +Start the Software PWM + +* Parameters + + channel - pin for software PWM is configured + duty_cycle - initial duty cycle of the PWM (optional) + frequency - frequency of the PWM (optional) + polarity - signal polarity of the PWM (optional) + +* Returns + + None + +* Examples + + ```python + PWM.start("PWM0") + PWM.start("PWM0", 37.0) + PWM.start("PWM0", 10.0, 500.0) + PWM.start("PWM0", 50.0, 1000.0, 1) + ``` + +### stop(channel) +Stop the PWM + +* Parameters + + channel - pin PWM is configured + +* Returns + + None + +* Examples + + ```python + PWM.stop("PWM0") + ``` + +### set_duty_cycle(channel, duty_cycle) +Set the duty cycle of the PWM + +* Parameters + + channel - pin PWM is configured + duty_cycle - duty cycle of the PWM (0.0 to 100.0) + +* Returns + + None + +* Examples + + ```python + PWM.set_duty_cycle("PWM0", 25.0) + ``` + +### set_pulse_width_ns(channel, pulse_width_ns) +Set the width of the PWM pulse in nano seconds + +* Parameters + + channel - pin PWM is configured + pulse_width_ns - pulse width of the PWM in nanoseconds + +* Returns + + None + +* Examples + + ```python + PWM.set_pulse_width_ns("PWM0", 2500.0) + ``` + +### set_frequency(channel, frequency) +Set the frequency of the PWM in Hertz + +* Parameters + + channel - pin software PWM is configured + frequency - frequency of the PWM + +* Returns + + None + +* Examples + + ```python + PWM.set_frequency("PWM0", 450.0) + ``` + +### set_period_ns(channel, pulse_width_ns) +Set the period of the PWM pulse in nano seconds + +* Parameters + + channel - pin PWM is configured + period_ns - period of the PWM in nanoseconds + +* Returns + + None + +* Examples + + ```python + PWM.set_period_ns("PWM0", 130.0) + ``` + +### cleanup(channel) +Cleanup PWM. If not channel input, all PWM will be cleaned up + +* Parameters + + channel - pin PWM is configured (optional) + +* Returns + + None + +* Examples + + ```python + PWM.cleanup() + PWM.cleanup("PWM0") + ``` [home](./index.md) diff --git a/docs/servo.md b/docs/servo.md index 594ae31..5158e2a 100644 --- a/docs/servo.md +++ b/docs/servo.md @@ -32,7 +32,7 @@ Function to report to the calling script if the SBC is a CHIP or a CHIP Pro * Examples ```python - is_chip_pro = UT.is_chip_pro() + is_chip_pro = SERVO.is_chip_pro() ``` ### start(channel, angle=0.0, range=180.0) diff --git a/docs/softpwm.md b/docs/softpwm.md index aa9f200..7cd6cbb 100644 --- a/docs/softpwm.md +++ b/docs/softpwm.md @@ -18,4 +18,115 @@ Enable/Disable the Debug SPWM.toggle_debug() ``` +### is_chip_pro() +Function to report to the calling script if the SBC is a CHIP or a CHIP Pro + +* Parameters + + None + +* Returns + + int - 1 for CHIP Pro, 0 for CHIP + +* Examples + + ```python + is_chip_pro = SPWM.is_chip_pro() + ``` + +### start(channel, duty_cycle=0.0, frequency=2000.0, polarity=0) +Start the Software PWM + +* Parameters + + channel - pin for software PWM is configured + duty_cycle - initial duty cycle of the PWM (optional) + frequency - frequency of the PWM (optional) + polarity - signal polarity of the PWM (optional) + +* Returns + + None + +* Examples + + ```python + SPWM.start("CSID0") + SPWM.start("CSID0", 37.0) + SPWM.start("CSID0", 10.0, 500.0) + SPWM.start("CSID0", 50.0, 1000.0, 1) + ``` + +### stop(channel) +Stop the Software PWM + +* Parameters + + channel - pin software PWM is configured + +* Returns + + None + +* Examples + + ```python + SPWM.stop("CSID0") + ``` + +### set_duty_cycle(channel, duty_cycle) +Set the duty cycle of the Software PWM + +* Parameters + + channel - pin software PWM is configured + duty_cycle - duty cycle of the PWM (0.0 to 100.0) + +* Returns + + None + +* Examples + + ```python + SPWM.set_duty_cycle("CSID0", 25.0) + ``` + +### set_frequency(channel, frequency) +Set the frequency of the Software PWM in Hertz + +* Parameters + + channel - pin PWM is configured + frequency - frequency of the PWM + +* Returns + + None + +* Examples + + ```python + SPWM.set_frequency("CSID0", 450.0) + ``` + +### cleanup(channel) +Cleanup Software PWM. If not channel input, all Software PWM will be cleaned up + +* Parameters + + channel - pin Software PWM is configured (optional) + +* Returns + + None + +* Examples + + ```python + SPWM.cleanup() + SPWM.cleanup("CSID0") + ``` + [home](./index.md) diff --git a/source/py_servo.c b/source/py_servo.c index 89b96fc..5a9f97d 100644 --- a/source/py_servo.c +++ b/source/py_servo.c @@ -50,6 +50,8 @@ static PyObject *py_toggle_debug(PyObject *self, PyObject *args) // python function cleanup() static PyObject *py_cleanup(PyObject *self, PyObject *args) { + // TODO: PER PIN CLEANUP LIKE EVERYTHING ELSE + // unexport the Servo servo_cleanup(); @@ -68,7 +70,7 @@ static int init_module(void) return 0; } -// python function value = is_chip_pro +// python function value = is_chip_pro() static PyObject *py_is_chip_pro(PyObject *self, PyObject *args) { PyObject *py_value; @@ -185,7 +187,7 @@ static PyObject *py_stop_channel(PyObject *self, PyObject *args, PyObject *kwarg Py_RETURN_NONE; } -// python method SERVO.set_range(channel, duty_cycle) +// python method SERVO.set_range(channel, range) static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs) { int gpio; @@ -241,7 +243,7 @@ static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs) Py_RETURN_NONE; } -// python method SERVO.set_angle(channel, duty_cycle) +// python method SERVO.set_angle(channel, angle) static PyObject *py_set_angle(PyObject *self, PyObject *args, PyObject *kwargs) { int gpio; diff --git a/source/py_softpwm.c b/source/py_softpwm.c index 5afc39e..2d00388 100644 --- a/source/py_softpwm.c +++ b/source/py_softpwm.c @@ -82,7 +82,7 @@ static int init_module(void) return 0; } -// python function value = is_chip_pro +// python function value = is_chip_pro() static PyObject *py_is_chip_pro(PyObject *self, PyObject *args) { PyObject *py_value; @@ -92,7 +92,7 @@ static PyObject *py_is_chip_pro(PyObject *self, PyObject *args) return py_value; } -// python function start(channel, duty_cycle, freq) +// python function start(channel, duty_cycle, freq, polarity) static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwargs) { char key[8];