Esempio n. 1
1
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);
}
Esempio n. 2
0
/**
 * Sets the 'gpio_pin' pin as a GPIO and sets the pull-up and
 * pull-down registers for that pin.
 * 'pullStatus' has no effect on output pins or GPIO16
 */
bool ICACHE_FLASH_ATTR
easygpio_pinMode(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus, EasyGPIO_PinMode pinMode) {
  uint32_t gpio_name;
  uint8_t gpio_func;

  if (16==gpio_pin) {
    // ignoring pull status on GPIO16 for now
    if (EASYGPIO_OUTPUT == pinMode) {
      gpio16_output_conf();
    } else {
      gpio16_input_conf();
    }
    return true;
  } else if (!easygpio_getGPIONameFunc(gpio_pin, &gpio_name, &gpio_func) ) {
    return false;
  }

  PIN_FUNC_SELECT(gpio_name, gpio_func);
  easygpio_setupPullsByName(gpio_name, pullStatus);

  if (EASYGPIO_OUTPUT != pinMode) {
    GPIO_DIS_OUTPUT(GPIO_ID_PIN(gpio_pin));
  } else {
    // must enable the pin or else the WRITE_PERI_REG won't work
    gpio_output_set(0, 0, BIT(GPIO_ID_PIN(gpio_pin)),0);
  }
  return true;
}
Esempio n. 3
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;
}
void ioInit() {
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);	//Button 1
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);	//Button 2
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);	//Output 2
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13);	//Output 1
	gpio16_output_conf();					//Led
        
	gpio_output_set(0, 0, (1<<GPIO_OUTPUT1)+(1<<GPIO_OUTPUT2), (1<<GPIO_BUTTON2)+(1<<GPIO_BUTTON1));
	os_timer_disarm(&eventTimer);
	os_timer_setfn(&eventTimer, eventTimerCb, NULL);
	os_timer_arm(&eventTimer, 100, 1);
}
Esempio n. 5
0
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);
}
Esempio n. 6
0
int platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull )
{
  NODE_DBG("Function platform_gpio_mode() is called. pin_mux:%d, func:%d\n", pin_mux[pin], pin_func[pin]);
  if (pin >= NUM_GPIO)
    return -1;

  if(pin == 0){
    if(mode==PLATFORM_GPIO_INPUT)
      gpio16_input_conf();
    else
      gpio16_output_conf();

    return 1;
  }

#ifdef LUA_USE_MODULES_PWM
  platform_pwm_close(pin);    // closed from pwm module, if it is used in pwm
#endif

  if (pull == PLATFORM_GPIO_PULLUP) {
    PIN_PULLUP_EN(pin_mux[pin]);
  } else {
    PIN_PULLUP_DIS(pin_mux[pin]);
  }

  switch(mode){

    case PLATFORM_GPIO_INPUT:
      GPIO_DIS_OUTPUT(pin_num[pin]);
      set_gpio_no_interrupt(pin, TRUE);
      break;
    case PLATFORM_GPIO_OUTPUT:
      set_gpio_no_interrupt(pin, TRUE);
      GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS, BIT(pin_num[pin]));
      break;
    case PLATFORM_GPIO_OPENDRAIN:
      set_gpio_no_interrupt(pin, FALSE);
      GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS, BIT(pin_num[pin]));
      break;

#ifdef GPIO_INTERRUPT_ENABLE
    case PLATFORM_GPIO_INT:
      set_gpio_interrupt(pin);
      break;
