Esempio n. 1
0
/**@brief Function for the SoftDevice initialization.
 *
 * @details This function initializes the SoftDevice and the BLE event interrupt.
 */
static void ble_stack_init(void)
{
    uint32_t err_code;
    
    // Initialize SoftDevice.
    // SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_8000MS_CALIBRATION, false);
    
    ble_enable_params_t ble_enable_params;
    err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
                                                    PERIPHERAL_LINK_COUNT,
                                                    &ble_enable_params);
    APP_ERROR_CHECK(err_code);
        
    //Check the ram settings against the used number of links
    CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT);

    extern void __data_start__;
    if (IDEAL_RAM_START_ADDRESS(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT) != (uint32_t)&__data_start__) {
      jsiConsolePrintf("WARNING: BLE RAM start address not correct - is 0x%x, should be 0x%x", (uint32_t)&__data_start__, IDEAL_RAM_START_ADDRESS(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT));
      jshTransmitFlush();
    }

    // Enable BLE stack.
    err_code = softdevice_enable(&ble_enable_params);
    APP_ERROR_CHECK(err_code);
    
    // Subscribe for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}
Esempio n. 2
0
/**
 * A callback function to be invoked when a line has been entered on the telnet client.
 * Here we want to pass that line to the JS parser for processing.
 */
static void telnetLineCB(char *line) {
  jsiConsolePrintf("LineCB: %s", line);
  // Pass the line to the interactive module ...

  jshPushIOCharEvents(jsiGetConsoleDevice(), line, strlen(line));
  //jspEvaluate(line);
  //jsiDumpState();
  telnet_send("JS> ");
} // End of lineCB
Esempio n. 3
0
/*JSON{
  "type" : "function",
  "name" : "trace",
  "ifndef" : "SAVE_ON_FLASH",
  "generate" : "jswrap_interface_trace",
  "params" : [
    ["root","JsVar","The symbol to output (optional). If nothing is specified, everything will be output"]
  ]
}
Output debugging information

Note: This is not included on boards with low amounts of flash memory, or the Espruino board.
 */
void jswrap_interface_trace(JsVar *root) {
  #ifdef ESPRUINOBOARD
  // leave this function out on espruino board - we need to save as much flash as possible
  jsiConsolePrintf("Trace not included on this board");
  #else
  if (jsvIsUndefined(root)) {
    jsvTrace(execInfo.root, 0);
  } else {
    jsvTrace(root, 0);
  }
  #endif
}
Esempio n. 4
0
/*
*********************************************************************************************************
*              Get an IP from the DHCP server.
*
* Description: 
* Arguments  : None.
* Returns    : None.
* Note       : 
*********************************************************************************************************
*/
uint8_t getIP_DHCPS(uint8_t s, wiz_NetInfo *pWIZNETINFO)
{
	uint8_t tmpip[4];
	
	DHCP_XID = 0x12345678;

	setSHAR((*pWIZNETINFO).mac);

	// SRC IP
	tmpip[0] = 0;
	tmpip[1] = 0;
	tmpip[2] = 0;
	tmpip[3] = 0;
	setSIPR(tmpip);
	setGAR(tmpip);
	setSUBR(tmpip);
	
	//sysinit(tx_mem_conf,	rx_mem_conf);

	socket(s, Sn_MR_UDP, DHCP_CLIENT_PORT, 0x00);
	
	// Create UDP socket for network configuration
	//socket(SOCK_CONFIG, Sn_MR_UDP, REMOTE_CLIENT_PORT, 0x00);
	send_DHCP_DISCOVER(s, pWIZNETINFO);
	
	dhcp_state = STATE_DHCP_DISCOVER;
	DHCP_timeout = 0;

	next_time = jshGetSystemTime() + DHCP_WAIT_TIME;
	retry_count = 0;

	while (dhcp_state != STATE_DHCP_LEASED)
	{

  //*************
 // Add James Kim for IWatchDog
#ifdef _IWDG
		/* Reload IWDG counter */
		IWDG_ReloadCounter();
#endif	  
//
//**************
		//if (Recv_ConfigMsg() == MSG_SETTING_REQ) return(2);

		if (DHCP_timeout == 1 || jspIsInterrupted()) {
			jsiConsolePrintf("> => DHCP Timeout occurred\r\n");
			return(0);
		}
		check_DHCP_state(s, pWIZNETINFO);
		
	}
	return 1;
}
Esempio n. 5
0
/**
 * \brief Set the state of the specific pin.
 *
 * The possible states are:
 *
 * JSHPINSTATE_UNDEFINED
 * JSHPINSTATE_GPIO_OUT
 * JSHPINSTATE_GPIO_OUT_OPENDRAIN
 * JSHPINSTATE_GPIO_IN
 * JSHPINSTATE_GPIO_IN_PULLUP
 * JSHPINSTATE_GPIO_IN_PULLDOWN
 * JSHPINSTATE_ADC_IN
 * JSHPINSTATE_AF_OUT
 * JSHPINSTATE_AF_OUT_OPENDRAIN
 * JSHPINSTATE_USART_IN
 * JSHPINSTATE_USART_OUT
 * JSHPINSTATE_DAC_OUT
 * JSHPINSTATE_I2C
 */
void jshPinSetState(Pin pin, //!< The pin to have its state changed.
		JshPinState state    //!< The new desired state of the pin.
	) {
	jsiConsolePrintf("ESP8266: jshPinSetState %d, %d\n", pin, state);

	assert(pin < 16);
	int periph = PERIPHS_IO_MUX + PERIPHS[pin];

	// Disable the pin's pull-up.
	PIN_PULLUP_DIS(periph);
	//PIN_PULLDWN_DIS(periph);

	uint8_t primary_func =
			pin < 6 ?
					(PERIPHS_IO_MUX_U0TXD_U == pin
							|| PERIPHS_IO_MUX_U0RXD_U == pin) ?
							FUNC_UART : FUNC_GPIO
					: 0;
	uint8_t select_func = pinFunction(state);
	PIN_FUNC_SELECT(periph, primary_func == select_func ? 0 : select_func);

	switch (state) {
	case JSHPINSTATE_GPIO_OUT:
	case JSHPINSTATE_GPIO_OUT_OPENDRAIN:
		//case JSHPINSTATE_AF_OUT:
		//case JSHPINSTATE_AF_OUT_OPENDRAIN:
		//case JSHPINSTATE_USART_OUT:
		//case JSHPINSTATE_DAC_OUT:
		gpio_output_set(0, 1 << pin, 1 << pin, 0);
		break;

	case JSHPINSTATE_GPIO_IN_PULLUP:
		PIN_PULLUP_EN(periph);
		//case JSHPINSTATE_GPIO_IN_PULLDOWN: if (JSHPINSTATE_GPIO_IN_PULLDOWN == pin) PIN_PULLDWN_EN(periph);
	case JSHPINSTATE_GPIO_IN:
		gpio_output_set(0, 0, 0, 1 << pin);
		break;

	case JSHPINSTATE_ADC_IN:
	case JSHPINSTATE_USART_IN:
	case JSHPINSTATE_I2C:
		PIN_PULLUP_EN(periph);
		break;

	default:
		break;
	}
} // End of jshPinSetState
Esempio n. 6
0
int handleErrors() {
  int e = 0;
  JsVar *exception = jspGetException();
  if (exception) {
    jsiConsolePrintf("Uncaught %v\n", exception);
    jsvUnLock(exception);
    e = 1;
  }

  if (jspIsInterrupted()) {
    jsiConsoleRemoveInputLine();
    jsiConsolePrint("Execution Interrupted.\n");
    jspSetInterrupted(false);
    e = 1;
  }
  return e;
}
Esempio n. 7
0
void jshSetOutputValue(JshPinFunction func, int value) {
	jsiConsolePrintf("ESP8266: jshSetOutputValue %d %d\n", func, value);
} // End of jshSetOutputValue
Esempio n. 8
0
JshPinFunction jshPinAnalogOutput(Pin pin, JsVarFloat value, JsVarFloat freq, JshAnalogOutputFlags flags) { // if freq<=0, the default is used
	jsiConsolePrintf("ESP8266: jshPinAnalogOutput: %d, %d, %d\n", pin, (int)value, (int)freq);
//pwm_set(pin, value < 0.0f ? 0 : 255.0f < value ? 255 : (uint8_t)value);
	return 0;
} // End of jshPinAnalogOutput
Esempio n. 9
0
int jshPinAnalogFast(Pin pin) {
	jsiConsolePrintf("ESP8266: jshPinAnalogFast: %d\n", pin);
	return NAN;
} // End of jshPinAnalogFast
Esempio n. 10
0
JsVarFloat jshPinAnalog(Pin pin) {
	jsiConsolePrintf("ESP8266: jshPinAnalog: %d\n", pin);
	return (JsVarFloat) system_adc_read();
} // End of jshPinAnalog
Esempio n. 11
0
bool jshIsUSBSERIALConnected() {
	jsiConsolePrintf("ESP8266: jshIsUSBSERIALConnected\n");
	return true;
} // End of jshIsUSBSERIALConnected
Esempio n. 12
0
bool jshIsDeviceInitialised(IOEventFlags device) {
	jsiConsolePrintf("ESP8266: jshIsDeviceInitialised %d\n", device);
	return true;
} // End of jshIsDeviceInitialised
Esempio n. 13
0
/**
 * \brief Get the value of the corresponding pin.
 * \return The current value of the pin.
 */
