Esempio n. 1
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. 2
0
void mp_hal_pin_output(mp_hal_pin_obj_t pin_id) {
    pin_mode[pin_id] = GPIO_MODE_OUTPUT;
    if (pin_id == 16) {
        WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | 1);
        WRITE_PERI_REG(RTC_GPIO_CONF, READ_PERI_REG(RTC_GPIO_CONF) & ~1);
        WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1) | 1); // output
    } else {
        const pyb_pin_obj_t *self = &pyb_pin_obj[pin_id];
        PIN_FUNC_SELECT(self->periph, self->func);
        PIN_PULLUP_DIS(self->periph);
        gpio_output_set(0, 0, 1 << self->phys_port, 0);
    }
}
Esempio n. 3
0
void
supla_esp_gpio_enable_input_port(char port) {

    gpio_output_set(0, 0, 0, GPIO_ID_PIN(port));

    gpio_register_set(GPIO_PIN_ADDR(port), 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_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(port));
    gpio_pin_intr_state_set(GPIO_ID_PIN(port), GPIO_PIN_INTR_ANYEDGE);

}
Esempio n. 4
0
File: io.c Progetto: bacl/WiFiPhot0
void ICACHE_FLASH_ATTR ioLed(int ena) {

	timerCounterOverAll++;
	triggerLastTime = system_get_time()/TIMEMILIMIL;
		
	gpio_output_set((1<<LEDGPIO), 0, (1<<LEDGPIO), 0);
	os_printf("[ %d  %d ] set led on.\n",timerCounterOverAll,timerCounter);
	// os_delay_us(10000);// em alternativa ao timer
	

	
    os_timer_disarm(&blinkTimer);  
    os_timer_setfn(&blinkTimer, blinkTimerFn, NULL);                 
    os_timer_arm(&blinkTimer, 700, 0);
}
static void gpioInit() {
	int x;
#if NEW_BUTTON
	//Keep the ESP powered on
	PIN_FUNC_SELECT(HOLD_MUX, HOLD_MUXVAL);
	gpio_output_set((1<<HOLD_PIN), 0, (1<<HOLD_PIN), 0);
	//Change PWM pins to GPIO and output 0 to kill the LEDs
	for (x=0; x<3; x++) {
		PIN_FUNC_SELECT(pwmIoInfo[x][0], pwmIoInfo[x][1]);
		gpio_output_set(0, (1<<pwmIoInfo[x][2]), 0, (1<<pwmIoInfo[x][2]));
	}
#endif
	//Initialize the input GPIOs
	for (x=0; x<INPUT_COUNT; x++) {
		if (inputDesc[x].num==-1) {
			//Do nothing, input is undefined
		}else if (inputDesc[x].num==16) {
			gpio16_input_conf();
		} else {
			PIN_FUNC_SELECT(inputDesc[x].mux, inputDesc[x].func);
			gpio_output_set(0, (1<<inputDesc[x].num), 0, (1<<inputDesc[x].num));
		}
	}
}
Esempio n. 6
0
/******************************************************************************
 * FunctionName : sigma_delta_setup
 * Description  : Init Pin Config for Sigma_delta , change pin source to sigma-delta
 * Parameters   : uint32 GPIO_NUM (0...15)
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
sigma_delta_setup(uint32 GPIO_NUM)
{
    //============================================================================
    //STEP 1: SIGMA-DELTA CONFIG;REG SETUP
	GPIO_SIGMA_DELTA = (GPIO_SIGMA_DELTA & (~SIGMA_DELTA_SETTING_MASK)) | SIGMA_DELTA_ENABLE;
	//============================================================================
    //STEP 2: PIN FUNC CONFIG :SET PIN TO GPIO MODE AND ENABLE OUTPUT
	set_gpiox_mux_func_ioport(GPIO_NUM);
	gpio_output_set(0,0,1 << GPIO_NUM,0);
    //============================================================================
    //STEP 3: CONNECT SIGNAL TO GPIO PAD
	GPIO_PIN(GPIO_NUM) |= GPIO_PIN_SOURCE;
    //============================================================================
    //ets_printf("test reg gpio mtdi : 0x%08x \n",GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(GPIO_NUM))));
}
Esempio n. 7
0
/******************************************************************************
 * FunctionName : sigma_delta_close
 * Description  : DEinit Pin ,from Sigma_delta mode to GPIO input mode
 * Parameters   : uint32 GPIO_NUM (0...15)
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
    sigma_delta_close(uint32 GPIO_NUM)
{
    //============================================================================
    //STEP 1: SIGMA-DELTA DEINIT
	GPIO_SIGMA_DELTA &= ~ SIGMA_DELTA_SETTING_MASK;
    //ets_printf("test reg gpio sigma : 0x%08x \n",GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(GPIO_SIGMA_DELTA_NUM))));
    //============================================================================
    //STEP 2: GPIO OUTPUT DISABLE
	gpio_output_set(0,0,0, 1 << GPIO_NUM);
    //============================================================================
    //STEP 3: CONNECT GPIO TO PIN PAD
	GPIO_PIN(GPIO_NUM) &= ~ GPIO_PIN_SOURCE;
    //============================================================================
	set_gpiox_mux_func_default(GPIO_NUM);
}
Esempio n. 8
0
void ICACHE_FLASH_ATTR user_switch1_init() {
	uint8 i;
	
	for (i=0; i<SWITCH_COUNT; i++) {
		switch1_hardware[i].id = i;
		PIN_FUNC_SELECT(switch1_hardware[i].gpio.gpio_name, switch1_hardware[i].gpio.gpio_func);
		
		if (switch1_hardware[i].type == SWITCH1_SWITCH) {
			gpio_output_set(0, 0, 0, GPIO_ID_PIN(switch1_hardware[i].gpio.gpio_id));
			setInterval(switch1_toggle, &switch1_hardware[i], 10);
		}
	}
	
	webserver_register_handler_callback(SWITCH1_URL, switch1_handler);
	device_register(NATIVE, 0, SWITCH1_URL, switch1_init, switch1_down);
}
Esempio n. 9
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. 10
0
void
LED_init(void)
{
#ifdef DEBUG
    os_printf("[debug] LED_init\r\n");
#endif

    /* initialize GPIO2 as a OUTPUT function (D4) and turn it off */
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
    gpio_output_set(0, BIT(2), BIT(2), 0);

    /* initialize GPIO12 as a OUTPUT function (D6) */
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);

    /* turn on the green led */
    LED_toggle(GREEN_LED, LED_ON);
}
Esempio n. 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");
}
Esempio n. 12
0
int main()
{
	/*power_check相关变量*/
	int ret = -1;
	u8 mode;
	u16 set_timeout = 1000;

	/*I/O口相关变量*/
	u8 io_mode, io_od, io_pu;
	u8 io_clearval = 0;
	u8 io_setval = 1;						//I/O口输出高
	u8 io_trigger = 35;						//pb3触发掉电处理


	//环境初始化
	inittest();

	//测试用例1
	io_mode = GPIO_OUT;
	io_od = GPIO_ODD;
	io_pu = GPIO_PUD;

	ret = gpio_init();										//初始化I/O口
	if(ret != 0){
		printf("gpio_init error\r\n");
	}

	ret = gpio_set(io_trigger, io_mode, io_od, io_pu);		//设置pb0为输出口
	if(ret != 0){
		printf("gpio_set error\r\n");
	}
	gpio_output_set(io_trigger, io_clearval);					//PB3口输出低,模拟为掉电

	//测试用例2
    mode = POWERCHECK_MODE_BLOCK_UP;
	powercheck_init(mode);
	powercheck_setwaittime(set_timeout);
	ret = powercheck_check();
	assert(ret == 1,"powercheck_check 2 error");
	powercheck_close();

	finaltest();
	return 0;
}
Esempio n. 13
0
void ICACHE_FLASH_ATTR user_switch2_init() {
	uint8 i;
	
	for (i=0; i<SWITCH_COUNT; i++) {
		switch2_hardware[i].id = i;
		PIN_FUNC_SELECT(switch2_hardware[i].gpio.gpio_name, switch2_hardware[i].gpio.gpio_func);
		switch2_hardware[i].state = GPIO_INPUT_GET(GPIO_ID_PIN(switch2_hardware[i].gpio.gpio_id));
		
		if (switch2_hardware[i].type == SWITCH2_SWITCH) {
			gpio_output_set(0, 0, 0, GPIO_ID_PIN(switch2_hardware[i].gpio.gpio_id));
			setInterval(switch2_toggle, &switch2_hardware[i], 10);
		}
	}
	
	preferences_get(SWITCH2_STR, switch2_parse);
	
	webserver_register_handler_callback(SWITCH2_URL, switch2_handler);
	device_register(NATIVE, 0, SWITCH2_STR, SWITCH2_URL, switch2_init, switch2_down);
}
Esempio n. 14
0
void ICACHE_FLASH_ATTR user_init() {
    // Initialize
    gpio_init();
    uart_init(2400, 2400);
    os_delay_us(10000);
    //print("\r\n:)\r\n");

    if (0 && DEBUG) {
        wifi_station_disconnect();
        wifi_station_dhcpc_stop();
    }

    //setup_server();

    // -------------------------------------------------------------------------

    ets_uart_printf("S");

    //Set GPIO2 to output mode
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

    //Set GPIO2 low
    gpio_output_set(0, BIT2, BIT2, 0);

    //Disarm timer
    os_timer_disarm(&check_timer);

    //Setup timer
    os_timer_setfn(&check_timer, (os_timer_func_t *)check_timerfunc, NULL);

    //Arm the timer
    //1000 is the fire time in ms
    //0 for once and 1 for repeating
    os_timer_arm(&check_timer, 5000, 1); // Start going
    
    //Start os task
    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
    system_os_task(recvTask, recvTaskPrio, recvTaskQueue, recvTaskQueueLen);

    system_init_done_cb(init_done);

}
Esempio n. 15
0
void ICACHE_FLASH_ATTR
user_init(void)
{
#ifndef NDEBUG
	uart_init(9600, 9600);
#endif

	gpio_init();

	/* set GPIO0 and GPIO2 as HIGH outputs */
	gpio_output_set(GPIO0 | GPIO2, 0, GPIO0 | GPIO2, 0);

	/* select GPIO2 function for GPIO2 pin */
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
	PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);

	wifi_set_event_handler_cb(wifi_event_handler);

	client_connection_setup();
}
Esempio n. 16
0
void ICACHE_FLASH_ATTR user_init()
{
    //Initialize the GPIO subsystem
    gpio_init();

    //Set GPIO2 to output mode
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

    //Set GPIO2 low
    gpio_output_set(0, BIT2, BIT2, 0);

    //Disarm timer
    os_timer_disarm(&timer_id);

    //Setup timer
    os_timer_setfn(&timer_id, (os_timer_func_t *)handle_timeout, NULL);

    //Arm the timer register &timer_id. is the pointer
    os_timer_arm(&timer_id, DELAY_MS, REPEATING);
}
Esempio n. 17
0
void ICACHE_FLASH_ATTR _gpio_high(void* time_arg)
{
	led_glint* led = (led_glint*)time_arg;
	ETSTimer* timer = led->ptimer;

	os_timer_disarm(timer);

	if(led->limit_count && led->cur_count >= led->limit_count) {
		os_free(timer);
		os_free(led);
		os_printf("free timer and led_glint.\n");
		return ;
	}

	//输出高电平
	gpio_output_set(led->pin, 0, led->pin, 0);
	led->cur_count ++;
	os_timer_setfn(timer, _gpio_low, time_arg);
	os_timer_arm(timer, led->interval, 0);
}
Esempio n. 18
0
void ICACHE_FLASH_ATTR
vibrate_init(uint8 gpio_id)
{
    uint32 v_gpio_name=tisan_get_gpio_name(gpio_id);
    uint8 v_gpio_func=tisan_get_gpio_general_func(gpio_id);

    PIN_FUNC_SELECT(v_gpio_name, v_gpio_func);
    PIN_PULLUP_EN(v_gpio_name);
    gpio_output_set(0, 0, 0, GPIO_ID_PIN(gpio_id));   //set as input mode

	gpio_register_set(GPIO_PIN_ADDR(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 status
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(gpio_id));

	//enable interrupt
	gpio_pin_intr_state_set(GPIO_ID_PIN(gpio_id), GPIO_PIN_INTR_NEGEDGE);

	peri_alarm_init(ALARM_GPIO_ID);
	peri_vibrate_tim_start(100);
}
Esempio n. 19
0
//Init function 
void ICACHE_FLASH_ATTR
user_init()
{
    //Set GPIO2 to output mode
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

    //Set GPIO2 low
    gpio_output_set(0, BIT2, BIT2, 0);

    //Disarm timer
    os_timer_disarm(&some_timer);

    //Setup timer
    os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);

    //Arm the timer
    //&some_timer is the pointer
    //1000 is the fire time in ms
    //0 for once and 1 for repeating
    os_timer_arm(&some_timer, 1000, 1);
    
    //Start os task
    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
Esempio n. 20
0
void user_init(void)
{
	int access_point = 1;

	uart_init(BIT_RATE_115200, BIT_RATE_115200);
	os_delay_us(1000000);

	if(access_point) {

		wifi_set_opmode(STATIONAP_MODE);

	} else {

		gpio_init();
		PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1);
		gpio_output_set(0, 0, (1 << pin), 0);

    CFG_Load();

    MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security);
    //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);

    WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb);

    INFO("\r\nSystem started ...\r\n");
	}
}
Esempio n. 21
0
// Init function 
void ICACHE_FLASH_ATTR  // Store function in flash memory instead of RAM
user_init()
{
    // Initialize the GPIO subsystem.
    gpio_init();

    //Set GPIO2 to output mode
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

    //Set GPIO2 low
    gpio_output_set(0, BIT2, BIT2, 0);

    //Disarm timer
    os_timer_disarm(&some_timer);

    //Setup timer
    os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);

    //Arm the timer
    //&some_timer is the pointer
    //1000 is the fire time in ms
    //0 for once and 1 for repeating
    os_timer_arm(&some_timer, 1000, 1);
}
Esempio n. 22
0
// Main routine to initialize esp-link.
void ICACHE_FLASH_ATTR user_init(void) {
  // Init gpio pin registers
  gpio_init();
  gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled
  // init UART
  uart_init(115200);
  // Say hello (leave some time to cause break in TX after boot loader's msg
  os_delay_us(10000L);
  NOTICE("\n\n** %s\n", esp_link_version);
  // Wifi
  wifiInit();

  // mount the http handlers
  httpdInit(builtInUrls, 80);

  struct rst_info *rst_info = system_get_rst_info();
  NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]);
  NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x",
    rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3,
    rst_info->excvaddr, rst_info->depc);
  uint32_t fid = spi_flash_get_id();
  NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()],
      fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
}
Esempio n. 23
0
File: io.c Progetto: bacl/WiFiPhot0
static void ICACHE_FLASH_ATTR blinkTimerFn(void *arg) {
	gpio_output_set(0, (1<<LEDGPIO), (1<<LEDGPIO), 0);
	os_printf("[ %d  %d ] set led off.\n",timerCounterOverAll,timerCounter);
}
Esempio n. 24
0
static void ICACHE_FLASH_ATTR el_timer_callback(void* arg) {
  os_printf("Turning off EL\n");
  gpio_output_set(0, (1<<ELGPIO), (1<<ELGPIO), 0);
}
LOCAL void ICACHE_FLASH_ATTR recover_led(void *arg) {
	ETS_INTR_LOCK();
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1);
	gpio_output_set(0, 0x2, 0x2, 0);
	ETS_INTR_UNLOCK();
}
irom static void gpio_init_counter(gpio_t *gpio)
{
	gpio_output_set(0, 0, 0, 1 << gpio->index);
	arm_counter(gpio);
}
Esempio n. 27
0
/**
  * @brief  Client received callback function.
  * @param  arg: contain the ip link information
  * @param  pdata: received data
  * @param  len: the lenght of received data
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_tcpclient_recv(void *arg, char *pdata, unsigned short len)
{
  struct espconn *pespconn = (struct espconn *)arg;
  at_linkConType *linkTemp = (at_linkConType *)pespconn->reverse;
  char temp[32];
  char * onboarding = "onboarding";
  char * onboardingHTML = "<html><head><title>LemonBox</title><style>body{text-align:center;}form{display:inline-block}form input{display:block}</style></head><body><form method='POST' action='/onboard'><input type='text' placeholder='SSID' name='ssid!'/><input type='text'placeholder='PASSWORD' name='password'/><input type='submit' value='submit'/></form></body></html>";
  char * get = "GET /";
  char * post = "POST /";

  os_printf("recv\r\n");
  if(at_ipMux)
  {
    if (strstr(pdata,get) != NULL){
      if (strstr(pdata,onboarding) != NULL){
        uart0_sendStr("Sending LemonOboarding");

        espconn_sent(pLink[linkTemp->linkId].pCon, onboardingHTML, strlen(onboardingHTML));
        espconn_disconnect(pLink[linkTemp->linkId].pCon);
      }      
      char * htmlSSIDs;

      if (strstr(pdata,"/accesspoints") != NULL){
        uart0_sendStr("Sending accesspoints");
        struct station_info *station;
        struct station_info *next_station;
        char tempSSID[128];

        if(at_wifiMode == STATION_MODE)
        {
          at_backError;
          return;
        }
        station = wifi_softap_get_station_info();
        while(station)
        {
          os_sprintf(tempSSID, "%d.%d.%d.%d,"MACSTR"\r\n",
                     IP2STR(&station->ip), MAC2STR(station->bssid));
          uart0_sendStr(tempSSID);
          os_sprintf("<option value=",tempSSID,"</option>");
          next_station = STAILQ_NEXT(station, next);
          os_free(station);
          station = next_station;
        }
        os_sprintf("<select>",htmlSSIDs,"</option>");
        espconn_sent(pLink[linkTemp->linkId].pCon, htmlSSIDs, strlen(htmlSSIDs));
        espconn_disconnect(pLink[linkTemp->linkId].pCon);
      }
    }    


    if (strstr(pdata,post) != NULL){
      if (strstr(pdata, "/onboard") !=NULL){
        uart0_sendStr("onboarding started");
        char *tok =pdata;

        strtok(tok, "\n");
        tok =NULL;
        char * ssid = strtok(tok, "\n");        
        tok =NULL;
        strtok(tok, "\n");
        tok =NULL;
        char * pass = strtok(tok, "\n");
        uart0_sendStr(pass);

        espconn_sent(pLink[linkTemp->linkId].pCon, "OK", 2);
        espconn_disconnect(pLink[linkTemp->linkId].pCon);
      }        

      if (strstr(pdata, "gpio/on") !=NULL){
        uart0_sendStr("GPIO 2 ON");
        gpio_output_set(BIT2, 0, BIT2, 0);
        espconn_sent(pLink[linkTemp->linkId].pCon, "<html><head><title></title></head><body>ON</body></html>", 56);
        espconn_disconnect(pLink[linkTemp->linkId].pCon);

      }      

      if (strstr(pdata, "gpio/off") !=NULL){
        uart0_sendStr("GPIO 2 OFF");
        gpio_output_set(0, BIT2, BIT2, 0);
        espconn_sent(pLink[linkTemp->linkId].pCon, "<html><head><title></title></head><body>OFF</body></html>", 57);
        espconn_disconnect(pLink[linkTemp->linkId].pCon);

      }
    }    
    os_sprintf(temp, "\r\n+IPD,%d,%d:",
               linkTemp->linkId, len);
    uart0_sendStr(temp);
    uart0_tx_buffer(pdata, len);



  }
  else if(IPMODE == FALSE)
  {
    os_sprintf(temp, "\r\n+IPD,%d:", len);
    uart0_sendStr(temp);
    uart0_tx_buffer(pdata, len);
  }
  else
  {
    uart0_tx_buffer(pdata, len);
    return;
  }
  at_backOk;
}
Esempio n. 28
0
void ICACHE_FLASH_ATTR gpio_signal(int count) {
    while (count-- > 0) {
        gpio_output_set(BIT2, 0, BIT2, 0);
        gpio_output_set(0, BIT2, BIT2, 0);
    }
}
Esempio n. 29
0
void ICACHE_FLASH_ATTR gpio_init() {
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
    PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);

    gpio_output_set(0, BIT2, BIT2, 0);
}
Esempio n. 30
0
void ICACHE_FLASH_ATTR
pwm_start(void)
{
    uint8 i, j;
    PWM_DBG("--Function pwm_start() is called\n");
    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.period:%d,pwm.duty[0]:%d,[1]:%d,[2]:%d\n",pwm.period,pwm.duty[0],pwm.duty[1],pwm.duty[2]);

    LOCK_PWM(critical);   // enter critical

    struct pwm_single_param *local_single = pwm_single_toggle[pwm_toggle ^ 0x01];
    uint8 *local_channel = &pwm_channel_toggle[pwm_toggle ^ 0x01];

    // step 1: init PWM_CHANNEL+1 channels param
    for (i = 0; i < pwm_channel_num; i++) {
        uint32 us = pwm.period * pwm.duty[i] / PWM_DEPTH;
        local_single[i].h_time = US_TO_RTC_TIMER_TICKS(us);
        PWM_DBG("i:%d us:%d ht:%d\n",i,us,local_single[i].h_time);
        local_single[i].gpio_set = 0;
        local_single[i].gpio_clear = 1 << pin_num[pwm_out_io_num[i]];
    }

    local_single[pwm_channel_num].h_time = US_TO_RTC_TIMER_TICKS(pwm.period);
    local_single[pwm_channel_num].gpio_set = pwm_gpio;
    local_single[pwm_channel_num].gpio_clear = 0;
    PWM_DBG("i:%d period:%d ht:%d\n",pwm_channel_num,pwm.period,local_single[pwm_channel_num].h_time);
    // step 2: sort, small to big
    pwm_insert_sort(local_single, pwm_channel_num + 1);

    *local_channel = pwm_channel_num + 1;
    PWM_DBG("1channel:%d,single[0]:%d,[1]:%d,[2]:%d,[3]:%d\n",*local_channel,local_single[0].h_time,local_single[1].h_time,local_single[2].h_time,local_single[3].h_time);
    // step 3: combine same duty channels
    for (i = pwm_channel_num; i > 0; i--) {
        if (local_single[i].h_time == local_single[i - 1].h_time) {
            local_single[i - 1].gpio_set |= local_single[i].gpio_set;
            local_single[i - 1].gpio_clear |= local_single[i].gpio_clear;

            for (j = i + 1; j < *local_channel; j++) {
                os_memcpy(&local_single[j - 1], &local_single[j], sizeof(struct pwm_single_param));
            }

            (*local_channel)--;
        }
    }
    PWM_DBG("2channel:%d,single[0]:%d,[1]:%d,[2]:%d,[3]:%d\n",*local_channel,local_single[0].h_time,local_single[1].h_time,local_single[2].h_time,local_single[3].h_time);
    // step 4: cacl delt time
    for (i = *local_channel - 1; i > 0; i--) {
        local_single[i].h_time -= local_single[i - 1].h_time;
    }

    // step 5: last channel needs to clean
    local_single[*local_channel-1].gpio_clear = 0;

    // step 6: if first channel duty is 0, remove it
    if (local_single[0].h_time == 0) {
        local_single[*local_channel - 1].gpio_set &= ~local_single[0].gpio_clear;
        local_single[*local_channel - 1].gpio_clear |= local_single[0].gpio_clear;

        for (i = 1; i < *local_channel; i++) {
            os_memcpy(&local_single[i - 1], &local_single[i], sizeof(struct pwm_single_param));
        }

        (*local_channel)--;
    }

    // if timer is down, need to set gpio and start timer
    if (pwm_timer_down == 1) {
        pwm_channel = local_channel;
        pwm_single = local_single;
        // start
        gpio_output_set(local_single[0].gpio_set, local_single[0].gpio_clear, pwm_gpio, 0);

        // yeah, if all channels' duty is 0 or 255, don't need to start timer, otherwise start...
        if (*local_channel != 1) {
            pwm_timer_down = 0;
            RTC_REG_WRITE(FRC1_LOAD_ADDRESS, local_single[0].h_time);
        }
    }

    if (pwm_toggle == 1) {
        pwm_toggle = 0;
    } else {
        pwm_toggle = 1;
    }

    UNLOCK_PWM(critical);   // leave critical
    PWM_DBG("3channel:%d,single[0]:%d,[1]:%d,[2]:%d,[3]:%d\n",*local_channel,local_single[0].h_time,local_single[1].h_time,local_single[2].h_time,local_single[3].h_time);
}