Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
[Keyboard] Add audio support to Adafruit MacroPad RP2040 (qmk#20353)
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna authored and stratosgear committed Apr 26, 2023
1 parent 6b83372 commit 82a66d8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
11 changes: 8 additions & 3 deletions keyboards/adafruit/macropad/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions keyboards/adafruit/macropad/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 10 additions & 3 deletions keyboards/adafruit/macropad/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -111,4 +119,3 @@ bool oled_task_user(void) {
}

#endif

5 changes: 2 additions & 3 deletions keyboards/adafruit/macropad/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

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, _______,
_______, _______, _______,
_______, _______, _______,
_______, _______, _______
Expand Down Expand Up @@ -135,4 +135,3 @@ bool oled_task_user(void) {
}

#endif

25 changes: 25 additions & 0 deletions keyboards/adafruit/macropad/macropad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 3 additions & 0 deletions keyboards/adafruit/macropad/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions keyboards/adafruit/macropad/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82a66d8

Please sign in to comment.