add keep-alive detection
This commit is contained in:
parent
ecdcf07811
commit
017495692c
32
main.c
32
main.c
|
@ -52,6 +52,7 @@
|
|||
*/
|
||||
volatile bool rtc_tick_flag = false; /**< flag set when RTC ticked */
|
||||
volatile bool frame_flag = false; /**< flag set when a frame has passed */
|
||||
volatile bool keep_alive_flag = false; /**< flag to restart shutdown counter on power switch activity */
|
||||
/** @} */
|
||||
|
||||
#define SQUARE_WAVE_PORT B /**< port connected to RTC DS1307 square wave output */
|
||||
|
@ -74,8 +75,10 @@ volatile uint8_t frame_count = 0; /**< number of frames passed */
|
|||
#define MUX_S2_PORT B /**< port to select multiplexer output */
|
||||
#define MUX_S2_PIN 5 /**< pin to select multiplexer output */
|
||||
|
||||
#define POWER_PORT B /**< port to control power of all devices (including this micro-controller) */
|
||||
#define POWER_PIN 8 /**< pin to control power of all devices (including this micro-controller) */
|
||||
#define POWER_SWITCH_PORT B /**< port to switch power of all devices (including this micro-controller) */
|
||||
#define POWER_SWITCH_PIN 8 /**< pin to switch power of all devices (including this micro-controller) */
|
||||
#define POWER_BUTTON_PORT B /**< port to detect power switching activity (to keep alive) */
|
||||
#define POWER_BUTTON_PIN 1 /**< pin to detect power switching activity (to keep alive) */
|
||||
|
||||
/** user input command */
|
||||
static char command[32] = {0};
|
||||
|
@ -247,9 +250,16 @@ void main(void)
|
|||
rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock
|
||||
|
||||
// keep power on a soon as possible
|
||||
rcc_periph_clock_enable(RCC_GPIO(POWER_PORT)); // enable clock for GPIO
|
||||
gpio_set_mode(GPIO(POWER_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(POWER_PIN)); // set as output to control power
|
||||
gpio_set(GPIO(POWER_PORT), GPIO(POWER_PIN)); // enable power by saturating nMOS controlling power
|
||||
rcc_periph_clock_enable(RCC_GPIO(POWER_SWITCH_PORT)); // enable clock for GPIO
|
||||
gpio_set_mode(GPIO(POWER_SWITCH_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(POWER_SWITCH_PIN)); // set as output to control power
|
||||
gpio_set(GPIO(POWER_SWITCH_PORT), GPIO(POWER_SWITCH_PIN)); // enable power by saturating nMOS controlling power
|
||||
rcc_periph_clock_enable(RCC_GPIO(POWER_BUTTON_PORT)); // enable clock for GPIO domain
|
||||
gpio_set_mode(GPIO(POWER_BUTTON_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(POWER_BUTTON_PIN)); // set pin as input to detect power switching activity
|
||||
rcc_periph_clock_enable(RCC_AFIO); // enable alternate function clock for external interrupt
|
||||
exti_select_source(EXTI(POWER_BUTTON_PIN), GPIO(POWER_BUTTON_PORT)); // mask external interrupt of this pin only for this port
|
||||
exti_set_trigger(EXTI(POWER_BUTTON_PIN), EXTI_TRIGGER_BOTH); // trigger on any activity of the power switch
|
||||
exti_enable_request(EXTI(POWER_BUTTON_PIN)); // enable external interrupt
|
||||
nvic_enable_irq(NVIC_EXTI_IRQ(POWER_BUTTON_PIN)); // enable interrupt
|
||||
|
||||
#if DEBUG
|
||||
// enable functionalities for easier debug
|
||||
|
@ -460,7 +470,7 @@ void main(void)
|
|||
mux_select(tm1637); // selecting TM1637 display
|
||||
led_tm1637_off(); // switch off TM1637 display
|
||||
}
|
||||
gpio_clear(GPIO(POWER_PORT), GPIO(POWER_PIN)); // switch power of by disconnecting from battery
|
||||
gpio_clear(GPIO(POWER_SWITCH_PORT), GPIO(POWER_SWITCH_PIN)); // switch power of by disconnecting from battery
|
||||
SCB_SCR |= SCB_SCR_SLEEPDEEP; // enable deep sleep
|
||||
pwr_set_standby_mode(); // go to deep sleep
|
||||
while (true); // we should be shut down at this point
|
||||
|
@ -484,8 +494,8 @@ void main(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
while (pwr_get_wakeup_flag()) { // someone is moving the clapperboard
|
||||
pwr_clear_wakeup_flag(); // clear flag
|
||||
while (keep_alive_flag) { // power switch is detecting movement to keep clapperboard running
|
||||
keep_alive_flag = false; // clear flag
|
||||
standby_timer = 0; // restart standby timer
|
||||
}
|
||||
if (action) { // go to sleep if nothing had to be done, else recheck for activity
|
||||
|
@ -524,3 +534,9 @@ void TIM_ISR(FRAME_TIMER)(void)
|
|||
}
|
||||
}
|
||||
|
||||
/** power switch/keep alive activity */
|
||||
void EXTI_ISR(POWER_BUTTON_PIN)(void)
|
||||
{
|
||||
exti_reset_request(EXTI(POWER_BUTTON_PIN)); // reset interrupt
|
||||
keep_alive_flag = true; // perform button action
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue