Beispiel #1
0
// initialization
void IRrecv::enableIRIn() {
	
  // initialize state machine variables
  irparams.rcvstate = STATE_IDLE;
  irparams.rawlen = 0;

  // set pin modes  
  //PIN_FUNC_SELECT(IR_IN_MUX, IR_IN_FUNC);
  GPIO_DIS_OUTPUT(irparams.recvpin);
  
  // Initialize timer
  os_timer_disarm(&timer);
  os_timer_setfn(&timer, (os_timer_func_t *)read_timeout, &timer);
  
  // ESP Attach Interrupt
  ETS_GPIO_INTR_DISABLE();
  ETS_GPIO_INTR_ATTACH(gpio_intr, NULL);
  gpio_pin_intr_state_set(GPIO_ID_PIN(irparams.recvpin), GPIO_PIN_INTR_ANYEDGE);
  ETS_GPIO_INTR_ENABLE();
  //ETS_INTR_UNLOCK();  
  
  //attachInterrupt(irparams.recvpin, readIR, CHANGE);  
  //irReadTimer.initializeUs(USECPERTICK, readIR).start();
  //os_timer_arm_us(&irReadTimer, USECPERTICK, 1);
  //ets_timer_arm_new(&irReadTimer, USECPERTICK, 1, 0);
}
Beispiel #2
0
/******************************************************************************
 * FunctionName : key_init
 * Description  : init keys
 * Parameters   : key_param *keys - keys parameter, which inited by key_init_single
 * Returns	  : none
*******************************************************************************/
void ICACHE_FLASH_ATTR key_init() {
    uint8 i;

    ETS_GPIO_INTR_ATTACH(key_intr_handler, &key_parameters);

    ETS_GPIO_INTR_DISABLE();

    for (i = 0; i < key_parameters.key_num; i++) {
        key_parameters.single_key[i]->key_level = 1;
        key_parameters.single_key[i]->is_long = 0;

        PIN_FUNC_SELECT(key_parameters.single_key[i]->gpio_name, key_parameters.single_key[i]->gpio_func);

        // Set GPIO as input
        gpio_output_set(0, 0, 0, GPIO_ID_PIN(key_parameters.single_key[i]->gpio_id));

        gpio_register_set(
            GPIO_PIN_ADDR(key_parameters.single_key[i]->gpio_id),
            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)
        );

        //clear gpio14 status
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(key_parameters.single_key[i]->gpio_id));

        //enable interrupt
        gpio_pin_intr_state_set(GPIO_ID_PIN(key_parameters.single_key[i]->gpio_id), GPIO_PIN_INTR_NEGEDGE);
    }

    ETS_GPIO_INTR_ENABLE();
}
Beispiel #3
0
/******************************************************************************
 * FunctionName : key_init
 * Description  : init keys
 * Parameters   : key_param *keys - keys parameter, which inited by key_init_single
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
key_init(struct keys_param *keys)
{
    uint8 i;
    os_printf("-%s-%s \r\n", __FILE__, __func__);

    ETS_GPIO_INTR_ATTACH(key_intr_handler, keys);

    ETS_GPIO_INTR_DISABLE();

    for (i = 0; i < keys->key_num; i++) {
        keys->single_key[i]->key_level = 1;

        PIN_FUNC_SELECT(keys->single_key[i]->gpio_name, keys->single_key[i]->gpio_func);

        gpio_output_set(0, 0, 0, GPIO_ID_PIN(keys->single_key[i]->gpio_id));

        gpio_register_set(GPIO_PIN_ADDR(keys->single_key[i]->gpio_id), 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));

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

        //enable interrupt
        gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_ANYEGDE);
    }

    ETS_GPIO_INTR_ENABLE();
}
/**
 * Sets the 'gpio_pin' pin as a GPIO and sets the interrupt to trigger on that pin.
 * The 'interruptArg' is the function argument that will be sent to your interruptHandler
 */
