/** * @brief USBD_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBD_USR_Init(void) { /* Initialize LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ #if defined (USE_STM322xG_EVAL) STM322xG_LCD_Init(); #elif defined(USE_STM324xG_EVAL) STM324xG_LCD_Init(); #elif defined (USE_STM3210C_EVAL) STM3210C_LCD_Init(); #else #error "Missing define: Evaluation board (ie. USE_STM322xG_EVAL)" #endif LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS DFU Device"); #else LCD_LOG_SetHeader(" USB OTG FS DFU Device"); #endif LCD_UsrLog("> USB device library started.\n"); LCD_LOG_SetFooter (" USB Device Library v1.1.0" ); /* Information panel */ LCD_SetTextColor(Green); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, USER_INFORMATION1); LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); }
/** * @brief Initializes the STM322xG-EVAL's LCD and LEDs resources. * @param None * @retval None */ void LCD_LED_Init(void) { #ifdef USE_LCD /* Initialize the STM322xG-EVAL's LCD */ STM322xG_LCD_Init(); #endif /* Initialize STM322xG-EVAL's LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); #ifdef USE_LCD /* Clear the LCD */ LCD_Clear(Black); /* Set the LCD Back Color */ LCD_SetBackColor(Black); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Display message on the LCD*/ LCD_DisplayStringLine(Line0, (uint8_t*)MESSAGE1); LCD_DisplayStringLine(Line1, (uint8_t*)MESSAGE2); LCD_DisplayStringLine(Line2, (uint8_t*)MESSAGE3); LCD_DisplayStringLine(Line3, (uint8_t*)MESSAGE4); #endif }
/** * @brief USBH_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBH_USR_Init(void) { static uint8_t startup = 0; if(startup == 0 ) { startup = 1; /* Configure the LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); #ifdef USE_STM3210C_EVAL STM3210C_LCD_Init(); #else STM322xG_LCD_Init(); #endif LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS HID Host"); #else LCD_LOG_SetHeader(" USB OTG FS HID Host"); #endif LCD_UsrLog("> USB Host library started.\n"); LCD_LOG_SetFooter (" USB Host Library v2.0.0" ); } }
/** * @brief Display Init (LCD) * @param None * @retval None */ void Display_Init(void) { /* Initialize the LCD */ STM322xG_LCD_Init(); /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Text size */ LCD_SetFont(&Font8x12); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_DisplayStringLine(LINE(0x13), " STM32F2xx ADC1 VBAT Measurement example"); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); LCD_DisplayStringLine(LINE(0), "**VBAT Measurement**"); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(LINE(2)," Eval Board Instant "); LCD_DisplayStringLine(LINE(4)," Battery Voltage "); }
/** * @brief Displays the message on LCD on device lib initialization * @param None * @retval None */ void USBD_USR_Init(void) { /* Initialize LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ STM322xG_LCD_Init(); LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS MSC Device"); #else LCD_LOG_SetHeader(" USB OTG FS MSC Device"); #endif LCD_UsrLog("> USB device library started.\n"); LCD_LOG_SetFooter (" USB Device Library v1.0.0" ); /* Information panel */ LCD_SetTextColor(Green); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, USER_INFORMATION1); LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, USER_INFORMATION2); LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); }
/** * @brief Display Init (LCD or/and USART) * @param None * @retval None */ void Display_Init(void) { #ifdef PRINT_ON_USART USART_InitTypeDef USART_InitStructure; /* USARTx 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; STM_EVAL_COMInit(COM1, &USART_InitStructure); printf("\n\r ========================================\n"); printf("\n\r ==== Multiple RNG Generator Example ====\n"); printf("\n\r ======================================== \n\n\r"); printf("\n\r Press key button to generate 8 x 32bit random number\n"); #endif #ifdef PRINT_ON_LCD /* Initialize the LCD */ STM322xG_LCD_Init(); /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Text size */ LCD_SetFont(&Font8x12); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_DisplayStringLine(LINE(0x13), " To generate 8x32bit RNG, Press Key >>"); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); LCD_DisplayStringLine(LINE(0), "*** RNG Example ***"); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(LINE(3)," Press KEY button "); LCD_DisplayStringLine(LINE(5)," to START "); #endif }
/** * @brief Initializes the LCD. * @param None * @retval None */ void GL_LCD_Init(void) { /* Setups the LCD */ #if defined(USE_STM3210C_EVAL) STM3210C_LCD_Init(); #elif defined (USE_STM3210B_EVAL) STM3210B_LCD_Init(); #elif defined (USE_STM32100B_EVAL) STM32100B_LCD_Init(); #elif defined(USE_STM3210E_EVAL) STM3210E_LCD_Init(); #elif defined(USE_STM32100E_EVAL) STM32100E_LCD_Init(); #elif defined(USE_STM322xG_EVAL) STM322xG_LCD_Init(); #elif defined(USE_STM32L152_EVAL) STM32L152_LCD_Init(); #endif }
/** * @brief USBH_USR_Init * Displays the message on LCD for host lib initialization * @param None * @retval None */ void USBH_USR_Init(void) { static uint8_t startup = 0; if(startup == 0 ) { startup = 1; /* Configure the LEDs */ STM_EVAL_LEDInit(LED1); // STM_EVAL_LEDInit(LED2); // STM_EVAL_LEDInit(LED3); // STM_EVAL_LEDInit(LED4); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); #if defined (USE_STM322xG_EVAL) STM322xG_LCD_Init(); #elif defined(USE_STM324xG_EVAL) STM324xG_LCD_Init(); #elif defined (USE_STM3210C_EVAL) STM3210C_LCD_Init(); #else #error "Missing define: Evaluation board (ie. USE_STM322xG_EVAL)" #endif LCD_LOG_Init(); #ifdef USE_USB_OTG_HS LCD_LOG_SetHeader(" USB OTG HS MSC Host"); #else LCD_LOG_SetHeader(" USB OTG FS MSC Host"); #endif LCD_UsrLog("> USB Host library started.\n"); LCD_LOG_SetFooter (" USB Host Library v2.1.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_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; /* Configure the external interrupt "WAKEUP", "KEY" and "TAMPER" buttons */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_WAKEUP , BUTTON_MODE_GPIO); /* Initialize the LCD */ STM322xG_LCD_Init(); /* Configure the LCD Log Module */ LCD_LOG_Init(); LCD_LOG_SetHeader("RTC Backup Domain Example"); LCD_LOG_SetFooter (" Copyright (c) STMicroelectronics" ); /* Display the default RCC BDCR and RTC TAFCR Registers */ LCD_UsrLog ("Entry Point \n"); LCD_UsrLog ("RCC BDCR = 0x%x\n", RCC->BDCR); LCD_UsrLog ("RTC TAFCR = 0x%x\n", RTC->TAFCR); /* Enable the PWR APB1 Clock Interface */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the RTC Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* EXTI configuration *******************************************************/ EXTI_ClearITPendingBit(EXTI_Line22); EXTI_InitStructure.EXTI_Line = EXTI_Line22; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); if(RTC_ReadBackupRegister(RTC_BKP_DR0) != FIRST_DATA) { LCD_UsrLog ("RTC Config PLZ Wait. \n"); /* RTC Configuration */ RTC_Config(); /* Adjust Current Time */ Time_Adjust(); /* Adjust Current Date */ Date_Adjust(); } else { /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); RTC_ClearITPendingBit(RTC_IT_WUT); EXTI_ClearITPendingBit(EXTI_Line22); /* Backup SRAM ***************************************************************/ /* Enable BKPSRAM Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE); /* Check the written Data */ for (i = 0x0; i < 0x1000; i += 4) { if ((*(__IO uint32_t *) (BKPSRAM_BASE + i)) != i) { errorindex++; } } if(errorindex) { LCD_ErrLog ("BKP SRAM Number of errors = %d\n", errorindex); } else { LCD_UsrLog ("BKP SRAM Content OK \n"); } /* RTC Backup Data Registers **************************************************/ /* Check if RTC Backup DRx registers data are correct */ if (CheckBackupReg(FIRST_DATA) == 0x00) { /* OK, RTC Backup DRx registers data are correct */ LCD_UsrLog ("OK, RTC Backup DRx registers data are correct. \n"); } else { /* Error, RTC Backup DRx registers data are not correct */ LCD_ErrLog ("RTC Backup DRx registers data are not correct\n"); } } /* Infinite loop */ Calendar_Show(); while (1) { } }
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 Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2015 Oryx Embedded SARL\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: STM32F207\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 STM322xG_LCD_Init(); LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_SetFont(&Font16x24); LCD_Clear(Blue); //Welcome message lcdSetCursor(0, 0); printf("FTP Client Demo\r\n"); //TCP/IP stack initialization error = netInit(); //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 netSetInterfaceName(interface, "eth0"); //Set host name netSetHostname(interface, "FTPClientDemo"); //Select the relevant network adapter netSetDriver(interface, &stm32f2x7EthDriver); netSetPhyDriver(interface, &dp83848PhyDriver); //Set external interrupt line driver netSetExtIntDriver(interface, &extIntDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); netSetMacAddr(interface, &macAddr); //Initialize network interface error = netConfigInterface(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); //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); //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 //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 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 */ /* Initialize LEDs, Key Button, LCD available on STM322xG-EVAL board ******************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the Push buttons */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Key button for Pause/Resume */ STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_GPIO); /* Key button for Volume High */ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); /* Key button for Volume Low */ /* Initialize the LCD */ STM322xG_LCD_Init(); /* Display message on STM322xG-EVAL LCD *************************************/ /* Clear the LCD */ LCD_Clear(LCD_COLOR_BLUE); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); LCD_DisplayStringLine(Line2, MESSAGE3); /* Turn on leds available on STM322xG-EVAL **********************************/ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */ if (EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, volume, I2S_AudioFreq_48k) == 0) { LCD_DisplayStringLine(Line3, "===================="); LCD_DisplayStringLine(Line4, "Key : Play/Pause "); LCD_DisplayStringLine(Line5, "Tamper: Vol+/Headph"); LCD_DisplayStringLine(Line6, "Wakeup: Vol-/Spkr "); LCD_DisplayStringLine(Line7, "===================="); LCD_DisplayStringLine(Line8, " AUDIO CODEC OK "); } else { LCD_DisplayStringLine(Line4, " AUDIO CODEC FAIL "); LCD_DisplayStringLine(Line5, " Try to reset board "); } /* Normal mode description: Start playing the audio file (using DMA stream) . Using this mode, the application can run other tasks in parallel since the DMA is handling the Audio Transfer instead of the CPU. The only task remaining for the CPU will be the management of the DMA Transfer Complete interrupt or the Half Transfer Complete interrupt in order to load again the buffer and to calculate the remaining data. Circular mode description: Start playing the file from a circular buffer, once the DMA is enabled it always run. User has to fill periodically the buffer with the audio data using Transfer complete and/or half transfer complete interrupts callbacks (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()... In this case the audio data file is smaller than the DMA max buffer size 65535 so there is no need to load buffer continuously or manage the transfer complete or Half transfer interrupts callbacks. */ EVAL_AUDIO_Play((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS), (AUDIO_FILE_SZE - AUIDO_START_ADDRESS)); /* Display the state on the screen */ LCD_DisplayStringLine(Line8, " PLAYING "); /* Infinite loop */ while (1) { /* Check on the Pause/Resume button */ if (STM_EVAL_PBGetState(BUTTON_KEY) != Bit_SET) { /* wait to avoid rebound */ while (STM_EVAL_PBGetState(BUTTON_KEY) != Bit_SET); EVAL_AUDIO_PauseResume(cmd); if (cmd == AUDIO_PAUSE) { /* Display the current state of the player */ LCD_DisplayStringLine(Line8, " PAUSED "); /* Next time Resume command should be processed */ cmd = AUDIO_RESUME; /* Push buttons will be used to switch between Speaker and Headphone modes */ SpHpSwitch = 1; } else { /* Display the current state of the player */ LCD_DisplayStringLine(Line8, " PLAYING "); /* Next time Pause command should be processed */ cmd = AUDIO_PAUSE; /* Push buttons will be used to control volume level */ SpHpSwitch = 0; } } /* Check on the Volume high button */ if (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET) { /* Check if the current state is paused (push buttons are used for volume control or for speaker/headphone mode switching) */ if (SpHpSwitch) { /* Set output to Speaker */ Codec_SwitchOutput(OUTPUT_DEVICE_SPEAKER); /* Display the current state of the player */ LCD_DisplayStringLine(Line9, " SPEAKER "); } else { /* wait to avoid rebound */ while (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET); /* Decrease volume by 5% */ if (volume > 5) volume -= 5; else volume = 0; /* Apply the new volume to the codec */ EVAL_AUDIO_VolumeCtl(volume); LCD_DisplayStringLine(Line9, " VOL: - "); } } /* Check on the Volume high button */ if (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET) { /* Check if the current state is paused (push buttons are used for volume control or for speaker/headphone mode switching) */ if (SpHpSwitch) { /* Set output to Headphone */ Codec_SwitchOutput(OUTPUT_DEVICE_HEADPHONE); /* Display the current state of the player */ LCD_DisplayStringLine(Line9, " HEADPHONE "); } else { /* wait to avoid rebound */ while (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET); /* Increase volume by 5% */ if (volume < 95) volume += 5; else volume = 100; /* Apply the new volume to the codec */ EVAL_AUDIO_VolumeCtl(volume); LCD_DisplayStringLine(Line9, " VOL: + "); } } /* Toggle LD4 */ STM_EVAL_LEDToggle(LED3); /* Insert 50 ms delay */ Delay(5); /* Toggle LD2 */ STM_EVAL_LEDToggle(LED2); /* Insert 50 ms delay */ Delay(5); } }
/** * @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_stm32xxx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32xxx.c file */ /* Initialize LEDs, Key Button, LCD and COM port(USART) available on STM3210X-EVAL board ******************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize TIM6 */ TIM6_Config(); /* Initialize the LCD */ #ifdef USE_STM322xG_EVAL STM322xG_LCD_Init(); #elif defined USE_STM324xG_EVAL STM324xG_LCD_Init(); #elif defined USE_STM3210C_EVAL STM3210C_LCD_Init(); #elif defined USE_STM32100E_EVAL STM32100E_LCD_Init(); #elif defined USE_STM32L152_EVAL STM32L152_LCD_Init(); #elif defined USE_STM32L152D_EVAL STM32L152D_LCD_Init(); #endif /* Display message on STM3210X-EVAL LCD *************************************/ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(Yellow); LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); LCD_DisplayStringLine(Line5, MESSAGE3); /* Configure the Push buttons in interrupt mode *****************************/ #if defined (USE_STM32100E_EVAL) || defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL ) || defined (USE_STM324xG_EVAL) STM_EVAL_PBInit(BUTTON_KEY, Mode_EXTI); STM_EVAL_PBInit(BUTTON_TAMPER, Mode_EXTI); #elif defined (USE_STM32L152_EVAL) || defined (USE_STM32L152D_EVAL) STM_EVAL_PBInit(BUTTON_LEFT, Mode_EXTI); STM_EVAL_PBInit(BUTTON_RIGHT, Mode_EXTI); #endif /* USE_STM32100E_EVAL || USE_STM3210C_EVAL || USE_STM322xG_EVAL || USE_STM324xG_EVAL */ /* Start CPAL communication configuration ***********************************/ /* Initialize local Reception structures */ sRxStructure.wNumData = BufferSize; /* Maximum Number of data to be received */ sRxStructure.pbBuffer = tRxBuffer; /* Common Rx buffer for all received data */ sRxStructure.wAddr1 = OWN_ADDRESS; /* The own board address */ sRxStructure.wAddr2 = 0; /* Not needed */ /* Initialize local Transmission structures */ sTxStructure.wNumData = BufferSize; /* Maximum Number of data to be received */ sTxStructure.pbBuffer = (uint8_t*)tStateSignal; /* Common Rx buffer for all received data */ sTxStructure.wAddr1 = OWN_ADDRESS; /* The own board address */ sTxStructure.wAddr2 = 0; /* Not needed */ /* Configure the device structure */ CPAL_I2C_StructInit(&I2C_DevStructure); /* Set all fields to default values */ I2C_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE; #ifdef CPAL_I2C_DMA_PROGMODEL I2C_DevStructure.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_I2C_NACK_ADD; I2C_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) I2C_DevStructure.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_I2C_NACK_ADD; I2C_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif I2C_DevStructure.pCPAL_I2C_Struct->I2C_ClockSpeed = I2C_SPEED; I2C_DevStructure.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWN_ADDRESS; I2C_DevStructure.pCPAL_TransferRx = &sRxStructure; I2C_DevStructure.pCPAL_TransferTx = &sTxStructure; /* Initialize CPAL device with the selected parameters */ CPAL_I2C_Init(&I2C_DevStructure); /* Infinite loop */ while (1) { /* Write operations ------------------------------------------------------*/ /* Check if any action has been triggered by push buttons */ if ((ActionState != ACTION_PENDING) && (ActionState != ACTION_NONE)) { /* Check if the current CPAL device state allows write operation */ if (((DeviceMode == SLAVE) && (LastMode == SLAVE))||\ (((I2C_DevStructure.CPAL_State == CPAL_STATE_READY) ||\ (I2C_DevStructure.CPAL_State == CPAL_STATE_DISABLED)) && (DeviceMode == MASTER))) { if (LastMode == SLAVE) { /* Set the LCD Back Color */ LCD_SetBackColor(Red); /* Set the LCD Text Color */ LCD_SetTextColor(White); LCD_DisplayStringLine(Line3, (uint8_t*)" MASTER MODE ACTIVE "); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); /* Disable CPAL_OPT_I2C_NACK_ADD option when switch to Master mode */ I2C_DevStructure.wCPAL_Options &= (~CPAL_OPT_I2C_NACK_ADD); } LastMode = MASTER; /* Initialize local Reception structures */ sRxStructure.wNumData = BufferSize; /* Initialize local Transmission structures */ sTxStructure.wNumData = BufferSize; switch (ActionState) { case BUTTON_KEY: TransmitMode = STATE_ON; sTxStructure.pbBuffer = (uint8_t*)tSignal; Divider = 2; break; case BUTTON_TAMPER: TransmitMode = STATE_OFF; sRxStructure.pbBuffer = tRxBuffer; Divider = 4; break; case ACTION_PERIODIC: if(TransmitMode == STATE_ON) { sTxStructure.pbBuffer = (uint8_t*)tStateSignal; } break; default: break; } /* Configure the device mode to master */ I2C_DevStructure.CPAL_Mode = CPAL_MODE_MASTER; /* Force the CPAL state to ready (in case a read operation has been initiated) */ I2C_DevStructure.CPAL_State = CPAL_STATE_READY; /* Prevent other actions to be performed while the current is not finished */ ActionState = ACTION_PENDING; DeviceMode = MASTER; /* Configure a Timer to generate periodic interrupt: used to send state signal */ TIM7_Config(PeriodicValue/Divider); if(TransmitMode == STATE_ON) { /* Start writing data in master mode */ if (CPAL_I2C_Write(&I2C_DevStructure) == CPAL_PASS) { } } else { /* Start reading data in master mode */ if (CPAL_I2C_Read(&I2C_DevStructure) == CPAL_PASS) { } } } } /* Read Operations -------------------------------------------------------*/ if (((I2C_DevStructure.CPAL_State == CPAL_STATE_READY) || \ (I2C_DevStructure.CPAL_State == CPAL_STATE_DISABLED)) && \ (DeviceMode == SLAVE)) { /* Reconfigure device for slave receiver mode */ I2C_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE; I2C_DevStructure.CPAL_State = CPAL_STATE_READY; if (LastMode == SLAVE) { /* Set the LCD Back Color */ LCD_SetBackColor(Red); /* Set the LCD Text Color */ LCD_SetTextColor(White); LCD_DisplayStringLine(Line3, (uint8_t*)" SLAVE MODE ACTIVE "); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); } /* Start waiting for data to be received in slave mode */ if (CPAL_I2C_Listen(&I2C_DevStructure) == CPAL_PASS) { LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY); } } } }