qmk_firmware icon indicating copy to clipboard operation
qmk_firmware copied to clipboard

[Core] Adjust PWM hardware audio driver for RP2040

Open KarlK90 opened this issue 2 years ago • 1 comments

Description

WIP Working but depends on ~~https://github.com/ChibiOS/ChibiOS-Contrib/pull/328~~ (merged!) and https://github.com/qmk/qmk_firmware/pull/17706

Types of Changes

  • [x] Core
  • [ ] Bugfix
  • [x] New feature
  • [x] Enhancement/optimization
  • [ ] Keyboard (addition or update)
  • [ ] Keymap/layout/userspace (addition or update)
  • [x] Documentation

Issues Fixed or Closed by This PR

Checklist

  • [x] My code follows the code style of this project: C, Python
  • [x] I have read the PR Checklist document and have made the appropriate changes.
  • [x] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING document.
  • [ ] I have added tests to cover my changes.
  • [x] I have tested the changes and verified that they work and don't break anything (as well as I can manage).

KarlK90 avatar Jul 19 '22 18:07 KarlK90

Sweet! Just tested this PR on my trusty Adafruit Macropad and can confirm that it is working amazingly -- albeit a little too loud for my taste but nonetheless amazing job as always!

Jpe230 avatar Jul 19 '22 23:07 Jpe230

@KarlK90 Thank you for writing this code set to support the audio feature on RP2040 chip! I can't wait merging this pull request because I would like to use the audio feature on the Lunakey Pico keyboard which was designed by me and is using Raspberry Pi Pico. Therefore, I tried testing this code by using my keyboard. The diff I created is the following:

https://github.com/yoichiro/qmk_firmware/commit/247705834f295a166beae72e3b64b208c055c64f

The circuit design of the Lunakey Pico is the following. The speaker is connected to the GP8 pin.

スクリーンショット 2022-10-18 19 47 16

When compiling the code set with the qmk command, I got the following output including Compiling: platforms/chibios/drivers/audio_pwm_hardware.c. That is, I believe that the built result has an audio feature.

...
Compiling: quantum/process_keycode/process_audio.c                                                  [OK]
Compiling: quantum/process_keycode/process_clicky.c                                                 [OK]
Compiling: quantum/audio/audio.c                                                                    [OK]
Compiling: platforms/chibios/drivers/audio_pwm_hardware.c                                           [OK]
Compiling: quantum/audio/voices.c                                                                   [OK]
Compiling: quantum/audio/luts.c                                                                     [OK]
Compiling: quantum/process_keycode/process_music.c                                                  [OK]
...

I wrote the uf2 file and restarted my keyboard, unfortunately I was not able to hear any sounds.

I have already confirmed that the speaker worked normally with KMK firmware. Did I forget to write something? Could you give me an advice to work the audio feature on my keyboard with your code?

yoichiro avatar Oct 18 '22 11:10 yoichiro

@Jpe230 Could you share me your code which you tried the audio feature using your keyboard?

yoichiro avatar Oct 21 '22 03:10 yoichiro

@Jpe230 Could you share me your code which you tried the audio feature using your keyboard?

Sure, here it is

Jpe230 avatar Oct 21 '22 03:10 Jpe230

Finally, I can hear the sound from my keyboard using the code: https://github.com/yoichiro/qmk_firmware/commit/65a383e3a982236618f7ae6f56b769fea0329b6c The cause is wrong combination of PWMn and Channel. It is necessary to use the PWM4 and the Channel A (= 1) for GP8.

See: https://discordapp.com/channels/440868230475677696/1032861820228227132

I think that the diff of this pull request looks good to me and has comfirm that this code works normally. Thank you for the great contribution!

yoichiro avatar Oct 21 '22 07:10 yoichiro

@KarlK90 Congrats!

yoichiro avatar Oct 27 '22 21:10 yoichiro