Skip to content

Commit

Permalink
Control power of external devices through switching inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
WiseLord committed May 29, 2017
1 parent 5c041ba commit 9ae9337
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
23 changes: 22 additions & 1 deletion actions.c
Expand Up @@ -189,6 +189,25 @@ uint8_t getAction(void)
return action;
}

static void setExtPower(uint8_t input)
{
uint8_t offMask = 0b11111111; // By default switch off all devices

offMask &= ~(1 << input); // Don't off one of devices

if (offMask & 0b001)
PORT(EXT_POWER1) &= ~EXT_POWER1_LINE;
else
PORT(EXT_POWER1) |= EXT_POWER1_LINE;
if (offMask & 0b010)
PORT(EXT_POWER2) &= ~EXT_POWER2_LINE;
else
PORT(EXT_POWER2) |= EXT_POWER2_LINE;
if (offMask & 0b100)
PORT(EXT_POWER3) &= ~EXT_POWER3_LINE;
else
PORT(EXT_POWER3) |= EXT_POWER3_LINE;
}

void handleAction(uint8_t action)
{
Expand All @@ -198,7 +217,7 @@ void handleAction(uint8_t action)
case ACTION_EXIT_STANDBY:
PORT(STMU_STBY) |= STMU_STBY_LINE; /* Power up audio and tuner */
setWorkBrightness();

setExtPower(aproc.input);
setInitTimer(INIT_TIMER_START);

dispMode = MODE_SND_GAIN0 + aproc.input;
Expand All @@ -218,6 +237,7 @@ void handleAction(uint8_t action)
case CMD_RC_STBY:
sndSetMute(1);
sndPowerOff();
setExtPower(7);
tunerPowerOff();
displayPowerOff();

Expand Down Expand Up @@ -340,6 +360,7 @@ void handleAction(uint8_t action)
case CMD_RC_IN_2:
case CMD_RC_IN_3:
case CMD_RC_IN_4:
setExtPower(action - CMD_RC_IN_0);
sndSetInput(action - CMD_RC_IN_0);
dispMode = MODE_SND_GAIN0 + aproc.input;
setDisplayTime(DISPLAY_TIME_GAIN);
Expand Down
5 changes: 5 additions & 0 deletions main.c
Expand Up @@ -45,6 +45,11 @@ static void hwInit(void)

setStbyTimer(0);

// Set power switches as outputs
DDR(EXT_POWER1) |= EXT_POWER1_LINE;
DDR(EXT_POWER2) |= EXT_POWER2_LINE;
DDR(EXT_POWER3) |= EXT_POWER3_LINE;

return;
}

Expand Down
8 changes: 8 additions & 0 deletions pins.h
Expand Up @@ -69,6 +69,14 @@
#define KS0066_E DISP_STROB
#define KS0066_E_LINE DISP_STROB_LINE

/* External power pins */
#define EXT_POWER1 A
#define EXT_POWER1_LINE (1<<5)
#define EXT_POWER2 A
#define EXT_POWER2_LINE (1<<6)
#define EXT_POWER3 A
#define EXT_POWER3_LINE (1<<7)

/* KS0066 Backlight port */
#define KS0066_BCKL DISP_BCKL
#define KS0066_BCKL_LINE DISP_BCKL_LINE
Expand Down

0 comments on commit 9ae9337

Please sign in to comment.