diff --git a/cube/output/ttt2/ttt2.ioc b/cube/output/ttt2/ttt2.ioc index 3ef28b0..cadc6c7 100644 --- a/cube/output/ttt2/ttt2.ioc +++ b/cube/output/ttt2/ttt2.ioc @@ -98,9 +98,10 @@ PB9.GPIOParameters=GPIO_Label PB9.GPIO_Label=OLED_RST PB9.Locked=true PB9.Signal=GPIO_Output -PC13-TAMPER-RTC.GPIOParameters=GPIO_Label +PC13-TAMPER-RTC.GPIOParameters=PinState,GPIO_Label PC13-TAMPER-RTC.GPIO_Label=LED PC13-TAMPER-RTC.Locked=true +PC13-TAMPER-RTC.PinState=GPIO_PIN_RESET PC13-TAMPER-RTC.Signal=GPIO_Output PC14-OSC32_IN.GPIOParameters=GPIO_Label PC14-OSC32_IN.GPIO_Label=ERROR diff --git a/my_src/alarm.c b/my_src/alarm.c new file mode 100644 index 0000000..c51ed85 --- /dev/null +++ b/my_src/alarm.c @@ -0,0 +1,24 @@ +/* + * alarm.c + * + * Created on: Jun 2, 2017 + * Author: wn + */ + + +#include "stm32f1xx_hal.h" + + +void blink(void *handle) { + HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); +} + + +void enableAlarm() { + schAdd(blink, NULL, 0, 100); +} + +void disableAlarm() { + schDel(blink, NULL); + HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, RESET); +} diff --git a/my_src/alarm.h b/my_src/alarm.h new file mode 100644 index 0000000..389663f --- /dev/null +++ b/my_src/alarm.h @@ -0,0 +1,16 @@ +/* + * alarm.h + * + * Created on: Jun 2, 2017 + * Author: wn + */ + +#ifndef ALARM_H_ +#define ALARM_H_ + + +void enableAlarm(); +void disableAlarm(); + + +#endif /* ALARM_H_ */ diff --git a/my_src/display.c b/my_src/display.c index 72ad892..24782b8 100644 --- a/my_src/display.c +++ b/my_src/display.c @@ -8,6 +8,7 @@ #include "stm32f1xx_hal.h" #include "display.h" +#include "alarm.h" #include @@ -124,6 +125,9 @@ void buttonShort() { toggleSetMode(); } else if (display.timerState == IDLE) { startTimer(); + } else if (display.timerState == RUNNING || display.timerState == OVERRUN) { + stopTimer(); + disableAlarm(); } } diff --git a/my_src/main2.c b/my_src/main2.c index 7726f8e..be86b71 100644 --- a/my_src/main2.c +++ b/my_src/main2.c @@ -26,13 +26,9 @@ extern tDisplay display; -void blink(void *handle) { - HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); -} void my_setup_1() { schInit(); -// schAdd(blink, NULL, 0, 100); schAdd(updateDisplay, &display, 0, 250); schAdd(secondTick, &display, 0, 1000); } diff --git a/my_src/timer.c b/my_src/timer.c index 37b3bdd..a9513a1 100644 --- a/my_src/timer.c +++ b/my_src/timer.c @@ -7,6 +7,7 @@ #include "timer.h" #include "display.h" +#include "alarm.h" extern tDisplay display; @@ -15,23 +16,32 @@ void startTimer() { display.timerState = STARTED; } +void stopTimer() { + display.timerState = IDLE; +} + void secondTick(void *handle) { tDisplay *lDisplay = (tDisplay*) handle; switch (lDisplay->timerState) { case STARTED: lDisplay->currentTime = lDisplay->targetTime; + lDisplay->overrunTime = 0; lDisplay->timerState = RUNNING; break; case RUNNING: lDisplay->currentTime -= 1; if (lDisplay->currentTime == 0) { + enableAlarm(); lDisplay->timerState = OVERRUN; } break; case OVERRUN: lDisplay->overrunTime += 1; break; + case IDLE: + ; + break; default: ; } diff --git a/my_src/timer.h b/my_src/timer.h index 97a1761..4da8ca2 100644 --- a/my_src/timer.h +++ b/my_src/timer.h @@ -17,5 +17,6 @@ typedef enum { void secondTick(void *handle); void startTimer(); +void stopTimer(); #endif /* TIMER_H_ */