/******************************************************************************* * IO Driver for IdeasX * Author: curiousmuch * Description: HAL layer for IdeasX v0.3.X encoders * This lib has a couple functions * 1) Provide SW interface for encoder hardware for the following functions: * reset, shutdown, enable / disable assistive switches * 2) Provide the ability to attach custom ISR to assistive switch inputs and INTR pin on LSM6DS3. * Todo: *******************************************************************************/ #include "hal/io.h" // debounce timers static Encoder_Timer_t encoder_timer; void ICACHE_FLASH_ATTR Encoder_InitIO(uint32_t debounce_delay, switch_function_t switch_a_cb, switch_function_t switch_b_cb, switch_function_t imu_cb) { ETS_GPIO_INTR_DISABLE(); gpio_init(); // setup as GPIO pins PIN_FUNC_SELECT(LDO_SHUTDOWN_MUX, LDO_SHUTDOWN_FUNC); PIN_FUNC_SELECT(SWITCH_A_MUX, SWITCH_A_FUNC); PIN_FUNC_SELECT(SWITCH_B_MUX, SWITCH_B_FUNC); PIN_FUNC_SELECT(STATUS_LED_MUX, STATUS_LED_FUNC); // setup GPIO states gpio_output_set(BIT(LDO_SHUTDOWN), BIT(STATUS_LED), (BIT(LDO_SHUTDOWN)|BIT(STATUS_LED)), (BIT(SWITCH_A)|BIT(SWITCH_B))); // attach interrupts to switchs gpio_pin_intr_state_set(GPIO_ID_PIN(SWTICH_A), GPIO_PIN_INTR_ANYEDGE); gpio_pin_intr_state_set(GPIO_ID_PIN(SWITCH_B), GPIO_PIN_INTR_ANYEDGE); os_timer_disarm(&encoder_timer.switch_a); os_timer_disarm(&encoder_timer.switch_b); os_timer_setfn(&timerA, (os_timer_func_t *)switchA_debounce, NULL); os_timer_setfn(&timerB, (os_timer_func_t *)switchB_debounce, NULL); ETS_GPIO_INTR_ENABLE(); return; } void ICACHE_FLASH_ATTR Encoder_EnableAdaptiveSwitches(void) { gpio_pin_intr_state_set(GPIO_ID_PIN(SWTICH_A), GPIO_PIN_INTR_ANYEDGE); gpio_pin_intr_state_set(GPIO_ID_PIN(SWITCH_B), GPIO_PIN_INTR_ANYEDGE); } void ICACHE_FLASH_ATTR Encoder_DisableAdaptiveSwitches(void) { gpio_pin_intr_state_set(GPIO_ID_PIN(SWTICH_A), GPIO_PIN_INTR_DISABLE); gpio_pin_intr_state_set(GPIO_ID_PIN(SWITCH_B), GPIO_PIN_INTR_DISABLE); } void ICACHE_FLASH_ATTR Encoder_ShutDown(void) { GPIO_OUTPUT_SET(LDO_SHUTDOWN, 0); } void ICACHE_FLASH_ATTR Encoder_Restart(void) { return; } void ICACHE_FLASH_ATTR Encoder_GPIO_Handler(void) { uint8_t i; uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); // read interupt status of pins uint32_t gpio_states = GPIO_REG_READ(GPIO_IN_ADDRESS); // read pin status ETS_GPIO_INTR_DISABLE(); // disable GPIO interrupts for (i=0;i