Skip to content

Commit

Permalink
Use Deep-Sleep1 when suspending the pok3r
Browse files Browse the repository at this point in the history
This decreases the power consumption to <1mA when the host
suspends the pok3r.
  • Loading branch information
lactide committed May 26, 2018
1 parent 6d70a03 commit 4436d7d
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
37 changes: 35 additions & 2 deletions keyboards/vortex/boards/VORTEX_DUAL_60/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@
PAFIO(PORT, N, LINE_SPI_CS, AFIO_GPIO) | \
0)

#define PESSR_L(LINE) ((PAL_PAD(LINE) < 8) ? (HT32_PAL_IDX(LINE) << (PAL_PAD(LINE) * 4uL)) : 0)
#define PESSR_H(LINE) ((PAL_PAD(LINE) >=8) ? (HT32_PAL_IDX(LINE) << ((PAL_PAD(LINE) - 8uL) * 4uL)) : 0)

/* doesn't work due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=4210 */
/*
#define PESSR(N, LINE) ((N) ? (PESSR_H(LINE)) : (PESSR_L(LINE)))
#define ESSR_BITS(N) (\
PESSR(N, LINE_COL1) | \
PESSR(N, LINE_COL2) | \
PESSR(N, LINE_COL3) | \
PESSR(N, LINE_COL4) | \
PESSR(N, LINE_COL5) | \
PESSR(N, LINE_COL6) | \
PESSR(N, LINE_COL7) | \
PESSR(N, LINE_COL8) | \
0)
*/

#define ESSR_BITS_0 (\
PESSR_L(LINE_COL1) | \
PESSR_L(LINE_COL2) | \
PESSR_L(LINE_COL3) | \
PESSR_L(LINE_COL4) | \
0)

#define ESSR_BITS_1 (\
PESSR_H(LINE_COL5) | \
PESSR_H(LINE_COL6) | \
PESSR_H(LINE_COL7) | \
PESSR_H(LINE_COL8) | \
0)

/**
* @brief PAL setup.
* @details Digital I/O ports static configuration as defined in @p board.h.
Expand Down Expand Up @@ -144,8 +176,9 @@ const PALConfig pal_default_config = {
.CFG[0] = AF_BITS(IOPORTE, 0),
.CFG[1] = AF_BITS(IOPORTE, 1),
},
.ESSR[0] = 0x00000000,
.ESSR[1] = 0x00000000,
// Enable Column Pins for EXTI
.ESSR[0] = ESSR_BITS_0,
.ESSR[1] = ESSR_BITS_1,
};

const ioline_t row_list[MATRIX_ROWS] = {
Expand Down
1 change: 1 addition & 0 deletions keyboards/vortex/pok3r/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

SRC = \
matrix.c \
suspend.c \
eeprom.c \
backlight.c

Expand Down
62 changes: 62 additions & 0 deletions keyboards/vortex/suspend.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2018 Charlie Waters
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "hal.h"

#define WAKUPCR_EVWUPIEN_Mask 0x80000000uL
#define SCR_DEEPSLEEP_Mask 0x04uL

extern ioline_t row_list[MATRIX_ROWS];
extern ioline_t col_list[MATRIX_COLS];

void suspend_power_down(void) {
/* enable all rows */
for (int row = 0; row < MATRIX_ROWS; row++) {
palClearLine(row_list[row]);
}
/* enable EXTI clock */
CKCU->APBCCR0 |= CKCU_APBCCR0_EXTIEN;
/* enable Event Wakeup Interrupt */
NVIC_EnableIRQ(EVWUP_IRQn);
/* enable wakeup interrupt */
EXTI->WAKUPCR = WAKUPCR_EVWUPIEN_Mask;
for (int col = 0; col < MATRIX_COLS; col++) {
/* enable event wakeup for all column pads */
EXTI->WAKUPCR |= (1 << PAL_PAD(col_list[col]));
/* set wakeup polarity to low */
EXTI->WAKUPPOLR |= (1 << PAL_PAD(col_list[col]));
}
/* enable deep sleep */
SCB->SCR |= SCR_DEEPSLEEP_Mask;
/* sleep */
__WFI();
/* disable deep sleep */
SCB->SCR &= SCR_DEEPSLEEP_Mask;
/* disable all rows */
for (int row = 0; row < MATRIX_ROWS; row++) {
palSetLine(row_list[row]);
}
}

OSAL_IRQ_HANDLER(Vector58) {
OSAL_IRQ_PROLOGUE();
/* acknowledge interrupt */
EXTI->WAKUPFLG |= EXTI->WAKUPFLG;
/* disable interrupt */
EXTI->WAKUPCR = 0;
OSAL_IRQ_EPILOGUE();
}
2 changes: 1 addition & 1 deletion tmk_core/common/chibios/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void suspend_idle(uint8_t time) {
*
* FIXME: needs doc
*/
void suspend_power_down(void) {
__attribute__ ((weak)) void suspend_power_down(void) {
// TODO: figure out what to power down and how
// shouldn't power down TPM/FTM if we want a breathing LED
// also shouldn't power down USB
Expand Down

0 comments on commit 4436d7d

Please sign in to comment.