Пример #1
0
/*************************************************************************
 * Function Name: GLCD_LLInit
 * Parameters: none
 * Return: none
 *
 * Description: Init Reset and Backlight control outputs
 *
 *************************************************************************/
void GLCD_LLInit (void)
{
	// LCD Reset output
  LCD_RST_FDIR |= LCD_RST_MASK;

  GLCD_SetReset(0);

	// LCD backlight PWM 8bit init
  LCD_BL_PIN_SEL = 3;       // assign P3.26 to PWM1
  PCONP_bit.PCPWM1 = 1;     // enable clock of PWM1
  PWM1TCR_bit.PWMEN = 0;    // enable PWM function
  PWM1TCR_bit.CE = 0;       // disable counting
  PWM1TCR_bit.CR = 1;       // reset
  PWM1CTCR_bit.CM = 0;      // from prescaler
  PWM1MCR = 2;              // Reset on PWMMR0
  PWM1PCR_bit.PWMSEL3 = 0;  // Selects single edge controlled mode for PWM6
  PWM1PCR_bit.PWMENA3 = 1;  // The PWM3 output enabled
  PWM1PR = 0;
  PWM1MR0 = 0xFF;           // 8bit resolution
  PWM1LER_bit.EM0L = 1;
  PWM1MR3 = 0;
  PWM1LER_bit.EM3L = 1;
  PWM1TCR_bit.PWMEN = 1;    // enable PWM function
  PWM1TCR_bit.CR = 0;       // release reset
  PWM1TCR_bit.CE = 1;       // enable counting
  GLCD_Backlight(0);
}
Пример #2
0
/*******************************************************************************
* Function Name  : Menu_Init
* Description    : Initializes the navigation menu.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Menu_Init(void)
{
    DelayResolution100us(Dly);
    GLCD_PowerUpInit(0x0);
    GLCD_Backlight(BACKLIGHT_ON);
    GLCD_SetFont(&Terminal_9_12_6,0xF,0xFFF);
    psCurrentMenu = &MainMenu;
    psPrevMenu[nMenuLevel] = psCurrentMenu;
    psMenuItem = MainMenuItems;
}
Пример #3
0
void main(void)
{

    ENTR_CRT_SECTION();
    /* Setup STM32 system (clock, PLL and Flash configuration) */
    SystemInit();

    /* Set the Vector Table base location at 0x08000000 */
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

    // SysTick end of count event each 0.5s with input clock equal to 9MHz (HCLK/8, default)
    SysTick_Config(1500000);
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);

    // Step motor init
    StepMotorInit();
    // I2C1 init
    I2C1_Init();

    EXT_CRT_SECTION();

    // GLCD init
    GLCD_PowerUpInit((pInt8U)IAR_Logo.pPicStream); //(
    GLCD_Backlight(BACKLIGHT_ON);
    GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0);
    GLCD_SetWindow(10,104,131,131);

    // Init Accl sensor
    if(FALSE == Accl_Init())
    {
        // Initialization fault
        GLCD_TextSetPos(0,0);
        GLCD_print("\fLIS3LV020 Init.\r\nfault\r\n");
        while(1);
    }
    Car_Init();
    while(1)
    {
        A=position();
        /*   A = accX[1];
           B = velX[1];
           C = posX[1]; */

        if(SysTickFl) //
        {
            SysTickFl = FALSE;
            GLCD_TextSetPos(0,0);
            GLCD_print("\f%d Deg\r\n",A);
        }

        GoCar(Test, TestTurn);
    }
}
Пример #4
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
 int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */  
  /* Setup STM32 system (clock, PLL and Flash configuration) */
  SystemInit();
  
  /* GLCD init */
  GLCD_PowerUpInit((pInt8U)IAR_Logo.pPicStream);
  GLCD_Backlight(BACKLIGHT_ON);
  DelayResolution100us(5000);

  GLCD_PowerUpInit((pInt8U)STM32_Logo.pPicStream);
  GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0);
  GLCD_TextSetPos(4,6);
  GLCD_print("STM32F407ZG-SK");
  GLCD_Backlight(BACKLIGHT_ON);
  
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    
  /* Menu init */
  Menu_Init();
 
  Joystick_Init();
 
   
  DisplayMenu();
  
   
  /* Infinite loop */
  while (1)
  {
  }	
}
Пример #5
0
 void main(void)
{

  ENTR_CRT_SECTION();
  /* Setup STM32 system (clock, PLL and Flash configuration) */
  SystemInit();

  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
  


  // I2C1 init
  I2C1_Init();

  EXT_CRT_SECTION();

  // GLCD init
  GLCD_PowerUpInit(0x0); //(
  GLCD_Backlight(BACKLIGHT_ON);
  GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0);
  GLCD_SetWindow(10,10,131,131);

  // Init Accl sensor
  if(FALSE == Accl_Init())
  {
    // Initialization fault
    GLCD_TextSetPos(0,0);
    GLCD_print("\fLIS3LV020 Init.\r\nfault\r\n");
    while(1);
  }
    //Init CarControl and Delay
  Car_Init();
  DWT_Init();
  HCSR04_Init();
    // SysTick end of count event each 0.5s with input clock equal to 9MHz (HCLK/8, default)
  SysTick_Config(150000);
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);

  DWT_Delayms(1000);
  while(1)
  {

    //while(1){GLCD_print("Current state: %d \r",GPIO_ReadInputDataBit(JS_LEFT_PORT, JS_LEFT_MASK));} 
    //car_feedback=accl_feedback();
 /*   A = accX[1];
    B = velX[1];
    C = posX[1]; */
if(SysTickF1)
{
        SysTickF1 = FALSE;
        //GLCD_TextSetPos(0,0);
            GLCD_print("%d, %d \r", get_Xvel(), accl_feedback());
            DWT_Delayms(500);
            
}
    if(NewInstr) //
    {
      DWT_Delayms(1000);
      NewInstr = FALSE;
    
    //GoCar(Test, TestTurn);
    // 1. Give command (desired state)
    //desiredState;

    // 2. Run machine learning to test action
    action = goToState(car_instr);
    GoCars(action);
    //  testExp();
    int runTime = 0;
    while (runTime < 1){
        DWT_Delayms(700);
        runTime++;
    }
            GLCD_TextSetPos(0,0);
            GLCD_print("\f%d,%d;%d,%d\r\n", get_X_accFeedback(0), get_Y_accFeedback(0), get_X_vel(0), get_Y_vel(0));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(1), get_Y_accFeedback(1), get_X_vel(1), get_Y_vel(1));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(2), get_Y_accFeedback(2), get_X_vel(2), get_Y_vel(2));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(3), get_Y_accFeedback(3), get_X_vel(3), get_Y_vel(3));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(4), get_Y_accFeedback(4), get_X_vel(4), get_Y_vel(4));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(5), get_Y_accFeedback(5), get_X_vel(5), get_Y_vel(5));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(6), get_Y_accFeedback(6), get_X_vel(6), get_Y_vel(6));
      //      GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(7), get_Y_accFeedback(7), get_X_vel(7), get_Y_vel(7));
                car_instr=car_stop;
    GoCars(car_instr);
            DWT_Delayms(2000);
    }
    //GoCars(3); //Stopping the car
    
    
    // 3. Wait x ms
    //Wait in ML-method testAllActions
    
    // 4. Return value from accelerometer
    //Return value from accelerometer in ML-method testAllActions
    
    // 5. Evaluate action compared to state
    //Already implemented in ML-file. No need to alter (probably)
    
    // 6. Repeat 3-5 until all actions has been tested
    //Already implemented in ML-file. No need to alter (probably)
    
    // 7. Choose the correct state
    //Already implemented in ML-file. No need to alter (probably)
  }
}
Пример #6
0
/*************************************************************************
 * Function Name: GLCD_PowerUpInit
 * Parameters: pInt8U pInitData
 * Return: GLCD_Status_t
 *         GLCD_OK - init pass
 *         GLCD_ID_ERROR - unsupported driver type
 * Description: Power-up initialization of Graphic LCD
 *
 *************************************************************************/
