Пример #1
0
void HAL_Core_Button_Mirror_Pin(uint16_t pin, InterruptMode mode, uint8_t bootloader, uint8_t button, void *reserved) {
    (void)button; // unused
    if (pin > TOTAL_PINS) {
        return;
    }

    if (mode != RISING && mode != FALLING) {
        return;
    }

    button_config_t conf = {
        .pin = pin,
        .debounce_time = 0,
        .interrupt_mode = mode,
    };

    HAL_Buttons[BUTTON1_MIRROR] = conf;

    BUTTON_Init(BUTTON1_MIRROR, BUTTON_MODE_EXTI);

    if (pin == HAL_Buttons[BUTTON1].pin) {
        BUTTON_Mirror_Persist(NULL);
        return;
    }

    if (!bootloader) {
        BUTTON_Mirror_Persist(NULL);
        return;
    }

    button_config_t bootloader_conf = {
        .active = 0xAA,
        .debounce_time = 0xBBCC,
        .pin = pin,
        .interrupt_mode = mode,
    };

    BUTTON_Mirror_Persist(&bootloader_conf);
}

void BUTTON_Init_Ext() {
    button_config_t button_config = {0};
    dct_read_app_data_copy(DCT_MODE_BUTTON_MIRROR_OFFSET, &button_config, sizeof(button_config_t));

    if (button_config.active == 0xAA && button_config.debounce_time == 0xBBCC) {
        //int32_t state = HAL_disable_irq();
        memcpy((void*)&HAL_Buttons[BUTTON1_MIRROR], (void*)&button_config, sizeof(button_config_t));
        HAL_Buttons[BUTTON1_MIRROR].active = 0;
        HAL_Buttons[BUTTON1_MIRROR].debounce_time = 0;
        BUTTON_Init(BUTTON1_MIRROR, BUTTON_MODE_EXTI);
        //HAL_enable_irq(state);
    }
}

void BUTTON_Uninit() {
    button_timer_uninit();
    HAL_Interrupts_Uninit();
}
Пример #2
0
/* ------------------------------------------------------------------ */
int main (void)
{
	uint8_t state = ST_TOP_MENU;
	uint8_t nextstate = ST_TOP_MENU;
	uint8_t key = KEY_NONE;
	func_p pStateFunc = states[state];
	
	
	/* disable watchdog */
	wdt_reset();
	Wdt_clear_flag();
	Wdt_change_enable();
	Wdt_stop();
		
	Clear_prescaler();
	InitLED();
	Led1On();
	
	Timer0_Init();
	SPEAKER_Init();
	BUTTON_Init();
	LCD_Init();
	
	sei();
	
	while (1)
	{
		key = BUTTON_GetKey();
		nextstate = pStateFunc(key);
		
		if (nextstate != state) {
			pStateFunc = states[nextstate];
			state = nextstate;
		}
		
	} /* end of while(1) */
	return 0;
}