Explorar o código

[Audio] Enable Complementary output for PWM Hardware driver (#22726)

Co-authored-by: Joel Challis <git@zvecr.com>
Drashna Jaelre %!s(int64=2) %!d(string=hai) anos
pai
achega
29f8fa35cf
Modificáronse 2 ficheiros con 12 adicións e 1 borrados
  1. 5 0
      docs/audio_driver.md
  2. 7 1
      platforms/chibios/drivers/audio_pwm_hardware.c

+ 5 - 0
docs/audio_driver.md

@@ -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
 

+ 7 - 1
platforms/chibios/drivers/audio_pwm_hardware.c

@@ -22,6 +22,12 @@
 #    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;
@@ -29,7 +35,7 @@ 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;