/**
  * @brief this function checks if a NDEF message is available in the M24LR04E-R EEPROM
	* @par PayloadLength : the number of byte of the NDEF message
  * @retval SUCCESS : A NDEF message has been found
	* @retval ERROR :  a NDEF message doens't have been found
  */
static int8_t User_WriteFirmwareVersion ( void )			
{
uint8_t *OneByte = 0x00;
uint16_t WriteAddr = 0x01FC;				
	
		
	M24LR04E_Init();
		
	M24LR04E_WriteOneByte (M24LR16_EEPROM_ADDRESS_USER, WriteAddr++, FirmwareVersion [0]);			

	
	I2C_Cmd(M24LR04E_I2C, DISABLE);			
		
	CLK_PeripheralClockConfig(CLK_Peripheral_I2C1, DISABLE);	
	
	GPIO_HIGH(M24LR04E_I2C_SCL_GPIO_PORT,M24LR04E_I2C_SCL_PIN);	
	GPIO_HIGH(M24LR04E_I2C_SCL_GPIO_PORT,M24LR04E_I2C_SDA_PIN);	
		
		
	M24LR04E_DeInit();
	I2C_Cmd(M24LR04E_I2C, DISABLE);
	
	
	return SUCCESS;
}
Exemple #2
0
uint8_t read_DHT11(uint8_t *buf){
	uint16_t dt[42];
	uint16_t cnt;
	uint8_t i, check_sum; 
	
	//reset DHT11
	Delay(500);
 	GPIO_LOW(GPIOA,GPIO_Pin_2);
	Delay(20);
 	GPIO_HIGH(GPIOA,GPIO_Pin_2);
	
  //start reading	
 	cnt = 0; 
	for(i=0;i<83 && cnt<MAX_TICS;i++){
		if (i & 1){
			cnt = read_cycle(cnt, 1);
		}
		else {
			cnt = read_cycle(cnt, 0);
			dt[i/2]= cnt;
		}
	}
	
 	//release line
	GPIO_HIGH(GPIOA,GPIO_Pin_2);
	
	if (cnt>=MAX_TICS) return DHT11_NO_CONN;
	
	//convert data
 	for(i=2;i<42;i++){
		(*buf) <<= 1;
  	if (dt[i]>20) {
			(*buf)++;
 		}
		if (!((i-1)%8) && (i>2)) {
			buf++;
		}
 	}
	
	//calculate checksum
	buf -= 5;
	check_sum = 0;
 	for(i=0;i<4;i++){
		check_sum += *buf;
		buf++;
	}
	
	if (*buf != check_sum) return DHT11_CS_ERROR;
				
	return DHT11_OK;	
	//return check_sum;
}
Exemple #3
0
static inline void enable_motors
(unsigned int lstate, unsigned int rstate)
{
  GPIO_LOW(GPIOA, GPIO_Pin_3);

  if (rstate) GPIO_HIGH(GPIOA, GPIO_Pin_2);
  else GPIO_LOW(GPIOA, GPIO_Pin_2);

  if (lstate) GPIO_HIGH(GPIOA, GPIO_Pin_1);
  else GPIO_LOW(GPIOA, GPIO_Pin_1);

  GPIO_HIGH(GPIOA, GPIO_Pin_3);
}
Exemple #4
0
void SelectChip(unsigned char value){
	if ((value&0x01) == 0x00){
		GPIO_LOW(CRSLC_PORT, CRSLC_PIN0);	  
	}
	else{
		GPIO_HIGH(CRSLC_PORT, CRSLC_PIN0);	  
	}
	if ((value&0x02) == 0x00){
		GPIO_LOW(CRSLC_PORT, CRSLC_PIN1);	  
	}
	else{
		GPIO_HIGH(CRSLC_PORT, CRSLC_PIN1);	  
	}
}
Exemple #5
0
void WriteData(unsigned char value){
  GPIO_HIGH(CTRL_PORT, CTRL_RS);	//RS=1
  GPIO_LOW(CTRL_PORT, CTRL_RW);	  //RW=0
	WriteCommon( value );
	//Delay(EXT_LCD_DELAY);
	DelayBusy();
}
Exemple #6
0
static void prvQueueReceiveTask( void *pvParameters )
{
    unsigned long ulReceivedValue;

    /* Remove compiler warning about unused parameter. */
    ( void ) pvParameters;

    for( ;; ) {
        /* Wait until something arrives in the queue. */
        xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );

        /*  To get here something must have arrived, but is it the expected
        value?  If it is, turn the LED on for a short while. */
        if( ulReceivedValue == mainQUEUED_VALUE ) {
            /* LED on... */
            GPIO_HIGH( LD_GPIO_PORT, LD_GREEN_GPIO_PIN );

            /* ... short delay ... */
            vTaskDelay( mainLED_TOGGLE_DELAY );

            /* ... LED off again. */
            GPIO_LOW( LD_GPIO_PORT, LD_GREEN_GPIO_PIN );
        }
    }
}
Exemple #7
0
void gpio_high(int g)
{
#ifndef GPIO_SIMULATED
  GPIO_HIGH(g);
#else
  printf("gpio:high:%d\n", g);
#endif
}
Exemple #8
0
void Pulse_E(void){
  GPIO_HIGH(CTRL_PORT, CTRL_E);	//E=1
	//Delay(EXT_LCD_DELAY);
	GLCD_Delay(300);
  GPIO_LOW(CTRL_PORT, CTRL_E);	//E=0
	//Delay(EXT_LCD_DELAY);
	GLCD_Delay(300);
}
Exemple #9
0
void DelayBusy(void){
  GPIO_InitTypeDef GPIO_InitStructure;
	uint8_t busy_state = 1;
	
  GPIO_InitStructure.GPIO_Pin = DATA_PIN7;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_Init( DATA_PORT, &GPIO_InitStructure);

	GPIO_LOW(CTRL_PORT, CTRL_RS);	//RS=0
	GPIO_HIGH(CTRL_PORT, CTRL_RW);	//RW=1
	while (busy_state){
		GPIO_HIGH(CTRL_PORT, CTRL_E);	//E=1
		busy_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN7);
		GPIO_LOW(CTRL_PORT, CTRL_E);	//E=0
	}
	
}
Exemple #10
0
uint8_t GetByte(void){
  GPIO_InitTypeDef GPIO_InitStructure;
	uint8_t byte_state;
	uint8_t res_byte;
	
	GPIO_HIGH(CTRL_PORT, CTRL_RS);	//RS=1
	GPIO_HIGH(CTRL_PORT, CTRL_RW);	//RW=1

	GLCD_Delay(100);
	
  GPIO_InitStructure.GPIO_Pin = DATA_PIN0 | DATA_PIN1 | DATA_PIN2 | DATA_PIN3 | DATA_PIN4 | DATA_PIN5 | DATA_PIN6 | DATA_PIN7;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_Init( DATA_PORT, &GPIO_InitStructure);
	

 	GPIO_HIGH(CTRL_PORT, CTRL_E);	//E=1
	GLCD_Delay(100);
	
	byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN0);
	res_byte = byte_state;
	byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN1);
	res_byte += byte_state*0x02;
	byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN2);
	res_byte += byte_state*0x04;
	byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN3);
	res_byte += byte_state*0x08;
	byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN4);
	res_byte += byte_state*0x10;
	byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN5);
	res_byte += byte_state*0x20;
	byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN6);
	res_byte += byte_state*0x40;
	byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN7);
	res_byte += byte_state*0x80;
 	GPIO_LOW(CTRL_PORT, CTRL_E);	//E=0

	DelayBusy();
	
	
	return res_byte;
}
Exemple #11
0
int main(void)
{
    static unsigned int led_state = 0;

    RCC_ClocksTypeDef clockinfo;
    RCC_GetClocksFreq(&clockinfo);
    // regardless of clock speed this gives us 1000 ticks per second
    SysTick_Config(clockinfo.SYSCLK_Frequency / 1000);
    int blink_speed_ms = 400;

    setup_gpios();
    setup_adc();
    setup_usart();
    setup_button_irqs();

    kkputs("hello karl...\n");
    uint64_t lasttime = millis();
    while (1) {
        if (millis() - blink_speed_ms > lasttime) {
            if (led_state & 1) {
                switch_leds_on();
                kkputs("O");
            } else {
                switch_leds_off();
                kkputs("o");
            }
            led_state ^= 1;
            GPIO_TOGGLE(GPIOC, GPIO_Pin_3);
            lasttime = millis();
        }

        if (button_pressed) {
            button_pressed = 0;
            kkputs("button was pressed!\n");
            blink_speed_ms >>= 1;
            if (blink_speed_ms <= 50) {
                blink_speed_ms = 1000;
            }
        }

        // start and wait for adc to convert...
        ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_192Cycles);
        ADC_SoftwareStartConv(ADC1);
        while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0)
            ;

        uint16_t pot_val = ADC_GetConversionValue(ADC1);
        if (pot_val > 0x700) {
            GPIO_HIGH(GPIOA, GPIO_Pin_4);
        } else {
            GPIO_LOW(GPIOA, GPIO_Pin_4);
        }
    }
}
Exemple #12
0
/**
  * @brief this function checks if a NDEF message is available in the M24LR04E-R EEPROM
	* @par PayloadLength : the number of byte of the NDEF message
  * @retval SUCCESS : A NDEF message has been found
	* @retval ERROR :  a NDEF message doens't have been found
  */
static int8_t User_ReadNDEFMessage ( uint8_t *PayloadLength )			
{
uint8_t NthAttempt=0, 
				NbAttempt = 2;
				
	*PayloadLength = 0;
		
	for (NthAttempt = 0; NthAttempt < NbAttempt ; NthAttempt++)
	{
		M24LR04E_Init();
		// check if a NDEF message is available in the M24LR04 EEPROM					
		if (User_CheckNDEFMessage() == SUCCESS)
		{
			User_GetPayloadLength(PayloadLength);
			if (PayloadLength !=0x00)
			{
				(*PayloadLength) -=2;
				InitializeBuffer (NDEFmessage,(*PayloadLength)+10);
				User_GetNDEFMessage(*PayloadLength,NDEFmessage);
			
				I2C_Cmd(M24LR04E_I2C, DISABLE);			
				
				CLK_PeripheralClockConfig(CLK_Peripheral_I2C1, DISABLE);	
	
				GPIO_HIGH(M24LR04E_I2C_SCL_GPIO_PORT,M24LR04E_I2C_SCL_PIN);	
				GPIO_HIGH(M24LR04E_I2C_SCL_GPIO_PORT,M24LR04E_I2C_SDA_PIN);	
		
				ToUpperCase (*PayloadLength,NDEFmessage);
				
				return SUCCESS;
			}
		}
		
		M24LR04E_DeInit();
		I2C_Cmd(M24LR04E_I2C, DISABLE);
	}
	
	return ERROR;
}
Exemple #13
0
void gpio_write(int g, int v)
{
#ifndef GPIO_SIMULATED
  if (v != 0)
  {
    GPIO_HIGH(g);
  }
  else
  {
    GPIO_LOW(g);
  }
#else
  printf("gpio:write:%d=%d\n", g, v);
#endif
}
/*******************************************************************************
 * @brief  : Initialise the Adesto Data Flash.
 * @param  : Aucun.
 * @return : Rien.
 ******************************************************************************/
void LBF_BTLE_IOcfg(void)
{

GPIO_InitTypeDef GPIO_InitStruct;

// PC9 = BT_RST (active high)
// Std CMOS output, no pull-up/-down resistor, low speed
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL; 
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;  
  GPIO_InitStruct.Pin = BT_RST_PIN;
  HAL_GPIO_Init(BT_RST_PORT, &GPIO_InitStruct);


/* Initialise pin in high (active) state */
  GPIO_HIGH(BT_RST_PORT, BT_RST_PIN); // assert BTLE reset

}
/**
  * @brief  This function handles external interrupts generated by UserButton.
  * @param  None
  * @retval None
  */
void UserButtonHandler (void)
{ 
  uint32_t i=0;	
   
  /* set KeyPressed Flag */
  KeyPressed = TRUE;  
        
  /* check if user button is pressed for 4 seconds (approx.) */
    while ((USERBUTTON_GPIO_PORT->IDR & USERBUTTON_GPIO_PIN) == 1 )
    {
      i++;
      if (i == 0x0100000)
      {
        /* set autotest flag in E²prom*/
        AUTOTEST(TRUE) ; 
        return;
      }
    }
 
  /* if autotest is set in E²prom exit interrupt handler */  
  if (Auto_test)
    return ;
     
  /* Go to next state of state machine*/
    state_machine++;
    if (state_machine == MAX_STATE)
      state_machine = STATE_VREF;
          
    /* To update Bar graph & leds*/  
    switch (state_machine)
    {
      case STATE_VREF:
              GPIO_HIGH(LD_GPIO_PORT,LD_GREEN_GPIO_PIN);
              GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN);
              BAR0_OFF;
              BAR1_OFF;
              BAR2_OFF;
              BAR3_OFF;
              break;
              
      case STATE_SLIDER_VALUE:
             GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN);	
             GPIO_HIGH(LD_GPIO_PORT,LD_GREEN_GPIO_PIN);
             break;
              
      case STATE_SLIDER_BUTTON:
             GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN);	        
             GPIO_HIGH(LD_GPIO_PORT,LD_BLUE_GPIO_PIN);
             break;
          
      case STATE_ICC_RUN:
              GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN);	
              GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN);	        
              BAR0_ON;
              BAR1_OFF;
              BAR2_OFF;
              BAR3_OFF;
              break;
              
      case STATE_ICC_LP_RUN:
              GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN);	
              GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN);	
              BAR0_ON;
              BAR1_ON;
              BAR2_OFF;
              BAR3_OFF;
              break;

      case STATE_ICC_STOP:
              GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN);	
              GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN);	
              BAR0_ON;
              BAR1_ON;
              BAR2_ON;
              BAR3_OFF;
              break;              
      
      case STATE_ICC_STBY:
              GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN);	
              GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN);	
              BAR0_ON;
              BAR1_ON;
              BAR2_ON;
              BAR3_ON;
              break;					
    }	  
}
/**
  * @brief Current measurement in different MCU modes:
		RUN/HALT/LowPower withouto LCD/LowPower with LCD
	* @caller main and ADC_Icc_Test
  * @param MCU state
  * @retval ADC value.
  */
u16 ADC_Icc_Test(u8 Mcu_State)
{
  uint16_t res;
	uint8_t i;
	
/* Test MCU state for configuration */
  switch (Mcu_State)
  {
    /* test Run mode nothing to do */	
    case MCU_RUN:
      break;

    /* Low power mode */		
    case MCU_LPR:
      Halt_Init();
      sim();
      /* To prepare to start counter */
      GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  
      /* To configure Low Power */			
      LPR_init();
      break;

    /* Halt mode */
    case MCU_HALT:
      /* Init for Halt mode  */
      Halt_Init();
      sim();	
      
      /* To prepare to start counter */
      GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  
      /* Falling edge for start counter */		
      GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
      delay_10us(1);
      
      /* MCU in halt during measurement */	
      /* Wake up by Interrupt done counter Input Port E pin 6 */
      halt();
      break;
    
    case MCU_LPR_LCD:
      PWR->CSR2 = 0x2;
      sim();
      /* To configure GPIO for reduce current. */
      GPIO_LowPower_Config();

      /* To prepare to start counter */
      GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);

      /* To configure Low Power */
      LPR_init();
      break;		
  }
	
  sim();

/* re-start ADC chanel 24 for Current measurement */
  ADC_Icc_Init();	
	
/* Read ADC for current measurmeent */
/* initialize result */
  res = 0;

  for(i=8; i>0; i--)
  {
    /* start ADC convertion by software */
    ADC_SoftwareStartConv(ADC1);
    
    /* wait until end-of-covertion */
    while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 );
    
    /* read ADC convertion result */
    res += ADC_GetConversionValue(ADC1);
  }
	
  /* ICC_CNT_EN invalid */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
 
  GPIO_Init(BUTTON_GPIO_PORT, USER_GPIO_PIN,GPIO_Mode_In_FL_IT);

  rim();
	
/* Disable ADC 1 for reduce current */
  ADC_Cmd(ADC1, DISABLE);

  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);

  if (Mcu_State !=MCU_LPR_LCD)
  {
    CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);
    LCD_GLASS_Init();
  }

  return (res>>3);
}
Exemple #17
0
uint32 exModeMDIORead(uint32 reg){
	uint32 data = 0;
	uint8 i;
	uint8 Addr[32]={0};
	uint8 Data[32]={0};
	uint8 temp1[32]={0};
	//uint8 temp2[32]={0};
	uint8 mdio_signal_real[116*2] ={0};

	uint8 mdio_signal[116]={
		1,1,1,1,0,1,1,0,	//PRE  ST  OP
		1,1,				//ADDR 2bit
		1,0,1,1,1,1,1,1,
		1,0,1,1,0,1,0,1,
		0,0,0,0,1,0,0,0,
		0,0,0,0,0,0,0,0,	//ADDR  32bit  //0xbfb50800  //0xbfb50a00
		1,0, 				//TA
		0,0,0,0,0,0,0,1, 	//byte-enable  DATA 8bit

		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,

		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		1,0,1,1,0,1,0,0,	//byte-enable  DATA 64bit
	};

	uint8 mdc_signal[116*2+16]={
		1,0,1,0,1,0,1,0, 	//PRE  ST  OP
		1,0,				//ADDR 2bit
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,	//ADDR  32bit
		1,0, 				//TA
		1,0,1,0,1,0,1,0,	//byte-enable  DATA 8bit
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,	//byte-enable  DATA 64bit

		1,0,1,0,1,0,1,0, 	//PRE  ST  OP
		1,0,				//ADDR 2bit
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,	//ADDR  32bit
		1,0, 				//TA
		1,0,1,0,1,0,1,0,	//byte-enable  DATA 8bit
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,	//byte-enable  DATA 64bit

		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
	};
#ifdef DBG
	printk("%s(%d)Entry \n",__func__,__LINE__);
#endif

	if((reg>=0x7)&&(reg<=0xff))//contril register space
	{
		mdio_signal[8]=0;
		mdio_signal[9]=0;
	}
	else if(((reg&0xf)==0x0)||((reg&0xf)==0x8))  //high 32bit  addr bit[33:32] = 0x10
	{
		mdio_signal[8]=1;
		mdio_signal[9]=0;
		reg=reg-0xa0000000;//for 0xb4000000 ->0x14000000
	}
	else if(((reg&0xf)==0x4)||((reg&0xf)==0xc))//low 32bit  addr bit[33:32] = 0x01
	{
		mdio_signal[8]=0;
		mdio_signal[9]=1;
		reg=reg-0xa0000000;//for 0xb4000000 ->0x14000000
	}


	word2Bit(reg,temp1);


	for(i=0;i<32;i++)
	{
		Addr[i]=temp1[31-i];
	//	Data[i]=temp2[31-i];
		//printf("reg[%d]  = %d\r\n", i, Addr[i]);
		//printf("data[%d]  = %d\r\n", i, Data[i]);
	}

	for(i=10;i<42;i++)
	{
		mdio_signal[i]=Addr[i-10];

	}

	for (i=0;i<42;i++)
	{
		mdio_signal_real[i*2]=mdio_signal[i];
		mdio_signal_real[i*2+1]=mdio_signal[i];
		//printf("mdio_signal0[%d]  = %d\r\n", i, mdio_signal[i]);
	}

	HwGpioSetMode(MDIO_WRITE);//write
	//GPIO_HIGH(mdio_gpio);//let MDIO can be push by MDC
	//delayDmtSymbols(1);

	for (i=0;i<116*2+16;i++)
	{
		//printk("mdiod:%d ",mdio_signal_real[i]);
		//if(i % 10 == 0)
		//	printk("\n");
		if(i<42*2)
		{
			if (mdc_signal[i] ==0)
			{
				GPIO_LOW(mdc_gpio);
				//delayDmtSymbols(1);
			}
			else if (mdc_signal[i] ==1)
			{
				GPIO_HIGH(mdc_gpio);
				//delayDmtSymbols(1);
			}

			if (mdio_signal_real[i] ==0)
			{
				GPIO_LOW(mdio_gpio);
				//delayDmtSymbols(1);
			}
			else if (mdio_signal_real[i] ==1)
			{
				GPIO_HIGH(mdio_gpio);
				//delayDmtSymbols(1);
			}
		}
		else if (i==42*2)
		{
			if (mdc_signal[i] ==0)
			{
				GPIO_LOW(mdc_gpio);
				//delayDmtSymbols(1);
			}
			else if (mdc_signal[i] ==1)
			{
				GPIO_HIGH(mdc_gpio);
				//delayDmtSymbols(1);
			}

			//delayDmtSymbols(2);
			HwGpioSetMode(MDIO_READ);//read
		}
		else
		{
			//delayDmtSymbols(1);
			if (mdc_signal[i] ==0)
			{
				GPIO_LOW(mdc_gpio);
				//delayDmtSymbols(1);
			}
			else if (mdc_signal[i] ==1)
			{
				GPIO_HIGH(mdc_gpio);
				//delayDmtSymbols(1);
				if((i>42*2)&&(i<116*2+2))
				{
					mdio_signal_real[i-2] = GPIO_VALUE(mdio_gpio);
				}
			}

		}
	}

	for (i=0;i<116;i++)
	{
		mdio_signal[i]=mdio_signal_real[i*2];
		//printf("mdio_signal1[%d]  = %d\r\n", i, mdio_signal[i]);
	}
// get data from mdio_signal
	for(i=0;i<32;i++)
	{
		if((reg>=0x7)&&(reg<=0xff))//contril register space //data low 32bit
		{
			Data[i]=mdio_signal[i+84];
		}
		else if(((reg&0xf)==0x0)||((reg&0xf)==0x8))  //high 32bit  addr bit[33:32] = 0x10
		{
			Data[i]=mdio_signal[i+52];
		}
		else if(((reg&0xf)==0x4)||((reg&0xf)==0xc))//low 32bit  addr bit[33:32] = 0x01
		{
			Data[i]=mdio_signal[i+84];
		}
		//printf("Data[%d]  = %d\r\n", i, Data[i]);
	}
	data=bit2Word(Data);
#ifdef DBG
	printk("%s(%d)Exit \n",__func__,__LINE__);
#endif
	return data;

}
Exemple #18
0
void exModeMDIOWrite(uint32 reg, uint32 data){
	uint8 i;
	uint8 Addr[32]={0};
	uint8 Data[32]={0};
	uint8 temp1[32]={0};
	uint8 temp2[32]={0};
	//uint32 reg=0x8;
	//uint32 data=0xb;
	uint8 mdio_signal_real[116*2] ={0};
	uint8 mdio_signal[116]={
		1,1,1,1,0,1,0,1,	//PRE  ST  OP
		1,1,				//ADDR 2bit
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,1,1,1,	//ADDR  32bit  //0xbfb50800//0x7
		1,0,				//TA
		1,1,1,1,1,1,1,1,	//byte-enable  DATA 8bit

		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,

		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,	// DATA 64bit
	};

	uint8 mdc_signal[116*2+16]={
		1,0,1,0,1,0,1,0,	//PRE  ST  OP
		1,0,				//ADDR 2bit
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,	//ADDR  32bit
		1,0,				//TA
		1,0,1,0,1,0,1,0,	//byte-enable  DATA 8bit
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,	//byte-enable  DATA 64bit

		1,0,1,0,1,0,1,0,	//PRE  ST  OP
		1,0,				//ADDR 2bit
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,	//ADDR  32bit
		1,0,				//TA
		1,0,1,0,1,0,1,0,	//byte-enable  DATA 8bit
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,	//byte-enable  DATA 64bit

		1,0,1,0,1,0,1,0,
		1,0,1,0,1,0,1,0,
	};
#ifdef DBG
	printk("%s(%d)Entry \n",__func__,__LINE__);
#endif
	if((reg<0x7)||(reg>0xff)){
	reg=reg-0xa0000000;//for 0xb4000000 ->0x14000000
	}
	word2Bit(reg,temp1);
	word2Bit(data,temp2);

	for(i=0;i<32;i++)
	{
		Addr[i]=temp1[31-i];
		Data[i]=temp2[31-i];
		//printf("reg[%d]  = %d\r\n", i, Addr[i]);
		//printf("data[%d]  = %d\r\n", i, Data[i]);
	}

	if((reg>=0x7)&&(reg<=0xff))//contril register space
	{
		mdio_signal[8]=0;
		mdio_signal[9]=0;

		for (i=84;i<116;i++) //Data
		{
			mdio_signal[i]=Data[i-84];
		}
	}
	else if(((reg&0xf)==0x0)||((reg&0xf)==0x8))
	{
		mdio_signal[8]=1;//high 32bit  addr bit[33:32] = 0x10
		mdio_signal[9]=0;

		mdio_signal[44]=1;//byte-enable  DATA 8bit
		mdio_signal[45]=1;
		mdio_signal[46]=1;
		mdio_signal[47]=1;
		mdio_signal[48]=0;
		mdio_signal[49]=0;
		mdio_signal[50]=0;
		mdio_signal[51]=0;

		for (i=52;i<84;i++) //Data
		{
			mdio_signal[i]=Data[i-52];
		}


	}
	else if(((reg&0xf)==0x4)||((reg&0xf)==0xc))
	{
		mdio_signal[8]=0;//low 32bit  addr bit[33:32] = 0x01
		mdio_signal[9]=1;

		mdio_signal[44]=0;//byte-enable  DATA 8bit
		mdio_signal[45]=0;
		mdio_signal[46]=0;
		mdio_signal[47]=0;
		mdio_signal[48]=1;
		mdio_signal[49]=1;
		mdio_signal[50]=1;
		mdio_signal[51]=1;

		for (i=84;i<116;i++) //Data
		{
			mdio_signal[i]=Data[i-84];
		}
	}



	for(i=10;i<42;i++)
	{
		mdio_signal[i]=Addr[i-10];

	}

	for (i=0;i<116;i++)
	{
		mdio_signal_real[i*2]=mdio_signal[i];
		mdio_signal_real[i*2+1]=mdio_signal[i];
		//printf("mdio_signal[%d]  = %d\r\n", i, mdio_signal[i]);
	}

	HwGpioSetMode(MDIO_WRITE);//write

	//GPIO_HIGH(mdio_gpio);//let MDIO can be push by MDC
	//delayDmtSymbols(1);

	for (i=0;i<116*2+16;i++)
	{
		if (mdc_signal[i] ==0)
		{
			GPIO_LOW(mdc_gpio);
			//delayDmtSymbols(1);
		}
		else if (mdc_signal[i] ==1)
		{
			GPIO_HIGH(mdc_gpio);
			//delayDmtSymbols(1);
		}

		if(i<116*2)
		{
			if (mdio_signal_real[i] ==0)
			{
				GPIO_LOW(mdio_gpio);
				//delayDmtSymbols(1);
			}
			else if (mdio_signal_real[i] ==1)
			{
				GPIO_HIGH(mdio_gpio);
				//delayDmtSymbols(1);
			}
		}
	}
#ifdef DBG
	printk("%s(%d)Exit \n",__func__,__LINE__);
#endif
}
//.....................................................................
//const unsigned char Sys_Flash_Control_Bit = 0xff;
//__root __no_init volatile unsigned char Sys_Flash_Control_Bit @0x91e6;
//__root __no_init volatile unsigned char Sys_Flash_Control_Bit;
//volatile unsigned char Sys_Flash_Control_Bit = 0xff;
//==============================================================================
// Private functions
//==============================================================================
unsigned int FirstInitial_Func(void){

    //G_BAR_CODE_ID_Array[0] = ParsingFileName[0];
    _DUI_System_Init_And_Clk_Setup();

    //_DUI_BootloaderCheck_To_Disable();
    //_DUI_ReadOutProtection_Check_To_Enable();

//  GPIO_Init(GPIOA, GPIO_Pin_All ,GPIO_Mode_In_FL_No_IT);
//  GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_In_FL_No_IT);
//  GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_In_FL_No_IT);
//  GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_In_FL_No_IT);
//  GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_In_FL_No_IT);
//  GPIO_Init(GPIOF, GPIO_Pin_All,GPIO_Mode_In_FL_No_IT);
//

//    _DUI_delay_cycles(5000);    //5000 = 52ms at CCLK=4MHz.
//    _DUI_delay_cycles(500);     //500 = 5ms at CCLK=4MHz.
//    _DUI_delay_cycles(200);     //200 = 2ms at CCLK=4MHz.
//    _DUI_delay_cycles(100);     //100 = 1ms at CCLK=2MHz.
//
//    _DUI_delay_cycles(10000);   //10000 = 53ms at CCLK=8MHz.
//    _DUI_delay_cycles(1000);    //1000 = 5.38ms at CCLK=8MHz.
//    _DUI_delay_cycles(500);     //500 = 2.6ms at CCLK=8MHz.
//    _DUI_delay_cycles(100);     //100 = 550us at CCLK=8MHz.


#if(_LED_Control_Reverse_With_Lo_LEVEL_Turn_ON_ == 1)
    if(System_Control_Bit_EEPROM & SYS_UPDATED_FW){
        GPIO_Init(LED1_PORT, LED1_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
        GPIO_Init(LED3_PORT, LED3_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
        GPIO_LOW(LED1_PORT, LED1_PIN);
        GPIO_LOW(LED3_PORT, LED3_PIN);
        ((void(*)())Bootloader_After_ROP_Check_Address)();  //jump to the address directly
    }

//    if((Sys_Flash_Control_Bit & SYS_Ready_UPDATED_FW_Mask_Bit) == 0){
//        GPIO_Init(LED1_PORT, LED1_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
//        GPIO_Init(LED3_PORT, LED3_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
//        GPIO_LOW(LED1_PORT, LED1_PIN);
//        GPIO_LOW(LED3_PORT, LED3_PIN);
//        ((void(*)())Bootloader_After_ROP_Check_Address)();  //jump to the address directly
//    }
#else
    if(System_Control_Bit_EEPROM & SYS_UPDATED_FW){
        GPIO_Init(LED1_PORT, LED1_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
        GPIO_Init(LED3_PORT, LED3_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
        GPIO_HIGH(LED1_PORT, LED1_PIN);
        GPIO_HIGH(LED3_PORT, LED3_PIN);
        ((void(*)())Bootloader_After_ROP_Check_Address)();  //jump to the address directly
    }
//    if((Sys_Flash_Control_Bit & SYS_Ready_UPDATED_FW_Mask_Bit) == 0){
//        GPIO_Init(LED1_PORT, LED1_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
//        GPIO_Init(LED3_PORT, LED3_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
//        GPIO_HIGH(LED1_PORT, LED1_PIN);
//        GPIO_HIGH(LED3_PORT, LED3_PIN);
//        ((void(*)())Bootloader_After_ROP_Check_Address)();  //jump to the address directly
//    }
#endif
    _DUI_GPIO_LowPower_Config();
//    while(1){
//        wfi();
//    }
    _DUI_InitLEDDisplay();

    return StartUp;
}
/*******************************************************************************
* Function Name  : Red_Led_ON
* Description    : Switched Red LED On.
* Return         : None.
*******************************************************************************/
void Red_Led_ON(void)
{
    GPIO_HIGH(LED_RED_PORT, LED_RED_PIN);
}
/*******************************************************************************
 * @brief  : Enable generation of VDDH (14V) to OLED on the board 
 * @param  : none.
 * @return : none.
 ******************************************************************************/
void Turn_VDDH_On (void)
{
    GPIO_HIGH(VDDH_EN_PORT, VDDH_EN_PIN);
    VDDH_On = TRUE;
}
Exemple #22
0
void mrf_deselect(void) {
    delay_us(15);
    GPIO_HIGH(PORT_MRF_CHIPSELECT, PIN_MRF_CHIPSELECT);
    delay_us(15);
}
Exemple #23
0
static inline void switch_leds_on(void)
{
    GPIO_HIGH(GPIOB, LED_GREEN);
    GPIO_HIGH(GPIOB, LED_BLUE);
}
Exemple #24
0
/**
  * @brief Current measurement in different MCU modes:
  * RUN/SLEEP/LowPower/STANDBY with/without RTC
  * @caller main and ADC_Icc_Test
  * @param MCU state
  * @retval ADC value.
  */
uint16_t ADC_Icc_Test(uint8_t Mcu_State)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  uint16_t adc_measure;
  uint32_t i;
  RCC_TypeDef SavRCC;
  /* Reset UserButton State */
  UserButton = FALSE;
  /* Start counter */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  /* Disable the RTC Wakeup Interrupt */
  RTC_ITConfig(RTC_IT_WUT, DISABLE);
  /* Disable LCD */
  LCD_Cmd(DISABLE);
  /* wait until LCD disable */
  while (LCD_GetFlagStatus(LCD_FLAG_ENS) == SET);
  /*Reset Idd-WakeUP flag*/
  Idd_WakeUP = FALSE;
  /* Set IO in lowpower configuration*/
  GPIO_LowPower_Config(); 
  /*Disable fast wakeUp*/
  PWR_FastWakeUpCmd(DISABLE);
  
/* Test MCU state for configuration */
  switch (Mcu_State)
  {
    /* Run mode : Measurement Measurement performed with MSI 4 MHz without RTC*/	
    case MCU_RUN:
        /* switch on MSI clock */
        SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ;   
        /* shitch on MSI clock */
        Config_RCC(&SavRCC);    
        SysTick->CTRL = 0;     
        RCC->APB1ENR = 0;

        /* To run nops during measurement:
        it's the best case for low current */     

        for (i=0;i<0xffff;i++) {
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
        }
        
    break;

    /* SLEEP mode : Measurement performed with MSI 4 MHz without RTC in WFI mode*/
    case MCU_SLEEP:
         
        SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ;   
        Config_RCC(&SavRCC);  
        Config_Systick_50ms();
        Delay(1);

       /* Request Wait For Interrupt */
        PWR_EnterSleepMode(PWR_Regulator_ON,PWR_SLEEPEntry_WFI);   
           
        break;    

   /* RUN LOW POWER mode :   Measurement performed with MSI 32 Khz without RTC */
    case MCU_LP_RUN:
      
        /* Disable PVD */
        PWR_PVDCmd(DISABLE);

        /* Enable The ultra Low Power Mode */
        PWR_UltraLowPowerCmd(ENABLE);         

        /* Save the RCC configuration registers */
        Config_RCC(&SavRCC);      
        
        /* Stop the sys tick in order to avoid IT */
        SysTick->CTRL = 0; 
        
#ifdef TESTINRAM        
        SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; 
        
        PWR_EnterLowPowerRunMode(ENABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ;  

        DisableInterrupts();
        EnterLPRUNModeRAM();
        EnableInterrupts();        
#else         
        /* Swith in MSI 32KHz */
        SetHSICLKToMSI(RCC_MSIRange_64KHz,DIV2,NoRTC) ;    
                
        PWR_EnterLowPowerRunMode(ENABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ;              
        
        /* Launch the counter */
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);           
           
        /* To run the nop during measurement:
        it's the best case for low current
        until counter reach detected by IT --> Idd_WakeUP */
        do{
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP(); 
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();  
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP(); 
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();            
        }  while (Idd_WakeUP == FALSE );       
#endif        
        
        PWR_EnterLowPowerRunMode(DISABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET) ;  
    
        break; 
      
      /* SLEEP LOW POWER mode
         Measurement done to MSI 32 Khz without RTC
      */	
      case MCU_LP_SLEEP:
        
        /* Disable PVD */
        PWR_PVDCmd(DISABLE);   
        
        /* Enable Ultra low power mode */
        PWR_UltraLowPowerCmd(ENABLE);

                
        /* To save the RCC configuration registers */
        Config_RCC(&SavRCC);     
        
        /* To stop the sys tick for avoid IT */
        SysTick->CTRL = 0; 
        
        /* Swith in MSI 32KHz */
        SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;

#ifdef TESTINRAM
        DisableInterrupts();
        EnterLPSLEEPModeRAM();
        EnableInterrupts();
#else        
        /* Falling edge for start counter */		
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);

        /* Request Wait For Interrupt */    
        PWR_EnterSleepMode(PWR_Regulator_LowPower,PWR_SLEEPEntry_WFI);
#endif              
        break;   
        
      /* STOP modes
       Measurement done to MSI 32 Khz without or with RTC
       */		
      case MCU_STOP_NoRTC:
      case MCU_STOP_RTC:

        /* Disable PVD */
        PWR_PVDCmd(DISABLE);
          
        /* Enable Ultra low power mode */
        PWR_UltraLowPowerCmd(ENABLE);           
        
        /* To save the RCC configuration registers */
        Config_RCC(&SavRCC);  

        /* To stop the sys tick for avoid IT */
        SysTick->CTRL = 0; 
               
       /* Swith in MSI 32KHz */
        if( Mcu_State == MCU_STOP_NoRTC )
          SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;
        else
         SetHSICLKToMSI(RCC_MSIRange_0,DIV2,WITHRTC) ;          

        /* Falling edge for start counter */		
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
        
        /* Request Wait For Interrupt */    
        PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);              

        break;        
          
        /* Standby mode without RTC
          Measurement done to MSI 32 Khz without RTC
        */
        case MCU_STBY:
          
          /* Disable PVD */
          PWR_PVDCmd(DISABLE);
          
          /* Enable Ultra low power mode */
          PWR_UltraLowPowerCmd(ENABLE);
          
          RTC_OutputTypeConfig(RTC_OutputType_PushPull);
          RTC_OutputConfig(RTC_Output_WakeUp,RTC_OutputPolarity_High);        
          
          /* To configure PC13 WakeUP output */
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13  ;
          //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  ;
          GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
          GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz;  
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
          GPIO_Init( GPIOC, &GPIO_InitStructure); 
         // GPIO_Init( GPIOA, &GPIO_InitStructure);
          
         GPIO_PinAFConfig(GPIOC, GPIO_PinSource13,GPIO_AF_RTC_AF1) ;
          //GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,GPIO_AF_RTC_AF1) ;
          Config_RCC(&SavRCC);  
          
          SysTick->CTRL = 0; 
                  
          /* Swith in MSI 32KHz */
          SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;     
          
          PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE);
          
          PWR_UltraLowPowerCmd(ENABLE); 
          
           PWR_EnterSTANDBYMode();
          /* Stop here WakeUp EXIT on RESET */
        
        break;
      }
  
  SetHSICLK();  

  Config_Systick(); 
  RCC->AHBENR = SavRCC.AHBENR;	
         
  PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
  /* Wait Until the Voltage Regulator is ready */
  while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

   /* Read ADC for current measurmeent */
   adc_measure = Current_Measurement();
    
  /* ICC_CNT_EN Hi */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  UserButton = TRUE;

  /* To restore RCC registers */
  RCC->APB1ENR = SavRCC.APB1ENR;
  RCC->APB2ENR = SavRCC.APB2ENR; 
  RCC->AHBLPENR = SavRCC.AHBLPENR;	
  RCC->APB1LPENR = SavRCC.APB1LPENR;
  RCC->APB2LPENR = SavRCC.APB2LPENR;
  
  /* Need to reinit RCC for LCD*/
  RCC_Configuration();

  PWR_EnterLowPowerRunMode(DISABLE);
  
  /* Disable Ultra low power mode */
  PWR_UltraLowPowerCmd(DISABLE);
  
  /* Disable FLASH during SLeep LP */
  FLASH_SLEEPPowerDownCmd(DISABLE);
  
  Restore_GPIO_Config();  
 
  /* Clear Wake Up flag */
  PWR_ClearFlag(PWR_FLAG_WU);
  
  /* Enable PVD */
  PWR_PVDCmd(ENABLE);

  LCD_GLASS_Init();
   
  return (adc_measure);
}
Exemple #25
0
Fichier : lcd.c Projet : alepnm/lcd
// инициализируем дисплей
void Init_LCD(void)
  {
    GPIO_InitTypeDef GPIO_InitStructure;                 // структура инициализации

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

    GPIO_InitStructure.GPIO_Pin = LCD_RST;            // настраиваем только некоторые выводы порта
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;    // частота работы порта
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;        // режим - выход
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;       // пуш-пулл
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;     // без подтягивающих резисторов
    GPIO_Init(GPIOC, &GPIO_InitStructure);               // запуск настройки
    
    // управляющие выводы дисплея
    GPIO_LOW(LCD_PORT, LCD_RST);     // лог.0 на вывод RESET
    _delay_ms(50);
    // начинаем инициализацию LCD
    GPIO_HIGH(LCD_PORT, LCD_RST);    // лог.1 на вывод RESET
    _delay_ms(50);
    LCD_write_comand (0x01); // software reset comand
    _delay_ms(5);
    LCD_write_comand (0x28); // display off
    //------------power control------------------------------
    LCD_write_comand (0xc0); // power control
    LCD_write_data   (0x26); // GVDD = 4.75v
    LCD_write_comand (0xc1); // power control
    LCD_write_data   (0x11); // AVDD=VCIx2, VGH=VCIx7, VGL=-VCIx3
    //--------------VCOM-------------------------------------
    LCD_write_comand (0xc5); // vcom control
    LCD_write_data   (0x35); // Set the VCOMH voltage (0x35 = 4.025v)
    LCD_write_data   (0x3e); // Set the VCOML voltage (0x3E = -0.950v)
    LCD_write_comand (0xc7); // vcom control
    LCD_write_data   (0xbe); // 0x94 (0xBE = nVM: 1, VCOMH: VMH–2, VCOML: VML–2)
    //------------memory access control------------------------
    LCD_write_comand (0x36); // memory access control
    LCD_write_data   (0x48); // 0048 my,mx,mv,ml,BGR,mh,0.0 (mirrors)
    LCD_write_comand (0x3a); // pixel format set
    LCD_write_data   (0x55); // 16bit /pixel
    //-------------ddram ----------------------------
    LCD_write_comand (0x2a); // column set
    LCD_write_data   (0x00); // x0_HIGH---0
    LCD_write_data   (0x00); // x0_LOW----0
    LCD_write_data   (0x00); // x1_HIGH---240
    LCD_write_data   (0xEF); // x1_LOW----240
    LCD_write_comand (0x2b); // page address set
    LCD_write_data   (0x00); // y0_HIGH---0
    LCD_write_data   (0x00); // y0_LOW----0
    LCD_write_data   (0x01); // y1_HIGH---320
    LCD_write_data   (0x3F); // y1_LOW----320
    LCD_write_comand (0x34); // tearing effect off
    //LCD_write_cmd(0x35); // tearing effect on
    //LCD_write_cmd(0xb4); // display inversion
    LCD_write_comand (0xb7); // entry mode set
    // Deep Standby Mode: OFF
    // Set the output level of gate driver G1~G320: Normal display
    // Low voltage detection: Disable
    LCD_write_data   (0x07); 
    //-----------------display------------------------
    LCD_write_comand (0xb6); // display function control
    //Set the scan mode in non-display area
    //Determine source/VCOM output in a non-display area in the partial display mode
    LCD_write_data   (0x0a);
    //Select whether the liquid crystal type is normally white type or normally black type
    //Sets the direction of scan by the gate driver in the range determined by SCN and NL
    //Select the shift direction of outputs from the source driver
    //Sets the gate driver pin arrangement in combination with the GS bit to select the optimal scan mode for the module
    //Specify the scan cycle interval of gate driver in non-display area when PTG to select interval scan
    LCD_write_data   (0x82);
    // Sets the number of lines to drive the LCD at an interval of 8 lines
    LCD_write_data   (0x27); 
    LCD_write_data   (0x00); // clock divisor
    LCD_write_comand (0x11); // sleep out
    _delay_ms(100);
    LCD_write_comand (0x29); // display on
    _delay_ms(100);
    LCD_write_comand (0x2c); // memory write
    _delay_ms(5);
  }
/**
  * @brief  To initialize the I/O ports
  * @caller main
  * @param None
  * @retval None
  */
void  Init_GPIOs (void)
{
  /* GPIO, EXTI and NVIC Init structure declaration */
  GPIO_InitTypeDef GPIO_InitStructure;
  EXTI_InitTypeDef EXTI_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure User Button pin as input */
  GPIO_InitStructure.GPIO_Pin = USERBUTTON_GPIO_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_Init(USERBUTTON_GPIO_PORT, &GPIO_InitStructure);

  /* Select User Button pin as input source for EXTI Line */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);

  /* Configure EXT1 Line 0 in interrupt mode trigged on Rising edge */
  EXTI_InitStructure.EXTI_Line = EXTI_Line0 ;  // PA0 for User button AND IDD_WakeUP
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set EXTI0 Interrupt to the lowest priority */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn ;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Configure the LED_pin as output push-pull for LD3 & LD4 usage*/
  GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure);

  /* Force a low level on LEDs*/
  GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN);
  GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN);