bool ICACHE_FLASH_ATTR
easygpio_attachInterrupt(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus, void (*interruptHandler)(void *arg), void *interruptArg) {
  uint32_t gpio_name;
  uint8_t gpio_func;

  if (gpio_pin == 16) {
    os_printf("easygpio_setupInterrupt Error: GPIO16 does not have interrupts\n");
    return false;
  }
  if (!easygpio_getGPIONameFunc(gpio_pin, &gpio_name, &gpio_func) ) {
    return false;
  }

  ETS_GPIO_INTR_ATTACH(interruptHandler, interruptArg);
  ETS_GPIO_INTR_DISABLE();

  PIN_FUNC_SELECT(gpio_name, gpio_func);

  easygpio_setupPullsByName(gpio_name, pullStatus);

  // disable output
  GPIO_DIS_OUTPUT(gpio_pin);

  gpio_register_set(GPIO_PIN_ADDR(gpio_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));

  //clear gpio14 status
  GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(gpio_pin));
  ETS_GPIO_INTR_ENABLE();

  return true;
}
SoftwareSerial::SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic, unsigned int buffSize) {
   m_rxValid = m_txValid = false;
   m_buffer = NULL;
   m_invert = inverse_logic;
   if (isValidGPIOpin(receivePin)) {
      m_rxPin = receivePin;
      m_buffSize = buffSize;
      m_buffer = (uint8_t*)malloc(m_buffSize);
      if (m_buffer != NULL) {
         m_rxValid = true;
         m_inPos = m_outPos = 0;
         pinMode(m_rxPin, INPUT);
         if (!InterruptsEnabled) {
            ETS_GPIO_INTR_ATTACH(handle_interrupt, 0);
            InterruptsEnabled = true;
         }
         InterruptList[m_rxPin] = this;
         GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(m_rxPin));
         enableRx(true);
      }
   }
   if (isValidGPIOpin(transmitPin)) {
      m_txValid = true;
      m_txPin = transmitPin;
      pinMode(m_txPin, OUTPUT);
      digitalWrite(m_txPin, !m_invert);
   }
   // Default speed
   begin(9600);
}
Beispiel #6
0
void ICACHE_FLASH_ATTR user_init()
{
    // Initialize the GPIO subsystem.
    //UART_init(BIT_RATE_115200, BIT_RATE_115200, 0);
    //UART_SetPrintPort(UART0);
    stdout_init();

    i2c_master_gpio_init();

    user_set_station_config();

    pcf8754_i2c_write_byte(I2C_INPUT_ADDRESS, 0);
    // =================================================
    // Initialize GPIO2 and GPIO0 as GPIO
    // =================================================
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3);
    PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0RXD_U);

    gpio_output_set(0, 0, 0, GPIO_ID_PIN(3)); // set set gpio 0 as input

    ETS_GPIO_INTR_DISABLE();
    // Attach interrupt handle to gpio interrupts.
    ETS_GPIO_INTR_ATTACH(gpio_intr_handler, NULL);
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(3)); // clear gpio status
    gpio_pin_intr_state_set(GPIO_ID_PIN(3), GPIO_PIN_INTR_ANYEDGE); // clear gpio status.
    ETS_GPIO_INTR_ENABLE(); // Enable interrupts by GPIO


	// register a callback function to let user code know that system
	// initialization is complete
	system_init_done_cb(&post_user_init_func);

    //Start os task
    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
