Skip to content

Commit

Permalink
[Core] Adjust PWM hardware audio driver for RP2040 (qmk#17723)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlK90 committed Oct 27, 2022
1 parent efe5206 commit 1914570
Show file tree
Hide file tree
Showing 22 changed files with 82 additions and 133 deletions.
10 changes: 3 additions & 7 deletions docs/audio_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ A configuration example for the STM32F103C8 would be:
//halconf.h:
#define HAL_USE_PWM TRUE
#define HAL_USE_PAL TRUE
#define HAL_USE_GPT TRUE
#include_next <halconf.h>
```

Expand All @@ -168,8 +167,6 @@ A configuration example for the STM32F103C8 would be:
#include_next <mcuconf.h>
#undef STM32_PWM_USE_TIM1
#define STM32_PWM_USE_TIM1 TRUE
#undef STM32_GPT_USE_TIM4
#define STM32_GPT_USE_TIM4 TRUE
```

If we now target pin A8, looking through the data-sheet of the STM32F103C8, for the timers and alternate functions
Expand All @@ -184,7 +181,6 @@ with all this information, the configuration would contain these lines:
#define AUDIO_PIN A8
#define AUDIO_PWM_DRIVER PWMD1
#define AUDIO_PWM_CHANNEL 1
#define AUDIO_STATE_TIMER GPTD4
```
ChibiOS uses GPIOv1 for the F103, which only knows of one alternate function.
Expand All @@ -207,15 +203,15 @@ You can also change the timer used for software PWM by defining the driver. For

While not an exhaustive list, the following table provides the scenarios that have been partially validated:

| | DAC basic | DAC additive | PWM hardware | PWM software |
|--------------------------|--------------------|--------------------|--------------------|--------------------|
| | DAC basic | DAC additive | PWM hardware | PWM software |
| ------------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
| Atmega32U4 | :o: | :o: | :heavy_check_mark: | :o: |
| RP2040 | :x: | :x: | :heavy_check_mark: | ? |
| STM32F103C8 (bluepill) | :x: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| STM32F303CCT6 (proton-c) | :heavy_check_mark: | :heavy_check_mark: | ? | :heavy_check_mark: |
| STM32F405VG | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| L0xx | :x: (no Tim8) | ? | ? | ? |


:heavy_check_mark: : works and was tested
:o: : does not apply
:x: : not supported by MCU
Expand Down
4 changes: 2 additions & 2 deletions docs/platformdev_rp2040.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

The following table shows the current driver status for peripherals on RP2040 MCUs:

| System | Support |
| System | Support |
| ---------------------------------------------------------------- | ---------------------------------------------- |
| [ADC driver](adc_driver.md) | Support planned (no ETA) |
| [Audio](audio_driver.md) | Support planned (no ETA) |
| [Audio](audio_driver.md#pwm-hardware) | :heavy_check_mark: |
| [Backlight](feature_backlight.md) | :heavy_check_mark: |
| [I2C driver](i2c_driver.md) | :heavy_check_mark: |
| [SPI driver](spi_driver.md) | :heavy_check_mark: |
Expand Down
1 change: 0 additions & 1 deletion keyboards/bastardkb/charybdis/3x5/keymaps/drashna/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
#define AUDIO_PWM_DRIVER PWMD3
#define AUDIO_PWM_CHANNEL 4
#define AUDIO_PWM_PAL_MODE 2
#define AUDIO_STATE_TIMER GPTD4

/* serial.c configuration for split keyboard */
#undef SOFT_SERIAL_PIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
#define HAL_USE_SPI TRUE
#define SPI_USE_WAIT TRUE
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
#define HAL_USE_GPT TRUE

#include_next <halconf.h>
3 changes: 0 additions & 3 deletions keyboards/bastardkb/charybdis/3x5/keymaps/drashna/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,5 @@
#undef STM32_SERIAL_USE_USART2
#define STM32_SERIAL_USE_USART2 TRUE

#undef STM32_GPT_USE_TIM4
#define STM32_GPT_USE_TIM4 TRUE

#undef STM32_ST_USE_TIMER
#define STM32_ST_USE_TIMER 5
1 change: 0 additions & 1 deletion keyboards/bastardkb/charybdis/4x6/keymaps/drashna/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#define AUDIO_PWM_DRIVER PWMD4
#define AUDIO_PWM_CHANNEL 2
#define AUDIO_PWM_PAL_MODE 2
#define AUDIO_STATE_TIMER GPTD3
#define AUDIO_INIT_DELAY
#define AUDIO_ENABLE_TONE_MULTIPLEXING
#define AUDIO_TONE_MULTIPLEXING_RATE_DEFAULT 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#define HAL_USE_PWM TRUE
#define HAL_USE_PAL TRUE
#define HAL_USE_GPT TRUE
#define HAL_USE_SERIAL TRUE
// #define HAL_USE_I2C TRUE
#define HAL_USE_SPI TRUE
Expand Down
3 changes: 0 additions & 3 deletions keyboards/bastardkb/charybdis/4x6/keymaps/drashna/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,5 @@
#undef STM32_SERIAL_USE_USART1
#define STM32_SERIAL_USE_USART1 TRUE

#undef STM32_GPT_USE_TIM3
#define STM32_GPT_USE_TIM3 TRUE

#undef STM32_ST_USE_TIMER
#define STM32_ST_USE_TIMER 5
1 change: 0 additions & 1 deletion keyboards/handwired/macroboard/f411/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
#define AUDIO_PWM_DRIVER PWMD2
#define AUDIO_PWM_CHANNEL 3
#define AUDIO_PWM_PAL_MODE 1
#define AUDIO_STATE_TIMER GPTD1

#define AUDIO_CLICKY
#define AUDIO_CLICKY_FREQ_RANDOMNESS 1.5f
Expand Down
1 change: 0 additions & 1 deletion keyboards/handwired/macroboard/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@
#pragma once

#define HAL_USE_PWM TRUE
#define HAL_USE_GPT TRUE

#include_next <halconf.h>
3 changes: 0 additions & 3 deletions keyboards/handwired/macroboard/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@
#undef STM32_PWM_USE_TIM4
#define STM32_PWM_USE_TIM4 TRUE

#undef STM32_GPT_USE_TIM1
#define STM32_GPT_USE_TIM1 TRUE

#undef STM32_ST_USE_TIMER
#define STM32_ST_USE_TIMER 5
4 changes: 4 additions & 0 deletions keyboards/handwired/onekey/rp2040/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@

#define BACKLIGHT_PWM_DRIVER PWMD4
#define BACKLIGHT_PWM_CHANNEL RP2040_PWM_CHANNEL_B

#define AUDIO_PIN GP16
#define AUDIO_PWM_DRIVER PWMD0
#define AUDIO_PWM_CHANNEL RP2040_PWM_CHANNEL_A
3 changes: 3 additions & 0 deletions keyboards/handwired/onekey/rp2040/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@

#include_next "mcuconf.h"

#undef RP_PWM_USE_PWM0
#define RP_PWM_USE_PWM0 TRUE

#undef RP_PWM_USE_PWM4
#define RP_PWM_USE_PWM4 TRUE
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
#define AUDIO_PWM_DRIVER PWMD3
#define AUDIO_PWM_CHANNEL 4
#define AUDIO_PWM_PAL_MODE 2
#define AUDIO_STATE_TIMER GPTD4

/* serial.c configuration for split keyboard */
#define SERIAL_USART_FULL_DUPLEX // Enable full duplex operation mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
#define HAL_USE_SPI TRUE
#define SPI_USE_WAIT TRUE
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
#define HAL_USE_GPT TRUE

#include_next <halconf.h>
3 changes: 0 additions & 3 deletions keyboards/handwired/tractyl_manuform/5x6_right/f411/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,5 @@
#undef STM32_SERIAL_USE_USART2
#define STM32_SERIAL_USE_USART2 TRUE

#undef STM32_GPT_USE_TIM4
#define STM32_GPT_USE_TIM4 TRUE

#undef STM32_ST_USE_TIMER
#define STM32_ST_USE_TIMER 5
1 change: 0 additions & 1 deletion keyboards/yanghu/unicorne/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#define AUDIO_PWM_PAL_MODE 1
#define AUDIO_PWM_DRIVER PWMD1
#define AUDIO_PWM_CHANNEL 1
#define AUDIO_STATE_TIMER GPTD4

/* RGB LED */
#define RGB_DI_PIN B1
Expand Down
3 changes: 0 additions & 3 deletions keyboards/yanghu/unicorne/f411/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

/* PWM for AUDIO and RGB LED */
#define HAL_USE_PWM TRUE
/* GPT and PAL for Audio */
#define HAL_USE_GPT TRUE
#define HAL_USE_PAL TRUE
/* I2C for OLED display */
#define HAL_USE_I2C TRUE

Expand Down
3 changes: 0 additions & 3 deletions keyboards/yanghu/unicorne/f411/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
/* TIM1 PWM used for audio driver */
#undef STM32_PWM_USE_TIM1
#define STM32_PWM_USE_TIM1 TRUE
/* TIM5 GPT used for audio driver */
#undef STM32_GPT_USE_TIM4
#define STM32_GPT_USE_TIM4 TRUE

/* TIM3 used for WS2812 driver */
#undef STM32_PWM_USE_TIM3
Expand Down
10 changes: 10 additions & 0 deletions platforms/chibios/chibios_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@
# define USE_GPIOV1
# define PAL_OUTPUT_TYPE_OPENDRAIN _Static_assert(0, "RP2040 has no Open Drain GPIO configuration, setting this is not possible");

/* Aliases for GPIO PWM channels - every pin has at least one PWM channel
* assigned */
# define RP2040_PWM_CHANNEL_A 1U
# define RP2040_PWM_CHANNEL_B 2U

# define BACKLIGHT_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE)
# define BACKLIGHT_PWM_COUNTER_FREQUENCY 1000000
# define BACKLIGHT_PWM_PERIOD BACKLIGHT_PWM_COUNTER_FREQUENCY / 2048

# define AUDIO_PWM_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE)
# define AUDIO_PWM_COUNTER_FREQUENCY 500000

# define usb_lld_endpoint_fields

# define I2C1_SCL_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4)
Expand All @@ -55,6 +63,7 @@
# define USE_GPIOV1
# define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_STM32_ALTERNATE_OPENDRAIN
# define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_STM32_ALTERNATE_PUSHPULL
# define AUDIO_PWM_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
# else
# define PAL_OUTPUT_TYPE_OPENDRAIN PAL_STM32_OTYPE_OPENDRAIN
# define PAL_OUTPUT_TYPE_PUSHPULL PAL_STM32_OTYPE_PUSHPULL
Expand All @@ -76,6 +85,7 @@
# define USE_I2CV1
# define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_GD32_ALTERNATE_OPENDRAIN
# define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_GD32_ALTERNATE_PUSHPULL
# define AUDIO_PWM_PAL_MODE PAL_MODE_GD32_ALTERNATE_PUSHPULL
# endif
#endif

Expand Down
Loading

0 comments on commit 1914570

Please sign in to comment.