/* Counter enable: GPIO set in output for enable the counter */
  GPIO_InitStructure.GPIO_Pin = CTN_CNTEN_GPIO_PIN;
  GPIO_Init( CTN_GPIO_PORT, &GPIO_InitStructure);

/* To prepare to start counter */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);

/* Configure Port A LCD Output pins as alternate function */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_8 | GPIO_Pin_9 |GPIO_Pin_10 |GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init( GPIOA, &GPIO_InitStructure);

/* Select LCD alternate function for Port A LCD Output pins */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource1,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource3,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource8,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource15,GPIO_AF_LCD) ;

  /* Configure Port B LCD Output pins as alternate function */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 \
                                 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init( GPIOB, &GPIO_InitStructure);

  /* Select LCD alternate function for Port B LCD Output pins */
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource3,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource4,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource5,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource8,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource9,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource12,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource13,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource14,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource15,GPIO_AF_LCD) ;

  /* Configure Port C LCD Output pins as alternate function */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 \
                                 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |GPIO_Pin_11 ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init( GPIOC, &GPIO_InitStructure);

  /* Select LCD alternate function for Port B LCD Output pins */
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource0,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource1,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource2,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource3,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource6,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource7,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource8,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource9,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource10,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11,GPIO_AF_LCD) ;

  /* Configure ADC (IDD_MEASURE) pin as Analogue */
  GPIO_InitStructure.GPIO_Pin = IDD_MEASURE  ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_Init( IDD_MEASURE_PORT, &GPIO_InitStructure);
}
Exemple #27
0
/**
  * @brief  To initialize the I/O ports
  * @caller main
  * @param None
  * @retval None
  */