void ICACHE_FLASH_ATTR
gpio_init() {
	// Configure switch (relays)
	INFO("Configure Switch 1 %d\n", SWITCH01_GPIO );
	PIN_FUNC_SELECT(SWITCH01_GPIO_MUX, SWITCH01_GPIO_FUNC);
	set_switch(SWITCH01_GPIO, 0);
	//GPIO_OUTPUT_SET(SWITCH01_GPIO, 0);

	INFO("Configure Switch 2 %d\n", SWITCH02_GPIO );
	PIN_FUNC_SELECT(SWITCH02_GPIO_MUX, SWITCH02_GPIO_FUNC);
	set_switch(SWITCH02_GPIO, 0);
	//GPIO_OUTPUT_SET(SWITCH02_GPIO, 0);

	INFO("Configure Switch 3 %d\n", SWITCH03_GPIO );
	PIN_FUNC_SELECT(SWITCH03_GPIO_MUX, SWITCH03_GPIO_FUNC);
	set_switch(SWITCH03_GPIO, 0);
	//GPIO_OUTPUT_SET(SWITCH03_GPIO, 0);

	//Configure Toggle switches
	INFO("Configure Toggle 1 %d\n", TOGGLE01_GPIO );
	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	ETS_GPIO_INTR_ATTACH(toggle_changed, 0);  // GPIO interrupt handler
	PIN_FUNC_SELECT(TOGGLE01_GPIO_MUX, TOGGLE01_GPIO_FUNC); // Set function
	GPIO_DIS_OUTPUT(TOGGLE01_GPIO); // Set as input
	gpio_pin_intr_state_set(GPIO_ID_PIN(TOGGLE01_GPIO), GPIO_PIN_INTR_ANYEDGE); // Interrupt on any edge
	//ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts

	INFO("Configure Toggle 2 %d\n", TOGGLE02_GPIO );
	//ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	//ETS_GPIO_INTR_ATTACH(toggle_changed);  // GPIO interrupt handler
	PIN_FUNC_SELECT(TOGGLE02_GPIO_MUX, TOGGLE02_GPIO_FUNC); // Set function
	GPIO_DIS_OUTPUT(TOGGLE02_GPIO); // Set as input
	gpio_pin_intr_state_set(GPIO_ID_PIN(TOGGLE02_GPIO), GPIO_PIN_INTR_ANYEDGE); // Interrupt on any edge
	//ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts


	INFO("Configure Toggle 3 %d\n", TOGGLE03_GPIO );
	//ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	//ETS_GPIO_INTR_ATTACH(toggle_changed);  // GPIO interrupt handler
	PIN_FUNC_SELECT(TOGGLE03_GPIO_MUX, TOGGLE03_GPIO_FUNC); // Set function
	GPIO_DIS_OUTPUT(TOGGLE03_GPIO); // Set as input
	gpio_pin_intr_state_set(GPIO_ID_PIN(TOGGLE03_GPIO), GPIO_PIN_INTR_ANYEDGE); // Interrupt on any edge
	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts


	// Configure push button
//	INFO("Confgiure push button %d\n", BUTTON_GPIO );
//	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
//	ETS_GPIO_INTR_ATTACH(button_press, BUTTON_GPIO);  // GPIO0 interrupt handler
//	PIN_FUNC_SELECT(BUTTON_GPIO_MUX, BUTTON_GPIO_FUNC); // Set function
//	GPIO_DIS_OUTPUT(BUTTON_GPIO); // Set as input
//	gpio_pin_intr_state_set(GPIO_ID_PIN(BUTTON_GPIO), 2); // Interrupt on negative edge
//	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
}
Beispiel #8
0
void pin_init0(void) {
    ETS_GPIO_INTR_DISABLE();
    ETS_GPIO_INTR_ATTACH(pin_intr_handler_iram, NULL);
    // disable all interrupts
    memset(&MP_STATE_PORT(pin_irq_handler)[0], 0, 16 * sizeof(mp_obj_t));
    for (int p = 0; p < 16; ++p) {
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << p);
        SET_TRIGGER(p, 0);
    }
    ETS_GPIO_INTR_ENABLE();
}
Beispiel #9
0
void ICACHE_FLASH_ATTR setup_interrupt(){
	uart0_sendStr("setup interrupt\n");
	//disable interrupt if it is enabled
	ETS_GPIO_INTR_DISABLE();
	//setup a interrupt pin for possitive edge front trigger
	gpio_pin_intr_state_set(GPIO_ID_PIN(INT_PIN),GPIO_PIN_INTR_POSEDGE);//or GPIO_PIN_INTR_POSEDGE or GPIO_PIN_INTR_HILEVEL
	
	//set callback when interrupt trigeres 
	ETS_GPIO_INTR_ATTACH(pending_interrupt, 0);
	interrupt_set=1;
	
}
Beispiel #10
0
void ICACHE_FLASH_ATTR
buttons_init()
{
    //Attach the interrupt thing
    ETS_GPIO_INTR_ATTACH(rotary_intr_handler,12);

    //Disable interrupts
    ETS_GPIO_INTR_DISABLE();

    //Set GPIO to IO
    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_GPIO0_U, FUNC_GPIO0);

    //Set the GPIO to input
    gpio_output_set(0, 0, 0, GPIO_ID_PIN(12));
    gpio_output_set(0, 0, 0, GPIO_ID_PIN(13));
    gpio_output_set(0, 0, 0, GPIO_ID_PIN(0));

    //Not sure what this does
    gpio_register_set(GPIO_PIN_ADDR(12), 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));

    gpio_register_set(GPIO_PIN_ADDR(13), 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));

    gpio_register_set(GPIO_PIN_ADDR(0), 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));

    //clear gpio status
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(12));
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(13));
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(0));

    //re-enable gpio0 interrupt
    gpio_pin_intr_state_set(GPIO_ID_PIN(12), GPIO_PIN_INTR_ANYEDGE);

    //Global re-enable interrupts
    ETS_GPIO_INTR_ENABLE();

    os_timer_disarm(&button_timer);
    os_timer_setfn(&button_timer, (os_timer_func_t *)button_push, 1);
    os_timer_arm(&button_timer, 50, 1);
}
Beispiel #11
0
void user_init(void)
{
	uart_init(BIT_RATE_230400, BIT_RATE_230400);
	system_set_os_print(1); // enable/disable operating system printout

	os_sprintf(topic_temp, MQTT_TOPICTEMP, system_get_chip_id());
	os_sprintf(topic_hum, MQTT_TOPICHUM, system_get_chip_id());

	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13);


	   ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	   ETS_GPIO_INTR_ATTACH(interrupt_test, 4);
	   PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4);
	   gpio_output_set(0, 0, 0, GPIO_ID_PIN(4)); // Set GPIO12 as input
	   GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(4));
	   gpio_pin_intr_state_set(GPIO_ID_PIN(4), GPIO_PIN_INTR_ANYEDGE);
	   ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts

	config_load();

	DHTInit(DHT11);

	MQTT_InitConnection(&mqttClient, config.mqtt_host, config.mqtt_port, config.security);
	MQTT_InitClient(&mqttClient, config.device_id, config.mqtt_user, config.mqtt_pass, config.mqtt_keepalive, 1);
	MQTT_InitLWT(&mqttClient, "lwt/", "offline", 0, 0);
	MQTT_OnConnected(&mqttClient, mqtt_connected_cb);
	MQTT_OnDisconnected(&mqttClient, mqtt_disconnected_cb);
	MQTT_OnPublished(&mqttClient, mqtt_published_cb);
	MQTT_OnData(&mqttClient, mqtt_data_cb);

	WIFI_Connect(config.sta_ssid, config.sta_pwd, wifi_connect_cb);

	os_timer_disarm(&dhtTimer);
	os_timer_setfn(&dhtTimer, (os_timer_func_t *)dhtCb, (void *)0);
	os_timer_arm(&dhtTimer, DELAY, 1);

	os_timer_disarm(&hbTimer);
	os_timer_setfn(&hbTimer, (os_timer_func_t *)application_heartbeat, (void *)0);
	os_timer_arm(&hbTimer, 60000, 1);



	INFO("\r\nSystem started ...\r\n");
}
Beispiel #12
0
/******************************************************************************
 * FunctionName : peri_key_init.
 * Description  : initialize key device.
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
peri_single_key_init(uint8 gpio_id,key_function long_press, key_function short_press)
{
    struct key_param *single_key = (struct key_param *)os_zalloc(sizeof(struct key_param));

    uint32 gpio_name=tisan_get_gpio_name(gpio_id);
    uint8 gpio_func=tisan_get_gpio_general_func(gpio_id);
    single_key->gpio_id = gpio_id;
    single_key->key_level = 1;
    single_key->long_press = long_press;
    single_key->short_press = short_press;

    ETS_GPIO_INTR_DISABLE();

    peri_vibrate_init_NULL();
    key_init(gpio_name, gpio_id, gpio_func);
    ETS_GPIO_INTR_ATTACH(gpio_intr_handler,single_key);


    ETS_GPIO_INTR_ENABLE();
}
/**
 * Sets the 'gpio_pin' pin as a GPIO and sets the interrupt to trigger on that pin
 */
