Skip to content

Commit

Permalink
Fixed SW_timers for wake-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Markovic committed Sep 6, 2021
1 parent 2ef92b0 commit 820d8f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
7 changes: 3 additions & 4 deletions Src/TIM2_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ void TIM2_Setup_ENC (void) {
void TIM2_IRQHandler (void){

if (TIM2->SR & TIM_SR_UIF) {//update interupt
TIM2->CNT = ENC_IMPS_PER_STEP_HALF; //put on half for hysteresis
if (TIM2->CR1 & TIM_CR1_DIR) {//koji je smer
TIM2->CNT = ENC_IMPS_PER_STEP_HALF; //put on half for hysteresis
if (menu_active) {
if (!edit_active) {
if (MyData[MENU] > 0) MyData[MENU] --;
Expand All @@ -165,12 +165,11 @@ void TIM2_IRQHandler (void){
MyData[VOLUME] --;
save_change_flag = 1;
vol_change_flag = 1;
SW_timers[7]=0;
SW_timers[T_RY]=0;
current_seq_position = update_seq_up_down ? 0 : seq_position_max;
}
}
} else {
TIM2->CNT = ENC_IMPS_PER_STEP_HALF; //put on half for hysteresis
if (menu_active) {
if (!edit_active) {
if (MyData[MENU] < max_menu) MyData[MENU] ++;
Expand All @@ -185,7 +184,7 @@ void TIM2_IRQHandler (void){
MyData[VOLUME] ++;
save_change_flag = 1;
vol_change_flag = 1;
SW_timers[7]=0;
SW_timers[T_RY]=0;
current_seq_position = update_seq_up_down ? 0 : seq_position_max;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/USART3.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
USART3 kontrolne funkcije za KBD+LCD
USART3 kontrolne funkcije
Koriste se pinovi:
PB10 = USART TX - output
Expand Down
41 changes: 19 additions & 22 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ bool flag_edge_power;

//---------------------------------------------------------------------------


//handler koji resetuje IR strukturu kada istekne count (~650ms)
void TIM1_UP_IRQHandler(void) {
if (TIM1->SR & TIM_SR_UIF) {
Expand Down Expand Up @@ -277,7 +276,7 @@ const struct {
{"STB-PowerSave", 1},//17
{"*ResetSettings!", 0},//18
{"*forum.yu3ma.net", 0},//19
{"*FW 0.9.9 09-2021", 0},//20
{"*FW v1.0 09-2021", 0},//20
{"*Power OFF", 0},//21
{"*Save & Exit", 0},//22
};
Expand Down Expand Up @@ -376,6 +375,9 @@ void Handle_Relays_mode4() {
// Konfiguracija (72000) za SysTick da radi kao 1kHz (1ms) timer
// Iskoriscen SysTick HW tajmer za jos X SW tajmera + Handle_relays()
void SysTick_Handler (void) {

PC13_on; //for timing test

if (SW_timers_enable[T_BUTTON] == 1) SW_timers[T_BUTTON] ++;
SW_timers[T_EDIT_BLINK] ++;
SW_timers[T_EDIT_OFF] ++;
Expand Down Expand Up @@ -423,6 +425,7 @@ void SysTick_Handler (void) {
//power off/on OUT
if (power_off_on == 0) RY8_off; else RY8_on;

PC13_off;
}

//----------------------------------------
Expand All @@ -435,8 +438,8 @@ int main(void) {
USART3_init();
TIM2_Setup_ENC();
TIM1_Setup_TBASE();
ssd1306_Init();

ssd1306_Init();
ssd1306_Fill(0);
ssd1306_UpdateScreen();
//ssd1306_TestFonts();
Expand All @@ -448,18 +451,14 @@ int main(void) {
Flash_Read_MyData();
Update_Encoder_Settings();

//restore back TMR2 settings
TIM2->ARR = ENC_IMPS_PER_STEP = MyData[IMPSSTEP];
ENC_IMPS_PER_STEP_HALF = ENC_IMPS_PER_STEP / 2; //init
TIM2->SMCR = MyData[QEIMODE];

//sve je spremno, startuj glavni tajmer
SysTick_Config(72000); //1ms

//---------------------
//endless loop!
while (1) {
last_IR_cmd = NEC1.cmd;

fps++;
if (SW_timers[T_FPS] >= 1000) {
SW_timers[T_FPS] = 0;
Expand Down Expand Up @@ -629,7 +628,6 @@ int main(void) {
//ssd1306_WriteString(buffer, Font_11x18, White); //11px font
ssd1306_WriteString(buffer, Font_16x26, White); //16px font


if (last_IR_cmd != 0 && MyData[DEBUG] == 1) {
//print received IR cmd
sprintf(buffer, "IR=%d", last_IR_cmd); //
Expand All @@ -644,10 +642,10 @@ int main(void) {
//debug ----------------
if (MyData[DEBUG] == 1) {
//FPS
//sprintf(buffer, "VOL=%01B" PRINTF_BINARY_PATTERN_INT8, PRINTF_BYTE_TO_BINARY_INT8(MyData[VOLUME])); //
//sprintf(buffer, "FPS=%d", fps_last); //
//ssd1306_SetCursor(7, 10);
//ssd1306_WriteString(buffer, Font_7x10, White); //7px font
sprintf(buffer, "VOL=%01B" PRINTF_BINARY_PATTERN_INT8, PRINTF_BYTE_TO_BINARY_INT8(MyData[VOLUME])); //
sprintf(buffer, "FPS=%d", fps_last); //
ssd1306_SetCursor(70, 10);
ssd1306_WriteString(buffer, Font_7x10, White); //7px font

sprintf(buffer, "R17[%d %d %d %d %d %d %d]",
(_Bool) (GPIOA->IDR & GPIO_IDR_IDR3),
Expand Down Expand Up @@ -733,20 +731,19 @@ int main(void) {

if (power_off_on == 1) {
//Button dugacak klick > 1000ms aktivira menu | na glavnom ekranu
if (SW_timers[T_BUTTON] >= 1000 && !menu_active) {
menu_active = 1;
SW_timers[T_BUTTON] = 0;
SW_timers_enable[T_BUTTON] = 0;
}
//Button dugacak klick > 1000ms aktivira edit | u edit ekatu
if (SW_timers[T_BUTTON] >= 1000 && menu_active) {
edit_active = 1;
if (SW_timers[T_BUTTON] >= 1000) {
if (!menu_active) menu_active = 1;
SW_timers[T_BUTTON] = 0;
SW_timers_enable[T_BUTTON] = 0;
}
} else {
SW_timers_enable[T_BUTTON] = 0;
SW_timers_enable [T_WAKEUP] = Button ? 1 : 0;
if (Button) { //handle wakeup
SW_timers_enable [T_WAKEUP] = 1;
} else {
SW_timers_enable [T_WAKEUP] = 0;
SW_timers [T_WAKEUP] = 0;
}
}

//wakeup after 1 sec button on
Expand Down
4 changes: 2 additions & 2 deletions Src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#define RY8_on GPIOC->BSRR=GPIO_BSRR_BS14 //power off/on
#define RY9_on GPIOC->BSRR=GPIO_BSRR_BS15 //ch sw
#define PC13_on GPIOC->BSRR=GPIO_BSRR_BS13 //PC13 LED

#define RY1_off GPIOA->BSRR=GPIO_BSRR_BR3
#define RY2_off GPIOA->BSRR=GPIO_BSRR_BR4
Expand All @@ -38,7 +39,7 @@

#define IR_PIN (GPIOB->IDR & GPIO_IDR_IDR3) //IR
#define Button (GPIOA->IDR & GPIO_IDR_IDR2) //Button

#define PC13_off GPIOC->BSRR=GPIO_BSRR_BR13 //PC13 LED

/* --- PRINTF_BYTE_TO_BINARY macro's --- */
#define PRINTF_BINARY_PATTERN_INT8 "%c%c%c%c%c%c%c%c"
Expand Down Expand Up @@ -126,7 +127,6 @@ void GPIO_init(void) {
IR Input (EXTI3)
PB3
*/

//--------------- PA3 - Relay 1 -------------
Expand Down

0 comments on commit 820d8f7

Please sign in to comment.