summaryrefslogtreecommitdiffstats
path: root/keyboards/adafruit
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@drashna.net>2023-04-07 17:59:13 -0700
committerGitHub <noreply@github.com>2023-04-08 10:59:13 +1000
commit2c375e64785f3d69a14d7a3e02c041d774d1d75b (patch)
treebebc8ec37099bf4d14b3d0555a3ae848289d88ce /keyboards/adafruit
parenta5e68e5f748a98b57bd2865112f5e0caa46df255 (diff)
[Keyboard] Add audio support to Adafruit MacroPad RP2040 (#20353)
Diffstat (limited to 'keyboards/adafruit')
-rw-r--r--keyboards/adafruit/macropad/config.h11
-rw-r--r--keyboards/adafruit/macropad/halconf.h3
-rw-r--r--keyboards/adafruit/macropad/keymaps/default/keymap.c13
-rw-r--r--keyboards/adafruit/macropad/keymaps/via/keymap.c5
-rw-r--r--keyboards/adafruit/macropad/macropad.c25
-rw-r--r--keyboards/adafruit/macropad/mcuconf.h3
-rw-r--r--keyboards/adafruit/macropad/rules.mk4
7 files changed, 53 insertions, 11 deletions
diff --git a/keyboards/adafruit/macropad/config.h b/keyboards/adafruit/macropad/config.h
index c493c487e3..af72251dac 100644
--- a/keyboards/adafruit/macropad/config.h
+++ b/keyboards/adafruit/macropad/config.h
@@ -42,9 +42,14 @@
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_LED GP13
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT 500U
-/* Audio (Unsupported for now)*/
-// #define AUDIO_PIN GP16
-// #define SPEAKER_SHUTDOWN GP14
+/* Audio */
+#define AUDIO_PIN GP16
+#define AUDIO_PWM_DRIVER PWMD0
+#define AUDIO_PWM_CHANNEL RP2040_PWM_CHANNEL_A
+#define AUDIO_INIT_DELAY
+#define AUDIO_CLICKY
+
+#define SPEAKER_SHUTDOWN GP14
#ifdef RGB_MATRIX_ENABLE
diff --git a/keyboards/adafruit/macropad/halconf.h b/keyboards/adafruit/macropad/halconf.h
index 6cd66fd520..2e3be29bbf 100644
--- a/keyboards/adafruit/macropad/halconf.h
+++ b/keyboards/adafruit/macropad/halconf.h
@@ -26,3 +26,6 @@
#undef SPI_SELECT_MODE
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
+
+#undef HAL_USE_PWM
+#define HAL_USE_PWM TRUE
diff --git a/keyboards/adafruit/macropad/keymaps/default/keymap.c b/keyboards/adafruit/macropad/keymaps/default/keymap.c
index 34989ea0b6..808b202df4 100644
--- a/keyboards/adafruit/macropad/keymaps/default/keymap.c
+++ b/keyboards/adafruit/macropad/keymaps/default/keymap.c
@@ -18,17 +18,25 @@
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
- KC_MUTE,
+ LT(1,KC_MUTE),
KC_ENT, KC_0, KC_BSPC,
KC_7, KC_8, KC_9,
KC_4, KC_5, KC_6,
KC_1, KC_2, KC_3
- )
+ ),
+ [1] = LAYOUT(
+ _______,
+ CK_TOGG, AU_TOGG, _______,
+ _______, _______, _______,
+ _______, _______, _______,
+ _______, _______, _______
+ ),
};
#ifdef ENCODER_MAP_ENABLE
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
[0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
+ [1] = { ENCODER_CCW_CW(_______, _______) },
};
#endif
@@ -111,4 +119,3 @@ bool oled_task_user(void) {
}
#endif
-
diff --git a/keyboards/adafruit/macropad/keymaps/via/keymap.c b/keyboards/adafruit/macropad/keymaps/via/keymap.c
index 6ef3d3e29d..80efd80f2d 100644
--- a/keyboards/adafruit/macropad/keymaps/via/keymap.c
+++ b/keyboards/adafruit/macropad/keymaps/via/keymap.c
@@ -18,7 +18,7 @@
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
- KC_MUTE,
+ LT(1,KC_MUTE),
KC_ENT, KC_0, KC_BSPC,
KC_7, KC_8, KC_9,
KC_4, KC_5, KC_6,
@@ -26,7 +26,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
[1] = LAYOUT(
_______,
- _______, _______, _______,
+ CK_TOGG, AU_TOGG, _______,
_______, _______, _______,
_______, _______, _______,
_______, _______, _______
@@ -135,4 +135,3 @@ bool oled_task_user(void) {
}
#endif
-
diff --git a/keyboards/adafruit/macropad/macropad.c b/keyboards/adafruit/macropad/macropad.c
index 5cffdc6c97..398d0bbdfd 100644
--- a/keyboards/adafruit/macropad/macropad.c
+++ b/keyboards/adafruit/macropad/macropad.c
@@ -41,6 +41,31 @@ led_config_t g_led_config = { {
#endif
+#ifdef AUDIO_ENABLE
+void keyboard_pre_init_kb(void) {
+ // ensure pin is set and enabled pre-audio init
+ setPinOutput(SPEAKER_SHUTDOWN);
+ writePinHigh(SPEAKER_SHUTDOWN);
+ keyboard_pre_init_user();
+}
+
+void keyboard_post_init_kb(void) {
+ // set pin based on active status
+ writePin(SPEAKER_SHUTDOWN, audio_is_on());
+ keyboard_post_init_user();
+}
+
+void audio_on_user(void) {
+ writePinHigh(SPEAKER_SHUTDOWN);
+}
+
+void audio_off_user(void) {
+ // needs a delay or it runs right after play note.
+ wait_ms(200);
+ writePinLow(SPEAKER_SHUTDOWN);
+}
+#endif
+
#ifdef ENCODER_ENABLE
bool encoder_update_kb(uint8_t index, bool clockwise) {
if (!encoder_update_user(index, clockwise)) { return false; }
diff --git a/keyboards/adafruit/macropad/mcuconf.h b/keyboards/adafruit/macropad/mcuconf.h
index 198a2eea69..a833fb2af8 100644
--- a/keyboards/adafruit/macropad/mcuconf.h
+++ b/keyboards/adafruit/macropad/mcuconf.h
@@ -20,3 +20,6 @@
#undef RP_SPI_USE_SPI1
#define RP_SPI_USE_SPI1 TRUE
+
+#undef RP_PWM_USE_PWM0
+#define RP_PWM_USE_PWM0 TRUE
diff --git a/keyboards/adafruit/macropad/rules.mk b/keyboards/adafruit/macropad/rules.mk
index 0d1e17dde1..fd1ecf7cbc 100644
--- a/keyboards/adafruit/macropad/rules.mk
+++ b/keyboards/adafruit/macropad/rules.mk
@@ -9,8 +9,8 @@ COMMAND_ENABLE = no # Commands for debug and configuration
NKRO_ENABLE = yes # Enable N-Key Rollover
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
-AUDIO_ENABLE = no # Audio output
-# AUDIO_DRIVER = pwm_software
+AUDIO_ENABLE = yes # Audio output
+AUDIO_DRIVER = pwm_hardware
ENCODER_ENABLE = yes
RGB_MATRIX_ENABLE = yes
RGB_MATRIX_DRIVER = WS2812