irom static bool_t get_input(const gpio_t *gpio) { if(gpio->flags.rtc_gpio) return(rtcgpio_input_get()); return(!!(gpio_input_get() & (1 << gpio->index))); }
/* Read the inputs as defined in inputDesc. Returns an int with a bit set for each input that's active. Some inputs are connected to capacitors, because we want to be able read the state of the buttons that were pressed before the ESP started up. After the ESP has started, they hinder us: they'll lengthen the amount of time a button seems pressed, making a short press look like a long one. To go against that, we switch the GPIOs connected to those to outputs and manually drain the capacitors when not reading the inputs. */ int ICACHE_FLASH_ATTR io_get_inputs() { int ret, isHi, x; uint32 val_raw; //Switch discharged outputs back to input for (x=0; x<INPUT_COUNT; x++) { if (inputDesc[x].flags&FL_DISCHARGE) { if (inputDesc[x].flags&FL_ACTLO) gpio_output_set((1<<inputDesc[x].num), 0, 0, (1<<inputDesc[x].num)); if (!(inputDesc[x].flags&FL_ACTLO)) gpio_output_set(0, (1<<inputDesc[x].num), 0, (1<<inputDesc[x].num)); } } //Let parasitic capacitance of gpio pin drain os_delay_us(1000); //Read values val_raw = gpio_input_get()&0xffff; if (gpio16_input_get()) val_raw|=(1<<16); ret=0; for (x=0; x<INPUT_COUNT; x++) { if (inputDesc[x].num!=-1) { isHi=(val_raw&(1<<inputDesc[x].num)); if (isHi && !(inputDesc[x].flags&FL_ACTLO)) ret|=(1<<x); if (!isHi && (inputDesc[x].flags&FL_ACTLO)) ret|=(1<<x); } } //Go back to discharging capacitors where needed for (x=0; x<INPUT_COUNT; x++) { if (inputDesc[x].flags&FL_DISCHARGE) { if (inputDesc[x].flags&FL_ACTLO) gpio_output_set((1<<inputDesc[x].num), 0, (1<<inputDesc[x].num), 0); if (!(inputDesc[x].flags&FL_ACTLO)) gpio_output_set(0, (1<<inputDesc[x].num), (1<<inputDesc[x].num), 0); } } return ret; }
int main() { int ret1,ret2; u8 io = 2,get_val; ret1 = -1; ret2 = -1; u8 mode,od,pu; mode = GPIO_IN; od = GPIO_ODE; pu = GPIO_PUE; //环境初始化 inittest(); gpio_init(); gpio_set(io, mode, od, pu); //测试用例1 //测试用例2 ret2 = gpio_input_get(io, &get_val); assert((ret1 == 0) && (get_val == 1),"gpio_input_get 2 error"); finaltest(); return 0; }
static void user_procTask(os_event_t *events) { int rc = irmp_get_data (&irmp_data); if (rc) { os_printf("\nIRMP %10s(%2d): addr=0x%04x cmd=0x%04x, f=%d ", irmp_protocol_names[ irmp_data.protocol], irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags ); } // https://github.com/SuperHouse/esp-open-rtos/issues/18 // uart_rx_one_char ist offenbar eine ROM-Funktion. int c = my_rx_one_char(); if(c != -1) { uart_tx_one_char(0,c); os_printf("(0x%02x, %d) ",c,c); switch(c) { case '.': os_printf("\nTime=%d, GPIO12=%d, ", system_get_time(),GPIO_INPUT_GET(12)); os_printf("gpio=%08x ",gpio_input_get()); break; } } os_delay_us(100); system_os_post(user_procTaskPrio, 0, 0 ); }
unsigned int ICACHE_FLASH_ATTR dhgpio_read() { return gpio_input_get() & DHGPIO_SUITABLE_PINS; }
irom static inline uint32_t get_io(void) { return(gpio_input_get() & (sda_mask | scl_mask)); }