#endif

    default:
      break;
  }
  return 1;
}
Esempio n. 7
0
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;
	}
}
Esempio n. 8
0
//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 );

}
Esempio n. 9
0
int ICACHE_FLASH_ATTR set_gpio_mode(unsigned pin, unsigned mode, unsigned pull)
{
	if (pin >= GPIO_PIN_NUM)
		return -1;
	if(pin == 0) {
		if(mode == GPIO_INPUT)
			gpio16_input_conf();
		else
			gpio16_output_conf();
		return 1;
	}

	switch(pull) {
		case GPIO_PULLUP:
			// PIN_PULLDWN_DIS(pin_mux[pin]);
			PIN_PULLUP_EN(pin_mux[pin]);
			break;
		case GPIO_PULLDOWN:
			PIN_PULLUP_DIS(pin_mux[pin]);
			// PIN_PULLDWN_EN(pin_mux[pin]);
			break;
		case GPIO_FLOAT:
			PIN_PULLUP_DIS(pin_mux[pin]);
			// PIN_PULLDWN_DIS(pin_mux[pin]);
			break;
		default:
			PIN_PULLUP_DIS(pin_mux[pin]);
			// PIN_PULLDWN_DIS(pin_mux[pin]);
			break;
	}

	switch(mode) {
		case GPIO_INPUT:
			GPIO_DIS_OUTPUT(pin_num[pin]);
			break;
		case GPIO_OUTPUT:
			ETS_GPIO_INTR_DISABLE();
#ifdef GPIO_INTERRUPT_ENABLE
			pin_int_type[pin] = GPIO_PIN_INTR_DISABLE;
#endif
			PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]);
			//disable interrupt
			gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), GPIO_PIN_INTR_DISABLE);
			//clear interrupt status
			GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin]));
			GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin]))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); //disable open drain;
			ETS_GPIO_INTR_ENABLE();
			break;
#ifdef GPIO_INTERRUPT_ENABLE
		case GPIO_INT:
			ETS_GPIO_INTR_DISABLE();
			PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]);
			GPIO_DIS_OUTPUT(pin_num[pin]);
			gpio_register_set(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
                        | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
                        | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));
			ETS_GPIO_INTR_ENABLE();
			break;
#endif
		default:
			break;
	}
	return 1;
}
Esempio n. 10
0
int platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull )
{
  // NODE_DBG("Function platform_gpio_mode() is called. pin_mux:%d, func:%d\n",pin_mux[pin],pin_func[pin]);
  if (pin >= NUM_GPIO)
    return -1;
  if(pin == 0){
    if(mode==PLATFORM_GPIO_INPUT)
      gpio16_input_conf();
    else
      gpio16_output_conf();
    return 1;
  }

  platform_pwm_close(pin);    // closed from pwm module, if it is used in pwm

  switch(pull){
    case PLATFORM_GPIO_PULLUP:
      PIN_PULLDWN_DIS(pin_mux[pin]);
      PIN_PULLUP_EN(pin_mux[pin]);
      break;
    case PLATFORM_GPIO_PULLDOWN:
      PIN_PULLUP_DIS(pin_mux[pin]);
      PIN_PULLDWN_EN(pin_mux[pin]);
      break;
    case PLATFORM_GPIO_FLOAT:
      PIN_PULLUP_DIS(pin_mux[pin]);
      PIN_PULLDWN_DIS(pin_mux[pin]);
      break;
    default:
      PIN_PULLUP_DIS(pin_mux[pin]);
      PIN_PULLDWN_DIS(pin_mux[pin]);
      break;
  }

  switch(mode){
    case PLATFORM_GPIO_INPUT:
#if defined( LUA_USE_MODULES_GPIO ) && defined( GPIO_INTERRUPT_ENABLE )
      lua_gpio_unref(pin);    // unref the lua ref call back.
#endif
      GPIO_DIS_OUTPUT(pin_num[pin]);
    case PLATFORM_GPIO_OUTPUT:
      ETS_GPIO_INTR_DISABLE();
#ifdef GPIO_INTERRUPT_ENABLE
      pin_int_type[pin] = GPIO_PIN_INTR_DISABLE;
#endif
      PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]);
      //disable interrupt
      gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), GPIO_PIN_INTR_DISABLE);
      //clear interrupt status
      GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin]));
      GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin]))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); //disable open drain; 
      ETS_GPIO_INTR_ENABLE();
      break;
#ifdef GPIO_INTERRUPT_ENABLE
    case PLATFORM_GPIO_INT:
      ETS_GPIO_INTR_DISABLE();
      PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]);
      GPIO_DIS_OUTPUT(pin_num[pin]);
      gpio_register_set(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
                        | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
                        | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));
      ETS_GPIO_INTR_ENABLE();
      break;