bool jshPinGetValue(Pin pin //!< The pin to have its value read.
	) {
	jsiConsolePrintf("ESP8266: jshPinGetValue %d, %d\n", pin, GPIO_INPUT_GET(pin));
	return GPIO_INPUT_GET(pin);
} // End of jshPinGetValue
Esempio n. 14
0
/**
 * \brief Set the value of the corresponding pin.
 */
void jshPinSetValue(Pin pin, //!< The pin to have its value changed.
		bool value           //!< The new value of the pin.
	) {
	jsiConsolePrintf("ESP8266: jshPinSetValue %d, %d\n", pin, value);
	GPIO_OUTPUT_SET(pin, value);
} // End of jshPinSetValue
Esempio n. 15
0
// ---------------------------------------------------------------------------
// Error handlers...
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name) {
  jsiConsolePrintf("NRF ERROR 0x%x at %s:%d\n", error_code, p_file_name, line_num);
  jsiConsolePrint("REBOOTING.\n");
  jshTransmitFlush();
  NVIC_SystemReset();
}
Esempio n. 16
0
void jshEnableWatchDog(JsVarFloat timeout) {
	jsiConsolePrintf("ESP8266: jshEnableWatchDog %0.3f\n", timeout);
} // End of jshEnableWatchDog
Esempio n. 17
0
void LCD_init_panel() {
  uint16_t DeviceCode;
  delay_ms(100);
  DeviceCode = LCD_RD_CMD(0x0000);

  if (DeviceCode == 0x4532) { // For the 2.4" LCD boards
    LCD_Code = ILI9325;
    LCD_WR_CMD(0x0000,0x0001);
    LCD_DELAY(DELAY_SHORT);

    LCD_WR_CMD(0x0015,0x0030);
    LCD_WR_CMD(0x0011,0x0040);
    LCD_WR_CMD(0x0010,0x1628);
    LCD_WR_CMD(0x0012,0x0000);
    LCD_WR_CMD(0x0013,0x104d);
    LCD_DELAY(DELAY_SHORT);
    LCD_WR_CMD(0x0012,0x0010);
    LCD_DELAY(DELAY_SHORT);
    LCD_WR_CMD(0x0010,0x2620);
    LCD_WR_CMD(0x0013,0x344d); //304d
    LCD_DELAY(DELAY_SHORT);

    LCD_WR_CMD(0x0001,0x0100);
    LCD_WR_CMD(0x0002,0x0300);
    LCD_WR_CMD(0x0003,0x1030); // ORG is 0
    LCD_WR_CMD(0x0008,0x0604);
    LCD_WR_CMD(0x0009,0x0000);
    LCD_WR_CMD(0x000A,0x0008);

    LCD_WR_CMD(0x0041,0x0002);
    LCD_WR_CMD(0x0060,0x2700);
    LCD_WR_CMD(0x0061,0x0001);
    LCD_WR_CMD(0x0090,0x0182);
    LCD_WR_CMD(0x0093,0x0001);
    LCD_WR_CMD(0x00a3,0x0010);
    LCD_DELAY(DELAY_SHORT);

    //################# void Gamma_Set(void) ####################//
        LCD_WR_CMD(0x30,0x0000);
        LCD_WR_CMD(0x31,0x0502);
        LCD_WR_CMD(0x32,0x0307);
        LCD_WR_CMD(0x33,0x0305);
        LCD_WR_CMD(0x34,0x0004);
        LCD_WR_CMD(0x35,0x0402);
        LCD_WR_CMD(0x36,0x0707);
        LCD_WR_CMD(0x37,0x0503);
        LCD_WR_CMD(0x38,0x1505);
        LCD_WR_CMD(0x39,0x1505);
        LCD_DELAY(DELAY_SHORT);

        //################## void Display_ON(void) ####################//
        LCD_WR_CMD(0x0007,0x0001);
        LCD_DELAY(DELAY_SHORT);
        LCD_WR_CMD(0x0007,0x0021);
        LCD_WR_CMD(0x0007,0x0023);
        LCD_DELAY(DELAY_SHORT);
        LCD_WR_CMD(0x0007,0x0033);
        LCD_DELAY(DELAY_SHORT);
        LCD_WR_CMD(0x0007,0x0133);
  }
  else if( DeviceCode == 0x9325 || DeviceCode == 0x9328 )
  {
    LCD_Code = ILI9325;
    LCD_WR_CMD(0x00e7,0x0010);
    LCD_WR_CMD(0x0000,0x0001);  	/* start internal osc */
    LCD_WR_CMD(0x0001,0x0100);
    LCD_WR_CMD(0x0002,0x0700); 	/* power on sequence */
    LCD_WR_CMD(0x0003,(1<<12)|(1<<5)|(1<<4)|(0<<3) ); 	/* importance */
    LCD_WR_CMD(0x0004,0x0000);
    LCD_WR_CMD(0x0008,0x0207);
    LCD_WR_CMD(0x0009,0x0000);
    LCD_WR_CMD(0x000a,0x0000); 	/* display setting */
    LCD_WR_CMD(0x000c,0x0001);	/* display setting */
    LCD_WR_CMD(0x000d,0x0000);
    LCD_WR_CMD(0x000f,0x0000);
    /* Power On sequence */
    LCD_WR_CMD(0x0010,0x0000);
    LCD_WR_CMD(0x0011,0x0007);
    LCD_WR_CMD(0x0012,0x0000);
    LCD_WR_CMD(0x0013,0x0000);
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0010,0x1590);
    LCD_WR_CMD(0x0011,0x0227);
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0012,0x009c);
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0013,0x1900);
    LCD_WR_CMD(0x0029,0x0023);
    LCD_WR_CMD(0x002b,0x000e);
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0020,0x0000);
    LCD_WR_CMD(0x0021,0x0000);
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0030,0x0007);
    LCD_WR_CMD(0x0031,0x0707);
    LCD_WR_CMD(0x0032,0x0006);
    LCD_WR_CMD(0x0035,0x0704);
    LCD_WR_CMD(0x0036,0x1f04);
    LCD_WR_CMD(0x0037,0x0004);
    LCD_WR_CMD(0x0038,0x0000);
    LCD_WR_CMD(0x0039,0x0706);
    LCD_WR_CMD(0x003c,0x0701);
    LCD_WR_CMD(0x003d,0x000f);
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0050,0x0000);
    LCD_WR_CMD(0x0051,0x00ef);
    LCD_WR_CMD(0x0052,0x0000);
    LCD_WR_CMD(0x0053,0x013f);
    LCD_WR_CMD(0x0060,0xa700);
    LCD_WR_CMD(0x0061,0x0001);
    LCD_WR_CMD(0x006a,0x0000);
    LCD_WR_CMD(0x0080,0x0000);
    LCD_WR_CMD(0x0081,0x0000);
    LCD_WR_CMD(0x0082,0x0000);
    LCD_WR_CMD(0x0083,0x0000);
    LCD_WR_CMD(0x0084,0x0000);
    LCD_WR_CMD(0x0085,0x0000);

    LCD_WR_CMD(0x0090,0x0010);
    LCD_WR_CMD(0x0092,0x0000);
    LCD_WR_CMD(0x0093,0x0003);
    LCD_WR_CMD(0x0095,0x0110);
    LCD_WR_CMD(0x0097,0x0000);
    LCD_WR_CMD(0x0098,0x0000);
    /* display on sequence */
    LCD_WR_CMD(0x0007,0x0133);

    LCD_WR_CMD(0x0020,0x0000);  /* ÐÐÊ×Ö·0 */
    LCD_WR_CMD(0x0021,0x0000);  /* ÁÐÊ×Ö·0 */
  }
  else if( DeviceCode == 0x9320 || DeviceCode == 0x9300 )
  {
    LCD_Code = ILI9320;
    LCD_WR_CMD(0x00,0x0000);
    LCD_WR_CMD(0x01,0x0100);	/* Driver Output Contral */
    LCD_WR_CMD(0x02,0x0700);	/* LCD Driver Waveform Contral */
    LCD_WR_CMD(0x03,0x1018);	/* Entry Mode Set */

    LCD_WR_CMD(0x04,0x0000);	/* Scalling Contral */
    LCD_WR_CMD(0x08,0x0202);	/* Display Contral */
    LCD_WR_CMD(0x09,0x0000);	/* Display Contral 3.(0x0000) */
    LCD_WR_CMD(0x0a,0x0000);	/* Frame Cycle Contal.(0x0000) */
    LCD_WR_CMD(0x0c,(1<<0));	/* Extern Display Interface Contral */
    LCD_WR_CMD(0x0d,0x0000);	/* Frame Maker Position */
    LCD_WR_CMD(0x0f,0x0000);	/* Extern Display Interface Contral 2. */

    delay_ms(100);  /* delay 100 ms */
    LCD_WR_CMD(0x07,0x0101);	/* Display Contral */
    delay_ms(100);  /* delay 100 ms */

    LCD_WR_CMD(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4));	/* Power Control 1.(0x16b0)	*/
    LCD_WR_CMD(0x11,0x0007);								/* Power Control 2 */
    LCD_WR_CMD(0x12,(1<<8)|(1<<4)|(0<<0));				/* Power Control 3.(0x0138)	*/
    LCD_WR_CMD(0x13,0x0b00);								/* Power Control 4 */
    LCD_WR_CMD(0x29,0x0000);								/* Power Control 7 */

    LCD_WR_CMD(0x2b,(1<<14)|(1<<4));

    LCD_WR_CMD(0x50,0);       /* Set X Start */
    LCD_WR_CMD(0x51,239);	    /* Set X End */
    LCD_WR_CMD(0x52,0);	    /* Set Y Start */
    LCD_WR_CMD(0x53,319);	    /* Set Y End */

    LCD_WR_CMD(0x60,0x2700);	/* Driver Output Control */
    LCD_WR_CMD(0x61,0x0001);	/* Driver Output Control */
    LCD_WR_CMD(0x6a,0x0000);	/* Vertical Srcoll Control */

    LCD_WR_CMD(0x80,0x0000);	/* Display Position? Partial Display 1 */
    LCD_WR_CMD(0x81,0x0000);	/* RAM Address Start? Partial Display 1 */
    LCD_WR_CMD(0x82,0x0000);	/* RAM Address End-Partial Display 1 */
    LCD_WR_CMD(0x83,0x0000);	/* Displsy Position? Partial Display 2 */
    LCD_WR_CMD(0x84,0x0000);	/* RAM Address Start? Partial Display 2 */
    LCD_WR_CMD(0x85,0x0000);	/* RAM Address End? Partial Display 2 */

    LCD_WR_CMD(0x90,(0<<7)|(16<<0));	/* Frame Cycle Contral.(0x0013)	*/
    LCD_WR_CMD(0x92,0x0000);	/* Panel Interface Contral 2.(0x0000) */
    LCD_WR_CMD(0x93,0x0001);	/* Panel Interface Contral 3. */
    LCD_WR_CMD(0x95,0x0110);	/* Frame Cycle Contral.(0x0110)	*/
    LCD_WR_CMD(0x97,(0<<8));
    LCD_WR_CMD(0x98,0x0000);	/* Frame Cycle Contral */

    LCD_WR_CMD(0x07,0x0173);
  }