void  Init_GPIOs (void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  /* USER button and WakeUP button init: GPIO set in input interrupt active mode */
  EXTI_InitTypeDef EXTI_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure User Button pin as input */
  GPIO_InitStructure.GPIO_Pin = USER_GPIO_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_Init(BUTTON_GPIO_PORT, &GPIO_InitStructure);

  /* Connect Button EXTI Line to Button GPIO Pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);

  /* Configure User Button and IDD_WakeUP EXTI line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line0 ;  // PA0 for User button AND IDD_WakeUP
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set User Button and IDD_WakeUP EXTI Interrupt to the lowest priority */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn ;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure); 

/* Configure the GPIO_LED pins  LD3 & LD4*/
  GPIO_InitStructure.GPIO_Pin = LD_GREEN|LD_BLUE;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_Init(LD_PORT, &GPIO_InitStructure);
  GPIO_LOW(LD_PORT,LD_GREEN);	
  GPIO_LOW(LD_PORT,LD_BLUE);
    
/* Counter enable: GPIO set in output for enable the counter */
  GPIO_InitStructure.GPIO_Pin = CTN_CNTEN_GPIO_PIN;
  GPIO_Init( CTN_GPIO_PORT, &GPIO_InitStructure);
  
/* To prepare to start counter */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
      
