Skip to content

Commit

Permalink
Add command to toggle external audio amplifier #15
Browse files Browse the repository at this point in the history
  • Loading branch information
edgetriggered committed Oct 16, 2023
1 parent 10ebc70 commit c553989
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/r5f1026a/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -471,3 +471,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
}
}
23 changes: 23 additions & 0 deletions src/sa8x8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit c553989

Please sign in to comment.