Skip to content

Commit

Permalink
[Audio] Enable Complementary output for PWM Hardware driver (qmk#22726)
Browse files Browse the repository at this point in the history
Co-authored-by: Joel Challis <git@zvecr.com>
  • Loading branch information
2 people authored and mechlovin committed Jan 19, 2024
1 parent 345354f commit 358c9e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/audio_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ with all this information, the configuration would contain these lines:
ChibiOS uses GPIOv1 for the F103, which only knows of one alternate function.
On 'larger' STM32s, GPIOv2 or GPIOv3 are used; with them it is also necessary to configure `AUDIO_PWM_PAL_MODE` to the correct alternate function for the selected pin, timer and timer-channel.
You can also use the Complementary output (`TIMx_CHyN`) for PWM on supported controllers. To enable this functionality, you will need to make the following changes:
```c
// config.h:
#define AUDIO_PWM_COMPLEMENTARY_OUTPUT
```

### PWM software :id=pwm-software

Expand Down
8 changes: 7 additions & 1 deletion platforms/chibios/drivers/audio_pwm_hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@
# define AUDIO_PWM_COUNTER_FREQUENCY 100000
#endif

#ifndef AUDIO_PWM_COMPLEMENTARY_OUTPUT
# define AUDIO_PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH
#else
# define AUDIO_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
#endif

extern bool playing_note;
extern bool playing_melody;
extern uint8_t note_timbre;

static PWMConfig pwmCFG = {.frequency = AUDIO_PWM_COUNTER_FREQUENCY, /* PWM clock frequency */
.period = 2,
.callback = NULL,
.channels = {[(AUDIO_PWM_CHANNEL - 1)] = {.mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}}};
.channels = {[(AUDIO_PWM_CHANNEL - 1)] = {.mode = AUDIO_PWM_OUTPUT_MODE, .callback = NULL}}};

static float channel_1_frequency = 0.0f;

Expand Down

0 comments on commit 358c9e7

Please sign in to comment.