diff --git a/src/common.h b/src/common.h index 0d7b57b..ebe5561 100644 --- a/src/common.h +++ b/src/common.h @@ -102,6 +102,7 @@ void platform_turbo(void); void platform_refresh(bool *sq, bool *css, bool *vox); bool platform_poke(uint8_t addr, uint8_t reg, uint16_t val); void platform_amp_enable(bool state); +void platform_audio_enable(bool state); /* * UART peripheral control diff --git a/src/r5f1026a/platform.c b/src/r5f1026a/platform.c index 4004bc6..04aaaee 100644 --- a/src/r5f1026a/platform.c +++ b/src/r5f1026a/platform.c @@ -385,9 +385,9 @@ void platform_init(void) { P1_bit.no0 = 0; // P10 (RXEN) is low PM1_bit.no0 = 0; // P10 (RXEN) is output - ADPC |= 0x01; // P20-P23 are digital I/O + ADPC = 0x01; // P20-P23 are digital I/O - P2_bit.no0 = 1; // P20 (SQ) is high + P2_bit.no0 = 0; // P20 (SQ) is low PM2_bit.no0 = 0; // P20 (SQ) is output P2_bit.no1 = 1; // P21 (H/L) is high @@ -434,9 +434,7 @@ void platform_turbo(void) { } void platform_refresh(bool *sq, bool *css, bool *vox) { - *sq = P2_bit.no3; // Squelch status from internal AT1846S - P2_bit.no0 = !*sq; // Squelch status to external pin - + *sq = P2_bit.no3; // Squelch status from internal AT1846S *css = P1_bit.no4; // CSS status from internal AT1846S *vox = P13_bit.no7; // VOX status from internal AT1846S } @@ -471,3 +469,13 @@ void platform_amp_enable(bool state) { P2_bit.no1 = 1; // P21 (H/L) is high } } + +void platform_audio_enable(bool state) { + if (state) { + // Enable external audio amplifier + P2_bit.no0 = 0; // P20 (SQ) is low + } else { + // Disable external audio amplifier + P2_bit.no0 = 1; // P20 (SQ) is high + } +} diff --git a/src/sa8x8.c b/src/sa8x8.c index ffe90a7..be5b563 100644 --- a/src/sa8x8.c +++ b/src/sa8x8.c @@ -24,6 +24,7 @@ const char CMD_TURBO[] = "+TURBO"; const char CMD_PEEK[] = "+PEEK="; const char CMD_POKE[] = "+POKE="; const char CMD_AMP[] = "+AMP="; +const char CMD_AUDIO[] = "+AUDIO="; const char VERSION[] = "sa8x8-fw/" GIT_INFO "\r\n"; const char MODEL[] = MODULE_MODEL "\r\n"; @@ -321,6 +322,28 @@ int main(void) { continue; } + // AT+AUDIO=<0,1>: Set external audio amplifier state + if (eq(&cmd[2], (char *)CMD_AUDIO, sizeof(CMD_AUDIO) - 1)) { + uint8_t i = sizeof(CMD_AUDIO) + 1; + + // Parse state + bool state = (bool) a2i(cmd, &i); + + // Error if missing terminator + if (!(cmd[i] == '\0')) { + uart_puts(ERR); + continue; + } + + // Set requested amplifier state + platform_audio_enable(state); + + // Send command valid response + uart_puts(OK); + + continue; + } + // All other requests are errors uart_puts(ERR); }