#endif
    default:
      break;
  }
  return 1;
}
Esempio n. 11
0
void ICACHE_FLASH_ATTR
supla_esp_gpio_init(void) {

	switch_cfgbtn_state_check = 0;
	switch_cfgbtn_last_state = -1;
	switch_cfgbtn_counter = 0;

	#if defined(USE_GPIO3) || defined(UART_SWAP)
		 system_uart_swap ();
	#endif

	ETS_GPIO_INTR_DISABLE();

	GPIO_PORT_INIT;

    #ifdef USE_GPIO16_INPUT
	gpio16_input_conf();
    #endif

	#ifdef USE_GPIO16_OUTPUT
	gpio16_output_conf();
	#endif


    #ifdef USE_GPIO3
	   PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3);
	   PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0RXD_U);
    #endif

    #ifdef BTN_PULLUP
        #if CFG_PORT == 0
	      PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO0_U);
        #elif CFG_PORT == 2
          PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U);
        #elif CFG_PORT == 4
	      PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO4_U);
		#elif CFG_PORT == 12
	     PIN_PULLUP_EN(PERIPHS_IO_MUX_MTDI_U);
		#elif CFG_PORT == 13
	      PIN_PULLUP_EN(PERIPHS_IO_MUX_MTCK_U);
		#elif CFG_PORT == 14
	      PIN_PULLUP_EN(PERIPHS_IO_MUX_MTMS_U);
       #endif
    #endif

    #ifdef LED_RED_PORT
      #if LED_RED_PORT != 16
	    gpio_pin_intr_state_set(GPIO_ID_PIN(LED_RED_PORT), GPIO_PIN_INTR_DISABLE);
      #endif
    #endif

    #ifdef LED_GREEN_PORT
    gpio_pin_intr_state_set(GPIO_ID_PIN(LED_GREEN_PORT), GPIO_PIN_INTR_DISABLE);
    #endif

    #ifdef LED_BLUE_PORT
    gpio_pin_intr_state_set(GPIO_ID_PIN(LED_BLUE_PORT), GPIO_PIN_INTR_DISABLE);
    #endif


    #ifdef RELAY1_PORT
    gpio_pin_intr_state_set(GPIO_ID_PIN(RELAY1_PORT), GPIO_PIN_INTR_DISABLE);
    #endif

    #ifdef RELAY2_PORT
    gpio_pin_intr_state_set(GPIO_ID_PIN(RELAY2_PORT), GPIO_PIN_INTR_DISABLE);
    #endif

	#ifdef ZAM_INPUT1
	supla_esp_gpio_enable_input_port(ZAM_INPUT1);
	#endif

	#ifdef ZAM_INPUT2
	supla_esp_gpio_enable_input_port(ZAM_INPUT2);
	#endif

	ETS_GPIO_INTR_ENABLE();

	keys.key_num = 0;

	single_key[0] = key_init_single(CFG_PORT, supla_esg_gpio_cfg_pressed, supla_esg_gpio_manual_pressed);
	keys.key_num++;

    #if defined(BUTTON1_PORT) && defined(RELAY1_PORT)

		single_key[keys.key_num] = key_init_single(BUTTON1_PORT, NULL, supla_esg_gpio_button1_pressed);
		keys.key_num++;

    #endif

	#if defined(BUTTON1_PORT) && defined(RELAY1_PORT)

		single_key[keys.key_num] = key_init_single(BUTTON2_PORT, NULL, supla_esg_gpio_button2_pressed);
		keys.key_num++;

	#endif

	keys.single_key = single_key;
	keys.handler = supla_esp_key_intr_handler;

    #ifdef RELAY_STATE_RESTORE

		struct rst_info *rtc_info = system_get_rst_info();

		#ifdef RELAY1_PORT
			if ( rtc_info->reason == 0 ) {
				   supla_esp_gpio_relay1_hi(supla_esp_state.Relay1);
			}
		#endif

		#ifdef RELAY2_PORT
		    if ( rtc_info->reason == 0 ) {
			   supla_esp_gpio_relay2_hi(supla_esp_state.Relay2);
			}
		#endif

    #elif defined(RESET_RELAY_PORT)

		#ifdef RELAY1_PORT
		   supla_esp_gpio_relay1_hi(RELAY_INIT_VALUE);
		#endif

		#ifdef RELAY2_PORT
		   supla_esp_gpio_relay2_hi(RELAY_INIT_VALUE);
		#endif

    #endif

	key_init(&keys);


    GPIO_PORT_POST_INIT;

    supla_esp_gpio_init_time = system_get_time();

}
Esempio n. 12
0
IROM void LedBlink::init() {
	gpio16_output_conf();
	gpio16_output_set(0); 	// LED is ON
}