bool ICACHE_FLASH_ATTR
easygpio_setupInterrupt(uint8_t gpio_pin, bool pullUp, bool pullDown, void (*interruptHandler)(void)) {
    uint32_t gpio_name;
    uint8_t gpio_func;

    if (gpio_pin == 6 || gpio_pin == 7 || gpio_pin == 8 || gpio_pin == 11 || gpio_pin >= 17) {
        os_printf("easygpio_setupInterrupt Error: There is no GPIO%d, check your code\n", gpio_pin);
        return false;
    }
    if (gpio_pin == 16) {
        os_printf("easygpio_setupInterrupt Error: GPIO16 does not have interrupts\n");
        return false;
    }
    if (!easygpio_getGpioNameFunc(gpio_pin, &gpio_name, &gpio_func) ) {
        return false;
    }

    ETS_GPIO_INTR_ATTACH(interruptHandler, NULL);
    ETS_GPIO_INTR_DISABLE();

    PIN_FUNC_SELECT(gpio_name, gpio_func);

    easygpio_setupPulls(gpio_name, pullUp, pullDown);

    // disable output
    GPIO_DIS_OUTPUT(gpio_pin);

    gpio_register_set(GPIO_PIN_ADDR(gpio_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));

    //clear gpio14 status
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(gpio_pin));
    ETS_GPIO_INTR_ENABLE();

    return true;
}
void Softuart_Init(Softuart *s, uint16_t baudrate)
{
	//disable rs485
	s->is_rs485 = 0;

	if(! _Softuart_Instances_Count) {
		os_printf("SOFTUART initialize gpio\r\n");
		//Initilaize gpio subsystem
		gpio_init();
	}

	//set bit time
	s->bit_time = (1000000 / baudrate);
	os_printf("SOFTUART bit_time is %d\r\n",s->bit_time);


	//init tx pin
	if(!s->pin_tx.gpio_mux_name) {
		os_printf("SOFTUART ERROR: Set tx pin (%d)\r\n",s->pin_tx.gpio_mux_name);
	} else {
		//enable pin as gpio
    	PIN_FUNC_SELECT(s->pin_tx.gpio_mux_name, s->pin_tx.gpio_func);

		//set pullup (UART idle is VDD)
		PIN_PULLUP_EN(s->pin_tx.gpio_mux_name);
		
		//set high for tx idle
		GPIO_OUTPUT_SET(GPIO_ID_PIN(s->pin_tx.gpio_id), 1);
		os_delay_us(100000);
		
		os_printf("SOFTUART TX INIT DONE\r\n");
	}

	//init rx pin
	if(!s->pin_rx.gpio_mux_name) {
		os_printf("SOFTUART ERROR: Set rx pin (%d)\r\n",s->pin_rx.gpio_mux_name);
	} else {
		//enable pin as gpio
    	PIN_FUNC_SELECT(s->pin_rx.gpio_mux_name, s->pin_rx.gpio_func);

		//set pullup (UART idle is VDD)
		PIN_PULLUP_EN(s->pin_rx.gpio_mux_name);
		
		//set to input -> disable output
		GPIO_DIS_OUTPUT(GPIO_ID_PIN(s->pin_rx.gpio_id));

		//set interrupt related things

		//disable interrupts by GPIO
		ETS_GPIO_INTR_DISABLE();

		//attach interrupt handler and a pointer that will be passed around each time
		ETS_GPIO_INTR_ATTACH(Softuart_Intr_Handler, s);

		//not sure what this does... (quote from example):
		//    void gpio_register_set(uint32 reg_id, uint32 value);
		//
		// From include file
		//   Set the specified GPIO register to the specified value.
		//   This is a very general and powerful interface that is not
		//   expected to be used during normal operation.  It is intended
		//   mainly for debug, or for unusual requirements.
		//
		// All people repeat this mantra but I don't know what it means
		//
		gpio_register_set(GPIO_PIN_ADDR(s->pin_rx.gpio_id),
							   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));
		
		//clear interrupt handler status, basically writing a low to the output
		GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(s->pin_rx.gpio_id));

		//enable interrupt for pin on any edge (rise and fall)
		//@TODO: should work with ANYEDGE (=3), but complie error
		gpio_pin_intr_state_set(GPIO_ID_PIN(s->pin_rx.gpio_id), 3);

		//globally enable GPIO interrupts
		ETS_GPIO_INTR_ENABLE();
	
		os_printf("SOFTUART RX INIT DONE\r\n");
	}

	//add instance to array of instances
	_Softuart_GPIO_Instances[s->pin_rx.gpio_id] = s;
	_Softuart_Instances_Count++;
		
	os_printf("SOFTUART INIT DONE\r\n");
}
void ICACHE_FLASH_ATTR dhgpio_init() {
	ETS_GPIO_INTR_ATTACH(gpio_intr, NULL);
	ETS_GPIO_INTR_ENABLE();
}
Beispiel #16
0
void platform_gpio_init( task_handle_t gpio_task )
{
  gpio_task_handle = gpio_task;

  ETS_GPIO_INTR_ATTACH(platform_gpio_intr_dispatcher, NULL);
}
Beispiel #17
0
// initialize the custom stuff that goes beyond esp-link
void user_init()
{
	// Initialize the GPIO subsystem.
	gpio_init();

	/* ====================================== */
	/* UART                                   */
	/* ====================================== */

	// Initialize UART0 and UART1
	/* NOTE: UART1 and I2S share same GPIO. Cannot use simultaneously. */
	uart_init( BIT_RATE_115200, BIT_RATE_115200 );

//	uart0_sendStr( "\nUART0 - USED TO PROGRAM THE MODULE\n" );

	os_printf("\n===================\nUART1 - DEBUG OUPUT\n===================\n");

	/* NOTE: PWM CANNOT BE USED SIMULTANEOUSLY WITH HW TIMER */
#if 0
	/* ====================================== */
	/* PWM                                    */
	/* ====================================== */

    uint32  pwm_period = 1000;
	uint32 pwm_duty[PWM_CHANNEL] = {0};


    uint32 io_info[][3] = {   {PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM},
    		                  {PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM},
    		              };

	/* PIN FUNCTION INIT FOR PWM OUTPUT */
	pwm_init(pwm_period, pwm_duty, PWM_CHANNEL, io_info);

	/* set pwm_duty cycle */
	pwm_set_duty (14185, 0);
	pwm_set_duty (22222, 1); // todo: explain why 22222 is the highest possible value

	/* start PWM */
	pwm_start(); // NOTE: PWM causes spikes in other GPIOs
#endif


	/* ====================================== */
	/* GPIO INTERRPUT                         */
	/* ====================================== */

	/* Set GPIO12 in GPIO mode */
	PIN_FUNC_SELECT( PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12 );

	/* Set GPIO12 as input */
	GPIO_DIS_OUTPUT( GPIO_ID_PIN(12) );

	/* Disable all GPIO interrupts */
	ETS_GPIO_INTR_DISABLE();

	/* Set a GPIO callback function */
	ETS_GPIO_INTR_ATTACH( gpioCallback, NULL );

	/* Configure the type of edge */
	gpio_pin_intr_state_set( GPIO_ID_PIN(12), GPIO_PIN_INTR_ANYEDGE );

	ETS_GPIO_INTR_ENABLE();


	/* ====================================== */
	/* SOFTWARE TIMER                         */
	/* ====================================== */

	// Set GPIO0 to output mode
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);

	//Set GPIO0 low
	gpio_output_set(0, RELAY_PIN, RELAY_PIN, 0);

	/* disarm timer */
	os_timer_disarm((ETSTimer*)&some_timer);

	/* set callback */
	os_timer_setfn((ETSTimer*)&some_timer, (os_timer_func_t *) softwareTimerCallback, NULL);

	/* arm the timer -> os_timer_arm(<pointer>, <period in ms>, <fire periodically>) */
	os_timer_arm((ETSTimer*)&some_timer, 10, 1);

	/* ====================================== */
	/* OS TASK                                */
	/* ====================================== */

	/* setup OS task */
