示例#1
0
void attachInterruptHandler(uint8_t pin, GPIO_INT_TYPE mode)
{
	portENTER_CRITICAL();

	if (!_gpioInterruptsInitialied)
	{
		gpio_intr_handler_register((void*)interruptHandler, NULL); // Register interrupt handler
		_xt_isr_unmask(1<<ETS_GPIO_INUM);
		_gpioInterruptsInitialied = true;
	}

	pinMode(pin, INPUT);

	gpio_pin_intr_state_set(GPIO_ID_PIN(pin), mode); // Enable GPIO pin interrupt

	portEXIT_CRITICAL();
}
示例#2
0
/******************************************************************************
 * FunctionName : key_init
 * Description  : init keys
 * Parameters   : key_param *keys - keys parameter, which inited by key_init_single
 * Returns      : none
*******************************************************************************/
void  
key_init(struct keys_param *keys)
{
    u32 i;
    GPIO_ConfigTypeDef *pGPIOConfig;

    pGPIOConfig = (GPIO_ConfigTypeDef*)zalloc(sizeof(GPIO_ConfigTypeDef));
    gpio_intr_handler_register(key_intr_handler,keys);
    
    for (i = 0; i < keys->key_num; i++) {
        keys->single_key[i]->key_level = 1;
        pGPIOConfig->GPIO_IntrType = GPIO_PIN_INTR_NEGEDGE;
        pGPIOConfig->GPIO_Pullup = GPIO_PullUp_EN;
        pGPIOConfig->GPIO_Mode = GPIO_Mode_Input;
        pGPIOConfig->GPIO_Pin = (1 << keys->single_key[i]->gpio_id);//this is GPIO_Pin_13 for switch
        gpio_config(pGPIOConfig);
    }
    //enable gpio iterrupt
    _xt_isr_unmask(1<<ETS_GPIO_INUM);
}
示例#3
0
/**
 * Initialize the ESP8266 hardware environment.
 *
 * TODO: we should move stuff from user_main.c here
 */
void jshInit() {
  // A call to jshInitDevices is architected as something we have to do.
  os_printf("> jshInit\n");

  // Initialize the ESP8266 GPIO subsystem.
  gpio_init();

  systemTimeInit();
  utilTimerInit();
  jshInitDevices();

  // sanity check for pin function enum to catch ordering changes
  if (JSHPINSTATE_I2C != 12 || JSHPINSTATE_GPIO_IN_PULLDOWN != 5 || JSHPINSTATE_MASK != 15) {
    jsError("JshPinState #defines have changed, please update pinStateToString()");
  }

  // Register a callback function to be called for a GPIO interrupt
  gpio_intr_handler_register(intrHandlerCB, NULL);

  ETS_GPIO_INTR_ENABLE();
  os_printf("< jshInit\n");
} // End of jshInit
void ICACHE_FLASH_ATTR user_init()
{
    // init UART for debugging baud rate comes from user_config.h
    uart_div_modify(0, UART_CLK_FREQ / BAUD_RATE);
    os_printf("\r\nESP8266 OOK decoding\r\n");

    // speed boost (hopefully)
    //system_update_cpu_freq(160);
    system_update_cpu_freq(80);

    // setup loop callback in system task queue
    system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen);
    system_os_post(user_procTaskPrio, 0, 0);

    // init wifi using creds in wifi_config.h. Put your own creds in the file
    connect_wifi(WIFI_SSID, WIFI_PSK);

    // apparently an accurate system time is needed for SSL, so start up
    //   SNTP stuff.
    // SNTP is also used for timestamping emails and alarm triggeringings
    sntp_setservername(0, "time.nist.gov");
    sntp_setservername(1, "time-c.nist.gov");
    sntp_set_timezone(TIMEZONE);
    sntp_init();

    // init stuff for the ook decoder
    gpio_init();
    gpio_intr_handler_register(ook_intr_handler, (void*) &unprocessedPackets);
    init_ook_decoder();

    // webserver-related initialisation
    init_web_server();
    attach_btn_clear(clearTriggeredSensors);
    attach_btn_arm_alarm(arm_alarm);
    attach_btn_disarm_alarm(disarm_alarm);
    // update so we don't just have a blank page on startup
    updateWebpage(); 
}
示例#5
0
/**
 * Initialize the ESP8266 hardware environment.
 *
 * TODO: we should move stuff from user_main.c here
 */
void jshInit() {
  // A call to jshInitDevices is architected as something we have to do.
  os_printf("> jshInit\n");

  // Initialize the ESP8266 GPIO subsystem.
  gpio_init();

  systemTimeInit();
  utilTimerInit();
  jshInitDevices();

  // sanity check for pin function enum to catch ordering changes
  if (JSHPINSTATE_I2C != 12 || JSHPINSTATE_GPIO_IN_PULLDOWN != 5 || JSHPINSTATE_MASK != 15) {
    jsError("JshPinState #defines have changed, please update pinStateToString()");
  }

  // Register a callback function to be called for a GPIO interrupt
  gpio_intr_handler_register(intrHandlerCB, NULL);

  ETS_GPIO_INTR_ENABLE();

#ifndef HARDWARE_PWM
  BITFIELD_CLEAR(jshPinSoftPWM);
#endif

  // Initialize something for each of the possible pins.
  for (int i=0; i<JSH_PIN_COUNT; i++) {
#ifdef HARDWARE_PWM
    // For each of the PWM records, flag the PWM as having been not initialized.
    g_PWMRecords[i].enabled = false;
#endif
    g_pinState[i] = 0;
  }

  os_printf("< jshInit\n");
} // End of jshInit
irom void gpios_init(void)
{
	unsigned int current;
	unsigned int pwmchannel;
	gpio_t *gpio;
	gpio_config_entry_t *cfg;
	uint32_t pwm_io_info[gpio_pwm_size][3];
	uint32_t pwm_duty_init[gpio_pwm_size];
	uint32_t state_change_mask;
	int sda, scl;

	sda = scl = -1;

	gpio_init();

	state_change_mask = 0;

	for(current = 0, pwmchannel = 0; current < gpio_size; current++)
	{
		gpio = &gpios[current];
		cfg = get_config(gpio);

		if(cfg->mode != gpio_disabled)
			select_pin_function(gpio);

		if(cfg->mode == gpio_counter)
			state_change_mask |= (1 << gpio->index);

		if((cfg->mode == gpio_pwm) && (pwmchannel < gpio_pwm_size))
		{
			gpio->pwm.channel = pwmchannel;
			pwm_io_info[pwmchannel][0] = gpio->io_mux;
			pwm_io_info[pwmchannel][1] = gpio->io_func;
			pwm_io_info[pwmchannel][2] = gpio->index;
			pwm_duty_init[pwmchannel] = cfg->pwm.min_duty;
			pwmchannel++;
		}

		if(cfg->mode == gpio_i2c)
		{
			if(cfg->i2c.pin == gpio_i2c_sda)
				sda = gpio->index;

			if(cfg->i2c.pin == gpio_i2c_scl)
				scl = gpio->index;
		}
	}

	if(state_change_mask != 0)
		gpio_intr_handler_register(pc_int_handler, 0);

	if(pwmchannel > 0)
	{
		pwm_init(3000, pwm_duty_init, pwmchannel, pwm_io_info);
		gpio_flags.pwm_subsystem_active = true;
	}

	for(current = 0; current < gpio_size; current++)
		gpio_mode_trait[config->gpios.entry[current].mode].init_fn(&gpios[current]);

	if((sda > 0) && (scl > 0))
		i2c_init(sda, scl, config->i2c_delay);
}