#ifndef SAVE_ON_FLASH
  else if( DeviceCode == 0x9331 )
  {
    LCD_Code = ILI9331;
    LCD_WR_CMD(0x00E7, 0x1014);
    LCD_WR_CMD(0x0001, 0x0100);   /* set SS and SM bit */
    LCD_WR_CMD(0x0002, 0x0200);   /* set 1 line inversion */
    LCD_WR_CMD(0x0003, 0x1030);   /* set GRAM write direction and BGR=1 */
    LCD_WR_CMD(0x0008, 0x0202);   /* set the back porch and front porch */
    LCD_WR_CMD(0x0009, 0x0000);   /* set non-display area refresh cycle ISC[3:0] */
    LCD_WR_CMD(0x000A, 0x0000);   /* FMARK function */
    LCD_WR_CMD(0x000C, 0x0000);   /* RGB interface setting */
    LCD_WR_CMD(0x000D, 0x0000);   /* Frame marker Position */
    LCD_WR_CMD(0x000F, 0x0000);   /* RGB interface polarity */
    /* Power On sequence */
    LCD_WR_CMD(0x0010, 0x0000);   /* SAP, BT[3:0], AP, DSTB, SLP, STB	*/
    LCD_WR_CMD(0x0011, 0x0007);   /* DC1[2:0], DC0[2:0], VC[2:0] */
    LCD_WR_CMD(0x0012, 0x0000);   /* VREG1OUT voltage	*/
    LCD_WR_CMD(0x0013, 0x0000);   /* VDV[4:0] for VCOM amplitude */
    delay_ms(200);  /* delay 200 ms */
    LCD_WR_CMD(0x0010, 0x1690);   /* SAP, BT[3:0], AP, DSTB, SLP, STB	*/
    LCD_WR_CMD(0x0011, 0x0227);   /* DC1[2:0], DC0[2:0], VC[2:0] */
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0012, 0x000C);   /* Internal reference voltage= Vci	*/
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0013, 0x0800);   /* Set VDV[4:0] for VCOM amplitude */
    LCD_WR_CMD(0x0029, 0x0011);   /* Set VCM[5:0] for VCOMH */
    LCD_WR_CMD(0x002B, 0x000B);   /* Set Frame Rate */
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0020, 0x0000);   /* GRAM horizontal Address */
    LCD_WR_CMD(0x0021, 0x0000);   /* GRAM Vertical Address */
    /* Adjust the Gamma Curve */
    LCD_WR_CMD(0x0030, 0x0000);
    LCD_WR_CMD(0x0031, 0x0106);
    LCD_WR_CMD(0x0032, 0x0000);
    LCD_WR_CMD(0x0035, 0x0204);
    LCD_WR_CMD(0x0036, 0x160A);
    LCD_WR_CMD(0x0037, 0x0707);
    LCD_WR_CMD(0x0038, 0x0106);
    LCD_WR_CMD(0x0039, 0x0707);
    LCD_WR_CMD(0x003C, 0x0402);
    LCD_WR_CMD(0x003D, 0x0C0F);
    /* Set GRAM area */
    LCD_WR_CMD(0x0050, 0x0000);   /* Horizontal GRAM Start Address */
    LCD_WR_CMD(0x0051, 0x00EF);   /* Horizontal GRAM End Address */
    LCD_WR_CMD(0x0052, 0x0000);   /* Vertical GRAM Start Address */
    LCD_WR_CMD(0x0053, 0x013F);   /* Vertical GRAM Start Address */
    LCD_WR_CMD(0x0060, 0x2700);   /* Gate Scan Line */
    LCD_WR_CMD(0x0061, 0x0001);   /*  NDL,VLE, REV */
    LCD_WR_CMD(0x006A, 0x0000);   /* set scrolling line */
    /* Partial Display Control */
    LCD_WR_CMD(0x0080, 0x0000);
    LCD_WR_CMD(0x0081, 0x0000);
    LCD_WR_CMD(0x0082, 0x0000);
    LCD_WR_CMD(0x0083, 0x0000);
    LCD_WR_CMD(0x0084, 0x0000);
    LCD_WR_CMD(0x0085, 0x0000);
    /* Panel Control */
    LCD_WR_CMD(0x0090, 0x0010);
    LCD_WR_CMD(0x0092, 0x0600);
    LCD_WR_CMD(0x0007,0x0021);
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0007,0x0061);
    delay_ms(50);  /* delay 50 ms */
    LCD_WR_CMD(0x0007,0x0133);    /* 262K color and display ON */
  }
  else if( DeviceCode == 0x9919 )
  {
    LCD_Code = SSD2119;
    /* POWER ON &RESET DISPLAY OFF */
    LCD_WR_CMD(0x28,0x0006);
    LCD_WR_CMD(0x00,0x0001);
    LCD_WR_CMD(0x10,0x0000);
    LCD_WR_CMD(0x01,0x72ef);
    LCD_WR_CMD(0x02,0x0600);
    LCD_WR_CMD(0x03,0x6a38);
    LCD_WR_CMD(0x11,0x6874);
    LCD_WR_CMD(0x0f,0x0000);    /* RAM WRITE DATA MASK */
    LCD_WR_CMD(0x0b,0x5308);    /* RAM WRITE DATA MASK */
    LCD_WR_CMD(0x0c,0x0003);
    LCD_WR_CMD(0x0d,0x000a);
    LCD_WR_CMD(0x0e,0x2e00);
    LCD_WR_CMD(0x1e,0x00be);
    LCD_WR_CMD(0x25,0x8000);
    LCD_WR_CMD(0x26,0x7800);
    LCD_WR_CMD(0x27,0x0078);
    LCD_WR_CMD(0x4e,0x0000);
    LCD_WR_CMD(0x4f,0x0000);
    LCD_WR_CMD(0x12,0x08d9);
    /* Adjust the Gamma Curve */
    LCD_WR_CMD(0x30,0x0000);
    LCD_WR_CMD(0x31,0x0104);
    LCD_WR_CMD(0x32,0x0100);
    LCD_WR_CMD(0x33,0x0305);
    LCD_WR_CMD(0x34,0x0505);
    LCD_WR_CMD(0x35,0x0305);
    LCD_WR_CMD(0x36,0x0707);
    LCD_WR_CMD(0x37,0x0300);
    LCD_WR_CMD(0x3a,0x1200);
    LCD_WR_CMD(0x3b,0x0800);
    LCD_WR_CMD(0x07,0x0033);
  }
  else if( DeviceCode == 0x1505 || DeviceCode == 0x0505 )
  {
    LCD_Code = R61505U;
    /* initializing funciton */
    LCD_WR_CMD(0xe5,0x8000);  /* Set the internal vcore voltage */
    LCD_WR_CMD(0x00,0x0001);  /* start OSC */
    LCD_WR_CMD(0x2b,0x0010);  /* Set the frame rate as 80 when the internal resistor is used for oscillator circuit */
    LCD_WR_CMD(0x01,0x0100);  /* s720  to  s1 ; G1 to G320 */
    LCD_WR_CMD(0x02,0x0700);  /* set the line inversion */
    LCD_WR_CMD(0x03,0x1018);  /* 65536 colors */
    LCD_WR_CMD(0x04,0x0000);
    LCD_WR_CMD(0x08,0x0202);  /* specify the line number of front and back porch periods respectively */
    LCD_WR_CMD(0x09,0x0000);
    LCD_WR_CMD(0x0a,0x0000);
    LCD_WR_CMD(0x0c,0x0000);  /* select  internal system clock */
    LCD_WR_CMD(0x0d,0x0000);
    LCD_WR_CMD(0x0f,0x0000);
    LCD_WR_CMD(0x50,0x0000);  /* set windows adress */
    LCD_WR_CMD(0x51,0x00ef);
    LCD_WR_CMD(0x52,0x0000);
    LCD_WR_CMD(0x53,0x013f);
    LCD_WR_CMD(0x60,0x2700);
    LCD_WR_CMD(0x61,0x0001);
    LCD_WR_CMD(0x6a,0x0000);
    LCD_WR_CMD(0x80,0x0000);
    LCD_WR_CMD(0x81,0x0000);
    LCD_WR_CMD(0x82,0x0000);
    LCD_WR_CMD(0x83,0x0000);
    LCD_WR_CMD(0x84,0x0000);
    LCD_WR_CMD(0x85,0x0000);
    LCD_WR_CMD(0x90,0x0010);
    LCD_WR_CMD(0x92,0x0000);
    LCD_WR_CMD(0x93,0x0003);
    LCD_WR_CMD(0x95,0x0110);
    LCD_WR_CMD(0x97,0x0000);
    LCD_WR_CMD(0x98,0x0000);
    /* power setting function */
    LCD_WR_CMD(0x10,0x0000);
    LCD_WR_CMD(0x11,0x0000);
    LCD_WR_CMD(0x12,0x0000);
    LCD_WR_CMD(0x13,0x0000);
    delay_ms(100);
    LCD_WR_CMD(0x10,0x17b0);
    LCD_WR_CMD(0x11,0x0004);
    delay_ms(50);
    LCD_WR_CMD(0x12,0x013e);
    delay_ms(50);
    LCD_WR_CMD(0x13,0x1f00);
    LCD_WR_CMD(0x29,0x000f);
    delay_ms(50);
    LCD_WR_CMD(0x20,0x0000);
    LCD_WR_CMD(0x21,0x0000);

    /* initializing function */
    LCD_WR_CMD(0x30,0x0204);
    LCD_WR_CMD(0x31,0x0001);
    LCD_WR_CMD(0x32,0x0000);
    LCD_WR_CMD(0x35,0x0206);
    LCD_WR_CMD(0x36,0x0600);
    LCD_WR_CMD(0x37,0x0500);
    LCD_WR_CMD(0x38,0x0505);
    LCD_WR_CMD(0x39,0x0407);
    LCD_WR_CMD(0x3c,0x0500);
    LCD_WR_CMD(0x3d,0x0503);

    /* display on */
    LCD_WR_CMD(0x07,0x0173);
  }
  else if( DeviceCode == 0x8989 )
  {
    LCD_Code = SSD1289;
    LCD_WR_CMD(0x0000,0x0001);    delay_ms(50);   /* Žò¿ªŸ§Õñ */
    LCD_WR_CMD(0x0003,0xA8A4);    delay_ms(50);
    LCD_WR_CMD(0x000C,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x000D,0x080C);    delay_ms(50);
    LCD_WR_CMD(0x000E,0x2B00);    delay_ms(50);
    LCD_WR_CMD(0x001E,0x00B0);    delay_ms(50);
    LCD_WR_CMD(0x0001,0x2B3F);    delay_ms(50);   /* Çý¶¯Êä³ö¿ØÖÆ320*240 0x2B3F */
    LCD_WR_CMD(0x0002,0x0600);    delay_ms(50);
    LCD_WR_CMD(0x0010,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0011,0x6070);    delay_ms(50);   /* ¶šÒåÊýŸÝžñÊœ 16λɫ ºáÆÁ 0x6070 */
    LCD_WR_CMD(0x0005,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0006,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0016,0xEF1C);    delay_ms(50);
    LCD_WR_CMD(0x0017,0x0003);    delay_ms(50);
    LCD_WR_CMD(0x0007,0x0133);    delay_ms(50);
    LCD_WR_CMD(0x000B,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x000F,0x0000);    delay_ms(50);   /* ÉšÃ迪ʌµØÖ· */
    LCD_WR_CMD(0x0041,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0042,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0048,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0049,0x013F);    delay_ms(50);
    LCD_WR_CMD(0x004A,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x004B,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0044,0xEF00);    delay_ms(50);
    LCD_WR_CMD(0x0045,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0046,0x013F);    delay_ms(50);
    LCD_WR_CMD(0x0030,0x0707);    delay_ms(50);
    LCD_WR_CMD(0x0031,0x0204);    delay_ms(50);
    LCD_WR_CMD(0x0032,0x0204);    delay_ms(50);
    LCD_WR_CMD(0x0033,0x0502);    delay_ms(50);
    LCD_WR_CMD(0x0034,0x0507);    delay_ms(50);
    LCD_WR_CMD(0x0035,0x0204);    delay_ms(50);
    LCD_WR_CMD(0x0036,0x0204);    delay_ms(50);
    LCD_WR_CMD(0x0037,0x0502);    delay_ms(50);
    LCD_WR_CMD(0x003A,0x0302);    delay_ms(50);
    LCD_WR_CMD(0x003B,0x0302);    delay_ms(50);
    LCD_WR_CMD(0x0023,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0024,0x0000);    delay_ms(50);
    LCD_WR_CMD(0x0025,0x8000);    delay_ms(50);
    LCD_WR_CMD(0x004f,0);        /* ÐÐÊ×Ö·0 */
    LCD_WR_CMD(0x004e,0);        /* ÁÐÊ×Ö·0 */
  }
  else if( DeviceCode == 0x8999 )
  {
    LCD_Code = SSD1298;
    LCD_WR_CMD(0x0028,0x0006);
    LCD_WR_CMD(0x0000,0x0001);
    LCD_WR_CMD(0x0003,0xaea4);    /* power control 1---line frequency and VHG,VGL voltage */
    LCD_WR_CMD(0x000c,0x0004);    /* power control 2---VCIX2 output voltage */
    LCD_WR_CMD(0x000d,0x000c);    /* power control 3---Vlcd63 voltage */
    LCD_WR_CMD(0x000e,0x2800);    /* power control 4---VCOMA voltage VCOML=VCOMH*0.9475-VCOMA */
    LCD_WR_CMD(0x001e,0x00b5);    /* POWER CONTROL 5---VCOMH voltage */
    LCD_WR_CMD(0x0001,0x3b3f);
    LCD_WR_CMD(0x0002,0x0600);
    LCD_WR_CMD(0x0010,0x0000);
    LCD_WR_CMD(0x0011,0x6830);
    LCD_WR_CMD(0x0005,0x0000);
    LCD_WR_CMD(0x0006,0x0000);
    LCD_WR_CMD(0x0016,0xef1c);
    LCD_WR_CMD(0x0007,0x0033);    /* Display control 1 */
    /* when GON=1 and DTE=0,all gate outputs become VGL */
    /* when GON=1 and DTE=0,all gate outputs become VGH */
    /* non-selected gate wires become VGL */
    LCD_WR_CMD(0x000b,0x0000);
    LCD_WR_CMD(0x000f,0x0000);
    LCD_WR_CMD(0x0041,0x0000);
    LCD_WR_CMD(0x0042,0x0000);
    LCD_WR_CMD(0x0048,0x0000);
    LCD_WR_CMD(0x0049,0x013f);
    LCD_WR_CMD(0x004a,0x0000);
    LCD_WR_CMD(0x004b,0x0000);
    LCD_WR_CMD(0x0044,0xef00);	/* Horizontal RAM start and end address */
    LCD_WR_CMD(0x0045,0x0000);	/* Vretical RAM start address */
    LCD_WR_CMD(0x0046,0x013f);	/* Vretical RAM end address */
    LCD_WR_CMD(0x004e,0x0000);	/* set GDDRAM x address counter */
    LCD_WR_CMD(0x004f,0x0000);    /* set GDDRAM y address counter */
    /* y control */
    LCD_WR_CMD(0x0030,0x0707);
    LCD_WR_CMD(0x0031,0x0202);
    LCD_WR_CMD(0x0032,0x0204);
    LCD_WR_CMD(0x0033,0x0502);
    LCD_WR_CMD(0x0034,0x0507);
    LCD_WR_CMD(0x0035,0x0204);
    LCD_WR_CMD(0x0036,0x0204);
    LCD_WR_CMD(0x0037,0x0502);
    LCD_WR_CMD(0x003a,0x0302);
    LCD_WR_CMD(0x003b,0x0302);
    LCD_WR_CMD(0x0023,0x0000);
    LCD_WR_CMD(0x0024,0x0000);
    LCD_WR_CMD(0x0025,0x8000);
    LCD_WR_CMD(0x0026,0x7000);
    LCD_WR_CMD(0x0020,0xb0eb);
    LCD_WR_CMD(0x0027,0x007c);
  }
  else if( DeviceCode == 0x5408 )
  {
    LCD_Code = SPFD5408B;

    LCD_WR_CMD(0x0001,0x0100);	  /* Driver Output Contral Register */
    LCD_WR_CMD(0x0002,0x0700);      /* LCD Driving Waveform Contral */
    LCD_WR_CMD(0x0003,0x1030);	  /* Entry ModeÉèÖÃ */

    LCD_WR_CMD(0x0004,0x0000);	  /* Scalling Control register */
    LCD_WR_CMD(0x0008,0x0207);	  /* Display Control 2 */
    LCD_WR_CMD(0x0009,0x0000);	  /* Display Control 3 */
    LCD_WR_CMD(0x000A,0x0000);	  /* Frame Cycle Control */
    LCD_WR_CMD(0x000C,0x0000);	  /* External Display Interface Control 1 */
    LCD_WR_CMD(0x000D,0x0000);      /* Frame Maker Position */
    LCD_WR_CMD(0x000F,0x0000);	  /* External Display Interface Control 2 */
    delay_ms(50);
    LCD_WR_CMD(0x0007,0x0101);	  /* Display Control */
    delay_ms(50);
    LCD_WR_CMD(0x0010,0x16B0);      /* Power Control 1 */
    LCD_WR_CMD(0x0011,0x0001);      /* Power Control 2 */
    LCD_WR_CMD(0x0017,0x0001);      /* Power Control 3 */
    LCD_WR_CMD(0x0012,0x0138);      /* Power Control 4 */
    LCD_WR_CMD(0x0013,0x0800);      /* Power Control 5 */
    LCD_WR_CMD(0x0029,0x0009);	  /* NVM read data 2 */
    LCD_WR_CMD(0x002a,0x0009);	  /* NVM read data 3 */
    LCD_WR_CMD(0x00a4,0x0000);
    LCD_WR_CMD(0x0050,0x0000);	  /* ÉèÖòÙ×÷Ž°¿ÚµÄXÖῪʌÁÐ */
    LCD_WR_CMD(0x0051,0x00EF);	  /* ÉèÖòÙ×÷Ž°¿ÚµÄXÖáœáÊøÁÐ */
    LCD_WR_CMD(0x0052,0x0000);	  /* ÉèÖòÙ×÷Ž°¿ÚµÄYÖῪʌÐÐ */
    LCD_WR_CMD(0x0053,0x013F);	  /* ÉèÖòÙ×÷Ž°¿ÚµÄYÖáœáÊøÐÐ */

    LCD_WR_CMD(0x0060,0x2700);	  /* Driver Output Control */
    /* ÉèÖÃÆÁÄ»µÄµãÊýÒÔŒ°ÉšÃèµÄÆðÊŒÐÐ */
    LCD_WR_CMD(0x0061,0x0003);	  /* Driver Output Control */
    LCD_WR_CMD(0x006A,0x0000);	  /* Vertical Scroll Control */

    LCD_WR_CMD(0x0080,0x0000);	  /* Display Position šC Partial Display 1 */
    LCD_WR_CMD(0x0081,0x0000);	  /* RAM Address Start šC Partial Display 1 */
    LCD_WR_CMD(0x0082,0x0000);	  /* RAM address End - Partial Display 1 */
    LCD_WR_CMD(0x0083,0x0000);	  /* Display Position šC Partial Display 2 */
    LCD_WR_CMD(0x0084,0x0000);	  /* RAM Address Start šC Partial Display 2 */
    LCD_WR_CMD(0x0085,0x0000);	  /* RAM address End šC Partail Display2 */
    LCD_WR_CMD(0x0090,0x0013);	  /* Frame Cycle Control */
    LCD_WR_CMD(0x0092,0x0000); 	  /* Panel Interface Control 2 */
    LCD_WR_CMD(0x0093,0x0003);	  /* Panel Interface control 3 */
    LCD_WR_CMD(0x0095,0x0110);	  /* Frame Cycle Control */
    LCD_WR_CMD(0x0007,0x0173);
  }
  else if( DeviceCode == 0x4531 )
  {
    LCD_Code = LGDP4531;
    /* Setup display */
    LCD_WR_CMD(0x00,0x0001);
    LCD_WR_CMD(0x10,0x0628);
    LCD_WR_CMD(0x12,0x0006);
    LCD_WR_CMD(0x13,0x0A32);
    LCD_WR_CMD(0x11,0x0040);
    LCD_WR_CMD(0x15,0x0050);
    LCD_WR_CMD(0x12,0x0016);
    delay_ms(50);
    LCD_WR_CMD(0x10,0x5660);
    delay_ms(50);
    LCD_WR_CMD(0x13,0x2A4E);
    LCD_WR_CMD(0x01,0x0100);
    LCD_WR_CMD(0x02,0x0300);
    LCD_WR_CMD(0x03,0x1030);
    LCD_WR_CMD(0x08,0x0202);
    LCD_WR_CMD(0x0A,0x0000);
    LCD_WR_CMD(0x30,0x0000);
    LCD_WR_CMD(0x31,0x0402);
    LCD_WR_CMD(0x32,0x0106);
    LCD_WR_CMD(0x33,0x0700);
    LCD_WR_CMD(0x34,0x0104);
    LCD_WR_CMD(0x35,0x0301);
    LCD_WR_CMD(0x36,0x0707);
    LCD_WR_CMD(0x37,0x0305);
    LCD_WR_CMD(0x38,0x0208);
    LCD_WR_CMD(0x39,0x0F0B);
    delay_ms(50);
    LCD_WR_CMD(0x41,0x0002);
    LCD_WR_CMD(0x60,0x2700);
    LCD_WR_CMD(0x61,0x0001);
    LCD_WR_CMD(0x90,0x0119);
    LCD_WR_CMD(0x92,0x010A);
    LCD_WR_CMD(0x93,0x0004);
    LCD_WR_CMD(0xA0,0x0100);
    delay_ms(50);
    LCD_WR_CMD(0x07,0x0133);
    delay_ms(50);
    LCD_WR_CMD(0xA0,0x0000);
  }
  else if( DeviceCode == 0x4535 )
  {
    LCD_Code = LGDP4535;
    LCD_WR_CMD(0x15, 0x0030); 	 /* Set the internal vcore voltage */
    LCD_WR_CMD(0x9A, 0x0010); 	 /* Start internal OSC */
    LCD_WR_CMD(0x11, 0x0020);	     /* set SS and SM bit */
    LCD_WR_CMD(0x10, 0x3428);	     /* set 1 line inversion */
    LCD_WR_CMD(0x12, 0x0002);	     /* set GRAM write direction and BGR=1 */
    LCD_WR_CMD(0x13, 0x1038);	     /* Resize register */
    delay_ms(40);
    LCD_WR_CMD(0x12, 0x0012);	     /* set the back porch and front porch */
    delay_ms(40);
    LCD_WR_CMD(0x10, 0x3420);	     /* set non-display area refresh cycle ISC[3:0] */
    LCD_WR_CMD(0x13, 0x3045);	     /* FMARK function */
    delay_ms(70);
    LCD_WR_CMD(0x30, 0x0000);      /* RGB interface setting */
    LCD_WR_CMD(0x31, 0x0402);	     /* Frame marker Position */
    LCD_WR_CMD(0x32, 0x0307);      /* RGB interface polarity */
    LCD_WR_CMD(0x33, 0x0304);      /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    LCD_WR_CMD(0x34, 0x0004);      /* DC1[2:0], DC0[2:0], VC[2:0] */
    LCD_WR_CMD(0x35, 0x0401);      /* VREG1OUT voltage */
    LCD_WR_CMD(0x36, 0x0707);      /* VDV[4:0] for VCOM amplitude */
    LCD_WR_CMD(0x37, 0x0305);      /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    LCD_WR_CMD(0x38, 0x0610);      /* DC1[2:0], DC0[2:0], VC[2:0] */
    LCD_WR_CMD(0x39, 0x0610);      /* VREG1OUT voltage */
    LCD_WR_CMD(0x01, 0x0100);      /* VDV[4:0] for VCOM amplitude */
    LCD_WR_CMD(0x02, 0x0300);      /* VCM[4:0] for VCOMH */
    LCD_WR_CMD(0x03, 0x1030);      /* GRAM horizontal Address */
    LCD_WR_CMD(0x08, 0x0808);      /* GRAM Vertical Address */
    LCD_WR_CMD(0x0A, 0x0008);
    LCD_WR_CMD(0x60, 0x2700);	     /* Gate Scan Line */
    LCD_WR_CMD(0x61, 0x0001);	     /* NDL,VLE, REV */
    LCD_WR_CMD(0x90, 0x013E);
    LCD_WR_CMD(0x92, 0x0100);
    LCD_WR_CMD(0x93, 0x0100);
    LCD_WR_CMD(0xA0, 0x3000);
    LCD_WR_CMD(0xA3, 0x0010);
    LCD_WR_CMD(0x07, 0x0001);
    LCD_WR_CMD(0x07, 0x0021);
    LCD_WR_CMD(0x07, 0x0023);
    LCD_WR_CMD(0x07, 0x0033);
    LCD_WR_CMD(0x07, 0x0133);
  }
  else if( DeviceCode == 0x0047 )
  {
    LCD_Code = HX8347D;
    /* Start Initial Sequence */
    LCD_WR_CMD(0xEA,0x00);
    LCD_WR_CMD(0xEB,0x20);
    LCD_WR_CMD(0xEC,0x0C);
    LCD_WR_CMD(0xED,0xC4);
    LCD_WR_CMD(0xE8,0x40);
    LCD_WR_CMD(0xE9,0x38);
    LCD_WR_CMD(0xF1,0x01);
    LCD_WR_CMD(0xF2,0x10);
    LCD_WR_CMD(0x27,0xA3);
    /* GAMMA SETTING */
    LCD_WR_CMD(0x40,0x01);
    LCD_WR_CMD(0x41,0x00);
    LCD_WR_CMD(0x42,0x00);
    LCD_WR_CMD(0x43,0x10);
    LCD_WR_CMD(0x44,0x0E);
    LCD_WR_CMD(0x45,0x24);
    LCD_WR_CMD(0x46,0x04);
    LCD_WR_CMD(0x47,0x50);
    LCD_WR_CMD(0x48,0x02);
    LCD_WR_CMD(0x49,0x13);
    LCD_WR_CMD(0x4A,0x19);
    LCD_WR_CMD(0x4B,0x19);
    LCD_WR_CMD(0x4C,0x16);
    LCD_WR_CMD(0x50,0x1B);
    LCD_WR_CMD(0x51,0x31);
    LCD_WR_CMD(0x52,0x2F);
    LCD_WR_CMD(0x53,0x3F);
    LCD_WR_CMD(0x54,0x3F);
    LCD_WR_CMD(0x55,0x3E);
    LCD_WR_CMD(0x56,0x2F);
    LCD_WR_CMD(0x57,0x7B);
    LCD_WR_CMD(0x58,0x09);
    LCD_WR_CMD(0x59,0x06);
    LCD_WR_CMD(0x5A,0x06);
    LCD_WR_CMD(0x5B,0x0C);
    LCD_WR_CMD(0x5C,0x1D);
    LCD_WR_CMD(0x5D,0xCC);
    /* Power Voltage Setting */
    LCD_WR_CMD(0x1B,0x18);
    LCD_WR_CMD(0x1A,0x01);
    LCD_WR_CMD(0x24,0x15);
    LCD_WR_CMD(0x25,0x50);
    LCD_WR_CMD(0x23,0x8B);
    LCD_WR_CMD(0x18,0x36);
    LCD_WR_CMD(0x19,0x01);
    LCD_WR_CMD(0x01,0x00);
    LCD_WR_CMD(0x1F,0x88);
    delay_ms(50);
    LCD_WR_CMD(0x1F,0x80);
    delay_ms(50);
    LCD_WR_CMD(0x1F,0x90);
    delay_ms(50);
    LCD_WR_CMD(0x1F,0xD0);
    delay_ms(50);
    LCD_WR_CMD(0x17,0x05);
    LCD_WR_CMD(0x36,0x00);
    LCD_WR_CMD(0x28,0x38);
    delay_ms(50);
    LCD_WR_CMD(0x28,0x3C);
  }
  else if( DeviceCode == 0x7783 )
  {
    LCD_Code = ST7781;
    /* Start Initial Sequence */
    LCD_WR_CMD(0x00FF,0x0001);
    LCD_WR_CMD(0x00F3,0x0008);
    LCD_WR_CMD(0x0001,0x0100);
    LCD_WR_CMD(0x0002,0x0700);
    LCD_WR_CMD(0x0003,0x1030);
    LCD_WR_CMD(0x0008,0x0302);
    LCD_WR_CMD(0x0008,0x0207);
    LCD_WR_CMD(0x0009,0x0000);
    LCD_WR_CMD(0x000A,0x0000);
    LCD_WR_CMD(0x0010,0x0000);
    LCD_WR_CMD(0x0011,0x0005);
    LCD_WR_CMD(0x0012,0x0000);
    LCD_WR_CMD(0x0013,0x0000);
    delay_ms(50);
    LCD_WR_CMD(0x0010,0x12B0);
    delay_ms(50);
    LCD_WR_CMD(0x0011,0x0007);
    delay_ms(50);
    LCD_WR_CMD(0x0012,0x008B);
    delay_ms(50);
    LCD_WR_CMD(0x0013,0x1700);
    delay_ms(50);
    LCD_WR_CMD(0x0029,0x0022);
    LCD_WR_CMD(0x0030,0x0000);
    LCD_WR_CMD(0x0031,0x0707);
    LCD_WR_CMD(0x0032,0x0505);
    LCD_WR_CMD(0x0035,0x0107);
    LCD_WR_CMD(0x0036,0x0008);
    LCD_WR_CMD(0x0037,0x0000);
    LCD_WR_CMD(0x0038,0x0202);
    LCD_WR_CMD(0x0039,0x0106);
    LCD_WR_CMD(0x003C,0x0202);
    LCD_WR_CMD(0x003D,0x0408);
    delay_ms(50);
    LCD_WR_CMD(0x0050,0x0000);
    LCD_WR_CMD(0x0051,0x00EF);
    LCD_WR_CMD(0x0052,0x0000);
    LCD_WR_CMD(0x0053,0x013F);
    LCD_WR_CMD(0x0060,0xA700);
    LCD_WR_CMD(0x0061,0x0001);
    LCD_WR_CMD(0x0090,0x0033);
    LCD_WR_CMD(0x002B,0x000B);
    LCD_WR_CMD(0x0007,0x0133);
  }
  else	/* special ID */
  {
    uint16_t DeviceCode2 = LCD_RD_CMD(0x67);
    if( DeviceCode2 == 0x0046 )
    {
      LCD_Code = HX8346A;

      /* Gamma for CMO 3.2 */
      LCD_WR_CMD(0x46,0x94);
      LCD_WR_CMD(0x47,0x41);
      LCD_WR_CMD(0x48,0x00);
      LCD_WR_CMD(0x49,0x33);
      LCD_WR_CMD(0x4a,0x23);
      LCD_WR_CMD(0x4b,0x45);
      LCD_WR_CMD(0x4c,0x44);
      LCD_WR_CMD(0x4d,0x77);
      LCD_WR_CMD(0x4e,0x12);
      LCD_WR_CMD(0x4f,0xcc);
      LCD_WR_CMD(0x50,0x46);
      LCD_WR_CMD(0x51,0x82);
      /* 240x320 window setting */
      LCD_WR_CMD(0x02,0x00);
      LCD_WR_CMD(0x03,0x00);
      LCD_WR_CMD(0x04,0x01);
      LCD_WR_CMD(0x05,0x3f);
      LCD_WR_CMD(0x06,0x00);
      LCD_WR_CMD(0x07,0x00);
      LCD_WR_CMD(0x08,0x00);
      LCD_WR_CMD(0x09,0xef);

      /* Display Setting */
      LCD_WR_CMD(0x01,0x06);
      LCD_WR_CMD(0x16,0xC8);	/* MY(1) MX(1) MV(0) */

      LCD_WR_CMD(0x23,0x95);
      LCD_WR_CMD(0x24,0x95);
      LCD_WR_CMD(0x25,0xff);

      LCD_WR_CMD(0x27,0x02);
      LCD_WR_CMD(0x28,0x02);
      LCD_WR_CMD(0x29,0x02);
      LCD_WR_CMD(0x2a,0x02);
      LCD_WR_CMD(0x2c,0x02);
      LCD_WR_CMD(0x2d,0x02);

      LCD_WR_CMD(0x3a,0x01);
      LCD_WR_CMD(0x3b,0x01);
      LCD_WR_CMD(0x3c,0xf0);
      LCD_WR_CMD(0x3d,0x00);
      delay_ms(2);
      LCD_WR_CMD(0x35,0x38);
      LCD_WR_CMD(0x36,0x78);

      LCD_WR_CMD(0x3e,0x38);

      LCD_WR_CMD(0x40,0x0f);
      LCD_WR_CMD(0x41,0xf0);
      /* Power Supply Setting */
      LCD_WR_CMD(0x19,0x49);
      LCD_WR_CMD(0x93,0x0f);
      delay_ms(1);
      LCD_WR_CMD(0x20,0x30);
      LCD_WR_CMD(0x1d,0x07);
      LCD_WR_CMD(0x1e,0x00);
      LCD_WR_CMD(0x1f,0x07);
      /* VCOM Setting for CMO 3.2¡± Panel */
      LCD_WR_CMD(0x44,0x4d);
      LCD_WR_CMD(0x45,0x13);
      delay_ms(1);
      LCD_WR_CMD(0x1c,0x04);
      delay_ms(2);
      LCD_WR_CMD(0x43,0x80);
      delay_ms(5);
      LCD_WR_CMD(0x1b,0x08);
      delay_ms(4);
      LCD_WR_CMD(0x1b,0x10);
      delay_ms(4);
      /* Display ON Setting */
      LCD_WR_CMD(0x90,0x7f);
      LCD_WR_CMD(0x26,0x04);
      delay_ms(4);
      LCD_WR_CMD(0x26,0x24);
      LCD_WR_CMD(0x26,0x2c);
      delay_ms(4);
      LCD_WR_CMD(0x26,0x3c);
      /* Set internal VDDD voltage */
      LCD_WR_CMD(0x57,0x02);
      LCD_WR_CMD(0x55,0x00);
      LCD_WR_CMD(0x57,0x00);
    }
    if( DeviceCode2 == 0x0047 )
    {
      LCD_Code = HX8347A;
      LCD_WR_CMD(0x0042,0x0008);
      /* Gamma setting */
      LCD_WR_CMD(0x0046,0x00B4);
      LCD_WR_CMD(0x0047,0x0043);
      LCD_WR_CMD(0x0048,0x0013);
      LCD_WR_CMD(0x0049,0x0047);
      LCD_WR_CMD(0x004A,0x0014);
      LCD_WR_CMD(0x004B,0x0036);
      LCD_WR_CMD(0x004C,0x0003);
      LCD_WR_CMD(0x004D,0x0046);
      LCD_WR_CMD(0x004E,0x0005);
      LCD_WR_CMD(0x004F,0x0010);
      LCD_WR_CMD(0x0050,0x0008);
      LCD_WR_CMD(0x0051,0x000a);
      /* Window Setting */
      LCD_WR_CMD(0x0002,0x0000);
      LCD_WR_CMD(0x0003,0x0000);
      LCD_WR_CMD(0x0004,0x0000);
      LCD_WR_CMD(0x0005,0x00EF);
      LCD_WR_CMD(0x0006,0x0000);
      LCD_WR_CMD(0x0007,0x0000);
      LCD_WR_CMD(0x0008,0x0001);
      LCD_WR_CMD(0x0009,0x003F);
      delay_ms(10);
      LCD_WR_CMD(0x0001,0x0006);
      LCD_WR_CMD(0x0016,0x00C8);
      LCD_WR_CMD(0x0023,0x0095);
      LCD_WR_CMD(0x0024,0x0095);
      LCD_WR_CMD(0x0025,0x00FF);
      LCD_WR_CMD(0x0027,0x0002);
      LCD_WR_CMD(0x0028,0x0002);
      LCD_WR_CMD(0x0029,0x0002);
      LCD_WR_CMD(0x002A,0x0002);
      LCD_WR_CMD(0x002C,0x0002);
      LCD_WR_CMD(0x002D,0x0002);
      LCD_WR_CMD(0x003A,0x0001);
      LCD_WR_CMD(0x003B,0x0001);
      LCD_WR_CMD(0x003C,0x00F0);
      LCD_WR_CMD(0x003D,0x0000);
      delay_ms(20);
      LCD_WR_CMD(0x0035,0x0038);
      LCD_WR_CMD(0x0036,0x0078);
      LCD_WR_CMD(0x003E,0x0038);
      LCD_WR_CMD(0x0040,0x000F);
      LCD_WR_CMD(0x0041,0x00F0);
      LCD_WR_CMD(0x0038,0x0000);
      /* Power Setting */
      LCD_WR_CMD(0x0019,0x0049);
      LCD_WR_CMD(0x0093,0x000A);
      delay_ms(10);
      LCD_WR_CMD(0x0020,0x0020);
      LCD_WR_CMD(0x001D,0x0003);
      LCD_WR_CMD(0x001E,0x0000);
      LCD_WR_CMD(0x001F,0x0009);
      LCD_WR_CMD(0x0044,0x0053);
      LCD_WR_CMD(0x0045,0x0010);
      delay_ms(10);
      LCD_WR_CMD(0x001C,0x0004);
      delay_ms(20);
      LCD_WR_CMD(0x0043,0x0080);
      delay_ms(5);
      LCD_WR_CMD(0x001B,0x000a);
      delay_ms(40);
      LCD_WR_CMD(0x001B,0x0012);
      delay_ms(40);
      /* Display On Setting */
      LCD_WR_CMD(0x0090,0x007F);
      LCD_WR_CMD(0x0026,0x0004);
      delay_ms(40);
      LCD_WR_CMD(0x0026,0x0024);
      LCD_WR_CMD(0x0026,0x002C);
      delay_ms(40);
      LCD_WR_CMD(0x0070,0x0008);
      LCD_WR_CMD(0x0026,0x003C);
      LCD_WR_CMD(0x0057,0x0002);
      LCD_WR_CMD(0x0055,0x0000);
      LCD_WR_CMD(0x0057,0x0000);
    } else {
      jsiConsolePrintf("Unknown LCD code %d %d\n", DeviceCode, DeviceCode2);
    }
  }