//	system_os_task(user_procTask, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen);

	/* send a message to OS task (fire task) */
//	system_os_post(user_procTaskPrio, 0, 0 );


	/* ====================================== */
	/* HARDWARE TIMER                         */
	/* ====================================== */

	/* The hardware timer is used to indicate when a complete IR message frame should have
	 * arrived in order to process the received data and calculate the IR command.
	 *
	 * It is configured in "one-shot" mode. It is started when the beginning of an
	 * IR message frame is detected and stopped after the complete message frame has been read.
	 * This means that the duration of the HW timer should be longer than the duration of
	 * the longest message frame. In the NEC IR tranmission protocol all message frames have
	 * a duration of approximately 67.5ms.
	 */

	/* load the HW TIMER */
	uint32 ticks = usToTicks(70000); // 70ms
	RTC_REG_WRITE(FRC1_LOAD_ADDRESS, ticks);

	/* register callback function */
	ETS_FRC_TIMER1_INTR_ATTACH( hwTimerCallback, NULL );

	/* enable interrupts */
	TM1_EDGE_INT_ENABLE();
	ETS_FRC1_INTR_ENABLE();

	/* don't start timer yet */
	/* the timer is started inside the GPIO INT callback */


	/* ====================================== */
	/* UDP SERVER                         	  */
	/* ====================================== */

	/* usage:	echo <data> | nc -wl -u <ip address> <port>
	 * example: echo "foo" | nc -w1 -u 192.168.1.187 7777 */

	/* allocate space for server */
	pUdpServer = (struct espconn *) os_zalloc(sizeof(struct espconn));

	/* clear allocated memory */
	ets_memset(pUdpServer, 0, sizeof(struct espconn));

	/* create the server */
	espconn_create(pUdpServer);

	/* set the type of server */
	pUdpServer->type = ESPCONN_UDP;

	/* allocate memory for UDP settings */
	pUdpServer->proto.udp = (esp_udp *) os_zalloc(sizeof(esp_udp));

	/* set the port that the server will be listening to */
	pUdpServer->proto.udp->local_port = 7777;

	/* register the callback */
	espconn_regist_recvcb(pUdpServer, udpServerRxCb);

	/* start listening */
	if (espconn_create(pUdpServer))
	{
		while (1) { os_printf("Error creating a UDP server\n"); }
	}


	/* ====================================== */
	/* WIFI                         	  	  */
	/* ====================================== */

	wifi_set_opmode(STATION_MODE);

	wifi_station_get_config_default(&stconf);

