void supla_esp_gpio_hi(int port, char hi) { //supla_log(LOG_DEBUG, "supla_esp_gpio_hi %i, %i", port, hi); if ( port == 16 ) { gpio16_output_set(hi == 1 ? 1 : 0); } else { GPIO_OUTPUT_SET(GPIO_ID_PIN(port), hi == 1 ? 1 : 0); } }
int ICACHE_FLASH_ATTR gpio_write(unsigned pin, unsigned level) { if (pin >= GPIO_PIN_NUM) return -1; if(pin == 0){ gpio16_output_conf(); gpio16_output_set(level); return 1; } GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), level); }
void ICACHE_FLASH_ATTR ioSetLed(int ena) { if (ena) { gpio16_output_set(1); } else { gpio16_output_set(0); } }
// **************************************************************************** // KEY_LED functions uint8_t platform_key_led( uint8_t level){ uint8_t temp; gpio16_output_set(1); // set to high first, for reading key low level gpio16_input_conf(); temp = gpio16_input_get(); gpio16_output_conf(); gpio16_output_set(level); return temp; }
IROM bool LedBlink::dispatch(Msg& msg) { PT_BEGIN() PT_WAIT_UNTIL(msg.is(0, SIG_INIT)); init(); while (true) { timeout(_msecInterval); PT_YIELD_UNTIL( msg.is(_src, SIG_CONNECTED) || msg.is(_src, SIG_DISCONNECTED) || timeout()); switch (msg.signal()) { case SIG_TICK: { gpio16_output_set(_isOn); _isOn = !_isOn; break; } case SIG_CONNECTED: { _msecInterval = 1000; break; } case SIG_DISCONNECTED: { _msecInterval = 200; break; } default: { } } } PT_END(); return false; }
int platform_gpio_write( unsigned pin, unsigned level ) { // NODE_DBG("Function platform_gpio_write() is called. pin:%d, level:%d\n",GPIO_ID_PIN(pin_num[pin]),level); if (pin >= NUM_GPIO) return -1; if(pin == 0){ gpio16_output_conf(); gpio16_output_set(level); return 1; } GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), level); }
void user_init(void) { uint8_t state=0; ets_wdt_enable(); ets_wdt_disable(); // Configure pin as a GPIO PIN_FUNC_SELECT(LED_GPIO_MUX, LED_GPIO_FUNC); gpio16_output_conf(); for(;;) { GPIO_OUTPUT_SET(LED_GPIO, state); gpio16_output_set(state); os_delay_us(DELAY); state ^=1; } }
//Init function void ICACHE_FLASH_ATTR user_init() { char ssid[32] = "MY_SSID"; char password[64] = "MY_PASS"; struct station_config stationConf; os_printf("Init a\n\r"); uart_init(BIT_RATE_115200, BIT_RATE_115200); gpio16_output_conf(); gpio16_output_set(0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14); gpio_output_set(0, BIT12|BIT13|BIT14, BIT12|BIT13|BIT14, 0); //Set station mode //wifi_set_macaddr(uint8 if_index, uint8 *macaddr) wifi_set_opmode_current( STATION_MODE ); os_memcpy(&stationConf.ssid, ssid, 32); os_memcpy(&stationConf.password, password, 64); stationConf.bssid_set = 0; wifi_station_set_config_current(&stationConf); // wifi_status_led_install (16, uint32 gpio_name, FUNC_GPIO16) os_printf("Init Ok! %d\n\r", wifi_station_get_connect_status()); wifi_station_set_auto_connect(1); wifi_station_connect(); wifi_station_dhcpc_start(); user_server_init(8888); //Start os task system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen); // system_os_post(user_procTaskPrio, 0, 0 ); }
//Main code function static void ICACHE_FLASH_ATTR loop(os_event_t *events) { int i; gpio16_output_set(0); if (wifi_station_connect()){ os_printf("Not Connected to WiFi\n\r"); wifiStatus = true; } // for(i=0;i<1000;i++) os_delay_us(1000); // system_os_post(user_procTaskPrio, 0, 0 ); }
// TIMER interrupt code to collect raw data. // Widths of alternating SPACE, MARK are recorded in rawbuf. // Recorded in ticks of 50 microseconds. // rawlen counts the number of entries recorded so far. // First entry is the SPACE between transmissions. // As soon as a SPACE gets long, ready is set, state switches to IDLE, timing of SPACE continues. // As soon as first MARK arrives, gap width is recorded, ready is cleared, and new logging starts void ICACHE_FLASH_ATTR ir_cb(void *arg) { uint8_t irdata = (uint8_t) gpio_read(irparams.recvpin); irparams.value = irdata; irparams.timer++; // One more 50us tick if (irparams.rawlen >= RAWBUF) { // Buffer overflow11 irparams.rcvstate = STATE_STOP; } gpio16_output_set(!irdata); switch(irparams.rcvstate) { case STATE_IDLE: // In the middle of a gap if (irdata == MARK) { if (irparams.timer < GAP_TICKS) { // Not big enough to be a gap. irparams.timer = 0; } else { // gap just ended, record duration and start recording transmission irparams.rawlen = 0; irparams.rawbuf[irparams.rawlen++] = irparams.timer; irparams.timer = 0; irparams.rcvstate = STATE_MARK; } } break; case STATE_MARK: // timing MARK if (irdata == SPACE) { // MARK ended, record time irparams.rawbuf[irparams.rawlen++] = irparams.timer; irparams.timer = 0; irparams.rcvstate = STATE_SPACE; } break; case STATE_SPACE: // timing SPACE if (irdata == MARK) { // SPACE just ended, record it irparams.rawbuf[irparams.rawlen++] = irparams.timer; irparams.timer = 0; irparams.rcvstate = STATE_MARK; } else { // SPACE if (irparams.timer > GAP_TICKS) { // big SPACE, indicates gap between codes // Mark current code as ready for processing // Switch to STOP // Don't reset timer; keep counting space width irparams.rcvstate = STATE_STOP; } } break; case STATE_STOP: // waiting, measuring gap if (irdata == MARK) { // reset gap timer irparams.timer = 0; } break; } if (irparams.blinkflag) { /* if (irdata == MARK) { gpio16_output_set(1); // turn pin 16 LED on } else { gpio16_output_set(0); // turn pin 16 LED off } */ } }
static void ICACHE_RAM_ATTR gpio_pulse_timeout(os_param_t p) { (void) p; uint32_t now = system_get_time(); int delay; if (active_pulser) { delay = active_pulser->pending_delay; if (delay > 0) { if (delay > 1200000) { delay = 1000000; } active_pulser->pending_delay -= delay; platform_hw_timer_arm_us(TIMER_OWNER, delay); return; } } do { active_pulser->active_pos = active_pulser->entry_pos; if (!active_pulser || active_pulser->entry_pos >= active_pulser->entry_count) { if (active_pulser) { active_pulser->steps++; } platform_hw_timer_close(TIMER_OWNER); task_post_low(tasknumber, (task_param_t)0); return; } active_pulser->steps++; pulse_entry_t *entry = active_pulser->entry + active_pulser->entry_pos; // Yes, this means that there is more skew on D0 than on other pins.... if (entry->gpio_set & 0x10000) { gpio16_output_set(1); } GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, entry->gpio_set); GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, entry->gpio_clr); if (entry->gpio_clr & 0x10000) { gpio16_output_set(0); } int16_t stop = active_pulser->stop_pos; if (stop == -2 || stop == active_pulser->entry_pos) { platform_hw_timer_close(TIMER_OWNER); task_post_low(tasknumber, (task_param_t)0); return; } if (entry->loop) { if (entry->count_left == 0) { entry->count_left = entry->count + 1; } if (--entry->count_left >= 1) { active_pulser->entry_pos = entry->loop - 1; // zero offset } else { active_pulser->entry_pos++; } } else { active_pulser->entry_pos++; } delay = entry->delay; int delay_offset = 0; if (entry->delay_min != -1) { int offset = active_pulser->next_adjust; active_pulser->next_adjust = 0; delay_offset = ((0x7fffffff & (now - active_pulser->desired_end_time)) << 1) >> 1; delay -= delay_offset; delay += offset; //dbg_printf("%d(et %d diff %d): Delay was %d us, offset = %d, delay_offset = %d, new delay = %d, range=%d..%d\n", // now, active_pulser->desired_end_time, now - active_pulser->desired_end_time, // entry->delay, offset, delay_offset, delay, entry->delay_min, entry->delay_max); if (delay < entry->delay_min) { // we can't delay as little as 'delay', so we need to adjust // the next period as well. active_pulser->next_adjust = (entry->delay - entry->delay_min) + offset; delay = entry->delay_min; } else if (delay > entry->delay_max) { // we can't delay as much as 'delay', so we need to adjust // the next period as well. active_pulser->next_adjust = (entry->delay - entry->delay_max) + offset; delay = entry->delay_max; } } active_pulser->desired_end_time += delay + delay_offset; active_pulser->expected_end_time = system_get_time() + delay; } while (delay < 3);
IROM void LedBlink::init() { gpio16_output_conf(); gpio16_output_set(0); // LED is ON }