#endif				
  delay_ms(50);   /* delay 50 ms */

}
Esempio n. 18
0
/*
*********************************************************************************************************
*              SEND DHCP REQUEST
*
* Description: This function sends DHCP REQUEST message to DHCP server.
* Arguments  : s - is a socket number.
* Returns    : None.
* Note       : 
*********************************************************************************************************
*/
void send_DHCP_REQUEST(uint8_t s, uint8_t *Cip, uint8_t *d_addr, wiz_NetInfo *pWIZNETINFO)
{
	int i;
	uint8_t ip[10];
	uint16_t k = 0;

	MSG.op = DHCP_BOOTREQUEST;
	MSG.htype = DHCP_HTYPE10MB;
	MSG.hlen = DHCP_HLENETHERNET;
	MSG.hops = DHCP_HOPS;
	MSG.xid = DHCP_XID;
	MSG.secs = DHCP_SECS;
	//MSG.flags = DHCP_FLAGSBROADCAST;
	if (d_addr[0] == 0xff) 	MSG.flags = DHCP_FLAGSBROADCAST;
	else MSG.flags = 0;
	
	MSG.ciaddr[0] = Cip[0];
	MSG.ciaddr[1] = Cip[1];
	MSG.ciaddr[2] = Cip[2];
	MSG.ciaddr[3] = Cip[3];

	MSG.yiaddr[0] = 0;
	MSG.yiaddr[1] = 0;
	MSG.yiaddr[2] = 0;
	MSG.yiaddr[3] = 0;

	MSG.siaddr[0] = 0;
	MSG.siaddr[1] = 0;
	MSG.siaddr[2] = 0;
	MSG.siaddr[3] = 0;

	MSG.giaddr[0] = 0;
	MSG.giaddr[1] = 0;
	MSG.giaddr[2] = 0;
	MSG.giaddr[3] = 0;

	MSG.chaddr[0] = (*pWIZNETINFO).mac[0];
	MSG.chaddr[1] = (*pWIZNETINFO).mac[1];
	MSG.chaddr[2] = (*pWIZNETINFO).mac[2];
	MSG.chaddr[3] = (*pWIZNETINFO).mac[3];
	MSG.chaddr[4] = (*pWIZNETINFO).mac[4];
	MSG.chaddr[5] = (*pWIZNETINFO).mac[5];

	for (i = 6; i < 16; i++) MSG.chaddr[i] = 0;
	for (i = 0; i < 64; i++) MSG.sname[i] = 0;
	for (i = 0; i < 128; i++) MSG.file[i] = 0;

	// MAGIC_COOKIE 
	MSG.OPT[k++] = 0x63;
	MSG.OPT[k++] = 0x82;
	MSG.OPT[k++] = 0x53;
	MSG.OPT[k++] = 0x63;

	// Option Request Param.
	MSG.OPT[k++] = dhcpMessageType;
	MSG.OPT[k++] = 0x01;
	MSG.OPT[k++] = DHCP_REQUEST;

	MSG.OPT[k++] = dhcpClientIdentifier;
	MSG.OPT[k++] = 0x07;
	MSG.OPT[k++] = 0x01;
	MSG.OPT[k++] = (*pWIZNETINFO).mac[0];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[1];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[2];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[3];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[4];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[5];

	if (d_addr[0] == 0xff) {
		MSG.OPT[k++] = dhcpRequestedIPaddr;
		MSG.OPT[k++] = 0x04;
		MSG.OPT[k++] = (*pWIZNETINFO).ip[0];
		MSG.OPT[k++] = (*pWIZNETINFO).ip[1];
		MSG.OPT[k++] = (*pWIZNETINFO).ip[2];
		MSG.OPT[k++] = (*pWIZNETINFO).ip[3];
	
		MSG.OPT[k++] = dhcpServerIdentifier;
		MSG.OPT[k++] = 0x04;
		MSG.OPT[k++] = DHCP_SIP[0];
		MSG.OPT[k++] = DHCP_SIP[1];
		MSG.OPT[k++] = DHCP_SIP[2];
		MSG.OPT[k++] = DHCP_SIP[3];
	}

	// host name
	MSG.OPT[k++] = hostName;
	MSG.OPT[k++] = 9; // length of hostname
	MSG.OPT[k++] = HOST_NAME[0];
	MSG.OPT[k++] = HOST_NAME[1];
	MSG.OPT[k++] = HOST_NAME[2];
	MSG.OPT[k++] = HOST_NAME[3];
	MSG.OPT[k++] = HOST_NAME[4];
	MSG.OPT[k++] = HOST_NAME[5];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[3];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[4];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[5];
	
	MSG.OPT[k++] = dhcpParamRequest;
	MSG.OPT[k++] = 0x08;
	MSG.OPT[k++] = subnetMask;
	MSG.OPT[k++] = routersOnSubnet;
	MSG.OPT[k++] = dns;
	MSG.OPT[k++] = domainName;
	MSG.OPT[k++] = dhcpT1value;
	MSG.OPT[k++] = dhcpT2value;
	MSG.OPT[k++] = performRouterDiscovery;
	MSG.OPT[k++] = staticRoute;
	MSG.OPT[k++] = endOption;

	for (i = k; i < OPT_SIZE; i++) MSG.OPT[i] = 0;

	// send broadcasting packet
	for (i = 0; i < 4; i++) ip[i] = d_addr[i];

	jsiConsolePrintf("> Send DHCP_Request\r\n");
	
	sendto(s, (uint8_t *)(&MSG.op), RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);

}
Esempio n. 19
0
/*
*********************************************************************************************************
*              SEND DHCP DISCOVER
*
* Description: This function sends DHCP DISCOVER message to DHCP server.
* Arguments  : s - is a socket number.
* Returns    : None.
* Note       : 
*********************************************************************************************************
*/
void send_DHCP_DISCOVER(uint8_t s, wiz_NetInfo *pWIZNETINFO)
{
	uint16_t i;
	uint8_t ip[4];
	uint16_t k = 0;

	MSG.op = DHCP_BOOTREQUEST;
	MSG.htype = DHCP_HTYPE10MB;
	MSG.hlen = DHCP_HLENETHERNET;
	MSG.hops = DHCP_HOPS;
	MSG.xid = DHCP_XID;
	MSG.secs = DHCP_SECS;
	MSG.flags = DHCP_FLAGSBROADCAST;

	MSG.ciaddr[0] = 0;
	MSG.ciaddr[1] = 0;
	MSG.ciaddr[2] = 0;
	MSG.ciaddr[3] = 0;

	MSG.yiaddr[0] = 0;
	MSG.yiaddr[1] = 0;
	MSG.yiaddr[2] = 0;
	MSG.yiaddr[3] = 0;

	MSG.siaddr[0] = 0;
	MSG.siaddr[1] = 0;
	MSG.siaddr[2] = 0;
	MSG.siaddr[3] = 0;

	MSG.giaddr[0] = 0;
	MSG.giaddr[1] = 0;
	MSG.giaddr[2] = 0;
	MSG.giaddr[3] = 0;

	MSG.chaddr[0] = (*pWIZNETINFO).mac[0];
	MSG.chaddr[1] = (*pWIZNETINFO).mac[1];
	MSG.chaddr[2] = (*pWIZNETINFO).mac[2];
	MSG.chaddr[3] = (*pWIZNETINFO).mac[3];
	MSG.chaddr[4] = (*pWIZNETINFO).mac[4];
	MSG.chaddr[5] = (*pWIZNETINFO).mac[5];

	for (i = 6; i < 16; i++) MSG.chaddr[i] = 0;
	for (i = 0; i < 64; i++) MSG.sname[i] = 0;
	for (i = 0; i < 128; i++) MSG.file[i] = 0;

	// MAGIC_COOKIE
	MSG.OPT[k++] = 0x63;
	MSG.OPT[k++] = 0x82;
	MSG.OPT[k++] = 0x53;
	MSG.OPT[k++] = 0x63;

	// Option Request Param
	MSG.OPT[k++] = dhcpMessageType;
	MSG.OPT[k++] = 0x01;
	MSG.OPT[k++] = DHCP_DISCOVER;
	
	// Client identifier
	MSG.OPT[k++] = dhcpClientIdentifier;
	MSG.OPT[k++] = 0x07;
	MSG.OPT[k++] = 0x01;
	MSG.OPT[k++] = (*pWIZNETINFO).mac[0];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[1];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[2];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[3];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[4];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[5];
	
	// host name
	MSG.OPT[k++] = hostName;
	MSG.OPT[k++] = 9; // length of hostname
	MSG.OPT[k++] = HOST_NAME[0];
	MSG.OPT[k++] = HOST_NAME[1];
	MSG.OPT[k++] = HOST_NAME[2];
	MSG.OPT[k++] = HOST_NAME[3];
	MSG.OPT[k++] = HOST_NAME[4];
	MSG.OPT[k++] = HOST_NAME[5];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[3];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[4];
	MSG.OPT[k++] = (*pWIZNETINFO).mac[5];


	MSG.OPT[k++] = dhcpParamRequest;
	MSG.OPT[k++] = 0x06;	// length of request
	MSG.OPT[k++] = subnetMask;
	MSG.OPT[k++] = routersOnSubnet;
	MSG.OPT[k++] = dns;
	MSG.OPT[k++] = domainName;
	MSG.OPT[k++] = dhcpT1value;
	MSG.OPT[k++] = dhcpT2value;
	MSG.OPT[k++] = endOption;

	for (i = k; i < OPT_SIZE; i++) MSG.OPT[i] = 0;

	// send broadcasting packet
	for (i = 0; i < 4; i++) ip[i] = 255;

	jsiConsolePrintf("> Send DHCP_DISCOVER\r\n");
	sendto(s, (uint8_t *)(&MSG.op), RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
}
Esempio n. 20
0
/*
*********************************************************************************************************
*              CHECK DHCP STATE
*
* Description: This function checks the state of DHCP.
* Arguments  : None.
* Returns    : None.
* Note       : 
*********************************************************************************************************
*/
void check_DHCP_state(uint8_t s, wiz_NetInfo *pWIZNETINFO)
{
	uint16_t len, i;
	uint8_t type, flag;
	uint8_t d_addr[4];
	
	type = 0;
	
	if ((len = getSn_RX_RSR(s)) > 0) {
		type = parseDHCPMSG(s, len, pWIZNETINFO);
	}
	switch ( dhcp_state ) {
		case STATE_DHCP_DISCOVER :
			if (type == DHCP_OFFER) {
				jsiConsolePrintf("> Receive DHCP_OFFER\r\n");
				
				for (i = 0; i < 4; i++) d_addr[i] = 0xff;
				send_DHCP_REQUEST(s, Cip, d_addr, pWIZNETINFO);
				
				dhcp_state = STATE_DHCP_REQUEST;
			} else check_Timeout(s, pWIZNETINFO);
		break;

		case STATE_DHCP_REQUEST :
			if (type == DHCP_ACK) {
				

				jsiConsolePrintf("> Receive DHCP_ACK\r\n");
				
				if (check_leasedIP(s, pWIZNETINFO)) {
					//iinchip_init() - WIZnet chip reset & Delay (10ms);
					//Set_network();
					ctlwizchip(CW_RESET_WIZCHIP, 0);
					ctlnetwork(CN_SET_NETINFO, (void*)&(*pWIZNETINFO));
					/*
					for (i = 0; i < 12; i++) {
						
						//EEP_Write(EEP_LIP+i, *(uint8_t *)((*pWIZNETINFO).ip+i));
						
					}
					*/

					next_time = jshGetSystemTime() + DHCP_WAIT_TIME;
					retry_count = 0;
					dhcp_state = STATE_DHCP_LEASED;
				} else {

					next_time = jshGetSystemTime() + DHCP_WAIT_TIME1;
					retry_count = 0;
					//dhcp_state = STATE_DHCP_DISCOVER;
					dhcp_state = STATE_DHCP_LEASED;
					jsiConsolePrintf("> => Recceived IP is invalid\r\n");
					
					//iinchip_init();
					//Set_Default();
					//Set_network();
					//ctlwizchip(CW_RESET_WIZCHIP, 0);
					//set_default_netinfo();
					//ctlnetwork(CN_SET_NETINFO, (void*)&(*pWIZNETINFO));
				}
			} else if (type == DHCP_NAK) {
				jsiConsolePrintf("> Receive DHCP_NACK\r\n");

				next_time = jshGetSystemTime() + DHCP_WAIT_TIME;
				retry_count = 0;
				dhcp_state = STATE_DHCP_DISCOVER;
			} else check_Timeout(s, pWIZNETINFO);
		break;

		case STATE_DHCP_LEASED :
			if ((lease_time.lVal != 0xffffffff) && ((lease_time.lVal/2) < jshGetSystemTime())) {
				
				jsiConsolePrintf("> Renewal IP address \r\n");

				type = 0;
				for (i = 0; i < 4; i++)	OLD_SIP[i] = (*pWIZNETINFO).ip[i];
				for (i = 0; i < 4; i++)	d_addr[i] = DHCP_SIP[i];
				
				DHCP_XID++;
				send_DHCP_REQUEST(s, (*pWIZNETINFO).ip, d_addr, pWIZNETINFO);
				dhcp_state = STATE_DHCP_REREQUEST;


				next_time = jshGetSystemTime() + DHCP_WAIT_TIME;
			}
		break;

		case STATE_DHCP_REREQUEST :
			if (type == DHCP_ACK) {
				retry_count = 0;
				flag = 0;
				for (i = 0; i < 4; i++)	{
					if (OLD_SIP[i] != (*pWIZNETINFO).ip[i]) {
						flag = 1;
						break;
					}
				}
				
				// change to new IP address
				if (flag) {
					//iinchip_init();
					//Set_network();
					ctlwizchip(CW_RESET_WIZCHIP, 0);
					ctlnetwork(CN_SET_NETINFO, (void*)&(*pWIZNETINFO));
				}


				next_time = jshGetSystemTime() + DHCP_WAIT_TIME;

				dhcp_state = STATE_DHCP_LEASED;
			} else if (type == DHCP_NAK) {

				next_time = jshGetSystemTime() + DHCP_WAIT_TIME;
				retry_count = 0;
				dhcp_state = STATE_DHCP_DISCOVER;
//				jsiConsolePrintf("state : STATE_DHCP_DISCOVER\r\n");
			} else check_Timeout(s, pWIZNETINFO);
		break;

		case STATE_DHCP_RELEASE :
		break;

		default :
		break;
	}
}
Esempio n. 21
0
bool jshGetWatchedPinState(IOEventFlags device) {
	jsiConsolePrintf("ESP8266: jshGetWatchedPinState %d", device);
	return false;
} // End of jshGetWatchedPinState
Esempio n. 22
0
/**
 * \brief Return the current state of the selected pin.
 * \return The current state of the selected pin.
 */
JshPinState jshPinGetState(Pin pin) {
	jsiConsolePrintf("ESP8266: jshPinGetState %d\n", pin);
	return JSHPINSTATE_UNDEFINED;
} // End of jshPinGetState