//	os_strncpy((char*) stconf.ssid, "TP-LINK_2.4GHz_FC2E51", 32);
//	os_strncpy((char*) stconf.password, "tonytony", 64);

	os_strncpy((char*) stconf.ssid, "WLAN-PUB", 32);
	os_strncpy((char*) stconf.password, "", 64);

//	os_strncpy((char*) stconf.ssid, "MAD air", 32);
//	os_strncpy((char*) stconf.password, "glioninlog", 64);

	stconf.bssid_set = 0;
	wifi_station_set_config(&stconf);

//	/* ====================================== */
//	/* WS2812 LED STRIP                	  	  */
//	/* ====================================== */
//
//	/* NOTE: UART1 and I2S share same GPIO. Cannot use simultaneously. */
//	ws2812_init();
//
//	/*						G		R		B			*/
//	uint8_t ledout[] = 	{
//							0xff,	0x00,	0x00, 		//4th
////							0xff,	0x00,	0x00,		//3rd
////							0x00,	0xff,	0x00,		//2nd
////							0x00,	0x00,	0xff, 		//1st
//						};
//
//#if 0
//		os_printf("\r\nB R G: %x %x %x\r\n", ledout[0], ledout[1],ledout[2]);
//#endif
//
//	ws2812_push( ledout, sizeof( ledout ) );

	/* ====================================== */
	/* TCP CONNECTION                    	  */
	/* ====================================== */

	/* allocate space for server */
	pTcpConn = (struct espconn *) os_zalloc(sizeof(struct espconn));

	/* clear allocated memory */
	ets_memset(pTcpConn, 0, sizeof(struct espconn));

	/* set the type of connection */
	pTcpConn->type = ESPCONN_TCP;

	/* set state to NONE */
	pTcpConn->state = ESPCONN_NONE;

	/* allocate memory for TCP settings */
	pTcpConn->proto.tcp = (esp_tcp *) os_zalloc(sizeof(esp_tcp));

	/* set the port that the connection will be listening to */
	pTcpConn->proto.tcp->local_port = espconn_port();

	/* set the remote port and IP address */
	pTcpConn->proto.tcp->remote_port = 80;
	os_memcpy(pTcpConn->proto.tcp->remote_ip, server_ip_address, sizeof(server_ip_address));

	/* register callbacks */
	espconn_regist_connectcb(pTcpConn, tcpConnCb);
	espconn_regist_reconcb(pTcpConn, tcpReconnCb);

	/* disarm timer */
	os_timer_disarm((ETSTimer*)&wifi_setup_timer);

	/* set callback */
	os_timer_setfn((ETSTimer*)&wifi_setup_timer, (os_timer_func_t *) wifiConnectTimerCb, NULL);

	/* arm the timer -> os_timer_arm(<pointer>, <period in ms>, <fire periodically>) */
	os_timer_arm((ETSTimer*)&wifi_setup_timer, 5000, 1);

	return;

}
void init()
{
	_wdgHw._init();
	ds1820.init();

    ETS_GPIO_INTR_DISABLE();

	_gpio_init();

    ETS_GPIO_INTR_ATTACH((void*)gpio_intr_handler, NULL);

_uart0._conf(_BAUD_RATE_115200,_EIGHT_BITS,_TWO_STOP_BIT,_NONE_PARITY);

	// Config GPIO
	_gpio0._conf(_INTERRUPT,_PULL_NONE,_OFF,_INTR_POSEDGE);// S_REED
	//_gpio1._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// TXD0
	_gpio2._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);//
	//_gpio3._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// RXD0
	_gpioDtcNull._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// DTC_NULL
	_gpio5._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);//
	_gpio12._conf(_INPUT,_PULL_NONE,_ON,_INTR_DISABLE);// TEMP-IO (DS1820)
	_gpioRelay._conf(_OUTPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// CMD_RELAY
	_gpioAm2320._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// TEMP-IO (AM2320)
	_gpio15._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);//
