Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function and docs for libpigpio's gpioHardwareClock #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion doc/gpio.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- PWM
- [pwmWrite(dutyCycle)](#pwmwritedutycycle)
- [hardwarePwmWrite(frequency, dutyCycle)](#hardwarepwmwritefrequency-dutycycle)
- [hardwareClockWrite(frequency)](#hardwareclockwritefrequency)
- [getPwmDutyCycle()](#getpwmdutycycle)
- [pwmRange(range)](#pwmrangerange)
- [getPwmRange()](#getpwmrange)
Expand Down Expand Up @@ -195,6 +196,14 @@ have fewer steps. duytCycle is automatically scaled to take this into account.

All models of the Raspberry Pi support hardware PWM on GPIO18.

#### hardwareClockWrite(frequency)
- frequency - an unsigned integer >= 0 and <= 125000000 (>= 0 and <= 187500000 for the BCM2711)

Starts hardware Clock output on the GPIO at the specified frequency.
Frequencies above 30MHz are unlikely to work. Returns this.

<!--TODO: Fill this out-->

#### getPwmDutyCycle()
Returns the PWM duty cycle setting on the GPIO.

Expand Down Expand Up @@ -286,7 +295,7 @@ The frequencies in hertz for each sample rate are:
Returns the frequency (in hertz) used for the GPIO. The default frequency is
800Hz.

If hardware PWM is active on the GPIO the reported frequency will be that set
If hardware PWM or Clock is active on the GPIO the reported frequency will be that set
by hardwarePwmWrite.

#### servoWrite(pulseWidth)
Expand Down
6 changes: 6 additions & 0 deletions pigpio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,12 @@ export class Gpio extends EventEmitter {
*/
hardwarePwmWrite(frequency: number, dutyCycle: number): Gpio;

/**
* Starts hardware Clock output on the GPIO at the specified frequency. Frequencies above 30MHz are unlikely to work.
* @param frequency an unsigned integer >= 0 and <= 125000000 (>= 0 and <= 187500000 for the BCM2711)
*/
hardwareClockWrite(frequency: number): Gpio;

/**
* Returns the PWM duty cycle setting on the GPIO.
*/
Expand Down
5 changes: 5 additions & 0 deletions pigpio.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ class Gpio extends EventEmitter {
return this;
}

hardwareClockWrite(frequency) {
pigpio.gpioHardwareClock(this.gpio, +frequency);
return this;
}

getPwmDutyCycle() {
return pigpio.gpioGetPWMdutycycle(this.gpio);
}
Expand Down
18 changes: 18 additions & 0 deletions src/pigpio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,23 @@ NAN_METHOD(gpioHardwarePWM) {
}


NAN_METHOD(gpioHardwareClock) {
if (info.Length() < 2 ||
!info[0]->IsUint32() ||
!info[1]->IsUint32()) {
return Nan::ThrowError(Nan::ErrnoException(EINVAL, "gpioHardwareClock", ""));
}

unsigned gpio = Nan::To<uint32_t>(info[0]).FromJust();
unsigned frequency = Nan::To<uint32_t>(info[1]).FromJust();

int rc = gpioHardwareClock(gpio, frequency);
if (rc < 0) {
return ThrowPigpioError(rc, "gpioHardwareClock");
}
}


NAN_METHOD(gpioGetPWMdutycycle) {
if (info.Length() < 1 || !info[0]->IsUint32()) {
return Nan::ThrowError(Nan::ErrnoException(EINVAL, "gpioGetPWMdutycycle", ""));
Expand Down Expand Up @@ -1035,6 +1052,7 @@ NAN_MODULE_INIT(InitAll) {

SetFunction(target, "gpioPWM", gpioPWM);
SetFunction(target, "gpioHardwarePWM", gpioHardwarePWM);
SetFunction(target, "gpioHardwareClock", gpioHardwareClock);
SetFunction(target, "gpioGetPWMdutycycle", gpioGetPWMdutycycle);
SetFunction(target, "gpioSetPWMrange", gpioSetPWMrange);
SetFunction(target, "gpioGetPWMrange", gpioGetPWMrange);
Expand Down