static void platform_gpio_intr_dispatcher( platform_gpio_intr_handler_fn_t cb){
  uint8 i, level;
  uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
  for (i = 0; i < GPIO_PIN_NUM; i++) {
    if (pin_int_type[i] && (gpio_status & BIT(pin_num[i])) ) {
      //disable interrupt
      gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[i]), GPIO_PIN_INTR_DISABLE);
      //clear interrupt status
      GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(pin_num[i]));
      level = 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[i]));
      if(cb){
        cb(i, level);
      }
      gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[i]), pin_int_type[i]);
    }
  }
}
Esempio n. 2
0
/******************************************************************************
 * FunctionName : user_humiture_long_press
 * Description  : humiture key's function, needed to be installed
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_sensor_long_press(void)
{
    os_printf(" LVZAINA ===> SmartConfig start! \n");
	
	uint32 gpio_status;
	gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	//clear interrupt status
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
	
	user_link_led_timer_init();	
	
	smartconfig_stop();
    smartconfig_start(smartconfig_done);
	
    os_printf(" LVZAINA ===> SmartConfig end! \n");
}
Esempio n. 3
0
uint8_t platform_sigma_delta_close( uint8_t pin )
{
  if (pin < 1 || pin > NUM_GPIO)
    return 0;

  sigma_delta_stop();

  // set GPIO input mode for this pin
  platform_gpio_mode( pin, PLATFORM_GPIO_INPUT, PLATFORM_GPIO_PULLUP );

  // CONNECT GPIO TO PIN PAD
  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_SOURCE_MASK)) |
                 GPIO_PIN_SOURCE_SET( GPIO_AS_PIN_SOURCE ));

  return 1;
}
Esempio n. 4
0
void interrupt_test(){
	// disable interrupts
	ETS_GPIO_INTR_DISABLE();

	uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);

	// publish that button has been pressed
	INFO("Button pressed!!");

	pb1Transmit();

	//gpio_pin_intr_state_set(GPIO_ID_PIN(4), GPIO_PIN_INTR_POSEDGE);

	// enable interrupts
	ETS_GPIO_INTR_ENABLE();
}
Esempio n. 5
0
void setSigmaDeltaPrescaler(unsigned char prescaler)
{
	uint8 duty;
	duty = getSigmaDeltaDuty();
	if (GPIO_REG_READ(GPIO_SIGMA_DELTA) & 0x10000)
	{ // check to see if ΣΔ is running
		GPIO_REG_WRITE(GPIO_SIGMA_DELTA, 0);
		// turn off ΣΔ
		GPIO_REG_WRITE(GPIO_SIGMA_DELTA, 0x10000 | (prescaler<<8) | duty);
		// set Target Prescaler and restore duty
	}
	else
	{
		GPIO_REG_WRITE(GPIO_SIGMA_DELTA, (prescaler<<8)|duty);
		// set Target Prescaler and restore duty but leave turned off
	}

}
void ICACHE_RAM_ATTR SoftwareSerial::handle_interrupt(void *arg) {
   uint32_t gpioStatus = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
   // Clear the interrupt(s) otherwise we get called again
   GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpioStatus);
   ETS_GPIO_INTR_DISABLE();
   uint8_t pin = 0;
   while (gpioStatus) {
      while(!(gpioStatus & (1 << pin))) pin++;
      gpioStatus &= ~(1 << pin);
      if (InterruptList[pin]) {
         // For some reason there is always an interrupt directly after the
         // stop bit. Detect that by checking if we have a start bit
         if (digitalRead(pin) == InterruptList[pin]->m_invert)
            InterruptList[pin]->rxRead();
      }
   }
   ETS_GPIO_INTR_ENABLE();
}
Esempio n. 7
0
uint8_t platform_sigma_delta_setup( uint8_t pin )
{
  if (pin < 1 || pin > NUM_GPIO)
    return 0;

  sigma_delta_setup();

  // set GPIO output mode for this pin
  platform_gpio_mode( pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT );
  platform_gpio_write( pin, PLATFORM_GPIO_LOW );

  // enable sigma-delta on this 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_SOURCE_MASK)) |
                 GPIO_PIN_SOURCE_SET( SIGMA_AS_PIN_SOURCE ));

  return 1;
}
Esempio n. 8
0
LOCAL void ICACHE_FLASH_ATTR read_input_pin(void *arg)
{
	uint32 gpio_status;
	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	sleepms(15);
	if(!GPIO_INPUT_GET(PIN_GPIO13)) {
	button_counter++;
	console_printf("READ_INPUT_PIN executed...");
	console_printf("COUNTER:%d\n",button_counter);
	os_timer_disarm(&input_pin_timer); // Disarm input pin timer
	os_timer_setfn(&input_pin_timer, (os_timer_func_t *)handle_pin_press, NULL); // Setup input pin timer
	os_timer_arm(&input_pin_timer, button_timeout, 1); // Arm input pin timer, 0,5sec, repeat
	sleepms(button_debounce);  // debounce time
	}
	gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status); 	//clear interrupt status

	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts}
}
Esempio n. 9
0
void some_timerfunc(void *arg)
{
    //Do blinky stuff
    if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2)
    {
        //Set GPIO2 to LOW
        gpio_output_set(0, BIT2, BIT2, 0);
        os_printf("0");
    }
    else
    {
        //Set GPIO2 to HIGH
        gpio_output_set(BIT2, 0, BIT2, 0);
        os_printf("1");
    }
    if (count++ % 80 == 0) {
        os_printf("\n");
    }
}
static void gpio_intr_handler()
{
    uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);

	//m_printf("gpio_status:%X\n\r",gpio_status);

	if (gpio_status & BIT(0))// S_REED
	{
		debugf("irq00\n\r");
		//GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, (gpio_status & BIT(0)));
	}

	if(gpio_status & BIT(3))//
	{
    	debugf("irq03\n\r");
		//GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, (gpio_status & BIT(3)));
	}

	if (gpio_status & BIT(4))//
	{
 		debugf("irq04\n\r");
 		
 		_relay._changeStat();
 		
		//GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, (gpio_status & BIT(4)));
	}

	if (gpio_status & BIT(13))//
	{
		debugf("irq13\n\r");
		//GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, (gpio_status & BIT(13)));

		_relay._changeStat();
	}

	if (gpio_status & BIT(15))
	{
		debugf("irq15\n\r");
		//GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, (gpio_status & BIT(13)));
	}
}
Esempio n. 11
0
static void ICACHE_FLASH_ATTR gpio_intr(void *arg) {
    uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);

	if (irparams.rcvstate == STATE_STOP) {
		return;
	}	
    static uint32_t start = 0;
    uint32_t now = system_get_time();
	if (irparams.rcvstate == STATE_IDLE) {
		irparams.rcvstate = STATE_MARK;
		irparams.rawbuf[irparams.rawlen++] = 20;		
	}
    else if (irparams.rawlen < RAWBUF) {
		irparams.rawbuf[irparams.rawlen++] = (now - start) / USECPERTICK + 1;
    }
    start = now;

    os_timer_disarm(&timer);
    os_timer_arm(&timer, 15, 0);
}
LOCAL void gpio_intr(void *arg) {
	unsigned int gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
	if(gpio_status & mExternalIntPins) {
		dhgpio_extra_int(gpio_status & mExternalIntPins);
		gpio_status &= ~mExternalIntPins;
		if(gpio_status == 0)
			return;
	}
	mTriggeredIntrPins |= gpio_status;
	if(mGPIOTimerArmed)
		return;
	os_timer_disarm(&mGPIOTimer);
	if(mGPIOTimerTimeout) {
		mGPIOTimerArmed = 1;
		os_timer_setfn(&mGPIOTimer, (os_timer_func_t *)gpio_timeout, NULL);
		os_timer_arm(&mGPIOTimer, mGPIOTimerTimeout, 0);
	} else {
		gpio_timeout(0);
	}
}
Esempio n. 13
0
static void ICACHE_FLASH_ATTR
udpServerRxCb(void *arg, char *pData, unsigned short len)
{
	int i;

	for ( i = 0 ; i < len ; i++)
	{
		os_printf("%c", pData[i]);
	}

	/* Toggle PIN */
	if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & RELAY_PIN)
	{
		//Set GPIO0 to LOW
		gpio_output_set(0, RELAY_PIN, BIT0, 0);
	}
	else
	{
		//Set GPIO0 to HIGH
		gpio_output_set(RELAY_PIN, 0, RELAY_PIN, 0);
	}
}
Esempio n. 14
0
bool ICACHE_FLASH_ATTR
pwm_add(uint8 channel){
    PWM_DBG("--Function pwm_add() is called. channel:%d\n", channel);
    PWM_DBG("pwm_gpio:%x,pwm_channel_num:%d\n",pwm_gpio,pwm_channel_num);
    PWM_DBG("pwm_out_io_num[0]:%d,[1]:%d,[2]:%d\n",pwm_out_io_num[0],pwm_out_io_num[1],pwm_out_io_num[2]);
    PWM_DBG("pwm.duty[0]:%d,[1]:%d,[2]:%d\n",pwm.duty[0],pwm.duty[1],pwm.duty[2]);
    uint8 i;
    for(i=0;i<PWM_CHANNEL;i++){
        if(pwm_out_io_num[i]==channel)  // already exist
            return true;
        if(pwm_out_io_num[i] == -1){ // empty exist
            pwm_out_io_num[i] = channel;
            pwm.duty[i] = 0;
            pwm_gpio |= (1 << pin_num[channel]);
            PIN_FUNC_SELECT(pin_mux[channel], pin_func[channel]);
            GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel]))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); //disable open drain;
            pwm_channel_num++;
            return true;
        }
    }
    return false;
}
Esempio n. 15
0
void ICACHE_FLASH_ATTR gpio_intr_dispatcher(gpio_intr_handler cb)
{
	uint8 i, level;
	uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	for (i = 0; i < GPIO_PIN_NUM; i++) {
		if (pin_int_type[i] && (gpio_status & BIT(pin_num[i])) ) {
			//disable global interrupt
			ETS_GPIO_INTR_DISABLE();
			//disable interrupt
			gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[i]), GPIO_PIN_INTR_DISABLE);
			//clear interrupt status
			GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(pin_num[i]));
			level = 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[i]));
			if(cb){
				cb(i, level);
			}
			//enable interrupt
			gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[i]), pin_int_type[i]);
			//enable global interrupt
			ETS_GPIO_INTR_ENABLE();
		}
	}
}
Esempio n. 16
0
File: key.c Progetto: lvjh/ESP8266
/******************************************************************************
 * FunctionName : key_intr_handler
 * Description  : key interrupt handler
 * Parameters   : key_param *keys - keys parameter, which inited by key_init_single
 * Returns	  : none
*******************************************************************************/
LOCAL void key_intr_handler(struct keys_param *keys) {
    uint8 i;
    uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);

    for (i = 0; i < keys->key_num; i++) {
        if (gpio_status & BIT(keys->single_key[i]->gpio_id)) {
            //disable interrupt
            gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_DISABLE);

            //clear interrupt status
            GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(keys->single_key[i]->gpio_id));

            if (keys->single_key[i]->key_level == 1) {
                // 5s long release timer
                os_timer_disarm(&keys->single_key[i]->key_5s);
                os_timer_setfn(&keys->single_key[i]->key_5s, (os_timer_func_t *)key_5s_cb, keys->single_key[i]);
                os_timer_arm(&keys->single_key[i]->key_5s, 5000, 0);

                keys->single_key[i]->key_level = 0;
                keys->single_key[i]->is_long = 0;
                gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_POSEDGE);

                if (keys->single_key[i]->press) {
                    // PRESS callback
                    os_timer_disarm(&keys->single_key[i]->key_press);
                    os_timer_setfn(&keys->single_key[i]->key_press, (os_timer_func_t *)keys->single_key[i]->press, NULL);
                    os_timer_arm(&keys->single_key[i]->key_press, 5, 0);
                }
            } else {
                // 50ms check if this is a real key up
                os_timer_disarm(&keys->single_key[i]->key_50ms);
                os_timer_setfn(&keys->single_key[i]->key_50ms, (os_timer_func_t *)key_50ms_cb, keys->single_key[i]);
                os_timer_arm(&keys->single_key[i]->key_50ms, 50, 0);
            }
        }
    }
}
Esempio n. 17
0
static void
ping_intr_handler(void *key) {
  uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
  if (ping_allEchoPins & gpio_status) {
    if (ping_currentEchoPin>=0 && (gpio_status & BIT(ping_currentEchoPin))) {
      // This interrupt was intended for us - clear interrupt status
      GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(ping_currentEchoPin));

      if(!ping_echoStarted) {
        gpio_pin_intr_state_set(GPIO_ID_PIN(ping_currentEchoPin), GPIO_PIN_INTR_NEGEDGE);
        ping_timeStamp0 = system_get_time();
        ping_echoStarted = true;
      } else {
        ping_timeStamp1 = system_get_time();
        ping_echoEnded = true;
        ping_disableInterrupt(ping_currentEchoPin);
        ping_currentEchoPin = -1;
      }
    } else {
      // This interrupt was intended for us, but not at this moment - clear interrupt status anyway
      GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & ping_allEchoPins);
    }
  }
}
Esempio n. 18
0
void handle_timeout(void *arg) {
    if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2)
        gpio_output_set(0, BIT2, BIT2, 0); //Set GPIO2 to LOW
    else 
        gpio_output_set(BIT2, 0, BIT2, 0); //Set GPIO2 to HIGH
}
Esempio n. 19
0
void Softuart_Intr_Handler(Softuart *s)
{
	uint8_t level, gpio_id;
// clear gpio status. Say ESP8266EX SDK Programming Guide in  5.1.6. GPIO interrupt handler

    uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	gpio_id = Softuart_Bitcount(gpio_status);

	//if interrupt was by an attached rx pin
    if (gpio_id != 0xFF)
    {
		//load instance which has rx pin on interrupt pin attached
		s = _Softuart_GPIO_Instances[gpio_id];

// disable interrupt for GPIO0
        gpio_pin_intr_state_set(GPIO_ID_PIN(s->pin_rx.gpio_id), GPIO_PIN_INTR_DISABLE);

// Do something, for example, increment whatyouwant indirectly
		//check level
		level = GPIO_INPUT_GET(GPIO_ID_PIN(s->pin_rx.gpio_id));
		if(!level) {
			//pin is low
			//therefore we have a start bit

			//wait till start bit is half over so we can sample the next one in the center
			os_delay_us(s->bit_time/2);	

			//now sample bits
			unsigned i;
			unsigned d = 0;
			unsigned start_time = 0x7FFFFFFF & system_get_time();

			for(i = 0; i < 8; i ++ )
			{
				while ((0x7FFFFFFF & system_get_time()) < (start_time + (s->bit_time*(i+1))))
				{
					//If system timer overflow, escape from while loop
					if ((0x7FFFFFFF & system_get_time()) < start_time){break;}
				}
				//shift d to the right
				d >>= 1;

				//read bit
				if(GPIO_INPUT_GET(GPIO_ID_PIN(s->pin_rx.gpio_id))) {
					//if high, set msb of 8bit to 1
					d |= 0x80;
				}
			}

			//store byte in buffer

			// if buffer full, set the overflow flag and return
			uint8 next = (s->buffer.receive_buffer_tail + 1) % SOFTUART_MAX_RX_BUFF;
			if (next != s->buffer.receive_buffer_head)
			{
			  // save new data in buffer: tail points to where byte goes
			  s->buffer.receive_buffer[s->buffer.receive_buffer_tail] = d; // save new byte
			  s->buffer.receive_buffer_tail = next;
			} 
			else 
			{
			  s->buffer.buffer_overflow = 1;
			}

			//wait for stop bit
			os_delay_us(s->bit_time);	

			//done
		}
Esempio n. 20
0
uint32
gpio_output_get(void)
{
    return GPIO_REG_READ(GPIO_OUT_ADDRESS);
}
Esempio n. 21
0
void gpio_intr_handler(struct base_key_param **keys_param)
{
    uint8 i;
    uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	uint8 gpio_id;

	struct base_key_param * single_key = NULL;

    PRINTF("Get into gpio_intr_handler, gpio_status:%u\n", gpio_status);

	for(i = 0; i < KEY_MAX_NUM; i++)
	{
		single_key = keys_param[i];

		if(single_key == NULL)
		{
			PRINTF("\r\nintr sinle_key is NULL, i:%d\r\n",i);
			continue;
		}

		gpio_id = single_key->gpio_id;
		PRINTF("\r\ngpio_id:%d, BIT(gpio_id):%d\r\n",gpio_id, BIT(gpio_id));
		if(gpio_status & BIT(gpio_id))
		{
			PRINTF("\r\n key config start....\r\n");
			//disable interrupt
			gpio_pin_intr_state_set(GPIO_ID_PIN(gpio_id), GPIO_PIN_INTR_DISABLE);
			//clear interrupt status
			GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(gpio_id));

			//if need to manage special gpio event,  manage here
			//example: manage key config wifi connect, need call config_key_init() first
			if(i == 0)
			{
				if(single_key->level == 1)
				{// 5s, restart & enter softap mode
					PRINTF("\r\n sinle_key->level:%d....\r\n", single_key->level);
					os_timer_disarm(&single_key->k_timer1);
					os_timer_setfn(&single_key->k_timer1, (os_timer_func_t *)key_5s_cb,
							single_key);
					os_timer_arm(&single_key->k_timer1, LONG_PRESS_COUNT, 0);
					single_key->level = 0;
					gpio_pin_intr_state_set(GPIO_ID_PIN(gpio_id), GPIO_PIN_INTR_POSEDGE);
				}
				else
				{
					// 50ms, check if this is a real key up
					PRINTF("\r\n50ms sinle_key->level:%d....\r\n", single_key->level);
					os_timer_disarm(&single_key->k_timer2);
					os_timer_setfn(&single_key->k_timer2, (os_timer_func_t *)key_50ms_cb,
							single_key);
					os_timer_arm(&single_key->k_timer2, 50, 0);
				}

				continue;
			}

			//other manage

		}
	}


}
Esempio n. 22
0
unsigned char getSigmaDeltaDuty(void)
{
	return (unsigned char) (GPIO_REG_READ(GPIO_SIGMA_DELTA) & 0x0ff); // set Target duty cycle
}
Esempio n. 23
0
/*
 * Sample the value of GPIO input pins and returns a bitmask.
 *
 * Only GPIO0-GPIO31
 */
uint32 gpio_input_get(void)
{
    return GPIO_REG_READ(GPIO_IN);
}
Esempio n. 24
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. 25
0
/*
 * Sample the value of GPIO input pins and returns a bitmask.
 *
 * Only GPIO32-GPIO39
 */
uint32 gpio_input_get_high(void)
{
    return GPIO_REG_READ(GPIO_IN1);
}
Esempio n. 26
0
uint8_t relay_get_status()
{
	return (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT15) == 0 ? 0 : 1;
}
Esempio n. 27
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. 28
0
bool led_is_set (void)
{
    return ((GPIO_REG_READ(GPIO_OUT_ADDRESS) & LED_IO_MASK)) ? true : false;
}
Esempio n. 29
0
  static char *states[] = {
    "UNDEFINED", "GPIO_OUT", "GPIO_OUT_OPENDRAIN",
    "GPIO_IN", "GPIO_IN_PULLUP", "GPIO_IN_PULLDOWN",
    "ADC_IN", "AF_OUT", "AF_OUT_OPENDRAIN",
    "USART_IN", "USART_OUT", "DAC_OUT", "I2C",
  };
  return states[state];
}


