Merge pull request #5 from adafruit/mute-etc
Mute dac when mac is not making noise
This commit is contained in:
commit
646926f066
3 changed files with 25 additions and 9 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
*.img
|
||||||
|
*.bin
|
||||||
|
os.7z
|
||||||
|
picotool
|
||||||
|
|
@ -64,8 +64,8 @@ fi
|
||||||
# Append disk name to build directory if disk image is specified
|
# Append disk name to build directory if disk image is specified
|
||||||
if [ -n "$DISC_IMAGE" ] && [ -f "$DISC_IMAGE" ]; then
|
if [ -n "$DISC_IMAGE" ] && [ -f "$DISC_IMAGE" ]; then
|
||||||
# Extract filename without extension
|
# Extract filename without extension
|
||||||
|
CMAKE_ARGS="$CMAKE_ARGS -DDISC_IMAGE=${DISC_IMAGE}"
|
||||||
DISC_IMAGE=$(basename "$DISC_IMAGE" | sed 's/\.[^.]*$//')
|
DISC_IMAGE=$(basename "$DISC_IMAGE" | sed 's/\.[^.]*$//')
|
||||||
CMAKE_ARGS="$CMAKE_ARGS -DDISK_IMAGE=${DISC_IMAGE}"
|
|
||||||
TAG=${TAG}_${DISC_IMAGE}
|
TAG=${TAG}_${DISC_IMAGE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
28
src/main.c
28
src/main.c
|
|
@ -104,15 +104,11 @@ static void io_init()
|
||||||
|
|
||||||
static void poll_led_etc()
|
static void poll_led_etc()
|
||||||
{
|
{
|
||||||
static int led_on = 0;
|
|
||||||
static absolute_time_t last = 0;
|
static absolute_time_t last = 0;
|
||||||
absolute_time_t now = get_absolute_time();
|
absolute_time_t now = get_absolute_time();
|
||||||
|
|
||||||
if (absolute_time_diff_us(last, now) > 500*1000) {
|
if (absolute_time_diff_us(last, now) > 500*1000) {
|
||||||
last = now;
|
last = now;
|
||||||
|
|
||||||
//led_on ^= 1;
|
|
||||||
//gpio_put(GPIO_LED_PIN, led_on);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,10 +201,12 @@ static void poll_umac()
|
||||||
#if USE_SD
|
#if USE_SD
|
||||||
static int disc_do_read(void *ctx, uint8_t *data, unsigned int offset, unsigned int len)
|
static int disc_do_read(void *ctx, uint8_t *data, unsigned int offset, unsigned int len)
|
||||||
{
|
{
|
||||||
|
gpio_put(GPIO_LED_PIN, 1);
|
||||||
FIL *fp = (FIL *)ctx;
|
FIL *fp = (FIL *)ctx;
|
||||||
f_lseek(fp, offset);
|
f_lseek(fp, offset);
|
||||||
unsigned int did_read = 0;
|
unsigned int did_read = 0;
|
||||||
FRESULT fr = f_read(fp, data, len, &did_read);
|
FRESULT fr = f_read(fp, data, len, &did_read);
|
||||||
|
gpio_put(GPIO_LED_PIN, 0);
|
||||||
if (fr != FR_OK || len != did_read) {
|
if (fr != FR_OK || len != did_read) {
|
||||||
printf("disc: f_read returned %d, read %u (of %u)\n", fr, did_read, len);
|
printf("disc: f_read returned %d, read %u (of %u)\n", fr, did_read, len);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -218,10 +216,12 @@ static int disc_do_read(void *ctx, uint8_t *data, unsigned int offset, unsi
|
||||||
|
|
||||||
static int disc_do_write(void *ctx, uint8_t *data, unsigned int offset, unsigned int len)
|
static int disc_do_write(void *ctx, uint8_t *data, unsigned int offset, unsigned int len)
|
||||||
{
|
{
|
||||||
|
gpio_put(GPIO_LED_PIN, 1);
|
||||||
FIL *fp = (FIL *)ctx;
|
FIL *fp = (FIL *)ctx;
|
||||||
f_lseek(fp, offset);
|
f_lseek(fp, offset);
|
||||||
unsigned int did_write = 0;
|
unsigned int did_write = 0;
|
||||||
FRESULT fr = f_write(fp, data, len, &did_write);
|
FRESULT fr = f_write(fp, data, len, &did_write);
|
||||||
|
gpio_put(GPIO_LED_PIN, 0);
|
||||||
if (fr != FR_OK || len != did_write) {
|
if (fr != FR_OK || len != did_write) {
|
||||||
printf("disc: f_write returned %d, read %u (of %u)\n", fr, did_write, len);
|
printf("disc: f_write returned %d, read %u (of %u)\n", fr, did_write, len);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -676,9 +676,6 @@ static int volscale;
|
||||||
int16_t audio[SAMPLES_PER_BUFFER];
|
int16_t audio[SAMPLES_PER_BUFFER];
|
||||||
|
|
||||||
void umac_audio_trap() {
|
void umac_audio_trap() {
|
||||||
static int led_on;
|
|
||||||
led_on ^= 1;
|
|
||||||
gpio_put(GPIO_LED_PIN, 1);
|
|
||||||
int32_t offset = 128;
|
int32_t offset = 128;
|
||||||
uint16_t *audiodata = (uint16_t*)audio_base;
|
uint16_t *audiodata = (uint16_t*)audio_base;
|
||||||
int scale = volscale;
|
int scale = volscale;
|
||||||
|
|
@ -732,14 +729,29 @@ setup_i2s_dac();
|
||||||
static bool audio_poll() {
|
static bool audio_poll() {
|
||||||
audio_buffer_t *buffer = take_audio_buffer(producer_pool, false);
|
audio_buffer_t *buffer = take_audio_buffer(producer_pool, false);
|
||||||
if (!buffer) return false;
|
if (!buffer) return false;
|
||||||
gpio_put(GPIO_LED_PIN, 0);
|
|
||||||
memcpy(buffer->buffer->bytes, audio, sizeof(audio));
|
memcpy(buffer->buffer->bytes, audio, sizeof(audio));
|
||||||
buffer->sample_count = SAMPLES_PER_BUFFER;
|
buffer->sample_count = SAMPLES_PER_BUFFER;
|
||||||
give_audio_buffer(producer_pool, buffer);
|
give_audio_buffer(producer_pool, buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool mute_state = false;
|
||||||
|
static void set_mute_state(bool new_state) {
|
||||||
|
if(mute_state == new_state) return;
|
||||||
|
mute_state = new_state;
|
||||||
|
|
||||||
|
setPage(1);
|
||||||
|
if(mute_state) {
|
||||||
|
modifyRegister(0x28, 0x04, 0x04); // HP Left not muted
|
||||||
|
modifyRegister(0x29, 0x04, 0x04); // HP Right not muted
|
||||||
|
} else {
|
||||||
|
modifyRegister(0x28, 0x04, 0x0); // HP Left muted
|
||||||
|
modifyRegister(0x29, 0x04, 0x0); // HP Right muted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void umac_audio_cfg(int volume, int sndres) {
|
void umac_audio_cfg(int volume, int sndres) {
|
||||||
volscale = sndres ? 0 : 65536 * volume / 7;
|
volscale = sndres ? 0 : 65536 * volume / 7;
|
||||||
|
set_mute_state(volscale != 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue