mirror of
https://github.com/whowechina/geki_pico.git
synced 2024-11-12 01:50:46 +01:00
Sounds for WAD
This commit is contained in:
parent
1ef3c14dfa
commit
83d093a2b9
2391
firmware/src/music.h
Normal file
2391
firmware/src/music.h
Normal file
File diff suppressed because it is too large
Load Diff
1910
firmware/src/ring.h
Normal file
1910
firmware/src/ring.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,11 +10,41 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/irq.h"
|
||||
#include "hardware/pwm.h"
|
||||
|
||||
#include "ring.h"
|
||||
#include "music.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "board_defs.h"
|
||||
|
||||
static const uint8_t sound_gpio[2] = SOUND_DEF;
|
||||
static int slice_num[2];
|
||||
static int wav_pos[2];
|
||||
static const int wav_len[2] = { sizeof(MUSIC_DATA), sizeof(RING_DATA)};
|
||||
static const uint8_t *wav_data[2] = { MUSIC_DATA, RING_DATA};
|
||||
static bool active[2];
|
||||
|
||||
void pwm_interrupt_handler()
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
pwm_clear_irq(slice_num[i]);
|
||||
if (!active[i]) {
|
||||
wav_pos[i] = 0;
|
||||
continue;
|
||||
}
|
||||
uint8_t gpio = sound_gpio[i];
|
||||
int len = wav_len[i];
|
||||
const uint8_t *data = wav_data[i];
|
||||
if (wav_pos[i] < (len << 3) - 1) {
|
||||
pwm_set_gpio_level(gpio, data[wav_pos[i] >> 3]);
|
||||
wav_pos[i]++;
|
||||
} else {
|
||||
wav_pos[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sound_init()
|
||||
{
|
||||
@ -22,21 +52,41 @@ void sound_init()
|
||||
{
|
||||
uint8_t gpio = sound_gpio[i];
|
||||
gpio_init(gpio);
|
||||
gpio_set_dir(gpio, GPIO_OUT);
|
||||
gpio_put(gpio, false);
|
||||
gpio_set_function(gpio, GPIO_FUNC_PWM);
|
||||
slice_num[i] = pwm_gpio_to_slice_num(gpio);
|
||||
pwm_clear_irq(slice_num[i]);
|
||||
}
|
||||
irq_set_exclusive_handler(PWM_IRQ_WRAP, pwm_interrupt_handler);
|
||||
irq_set_enabled(PWM_IRQ_WRAP, true);
|
||||
|
||||
pwm_config cfg = pwm_get_default_config();
|
||||
pwm_config_set_clkdiv(&cfg, 8.0f);
|
||||
pwm_config_set_wrap(&cfg, 250);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
pwm_init(slice_num[i], &cfg, true);
|
||||
pwm_set_gpio_level(sound_gpio[i], 0);
|
||||
}
|
||||
|
||||
sound_toggle(false);
|
||||
}
|
||||
|
||||
void sound_toggle(bool on)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
pwm_set_irq_enabled(slice_num[i], on);
|
||||
}
|
||||
}
|
||||
|
||||
void sound_set(int id, bool on)
|
||||
{
|
||||
if (!geki_cfg->sound.enabled) {
|
||||
gpio_put(sound_gpio[id], false);
|
||||
active[id] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (id >= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_put(sound_gpio[id], on);
|
||||
active[id] = on;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "hardware/flash.h"
|
||||
|
||||
void sound_init();
|
||||
void sound_toggle(bool on);
|
||||
void sound_set(int id, bool on);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user