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

Using PWM tutorial fails to compile for Raspberry Pi Pico device #2304

Closed
awonak opened this issue Nov 22, 2021 · 2 comments
Closed

Using PWM tutorial fails to compile for Raspberry Pi Pico device #2304

awonak opened this issue Nov 22, 2021 · 2 comments
Labels
docs Documentation needed

Comments

@awonak
Copy link

awonak commented Nov 22, 2021

I am following the tutorial using a Raspberry Pi Pico device. I am able to get the Blinking LED example to work, however the Using PWM tutorial fails to compile with the following error:

$ tinygo flash -target=pico
# pwm-blinky
main.go:12:22: NewPWM not declared by package machine

If I alter the sample code as shown below, I am able to successfully compile the script and get the PWM working as expected on the Pico.

// pwm, err := machine.NewPWM(pin)
// if err != nil {
// 	println(err.Error())
// }
pwm := machine.PWM4

It seems that the current implementation (src) is missing the NewPWM function and instead has a similar looking function PWMPeripheral, but that returns the slice index of the PWM group, not a pointer to the initialized peripheral.

Perhaps a solutions could be to include the NewPWM function like this:

// NewPWM calls PWMPeripheral to get the RP2040 PWM peripheral slice number that
// corresponds to the package's PWM0 throughout PWM7 handler.
func NewPWM(pin Pin) (pwm *pwmGroup, err error) {
	sliceNum, err := PWMPeripheral(pin)
	if err != nil {
		return nil, err
	}
	return getPWMGroup(sliceNum)
}
@soypat
Copy link
Contributor

soypat commented Nov 22, 2021

It seems the tinygo site is outdated, as all NewPWM API has been removed as of the PWM interface refactor. I believe @aykevl was working on creating a better PWM page on tinygo.org to better reflect these changes.

Technical details aside, I agree we are missing some sort of API to get the underlying PWM peripheral from a pin. Right now it is quite unwieldy to do this user-side. I'm unsure why this was removed in the first place and whether it would be OK to add it as you have shown or some other way.

@deadprogram
Copy link
Member

The tutorial was updated some time ago, so now closing. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation needed
Projects
None yet
Development

No branches or pull requests

3 participants