static void jshDebugPin(Pin pin) {
  os_printf("PIN: %d out=%ld enable=%ld in=%ld\n",
      pin, (GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1, (GPIO_REG_READ(GPIO_ENABLE_ADDRESS)>>pin)&1,
      (GPIO_REG_READ(GPIO_IN_ADDRESS)>>pin)&1);

  uint32_t gpio_pin = GPIO_REG_READ(GPIO_PIN_ADDR(pin));
  uint32_t mux = READ_PERI_REG(PERIPHS_IO_MUX + 4*pin);
  os_printf("     dr=%s src=%s func=%ld pull-up=%ld oe=%ld\n",
      gpio_pin & 4 ? "open-drain" : "totem-pole",
      gpio_pin & 1 ? "sigma-delta" : "gpio",
      (mux>>2)&1 | (mux&3), (mux>>7)&1, mux&1);
}

/**
 * Set the state of the specific pin.
 *
 * The possible states are:
 *
 * JSHPINSTATE_UNDEFINED
 * JSHPINSTATE_GPIO_OUT
 * JSHPINSTATE_GPIO_OUT_OPENDRAIN
Esempio n. 30
0
bool ICACHE_FLASH_ATTR ssd1306_init(uint8_t id)
{
    oled_i2c_ctx *ctx = NULL;

    if ((id != 0) && (id != 1))
        goto oled_init_fail;

    // free old context (if any)
    ssd1306_term(id);

    ctx = zalloc(sizeof(oled_i2c_ctx));
    if (ctx == NULL)
    {
        dmsg_err_puts("Alloc OLED context failed.");
        goto oled_init_fail;
    }
    if (id == 0)
    {
#if (PANEL0_TYPE != 0)
  #if (PANEL0_TYPE == SSD1306_128x64)
        ctx->type = SSD1306_128x64;
        ctx->buffer = zalloc(1024); // 128 * 64 / 8
        ctx->width = 128;
        ctx->height = 64;
  #elif (PANEL0_TYPE == SSD1306_128x32)
        ctx->type = SSD1306_128x32;
        ctx->buffer = zalloc(512);  // 128 * 32 / 8
        ctx->width = 128;
        ctx->height = 32;
  #else
    #error "Panel 0 undefined"
  #endif
        if (ctx->buffer == NULL)
        {
            dmsg_err_puts("Alloc OLED buffer failed.");
            goto oled_init_fail;
        }
        ctx->address = PANEL0_ADDR;
  #if PANEL0_USE_RST
        // Panel 0 reset
        PIN_FUNC_SELECT(PANEL0_RST_MUX, PANEL0_RST_FUNC);
        GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | PANEL0_RST_BIT);
        GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, PANEL0_RST_BIT);
        os_delay_us(10000);
        GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, PANEL0_RST_BIT);
  #endif
#else
        dmsg_err_puts("Panel 0 not defined.");
        goto oled_init_fail;
#endif
    }
    else if (id == 1)
    {
#if (PANEL1_PANEL_TYPE != 0)
  #if (PANEL1_PANEL_TYPE ==SSD1306_128x64)
        ctx->type = SSD1306_128x64;
        ctx->buffer = zalloc(1024); // 128 * 64 / 8
        ctx->width = 128;
        ctx->height = 64;
  #elif (PANEL1_PANEL_TYPE == SSD1306_128x32)
        ctx->type = SSD1306_128x32;
        ctx->buffer = zalloc(512);  // 128 * 32 / 8
        ctx->width = 128;
        ctx->height = 32;
  #else
     #error "Unknown Panel 1 type"
  #endif
        if (ctx->buffer == NULL)
        {
            dmsg_err_puts("Alloc OLED buffer failed.");
            goto oled_init_fail;
        }
        ctx->address = PANEL1_ADDR;
  #if PANEL1_USE_RST
        // Panel 1 reset
        PIN_FUNC_SELECT(PANEL1_RST_MUX, PANEL1_RST_FUNC);
        GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | PANEL1_RST_BIT);
        GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, PANEL1_RST_BIT);
        os_delay_us(10000);
        GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, PANEL1_RST_BIT);
  #endif
#else
        dmsg_err_puts("Panel 1 not defined.");
        goto oled_init_fail;
#endif
    }

    // Panel initialization
    // Try send I2C address check if the panel is connected
    i2c_start();
    if (!i2c_write(ctx->address))
    {
        i2c_stop();
        dmsg_err_puts("OLED I2C bus not responding.");
        goto oled_init_fail;
    }
    i2c_stop();

    // Now we assume all sending will be successful
    if (ctx->type == SSD1306_128x64)
    {
        _command(ctx->address, 0xae); // SSD1306_DISPLAYOFF
        _command(ctx->address, 0xd5); // SSD1306_SETDISPLAYCLOCKDIV
        _command(ctx->address, 0x80); // Suggested value 0x80
        _command(ctx->address, 0xa8); // SSD1306_SETMULTIPLEX
        _command(ctx->address, 0x3f); // 1/64
        _command(ctx->address, 0xd3); // SSD1306_SETDISPLAYOFFSET
        _command(ctx->address, 0x00); // 0 no offset
        _command(ctx->address, 0x40); // SSD1306_SETSTARTLINE line #0
        _command(ctx->address, 0x20); // SSD1306_MEMORYMODE
        _command(ctx->address, 0x00); // 0x0 act like ks0108
        _command(ctx->address, 0xa1); // SSD1306_SEGREMAP | 1
        _command(ctx->address, 0xc8); // SSD1306_COMSCANDEC
        _command(ctx->address, 0xda); // SSD1306_SETCOMPINS
        _command(ctx->address, 0x12);
        _command(ctx->address, 0x81); // SSD1306_SETCONTRAST
        _command(ctx->address, 0xcf);
        _command(ctx->address, 0xd9); // SSD1306_SETPRECHARGE
        _command(ctx->address, 0xf1);
        _command(ctx->address, 0xdb); // SSD1306_SETVCOMDETECT
        _command(ctx->address, 0x30);
        _command(ctx->address, 0x8d); // SSD1306_CHARGEPUMP
        _command(ctx->address, 0x14); // Charge pump on
        _command(ctx->address, 0x2e); // SSD1306_DEACTIVATE_SCROLL
        _command(ctx->address, 0xa4); // SSD1306_DISPLAYALLON_RESUME
        _command(ctx->address, 0xa6); // SSD1306_NORMALDISPLAY
    }
    else if (ctx->type == SSD1306_128x32)
    {
        _command(ctx->address, 0xae); // SSD1306_DISPLAYOFF
        _command(ctx->address, 0xd5); // SSD1306_SETDISPLAYCLOCKDIV
        _command(ctx->address, 0x80); // Suggested value 0x80
        _command(ctx->address, 0xa8); // SSD1306_SETMULTIPLEX
        _command(ctx->address, 0x1f); // 1/32
        _command(ctx->address, 0xd3); // SSD1306_SETDISPLAYOFFSET
        _command(ctx->address, 0x00); // 0 no offset
        _command(ctx->address, 0x40); // SSD1306_SETSTARTLINE line #0
        _command(ctx->address, 0x8d); // SSD1306_CHARGEPUMP
        _command(ctx->address, 0x14); // Charge pump on
        _command(ctx->address, 0x20); // SSD1306_MEMORYMODE
        _command(ctx->address, 0x00); // 0x0 act like ks0108
        _command(ctx->address, 0xa1); // SSD1306_SEGREMAP | 1
        _command(ctx->address, 0xc8); // SSD1306_COMSCANDEC
        _command(ctx->address, 0xda); // SSD1306_SETCOMPINS
        _command(ctx->address, 0x02);
        _command(ctx->address, 0x81); // SSD1306_SETCONTRAST
        _command(ctx->address, 0x2f);
        _command(ctx->address, 0xd9); // SSD1306_SETPRECHARGE
        _command(ctx->address, 0xf1);
        _command(ctx->address, 0xdb); // SSD1306_SETVCOMDETECT
        _command(ctx->address, 0x40);
        _command(ctx->address, 0x2e); // SSD1306_DEACTIVATE_SCROLL
        _command(ctx->address, 0xa4); // SSD1306_DISPLAYALLON_RESUME
        _command(ctx->address, 0xa6); // SSD1306_NORMALDISPLAY
    }
    // Save context
    ctx->id = id;
    _ctxs[id] = ctx;

    ssd1306_clear(id);
    ssd1306_refresh(id, true);

    _command(ctx->address, 0xaf); // SSD1306_DISPLAYON

    return true;

oled_init_fail:
    if (ctx && ctx->buffer) free(ctx->buffer);
    if (ctx) free(ctx);
    return false;
}