/** * @brief Init the TS interface * @param None * @retval None */ void TSC_Init(void) { #if TOUCH_SCREEN_CAPABILITY /* Reset the STMPE811 using the serial communication interface */ IOE_Config(); #endif }
/** * @brief Initialise les ports utilisés par l'écran tactile et initialise les coefficients avec des valeurs par défaut. * @param none * @pre cette fonction doit être appelée avant tout appel à l'écran tactile. * @retval None */ void TS_Init(void) { /* Initiation bas niveau du STMPE811QTR */ IOE_Config(); ts_coeff = (TS_COEFF){-0.085,0.067,330,-18}; initialized = TRUE; }
/* * MAIN TASK */ int main(void) { //GPIO_InitTypeDef GPIO_InitStructure; SystemInit(); /*Initializes Erika related stuffs*/ EE_system_init(); SWatch_state.errorStatus = errorSig; SWatch_state.ModelData.prevZCSigState = &ZCSig; SWatch_state.ModelData.dwork = &DWork; /* init state machine */ SWatch_initialize(&SWatch_state, &Bplus, &Bminus, &Btime, &Btimer, &Balarm, &Bswatch, &Bstart, &Bstop, &hours, &minutes, &seconds, &tenths, &mode, &alarm_signal, &timer_exp); /*Initialize systick */ EE_systick_set_period(MILLISECONDS_TO_TICKS(1, SystemCoreClock)); EE_systick_enable_int(); EE_systick_start(); /* Initializes LCD and touchscreen */ IOE_Config(); /* Initialize the LCD */ STM32f4_Discovery_LCD_Init(); // LCD_Clear(White); /* Set the LCD Text size */ // LCD_SetFont(&Font8x12); // Lcd_Touch_Calibration(); InitTouch(-0.102, 0.0656, -335, 10); /* Draw the background */ DrawInit(MyWatchScr); LCD_SetTextColor(Black); LCD_SetBackColor(Black); LCD_DrawFullRect(10, 80, 240, 56); WPrint(&MyWatchScr[SEP1STR], ":"); WPrint(&MyWatchScr[SEP2STR], ":"); /* Program cyclic alarms which will fire after an initial offset, * and after that periodically * */ SetRelAlarm(AlarmTaskLCD, 10, 50); SetRelAlarm(AlarmTaskClock, 10, 100); /* Forever loop: background activities (if any) should go here */ for (;;) { } }
/** * @brief Resets the audio codec. It restores the default configuration of the * codec (this function shall be called before initializing the codec). * * @note This function calls an external driver function: The IO Expander driver. * * @param None. * @retval 0 if correct communication, else wrong communication */ static void Codec_Reset(void) { /* Configure the IO Expander (to use the Codec Reset pin mapped on the IOExpander) */ IOE_Config(); /* Power Down the codec */ IOE_WriteIOPin(AUDIO_RESET_PIN, BitReset); /* wait for a delay to insure registers erasing */ Delay(CODEC_RESET_DELAY); /* Power on the codec */ IOE_WriteIOPin(AUDIO_RESET_PIN, BitSet); }
/** * @brief Configure the IO Expander and the Touch Panel. * @param None * @retval None */ static void TP_Config(void) { /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Configure the IO Expander */ if (IOE_Config() == IOE_OK) { LCD_SetFont(&Font8x8); LCD_DisplayStringLine(LINE(32), (uint8_t*)" Touch Panel Paint "); LCD_DisplayStringLine(LINE(34), (uint8_t*)" Example "); LCD_SetTextColor(LCD_COLOR_BLUE2); LCD_DrawFullRect(5, 250, 30, 30); LCD_SetTextColor(LCD_COLOR_CYAN); LCD_DrawFullRect(40, 250, 30, 30); LCD_SetTextColor(LCD_COLOR_YELLOW); LCD_DrawFullRect(75, 250, 30, 30); LCD_SetTextColor(LCD_COLOR_RED); LCD_DrawFullRect(5, 288, 30, 30); LCD_SetTextColor(LCD_COLOR_BLUE); LCD_DrawFullRect(40, 288, 30, 30); LCD_SetTextColor(LCD_COLOR_GREEN); LCD_DrawFullRect(75, 288, 30, 30); LCD_SetTextColor(LCD_COLOR_MAGENTA); LCD_DrawFullRect(145, 288, 30, 30); LCD_SetTextColor(LCD_COLOR_BLACK); LCD_DrawFullRect(110, 288, 30, 30); LCD_DrawRect(180, 270, 48, 50); LCD_SetFont(&Font16x24); LCD_DisplayChar(LCD_LINE_12, 195, 0x43); LCD_DrawLine(0, 248, 240, LCD_DIR_HORIZONTAL); LCD_DrawLine(0, 284, 180, LCD_DIR_HORIZONTAL); LCD_DrawLine(1, 248, 71, LCD_DIR_VERTICAL); LCD_DrawLine(37, 248, 71, LCD_DIR_VERTICAL); LCD_DrawLine(72, 248, 71, LCD_DIR_VERTICAL); LCD_DrawLine(107, 248, 71, LCD_DIR_VERTICAL); LCD_DrawLine(142, 284, 36, LCD_DIR_VERTICAL); LCD_DrawLine(0, 319, 240, LCD_DIR_HORIZONTAL); } else { LCD_Clear(LCD_COLOR_RED); LCD_SetTextColor(LCD_COLOR_BLACK); LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)" IOE NOT OK "); LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)"Reset the board "); LCD_DisplayStringLine(LCD_LINE_8,(uint8_t*)"and try again "); } }
void prvInit() { //LCD init LCD_Init(); IOE_Config(); LTDC_Cmd( ENABLE ); LCD_LayerInit(); LCD_SetLayer( LCD_FOREGROUND_LAYER ); LCD_Clear( LCD_COLOR_BLACK ); LCD_SetTextColor( LCD_COLOR_WHITE ); //Button STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_GPIO ); //LED STM_EVAL_LEDInit( LED3 ); }
/* * Entry point of program execution */ int main( void ) { prvSetupHardware(); IOE_Config(); #ifdef CONFIG_ENABLE_PRINTER printQueue = xQueueCreate(128, 1); #endif setup_buttons(); initDisplay(); ipc_measure_init(); if(pdFALSE == ipc_init()) { ipc_watchdog_signal_error(0); } if(pdFALSE == task_measure_init()) { ipc_watchdog_signal_error(0); } #ifdef CONFIG_ENABLE_PRINTER xTaskCreate(printTask, "print", 100, NULL, 1, NULL); #endif xTaskCreate(task_controller, "Controller", 100, NULL, 1, NULL); xTaskCreate(task_watchdog, "Watchdog driver", 100, NULL, 1, NULL); xTaskCreate(task_input_gpio, "Input driver for GPIO", 100, NULL, 1, NULL); xTaskCreate(task_input_touch, "Input driver for touchscreen", 200, NULL, 1, NULL); xTaskCreate(task_display, "Display", 300, NULL, 1, NULL); xTaskCreate(task_measure_cmd, "ADC-driver: controller", 100, NULL, 1, NULL); xTaskCreate(task_measure, "ADC-driver: IRQ interface", 100, NULL, 1, NULL); vTaskStartScheduler(); ipc_watchdog_signal_error(0); while(1); }
/** * @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 files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Initialize LEDs mounted on EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Select the Button test mode (polling or interrupt) BUTTON_MODE in main.h */ STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE); STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE); /* Initialize the LCD */ LCD_Init(); /* Initialize the LCD Layers */ LCD_LayerInit(); /* Enable LCD display */ LCD_DisplayOn(); /* Set foreground layer */ LCD_SetLayer(LCD_FOREGROUND_LAYER); /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)" STM324x9I-EVAL "); LCD_DisplayStringLine(LCD_LINE_1, (uint8_t *)" Example on how to "); LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)" use the IO Expander "); /* Configure the IO Expander */ if (IOE_Config() == IOE_OK && IOE16_Config() == IOE16_OK) { LCD_DisplayStringLine(LCD_LINE_3, (uint8_t *)" IO Expander OK "); } else { LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"IO Expander FAILED "); LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)" Please Reset the "); LCD_DisplayStringLine(LCD_LINE_6, (uint8_t *)" board and start "); LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)" again "); while(1); } /* LEDs Control blocks */ LCD_SetTextColor(Blue); LCD_DrawRect(310, 180, 40, 60); LCD_SetTextColor(Red); LCD_DrawRect(230, 180, 40, 60); LCD_SetTextColor(Yellow); LCD_DrawRect(150, 180, 40, 60); LCD_SetTextColor(Green); LCD_DrawRect(70, 180, 40, 60); #ifdef IOE_INTERRUPT_MODE /* Configure motherboard interrupt source IO_EXP4 */ IOE16_IOPinConfig(IOE16_TS_IT,Direction_IN); IOE16_ITConfig(IOE16_TS_IT); /* Enable joystick interrupt */ IOE16_ITConfig(JOY_IO16_PINS); /* Enable the Touch Screen interrupt */ IOE_TSITConfig(); /* Read IOs state to let IO interrupt occur */ IOE16_I2C_ReadDeviceRegister(IOE16_REG_GPMR_LSB); IOE16_I2C_ReadDeviceRegister(IOE16_REG_GPMR_MSB); #endif /* IOE_INTERRUPT_MODE */ while(1) { #ifdef IOE_POLLING_MODE static JOY_State_TypeDef JoyState = JOY_NONE; static TS_STATE* TS_State; /* Get the Joystick State */ JoyState = IOE16_JoyStickGetState(); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); switch (JoyState) { case JOY_NONE: LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY: ---- "); break; case JOY_UP: LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY: UP "); break; case JOY_DOWN: LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY: DOWN "); break; case JOY_LEFT: LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY: LEFT "); break; case JOY_RIGHT: LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY: RIGHT "); break; case JOY_CENTER: LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY: CENTER "); break; default: LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"JOY: ERROR "); break; } /* Update the structure with the current position */ TS_State = IOE_TS_GetState(); if ((TS_State->TouchDetected) && (TS_State->Y < 92) && (TS_State->Y > 52)) { if ((TS_State->X > 60) && (TS_State->X < 120)) { LCD_SetTextColor(LCD_COLOR_GREEN); LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *)" LD1 "); STM_EVAL_LEDOn(LED1); } else if ((TS_State->X > 140) && (TS_State->X < 200)) { LCD_SetTextColor(LCD_COLOR_YELLOW); LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *)" LD2 "); STM_EVAL_LEDOn(LED2); } else if ((TS_State->X > 220) && (TS_State->X < 280)) { LCD_SetTextColor(LCD_COLOR_RED); LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *)" LD3 "); STM_EVAL_LEDOn(LED3); } else if ((TS_State->X > 300) && (TS_State->X < 360)) { LCD_SetTextColor(LCD_COLOR_BLUE); LCD_DisplayStringLine(LCD_LINE_10, (uint8_t *)" LD4 "); STM_EVAL_LEDOn(LED4); } } else { STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } #endif /* IOE_POLLING_MODE */ #ifdef BUTTON_POLLING_MODE /* Insert 10 ms delay */ Delay(1); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); if (STM_EVAL_PBGetState(BUTTON_TAMPER) == 0) { /* Toggle LD2 */ STM_EVAL_LEDToggle(LED2); LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"Pol: TAMPER/KEY Pressed "); } if (STM_EVAL_PBGetState(BUTTON_WAKEUP) != 0) { /* Toggle LD3 */ STM_EVAL_LEDToggle(LED3); LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"Pol: WAKEUP Pressed "); } #endif } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Initialize LEDs and push-buttons mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ #ifdef USE_STM3210C_EVAL STM3210C_LCD_Init(); #elif defined (USE_STM32100E_EVAL) STM32100E_LCD_Init(); #endif /* USE_STM3210C_EVAL */ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Display messages on the LCD */ LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); LCD_DisplayStringLine(Line2, MESSAGE3); /* Configure the IO Expander */ if (IOE_Config() == IOE_OK) { /* Display "IO Expander OK" on the LCD */ LCD_DisplayStringLine(Line4, " IO Expander OK "); } else { LCD_DisplayStringLine(Line4, "IO Expander FAILED "); LCD_DisplayStringLine(Line5, " Please Reset the "); LCD_DisplayStringLine(Line6, " board and start "); LCD_DisplayStringLine(Line7, " again "); while(1); } /* Draw a rectangle with the specifies parameters and Blue Color */ LCD_SetTextColor(Blue); LCD_DrawRect(180, 310, 40, 60); /* Draw a rectangle with the specifies parameters and Red Color */ LCD_SetTextColor(Red); LCD_DrawRect(180, 230, 40, 60); /* Draw a rectangle with the specifies parameters and Yellow Color */ LCD_SetTextColor(Yellow); LCD_DrawRect(180, 150, 40, 60); /* Draw a rectangle with the specifies parameters and Black Color */ LCD_SetTextColor(Black); LCD_DrawRect(180, 70, 40, 60); #ifdef IOE_INTERRUPT_MODE #ifdef USE_STM32100E_EVAL /* Enable the Touch Screen interrupts */ IOE_ITConfig(IOE_ITSRC_TSC); #else /* Enable the Touch Screen and Joystick interrupts */ IOE_ITConfig(IOE_ITSRC_JOYSTICK | IOE_ITSRC_TSC); #endif /* USE_STM32100E_EVAL */ #endif /* IOE_INTERRUPT_MODE */ /* Loop infinitely */ while(1) { #ifdef IOE_POLLING_MODE static TS_STATE* TS_State; #ifdef USE_STM3210C_EVAL static JOY_State_TypeDef JoyState = JOY_NONE; /* Get the Joytick State */ JoyState = IOE_JoyStickGetState(); switch (JoyState) { /* None Joystick has been selected */ case JOY_NONE: LCD_DisplayStringLine(Line5, "JOY: ---- "); break; case JOY_UP: LCD_DisplayStringLine(Line5, "JOY: UP "); break; case JOY_DOWN: LCD_DisplayStringLine(Line5, "JOY: DOWN "); break; case JOY_LEFT: LCD_DisplayStringLine(Line5, "JOY: LEFT "); break; case JOY_RIGHT: LCD_DisplayStringLine(Line5, "JOY: RIGHT "); break; case JOY_CENTER: LCD_DisplayStringLine(Line5, "JOY: CENTER "); break; default: LCD_DisplayStringLine(Line5, "JOY: ERROR "); break; } #endif /* USE_STM3210C_EVAL */ /* Update the structure with the current position of the Touch screen */ TS_State = IOE_TS_GetState(); if ((TS_State->TouchDetected) && (TS_State->Y < 220) && (TS_State->Y > 180)) { if ((TS_State->X > 10) && (TS_State->X < 70)) { /* Display LD4 on the LCD and turn on LED4 */ LCD_DisplayStringLine(Line6, " LD4 "); STM_EVAL_LEDOn(LED4); } else if ((TS_State->X > 90) && (TS_State->X < 150)) { /* Display LD3 on the LCD and turn on LED3 */ LCD_DisplayStringLine(Line6, " LD3 "); STM_EVAL_LEDOn(LED3); } else if ((TS_State->X > 170) && (TS_State->X < 230)) { /* Display LD2 on the LCD and turn on LED2 */ LCD_DisplayStringLine(Line6, " LD2 "); STM_EVAL_LEDOn(LED2); } else if ((TS_State->X > 250) && (TS_State->X < 310)) { /* Display LD1 on the LCD and turn on LED1 */ LCD_DisplayStringLine(Line6, " LD1 "); STM_EVAL_LEDOn(LED1); } } else { /* Turn off LED1..4 */ STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } #endif /* IOE_POLLING_MODE */ } }
/** * @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 */ /* USART configuration -----------------------------------------------------*/ USART_Config(); /* SysTick configuration ---------------------------------------------------*/ SysTickConfig(); /* LEDs configuration ------------------------------------------------------*/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* IO Expanderconfiguration ------------------------------------------------*/ #ifdef USART_TRANSMITTER_MODE TimeOut = USER_TIMEOUT; while ((IOE_Config() != IOE_OK) && (TimeOut != 0)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } #endif /* USART_TRANSMITTER_MODE */ while (1) { /******************************************************************************/ /* USART in Transmitter Mode */ /******************************************************************************/ #ifdef USART_TRANSMITTER_MODE /* Clear Buffers */ Fill_Buffer(CmdBuffer, 2); DMA_DeInit(USARTx_TX_DMA_STREAM); DMA_InitStructure.DMA_Channel = USARTx_TX_DMA_CHANNEL; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; /****************** USART will Transmit Specific Command ******************/ /* Prepare the DMA to transfer the transaction command (2bytes) from the memory to the USART */ DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)CmdBuffer; DMA_InitStructure.DMA_BufferSize = (uint16_t)2; DMA_Init(USARTx_TX_DMA_STREAM, &DMA_InitStructure); /* Prepare Command to be transmitted */ /* Waiting joystick pressed */ PressedButton = JOY_NONE; while (PressedButton == JOY_NONE) { PressedButton = IOE_JoyStickGetState(); } /* Waiting joystick released */ ReleasedButton = IOE_JoyStickGetState(); while ((PressedButton == ReleasedButton) && (ReleasedButton != JOY_NONE)) { ReleasedButton = IOE_JoyStickGetState(); } if(PressedButton != JOY_NONE) { /* For each joystick state correspond a command to be sent through USART */ switch (PressedButton) { /* JOY_RIGHT button pressed */ case JOY_RIGHT: CmdBuffer[0] = CMD_RIGHT; CmdBuffer[1] = CMD_RIGHT_SIZE; break; /* JOY_LEFT button pressed */ case JOY_LEFT: CmdBuffer[0] = CMD_LEFT; CmdBuffer[1] = CMD_LEFT_SIZE; break; /* JOY_UP button pressed */ case JOY_UP: CmdBuffer[0] = CMD_UP; CmdBuffer[1] = CMD_UP_SIZE; break; /* JOY_DOWN button pressed */ case JOY_DOWN: CmdBuffer[0] = CMD_DOWN; CmdBuffer[1] = CMD_DOWN_SIZE; break; /* JOY_SEL button pressed */ case JOY_SEL: CmdBuffer[0] = CMD_SEL; CmdBuffer[1] = CMD_SEL_SIZE; break; default: break; } /* Enable the USART DMA requests */ USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE); /* Clear the TC bit in the SR register by writing 0 to it */ USART_ClearFlag(USARTx, USART_FLAG_TC); /* Enable the DMA TX Stream, USART will start sending the command code (2bytes) */ DMA_Cmd(USARTx_TX_DMA_STREAM, ENABLE); /* Wait the USART DMA Tx transfer complete or time out */ TimeOut = USER_TIMEOUT; while ((DMA_GetFlagStatus(USARTx_TX_DMA_STREAM, USARTx_TX_DMA_FLAG_TCIF) == RESET)&&(TimeOut != 0)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } /* The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame’s end of transmission*/ TimeOut = USER_TIMEOUT; while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } /* Clear DMA Streams flags */ DMA_ClearFlag(USARTx_TX_DMA_STREAM, USARTx_TX_DMA_FLAG_HTIF | USARTx_TX_DMA_FLAG_TCIF); /* Disable the DMA Streams */ DMA_Cmd(USARTx_TX_DMA_STREAM, DISABLE); /* Disable the USART Tx DMA request */ USART_DMACmd(USARTx, USART_DMAReq_Tx, DISABLE); /******************* USART will Transmit Data Buffer ********************/ /* Prepare the DMA to transfer the transaction data (length defined by CmdBuffer[1] variable) from the memory to the USART */ DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)TxBuffer; DMA_InitStructure.DMA_BufferSize = (uint16_t)CmdBuffer[1]; DMA_Init(USARTx_TX_DMA_STREAM, &DMA_InitStructure); /* Enable the USART Tx DMA request */ USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE); /* Clear the TC bit in the SR register by writing 0 to it */ USART_ClearFlag(USARTx, USART_FLAG_TC); /* Enable DMA USART Tx Stream */ DMA_Cmd(USARTx_TX_DMA_STREAM, ENABLE); /* Wait the USART DMA Tx transfer complete or time out */ TimeOut = USER_TIMEOUT; while ((DMA_GetFlagStatus(USARTx_TX_DMA_STREAM, USARTx_TX_DMA_FLAG_TCIF) == RESET)&&(TimeOut != 0)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } /* The software must wait until TC=1, The TC flag remains cleared during all data transfers and it is set by hardware at the last frame’s end of transmission */ TimeOut = USER_TIMEOUT; while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } /* Clear all DMA Streams flags */ DMA_ClearFlag(USARTx_TX_DMA_STREAM, USARTx_TX_DMA_FLAG_HTIF | USARTx_TX_DMA_FLAG_TCIF); /* Disable the DMA Stream */ DMA_Cmd(USARTx_TX_DMA_STREAM, DISABLE); /* Disable the USART Tx DMA request */ USART_DMACmd(USARTx, USART_DMAReq_Tx, DISABLE); } #endif /* USART_TRANSMITTER_MODE */ /******************************************************************************/ /* USART in Receiver Mode */ /******************************************************************************/ #ifdef USART_RECEIVER_MODE /* Clear Buffers */ Fill_Buffer(RxBuffer, TXBUFFERSIZE); Fill_Buffer(CmdBuffer, 2); DMA_DeInit(USARTx_RX_DMA_STREAM); DMA_InitStructure.DMA_Channel = USARTx_RX_DMA_CHANNEL; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; /****************** USART will Receive Specific Command *******************/ /* Configure the DMA to receive 2 bytes (transaction command), in case of USART receiver */ DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)CmdBuffer; DMA_InitStructure.DMA_BufferSize = (uint16_t)2; DMA_Init(USARTx_RX_DMA_STREAM, &DMA_InitStructure); /* Enable the USART Rx DMA request */ USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE); /* Enable the DMA RX Stream */ DMA_Cmd(USARTx_RX_DMA_STREAM, ENABLE); /* Wait the USART DMA Rx transfer complete (to receive the transaction command) */ while (DMA_GetFlagStatus(USARTx_RX_DMA_STREAM, USARTx_RX_DMA_FLAG_TCIF) == RESET) { } /* Clear all DMA Streams flags */ DMA_ClearFlag(USARTx_RX_DMA_STREAM, USARTx_RX_DMA_FLAG_HTIF | USARTx_RX_DMA_FLAG_TCIF); /* Disable the DMA Rx Stream */ DMA_Cmd(USARTx_RX_DMA_STREAM, DISABLE); /* Disable the USART Rx DMA requests */ USART_DMACmd(USARTx, USART_DMAReq_Rx, DISABLE); /************* USART will receive the the transaction data ****************/ /* Transaction data (length defined by CmdBuffer[1] variable) */ DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)RxBuffer; DMA_InitStructure.DMA_BufferSize = (uint16_t)CmdBuffer[1]; DMA_Init(USARTx_RX_DMA_STREAM, &DMA_InitStructure); /* Enable the USART Rx DMA requests */ USART_DMACmd(USARTx, USART_DMAReq_Rx , ENABLE); /* Enable the DMA Stream */ DMA_Cmd(USARTx_RX_DMA_STREAM, ENABLE); /* Wait the USART DMA Rx transfer complete or time out */ TimeOut = USER_TIMEOUT; while ((DMA_GetFlagStatus(USARTx_RX_DMA_STREAM, USARTx_RX_DMA_FLAG_TCIF) == RESET)&&(TimeOut != 0)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } /* Clear all DMA Streams flags */ DMA_ClearFlag(USARTx_RX_DMA_STREAM, USARTx_RX_DMA_FLAG_HTIF | USARTx_RX_DMA_FLAG_TCIF); /* Disable the DMA Stream */ DMA_Cmd(USARTx_RX_DMA_STREAM, DISABLE); /* Disable the USART Rx DMA requests */ USART_DMACmd(USARTx, USART_DMAReq_Rx, DISABLE); switch (CmdBuffer[1]) { /* CMD_RIGHT command received */ case CMD_RIGHT_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_RIGHT_SIZE) != FAILED) { /* Turn ON LED2 and LED3 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); /* Turn OFF LED4 */ STM_EVAL_LEDOff(LED4); } break; /* CMD_LEFT command received */ case CMD_LEFT_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_LEFT_SIZE) != FAILED) { /* Turn ON LED4 */ STM_EVAL_LEDOn(LED4); /* Turn OFF LED2 and LED3 */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); } break; /* CMD_UP command received */ case CMD_UP_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_UP_SIZE) != FAILED) { /* Turn ON LED2 */ STM_EVAL_LEDOn(LED2); /* Turn OFF LED3 and LED4 */ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } break; /* CMD_DOWN command received */ case CMD_DOWN_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_DOWN_SIZE) != FAILED) { /* Turn ON LED3 */ STM_EVAL_LEDOn(LED3); /* Turn OFF LED2 and LED4 */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED4); } break; /* CMD_SEL command received */ case CMD_SEL_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_SEL_SIZE) != FAILED) { /* Turn ON all LED2, LED3 and LED4 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); } break; default: break; } #endif /* USART_RECEIVER_MODE */ } }
/******************************************************************************* * Function Name : CODEC_Config * Description : Configure the Codec in Headphone mode. * Input : - OutputDevice: OutputDeviceHEADPHONE or OutputDeviceSPEAKER * : - I2S_Standard: I2S communication standard could be I2S_Standard_Phillips * : I2S_Standard_MSB or I2S_Standard_LSB. * : - I2S_MCLKOutput: could be I2S_MCLKOutput_ * : - Volume: * Output : None * Return : 0-> correct communication, else wrong communication *******************************************************************************/ uint32_t CODEC_Config(uint16_t OutputDevice, uint16_t I2S_Standard, uint16_t I2S_MCLKOutput, uint8_t Volume) { uint32_t Standard = 0, counter = 0; /* Configure the IO Expander (Codec Reset pin) */ IOE_Config(); /* Configure the Codec related IOs */ CODEC_GPIO_Config(); /* Reset the Codec Registers */ CODEC_Reset(); /* Determine the I2S standard used */ switch (I2S_Standard) { case I2S_Standard_Phillips: Standard = 0x04; break; case I2S_Standard_MSB: Standard = 0x00; break; default : Standard = 0x08; break; } /* Initialization phase --------------------------------------*/ /* Keep Codec powered OFF */ counter += CODEC_WriteRegister(0x02, 0x01); switch (OutputDevice) { case OutputDevice_SPEAKER: counter += CODEC_WriteRegister(0x04, 0xFA); // SPK always ON & HP always OFF break; case OutputDevice_HEADPHONE: counter += CODEC_WriteRegister(0x04, 0xAF); // SPK always OFF & HP always ON break; case OutputDevice_BOTH: counter += CODEC_WriteRegister(0x04, 0xAA); // SPK always ON & HP always ON break; case OutputDevice_AUTO: counter += CODEC_WriteRegister(0x04, 0x05);// Detect the HP or the SPK automatically break; } /* Clock configuration: Auto detection */ counter += CODEC_WriteRegister(0x05, 0x81); //Auto speed detection /* Config the Slave Mode and the audio Standard */ counter += CODEC_WriteRegister(0x06, Standard); /* Set the Master volume */ CODEC_ControlVolume(Volume); /* Power on the Codec */ counter += CODEC_WriteRegister(0x02, 0x9E); /* Return the counter value */ return counter; }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); #ifndef USE_STM3210C_EVAL /* Initialize JoyStick Button mounted on STM3210X-EVAL board */ STM_EVAL_PBInit(Button_UP, Mode_GPIO); STM_EVAL_PBInit(Button_DOWN, Mode_GPIO); STM_EVAL_PBInit(Button_LEFT, Mode_GPIO); STM_EVAL_PBInit(Button_RIGHT, Mode_GPIO); STM_EVAL_PBInit(Button_SEL, Mode_GPIO); #else /* Configure the IO Expander */ if (IOE_Config()) { /* IO Expander config error */ while(1); } #endif /* USARTy configuration ------------------------------------------------------*/ /* USARTy configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure the USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE); /* Set the USARTy prescaler */ USART_SetPrescaler(USARTy, 0x1); /* Configure the USARTy IrDA mode */ USART_IrDAConfig(USARTy, USART_IrDAMode_Normal); /* Enable the USARTy IrDA mode */ USART_IrDACmd(USARTy, ENABLE); while (1) { /* Read Key */ MyKey = ReadKey(); switch(MyKey) { case JOY_UP: USART_SendData(USARTy, JOY_UP); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_DOWN: USART_SendData(USARTy, JOY_DOWN); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_LEFT: USART_SendData(USARTy, JOY_LEFT); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_RIGHT: USART_SendData(USARTy, JOY_RIGHT); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_CENTER: USART_SendData(USARTy, JOY_CENTER); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_NONE: USART_SendData(USARTy, JOY_NONE); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; default: break; } } }
/** * @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_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ /* USART configuration -----------------------------------------------------*/ USART_Config(); /* SysTick configuration ---------------------------------------------------*/ SysTickConfig(); /* Initialize LEDs mounted on STM322xG-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Configure the IO Expander mounted on STM322xG-EVAL board */ TimeOut = USER_TIMEOUT; while ((IOE_Config() != IOE_OK) && (TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } /* Enable the USARTx Receive interrupt: this interrupt is generated when the USARTx receive data register is not empty */ USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE); while (1) { TxIndex = 0x00; RxIndex = 0x00; UsartTransactionType = USART_TRANSACTIONTYPE_CMD; UsartMode = USART_MODE_RECEIVER; Fill_Buffer(CmdBuffer, 0x02); Fill_Buffer(AckBuffer, 0x02); /* Clear the RxBuffer */ Fill_Buffer(RxBuffer, TXBUFFERSIZE); PressedButton = IOE_JoyStickGetState(); /* Waiting Joystick is pressed or transaction command is received */ while ((PressedButton == JOY_NONE) && (CmdBuffer[0x00] == 0x00)) { PressedButton = IOE_JoyStickGetState(); } /* If the Joystick is pressed go to transmitter mode, otherwise (the transaction command is received) go to receiver mode */ /******************************************************************************/ /* USART in Mode Transmitter */ /******************************************************************************/ if ((PressedButton != JOY_NONE) && (CmdBuffer[0x00] == 0x00)) { UsartMode = USART_MODE_TRANSMITTER; switch (PressedButton) { /* JOY_RIGHT button pressed */ case JOY_RIGHT: CmdBuffer[0x00] = CMD_RIGHT; CmdBuffer[0x01] = CMD_RIGHT_SIZE; break; /* JOY_LEFT button pressed */ case JOY_LEFT: CmdBuffer[0x00] = CMD_LEFT; CmdBuffer[0x01] = CMD_LEFT_SIZE; break; /* JOY_UP button pressed */ case JOY_UP: CmdBuffer[0x00] = CMD_UP; CmdBuffer[0x01] = CMD_UP_SIZE; break; /* JOY_DOWN button pressed */ case JOY_DOWN: CmdBuffer[0x00] = CMD_DOWN; CmdBuffer[0x01] = CMD_DOWN_SIZE; break; /* JOY_SEL button pressed */ case JOY_SEL: CmdBuffer[0x00] = CMD_SEL; CmdBuffer[0x01] = CMD_SEL_SIZE; break; default: break; } if (CmdBuffer[0x00]!= 0x00) { /* Enable the USARTx transmit data register empty interrupt */ USART_ITConfig(USARTx, USART_IT_TXE, ENABLE); /* Wait until USART sends the command or time out */ TimeOut = USER_TIMEOUT; while ((TxIndex < 0x02)&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } /* The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame’s end of transmission*/ TimeOut = USER_TIMEOUT; while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0x00)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } /* Wait until USART receives the Ack command or time out*/ TimeOut = USER_TIMEOUT; while ((RxIndex < 0x02)&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } /* USART sends the data */ UsartTransactionType = USART_TRANSACTIONTYPE_DATA; TxIndex = 0x00; RxIndex = 0x00; /* Enable the USARTx transmit data register empty interrupt */ USART_ITConfig(USARTx, USART_IT_TXE, ENABLE); /* Wait until end of data transfer */ TimeOut = USER_TIMEOUT; while ((TxIndex < GetVar_NbrOfData())&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } /* The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame’s end of transmission*/ TimeOut = USER_TIMEOUT; while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0x00)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } } CmdBuffer[0x00] = 0x00; } /******************************************************************************/ /* USART in Receiver Mode */ /******************************************************************************/ if (CmdBuffer[0x00] != 0x00) { /* Wait until USART receives the command or time out */ TimeOut = USER_TIMEOUT; while ((RxIndex < 0x02)&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } UsartMode = USART_MODE_RECEIVER; /* Enable the USARTx transmit data register empty interrupt */ USART_ITConfig(USARTx, USART_IT_TXE, ENABLE); /* Wait until USART sends the ACK command or time out*/ TimeOut = USER_TIMEOUT; while ((TxIndex < 0x02)&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } /* The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame’s end of transmission*/ TimeOut = USER_TIMEOUT; while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0x00)) { } if(TimeOut == 0) { TimeOut_UserCallback(); } /* USART receives the data */ UsartTransactionType = USART_TRANSACTIONTYPE_DATA; TxIndex = 0x00; RxIndex = 0x00; /* Wait until end of data transfer or time out */ TimeOut = USER_TIMEOUT; while ((RxIndex < GetVar_NbrOfData())&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } switch (CmdBuffer[0x01]) { /* CMD_RIGHT command received */ case CMD_RIGHT_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_RIGHT_SIZE) != FAILED) { /* Turn ON LED2 and LED3 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); /* Turn OFF LED4 */ STM_EVAL_LEDOff(LED4); } break; /* CMD_LEFT command received */ case CMD_LEFT_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_LEFT_SIZE) != FAILED) { /* Turn ON LED4 */ STM_EVAL_LEDOn(LED4); /* Turn OFF LED2 and LED3 */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); } break; /* CMD_UP command received */ case CMD_UP_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_UP_SIZE) != FAILED) { /* Turn ON LED2 */ STM_EVAL_LEDOn(LED2); /* Turn OFF LED3 and LED4 */ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } break; /* CMD_DOWN command received */ case CMD_DOWN_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_DOWN_SIZE) != FAILED) { /* Turn ON LED3 */ STM_EVAL_LEDOn(LED3); /* Turn OFF LED2 and LED4 */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED4); } break; /* CMD_SEL command received */ case CMD_SEL_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_SEL_SIZE) != FAILED) { /* Turn ON all LED2, LED3 and LED4 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); } break; default: break; } CmdBuffer[0x00] = 0x00; } } }
/** * @brief Initialize resources used for this demo. * @param None * @retval Digit value */ uint8_t Demo_Init(void) { __IO uint32_t tmpValue = 0; PressedKey = NOKEY; /* Configure the IO Expander */ if(IOE_Config() == IOE_OK) { LCD_DisplayStringLine(LINE(6), (uint8_t*)"IO Expander OK "); Delay(0xFF); } else { LCD_SetTextColor(LCD_COLOR_RED); LCD_DisplayStringLine(LINE(6), (uint8_t*)"IO Expander FAILED Please Reset the board"); while (1); } /* Enable the Joystick interrupt */ IOE_ITConfig(IOE_ITSRC_JOYSTICK); Demo_LCD_Clear(); LCD_DisplayStringLine(LINE(6), (uint8_t*)"Main Menu: "); LCD_DisplayStringLine(LINE(7), (uint8_t*)"=========="); LCD_DisplayStringLine(LINE(8), (uint8_t*)"Use UP and DOWN Buttons to Navigate"); LCD_DisplayStringLine(LINE(9), (uint8_t*)"Use SEL Button to Select Image Format"); LCD_DisplayStringLine(LINE(11), (uint8_t*)"Select the Image Format:"); Display_Menu(ValueMin, ValueMax); while (1) { /* If "UP" pushbutton is pressed */ if (PressedKey == UP) { PressedKey = NOKEY; /* Increase the value of the digit */ if (tmpValue == ValueMin) { tmpValue = ValueMax - 1; } else { tmpValue--; } /* Display new Menu */ Display_Menu(tmpValue, ValueMax); } /* If "DOWN" pushbutton is pressed */ if (PressedKey == DOWN) { PressedKey = NOKEY; /* Decrease the value of the digit */ if (tmpValue == (ValueMax - 1)) { tmpValue = ValueMin; } else { tmpValue++; } /* Display new Menu */ Display_Menu(tmpValue, ValueMax); } /* If "SEL" pushbutton is pressed */ if (PressedKey == SEL) { PressedKey = NOKEY; /* Return the digit value and exit */ return (ImageFormat_TypeDef)tmpValue; } } }
void TP_Config() { IOE_Config(); }
/** * @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_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); #ifndef USE_STM3210C_EVAL /* Initialize JoyStick Button mounted on STM3210X-EVAL board */ STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_GPIO); #else /* Configure the IO Expander */ if (IOE_Config()) { /* IO Expander config error */ while(1); } #endif /* USARTy configuration ------------------------------------------------------*/ /* USARTy configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure the USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE); /* Set the USARTy prescaler */ USART_SetPrescaler(USARTy, 0x1); /* Configure the USARTy IrDA mode */ USART_IrDAConfig(USARTy, USART_IrDAMode_Normal); /* Enable the USARTy IrDA mode */ USART_IrDACmd(USARTy, ENABLE); while (1) { /* Read Key */ MyKey = ReadKey(); switch(MyKey) { case JOY_UP: USART_SendData(USARTy, JOY_UP); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_DOWN: USART_SendData(USARTy, JOY_DOWN); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_LEFT: USART_SendData(USARTy, JOY_LEFT); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_RIGHT: USART_SendData(USARTy, JOY_RIGHT); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_SEL: USART_SendData(USARTy, JOY_SEL); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_NONE: USART_SendData(USARTy, JOY_NONE); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; default: break; } } }
/** * @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_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ /* I2C configuration ---------------------------------------------------------*/ I2C_Config(); /* Initialize LEDs mounted on STM322xG-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); #if defined (I2C_MASTER) /* Initialize push-buttons mounted on STM322xG-EVAL board */ TimeOut = USER_TIMEOUT; while ((IOE_Config() != IOE_OK) && (TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } #endif /* I2C_MASTER */ /* SysTick configuration -----------------------------------------------------*/ SysTickConfig(); /*************************************Master Code******************************/ #if defined (I2C_MASTER) /* I2C De-initialize */ I2C_DeInit(I2Cx); /*!< I2C Struct Initialize */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DUTYCYCLE; I2C_InitStructure.I2C_OwnAddress1 = 0xA0; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED; #ifndef I2C_10BITS_ADDRESS I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; #else I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_10bit; #endif /* I2C_10BITS_ADDRESS */ /*!< I2C Initialize */ I2C_Init(I2Cx, &I2C_InitStructure); /* Enable Error Interrupt */ I2C_ITConfig(I2Cx, I2C_IT_ERR , ENABLE); /* I2C ENABLE */ I2C_Cmd(I2Cx, ENABLE); while (1) { CmdTransmitted = 0x00; NumberOfByte = 0x00; Tx_Idx = 0x00; /* Clear PressedButton by reading joystick */ PressedButton = IOE_JoyStickGetState(); /* Waiting joystick pressed */ while (PressedButton == JOY_NONE) { PressedButton = IOE_JoyStickGetState(); } /* I2C in Master Transmitter Mode ----------------------------------------*/ switch (PressedButton) { /* JOY_RIGHT button pressed */ case JOY_RIGHT: NumberOfByte = CMD_RIGHT_SIZE; CmdTransmitted = CMD_RIGHT; break; /* JOY_LEFT button pressed */ case JOY_LEFT: NumberOfByte = CMD_LEFT_SIZE; CmdTransmitted = CMD_LEFT; break; /* JOY_UP button pressed */ case JOY_UP: NumberOfByte = CMD_UP_SIZE; CmdTransmitted = CMD_UP; break; /* JOY_DOWN button pressed */ case JOY_DOWN: NumberOfByte = CMD_DOWN_SIZE; CmdTransmitted = CMD_DOWN; break; /* JOY_SEL button pressed */ case JOY_SEL: NumberOfByte = CMD_SEL_SIZE; CmdTransmitted = CMD_SEL; break; default: break; } if (CmdTransmitted != 0x00) { /* Enable Error and Buffer Interrupts */ I2C_ITConfig(I2Cx, (I2C_IT_EVT | I2C_IT_BUF), ENABLE); /* Generate the Start condition */ I2C_GenerateSTART(I2Cx, ENABLE); /* Data transfer is performed in the I2C interrupt routine */ /* Wait until end of data transfer or time out */ TimeOut = USER_TIMEOUT; while ((Tx_Idx < GetVar_NbrOfDataToTransfer())&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } TimeOut = USER_TIMEOUT; while ((I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))&&(TimeOut != 0x00)) {} if(TimeOut == 0) { TimeOut_UserCallback(); } } } #endif /* I2C_MASTER */ /**********************************Slave Code**********************************/ #if defined (I2C_SLAVE) I2C_DeInit(I2Cx); /* Initialize I2C peripheral */ /*!< I2C Init */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DUTYCYCLE; I2C_InitStructure.I2C_OwnAddress1 = SLAVE_ADDRESS; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED; #ifndef I2C_10BITS_ADDRESS I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; #else I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_10bit; #endif /* I2C_10BITS_ADDRESS */ I2C_Init(I2Cx, &I2C_InitStructure); /* Enable Error Interrupt */ I2C_ITConfig(I2Cx, (I2C_IT_ERR | I2C_IT_EVT | I2C_IT_BUF), ENABLE); /* I2C ENABLE */ I2C_Cmd(I2Cx, ENABLE); /* Infinite Loop */ while (1) { CmdReceived = 0x00; NumberOfByte = 0x00; /* Clear the RxBuffer */ Fill_Buffer(RxBuffer, RXBUFFERSIZE); while (CmdReceived == 0x00) {} /* Wait until end of data transfer */ while (Rx_Idx < GetVar_NbrOfDataToReceive()) {} /* I2C in Slave Receiver Mode --------------------------------------------*/ if (CmdReceived != 0x00) { switch (Rx_Idx) { /* Right button pressed */ case CMD_RIGHT_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_RIGHT_SIZE) == PASSED) { /* Turn ON LED2 and LED3 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); /* Turn all other LEDs off */ STM_EVAL_LEDOff(LED4); } break; /* Left button pressed*/ case CMD_LEFT_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_LEFT_SIZE) == PASSED) { /* Turn ON LED4 */ STM_EVAL_LEDOn(LED4); /* Turn all other LEDs off */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); } break; /* Up button pressed */ case CMD_UP_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_UP_SIZE) == PASSED) { /* Turn ON LED2 */ STM_EVAL_LEDOn(LED2); /* Turn all other LEDs off */ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } break; /* Down button pressed */ case CMD_DOWN_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_DOWN_SIZE) == PASSED) { /* Turn ON LED3 */ STM_EVAL_LEDOn(LED3); /* Turn all other LEDs off */ STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED4); } break; /* Sel button pressed */ case CMD_SEL_SIZE: if (Buffercmp(TxBuffer, RxBuffer, CMD_SEL_SIZE) == PASSED) { /* Turn ON all LEDs */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); } break; default: break; } } } #endif /* I2C_SLAVE */ }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Server Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: STM32F407\r\n"); TRACE_INFO("\r\n"); //LED configuration STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); //Clear LEDs STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); //Initialize I/O expander IOE_Config(); //Initialize user button STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); //Initialize LCD display STM324xG_LCD_Init(); LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_SetFont(&Font16x24); LCD_Clear(Blue); //Welcome message lcdSetCursor(0, 0); printf("FTP Server Demo"); //File system initialization error = fsInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize file system!\r\n"); } //TCP/IP stack initialization error = tcpIpStackInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name tcpIpStackSetInterfaceName(interface, "eth0"); //Set host name tcpIpStackSetHostname(interface, "FTPServerDemo"); //Select the relevant network adapter tcpIpStackSetDriver(interface, &stm32f4x7EthDriver); tcpIpStackSetPhyDriver(interface, &dp83848PhyDriver); //Set external interrupt line driver tcpIpStackSetExtIntDriver(interface, &extIntDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); tcpIpStackSetMacAddr(interface, &macAddr); //Initialize network interface error = tcpIpStackConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Get default settings ftpServerGetDefaultSettings(&ftpServerSettings); //Bind FTP server to the desired interface ftpServerSettings.interface = &netInterface[0]; //Listen to port 21 ftpServerSettings.port = FTP_PORT; //Root directory strcpy(ftpServerSettings.rootDir, "/"); //User verification callback function ftpServerSettings.checkUserCallback = ftpServerCheckUserCallback; //Password verification callback function ftpServerSettings.checkPasswordCallback = ftpServerCheckPasswordCallback; //Callback used to retrieve file permissions ftpServerSettings.getFilePermCallback = ftpServerGetFilePermCallback; //FTP server initialization error = ftpServerInit(&ftpServerContext, &ftpServerSettings); //Failed to initialize FTP server? if(error) { //Debug message TRACE_ERROR("Failed to initialize FTP server!\r\n"); } //Start FTP server error = ftpServerStart(&ftpServerContext); //Failed to start FTP server? if(error) { //Debug message TRACE_ERROR("Failed to start FTP server!\r\n"); } //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
/** * @brief LCD & LEDs periodic handling * @param localtime: the current LocalTime value * @retval None */ void Display_Periodic_Handle(__IO uint32_t localtime) { /* 250 ms */ if (localtime - DisplayTimer >= LCD_TIMER_MSECS) { DisplayTimer = localtime; /* We have got a new IP address so update the display */ if (IPaddress != netif.ip_addr.addr) { __IO uint8_t iptab[4]; uint8_t iptxt[20]; /* Read the new IP address */ IPaddress = netif.ip_addr.addr; iptab[0] = (uint8_t)(IPaddress >> 24); iptab[1] = (uint8_t)(IPaddress >> 16); iptab[2] = (uint8_t)(IPaddress >> 8); iptab[3] = (uint8_t)(IPaddress); sprintf((char*)iptxt, " %d.%d.%d.%d ", iptab[3], iptab[2], iptab[1], iptab[0]); /* Display the new IP address */ #if LWIP_DHCP if (netif.flags & NETIF_FLAG_DHCP) { /* Display the IP address */ LCD_DisplayStringLine(Line7, "IP address assigned "); LCD_DisplayStringLine(Line8, " by a DHCP server "); LCD_DisplayStringLine(Line9, iptxt); Delay(LCD_DELAY); /** Start the client/server application: only when a dynamic IP address has been obtained **/ /* Clear the LCD */ LCD_Clear(Black); LCD_SetBackColor(Black); LCD_SetTextColor(White); iptab[0] = (uint8_t)(IPaddress >> 24); iptab[1] = (uint8_t)(IPaddress >> 16); iptab[2] = (uint8_t)(IPaddress >> 8); iptab[3] = (uint8_t)(IPaddress); sprintf((char*)iptxt, "is: %d.%d.%d.%d ", iptab[3], iptab[2], iptab[1], iptab[0]); LCD_DisplayStringLine(Line0, " You are configured "); LCD_DisplayStringLine(Line2, iptxt); if(Server) { LCD_DisplayStringLine(Line1, "as a server, your IP"); /* Initialize the server application */ server_init(); } else { LCD_DisplayStringLine(Line1, "as a client, your IP"); /* Configure the IO Expander */ IOE_Config(); /* Enable the Touch Screen and Joystick interrupts */ IOE_ITConfig(IOE_ITSRC_TSC); /* Initialize the client application */ client_init(); } }