_gpioWdg._conf(_OUTPUT,_PULL_NONE,_ON,_INTR_DISABLE);// WDG_H + LED

	Serial.systemDebugOutput(true);

	_wdgHw.start();

	// _fileSys._mountFileSystem();

	// _fileSys._readCalandarFile();

	WifiAccessPoint.enable(false);
	WifiStation.enable(true);

	WifiStation.config(WIFI_SSID, WIFI_PWD);

#if IS_FIX_IP == 1
	IPAddress _ip;
	_ip = IPAddress(ADDR_IP_ESP);
	WifiStation.setIP(_ip);
	//WifiStation.enableDHCP(false);
#endif

	WifiStation.waitConnection(connectCb);
	


	debugf("\n\n\n");
	debugf("\r\nVersion %s\r\n", VERSION);

	int slot = rboot_get_current_rom();
	debugf("\r\nCurrently running rom %d.\r\n", slot);

	

	os_printf("restart system %s RADIATOR 0.0.0 %s\n\r",VERSION,WifiStation.getMAC().c_str());
	
	//ds1820.start();
	
	_am2320._start();

	_adc._start();
	
	networkTask.start();
}
Beispiel #19
0
void ICACHE_FLASH_ATTR gpio_intr_attach(gpio_intr_handler cb)
{
	ETS_GPIO_INTR_ATTACH(gpio_intr_dispatcher, cb);
}
Beispiel #20
0
//Main routine. Initialize stdout, the I/O and the webserver and we're done.
void user_init(void) {
// my stuff
	dBR_BOILER_SET=65; // default setting 65C boiler temperature on reboot
	dBR_TEMP_ROOM_SET=18; // default setting 18C room temperature on reboot
	dBR_HUMIDITY_SET=60; // default setting 65% humidity target on reboot
	dBR_MODE=2; // default BR MODE is AUTO
	dDEVICE_MODE=1; // This mode defines if device uses remote (MQTT) management or uses local logics - 0 for remote, 1 for local mode. DEFAULT is 0 - remote

// HTTPD
	stdoutInit();
	ioInit();
	httpdInit(builtInUrls, 80);
//MQTT
	uart_init(115200, 115200);
	CFG_Load();
	sleepms(1000);

	MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL);
	//MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0);
	MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1);
	//MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1);