/* Configure Output for LCD */
/* Port A */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_8 | GPIO_Pin_9 |GPIO_Pin_10 |GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init( GPIOA, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource1,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource3,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource8,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource15,GPIO_AF_LCD) ;  
  
/* Configure Output for LCD */
/* Port B */  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 \
                                 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init( GPIOB, &GPIO_InitStructure);
  
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource3,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource4,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource5,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource8,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource9,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_LCD) ;  
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource12,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource13,GPIO_AF_LCD) ;   
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource14,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource15,GPIO_AF_LCD) ;   
  
/* Configure Output for LCD */
/* Port C*/  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 \
                                 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |GPIO_Pin_11 ;                               
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init( GPIOC, &GPIO_InitStructure);  
  

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource0,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource1,GPIO_AF_LCD) ; 
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource2,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource3,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource6,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource7,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource8,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource9,GPIO_AF_LCD) ;
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource10,GPIO_AF_LCD) ; 
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11,GPIO_AF_LCD) ;  
  
/* ADC input */
  GPIO_InitStructure.GPIO_Pin = IDD_MEASURE  ;                               
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_Init( IDD_MEASURE_PORT, &GPIO_InitStructure);

}  
/*******************************************************************************
* Function Name  : Green_Led_ON
* Description    : Switched Green LED On.
* Return         : None.
*******************************************************************************/
void Green_Led_ON(void)
{
    GPIO_HIGH(LED_GREEN_PORT, LED_GREEN_PIN);
}