GLCD_Status_t GLCD_PowerUpInit (pInt8U pInitData)
{
Int32U Data;
pDATCTR_Data_t pDATCTR_Data;
volatile Int32U i;
   
  // Init SPI and IO
  // Init low level
  GLCD_SPI_Init(GLCD_DEF_CLOCK,GLCD_DEF_WIDTH);
  GLCD_LLInit();
  GLCD_Backlight(BACKLIGHT_ON);
  // H/W Reset
  // Rest L > 10us H
  GLCD_SetReset(0);
  for(i = GLCD_DLY_10US; i ; --i);
  GLCD_SetReset(1);
  // Wait 5 ms
  //DelayResolution100us(GLCD_RESET_DLY);
  for(i = GLCD_DLY_10US * 100; i ; --i);
  // Identify LCD and command interpreter
  Glcd_Iss = GLCD_ISS_0;
  /*GLCD_SendCmd(RDDID,(pInt8U)&Data,0);
  if(((Data        & 0xFF) != GLCD_MANF_ID) ||
     (((Data >> 16)& 0xFF) != GLCD_MOD_ID))
  {
  	// Iss = 1 don't support RDDID command
  	Glcd_Iss = GLCD_ISS_1;
  }*/
  // Power Supply Set
  if(Glcd_Iss == GLCD_ISS_1)
  {
    // Support only 4K colors
    assert(GLCD_DEF_DPL_ML == 0);
	  //  DISCTR (Display Control)
	  //	 - F1/F2 switching period set
	  //	 - Line inversion set
	  Data = 0 | (0x20UL << 8) | (0x11UL << 16);
	  GLCD_SendCmd(DISCTR,(pInt8U)&Data,0);
	  //  OSCON (Oscillator ON)
	  GLCD_SendCmd(OSCON,NULL,0);
    // Set contrast
    Data = 38 | (0x0UL << 8);
    GLCD_SendCmd(VOLCTR,(pInt8U)&Data,0);
  }
  else
  {
    // Set contrast
    Data = 0x3B;
    GLCD_SendCmd(SETCON,(pInt8U)&Data,0);
  }
  // SLPOUT (Sleep mode OFF & OSC/Booster On)
  GLCD_SendCmd(SLPOUT,NULL,0); // Sleep out
  if(Glcd_Iss == GLCD_ISS_0)
  {
    GLCD_SendCmd(BSTRON,NULL,0); // Booster voltage on
  }
  // Display Environment Set
  // Display inversion setting
  GLCD_SendCmd(GLCD_DEF_DPL_INV?INVON:INVOFF,NULL,0);
  // Display color scheme setting
  GLCD_SendCmd(GLCD_DEF_DPL_8_COLOR?IDMON:IDMOFF,NULL,0);
  // Display partial setting
  if(GLCD_DEF_DPL_PARTIAL_MODE)
  {
    GLCD_SendCmd(PTLOUT,NULL,0);
  }
  else
  {
#if GLCD_DEF_DPL_PARTIAL_MODE > 0
#error "PARTIAL_MODE not supported yet"
#endif // GLCD_DEF_DPL_PARTIAL_MODE > 0
  }
  // Memory Data Access Control
  Data = 0;
  pDATCTR_Data = (pDATCTR_Data_t)&Data;
  pDATCTR_Data->RGB = GLCD_DEF_DPL_RGB_ORD; // BGR / RGB order
  pDATCTR_Data->MY = GLCD_DEF_DPL_MY; 			// no mirror Y
  pDATCTR_Data->MX = GLCD_DEF_DPL_MX; 			// no mirror X
  pDATCTR_Data->MV = GLCD_DEF_DPL_V; 				// vertical RAM write in Y/X direction
  pDATCTR_Data->ML = GLCD_DEF_DPL_ML; 			// line address order (bottom to top) / (top to bottom)
  // support only 4k type A colored scheme
  GLCD_SendCmd(DATCTR,(pInt8U)&Data,0);
  // Display Data Write & Display On
  // COLUMN ADDRESS SET and PAGE ADDRESS SET
  Data = 0 | ((GLCD_HORIZONTAL_SIZE - 1)<<8);
  GLCD_SendCmd(RASET,(pInt8U)&Data,0);
  GLCD_SendCmd(CASET,(pInt8U)&Data,0);

  // Init display memory
  if(pInitData == NULL)
  {
    Data = DEF_BACKGND_COLOUR;
    for(i = 0; i < (GLCD_HORIZONTAL_SIZE * GLCD_VERTICAL_SIZE); ++i)
    {
		Data = 0xFFFFFFFF >> (i & 0x1F);
      LCD_WRITE_PIXEL(Data);
    }
    LCD_FLUSH_PIXELS();
  }
Пример #7
0
/*************************************************************************
 * Function Name: GLCD_LLInit
 * Parameters: none
 * Return: none
 *
 * Description: Init Reset and Backlight control outputs
 *
 *************************************************************************/
void GLCD_LLInit (void)
{
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;

  /* Enable GPIO clock and release reset*/
  RCC_AHB1PeriphClockCmd(LCD_RST_CLK | LCD_BL_CLK, ENABLE);
  RCC_AHB1PeriphResetCmd(LCD_RST_CLK | LCD_BL_CLK,DISABLE);

  /*LCD Reset pin init*/  
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_Pin = LCD_RST_MASK;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LCD_RST_PORT, &GPIO_InitStructure);

  GLCD_SetReset(0);

	/* LCD backlight Init*/ 
  // PWM DAC (TIM3/CH3)
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Pin = LCD_BL_MASK;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LCD_BL_PORT, &GPIO_InitStructure);

  GPIO_PinAFConfig(LCD_BL_PORT,LCD_BL_PIN_SOURCE,LCD_BL_PIN_AF);

  // Init PWM TIM3
  // Enable Timer3 clock and release reset
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3,DISABLE);

  TIM_InternalClockConfig(TIM3);

  // Time base configuration
  TIM_TimeBaseStructure.TIM_Prescaler = 140;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 0xFF; // 8 bit resolution
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);

  // Channel 4 Configuration in PWM mode
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0x00;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
  TIM_OC3Init(TIM3,&TIM_OCInitStructure);
  // Double buffered
  TIM_ARRPreloadConfig(TIM3,ENABLE);
  // TIM3 counter enable
  TIM_Cmd(TIM3,ENABLE);

  GLCD_Backlight(0);
}