//	MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0);
	MQTT_OnConnected(&mqttClient, mqttConnectedCb);
	MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
	MQTT_OnPublished(&mqttClient, mqttPublishedCb);
	MQTT_OnData(&mqttClient, mqttDataCb);

	INFO("device_ID:%s\r\n",sysCfg.device_id);
	INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host);
//DS18B20 timers
	os_timer_disarm(&ds18b20_timer);
	os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0);
	os_timer_arm(&ds18b20_timer, DELAY, 1);
// DHT22 initialize
	DHTInit(DHT22, DELAY);
	os_timer_disarm(&dht22_timer);
	os_timer_setfn(&dht22_timer, (os_timer_func_t *)dht22_cb, (void *)0);
	os_timer_arm(&dht22_timer, DELAY, 1);
// INPUT PIN initialize
	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	ETS_GPIO_INTR_ATTACH(read_input_pin, 13); // GPIO13 interrupt handler
	PIN_FUNC_SELECT(PIN_GPIO13_MUX, PIN_GPIO13_FUNC);
	gpio_output_set(0, 0, 0, BIT13); // Set GPIO13 as input
	PIN_PULLUP_EN(PIN_GPIO13_MUX); // Enable pullup
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(13)); // Clear GPIO12 status
	gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_NEGEDGE); // Interrupt on NEGATIVE GPIO13 edge
	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
//	INFO("Input pin INITIALIZED ! ! !");

// initialize GPIO12
	PIN_FUNC_SELECT(PIN_GPIO12_MUX, PIN_GPIO12_FUNC);
	GPIO_OUTPUT_SET(PIN_GPIO12, 0);
//	INFO("GPIO12 set to OFF\r\n");
// initialize GPIO5
	GPIO_OUTPUT_SET(PIN_GPIO5, 0);
//	INFO("GPIO5 set to OFF\r\n");
// initialize GPIO14
	PIN_FUNC_SELECT(PIN_GPIO14_MUX, PIN_GPIO14_FUNC);
	GPIO_OUTPUT_SET(PIN_GPIO14, 0);
//	INFO("GPIO14 set to OFF\r\n");
	WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb);

	os_printf("\nReady\n");
}
void platform_gpio_init( platform_gpio_intr_handler_fn_t cb )
{
  ETS_GPIO_INTR_ATTACH(platform_gpio_intr_dispatcher, cb);
}