int main(void) { uint8_t i; /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay functions */ TM_DELAY_Init(); /* Init LCD */ TM_LCD_Init(); /* Fill LCD with color */ TM_LCD_Fill(0xFFFF); /* Set custom orientation for LCD */ TM_LCD_SetOrientation(1); /* Get orientation from LCD and save to Touch Screen structure */ TS.Orientation = TM_LCD_GetOrientation(); /* Init touch, use default drivers, depends on defines in library */ /* Check library description for more information */ TM_TOUCH_Init(NULL, &TS); while (1) { /* Read touch */ TM_TOUCH_Read(&TS); /* Check if pressed */ if (TS.NumPresses) { /* Go through all presses on LCD */ for (i = 0; i < TS.NumPresses; i++) { /* Draw circle */ TM_LCD_DrawFilledCircle(TS.X[i], TS.Y[i], 5, TOUCH_Colors[i]); /* Format string */ sprintf(str, "X: %3d Y: %3d", TS.X[i], TS.Y[i]); /* Print on LCD */ TM_LCD_SetXY(10, 10 + i * 20); TM_LCD_Puts(str); } } Delayms(5); } }
int main(void) { char buff[100]; /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init LCD */ TM_LCD_Init(); /* Display fixes */ #if defined(STM32F7_DISCOVERY) TM_LCD_SetFont(&TM_Font_7x10); #elif defined(STM32F429_DISCOVERY) TM_LCD_SetFont(&TM_Font_7x10); TM_LCD_SetOrientation(3); #endif /* Format unique ID */ sprintf(buff, "Unique ID: 0x%08X 0x%08X 0x%08X", TM_ID_GetUnique32(0), TM_ID_GetUnique32(1), TM_ID_GetUnique32(2)); TM_LCD_SetXY(10, 10); TM_LCD_Puts(buff); /* Format device signature */ sprintf(buff, "Device signature: 0x%04X", TM_ID_GetSignature()); TM_LCD_SetXY(10, 30); TM_LCD_Puts(buff); /* Format revision */ sprintf(buff, "Revision: 0x%04X", TM_ID_GetRevision()); TM_LCD_SetXY(10, 50); TM_LCD_Puts(buff); /* Format package */ sprintf(buff, "Package: 0x%04X", TM_ID_GetPackage()); TM_LCD_SetXY(10, 70); TM_LCD_Puts(buff); /* Format flash size */ sprintf(buff, "Flash size: %04d kBytes", TM_ID_GetFlashSize()); TM_LCD_SetXY(10, 90); TM_LCD_Puts(buff); while (1) { } }
int main(void) { /* Init system */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay */ TM_DELAY_Init(); #if defined(STM32F429_DISCOVERY) || defined(STM32F7_DISCOVERY) || defined(STM32F439_EVAL) /* Init LCD */ TM_LCD_Init(); TM_LCD_SetFont(&TM_Font_7x10); TM_LCD_SetXY(5, 5); #if defined(STM32F7_DISCOVERY) /* Rotate LCD */ TM_LCD_SetOrientation(2); #endif #endif /* Init USB */ TM_USB_Init(); /* Init USB Host, FS and HS modes */ TM_USBH_Init(TM_USB_Both); /* Enable HID HOST class for USB FS mode */ TM_USBH_HID_Init(TM_USB_FS); /* Enable MSC HOST class for USB HS mode */ TM_USBH_MSC_Init(TM_USB_HS); /* Start USB host on FS and HS */ TM_USBH_Start(TM_USB_Both); while (1) { /* Process USB host FS and HS modes */ TM_USBH_Process(TM_USB_Both); /* Check if device connected on FS port */ if (TM_USBH_IsConnected(TM_USB_FS) == TM_USBH_Result_Ok) { /* Check if any HID devie is connected to FS port */ if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_Keyboard) { /* Keyboard is connected on FS port */ /* If not printed yet */ if (!FS_Printed) { /* Print to LCD */ printf("USB FS: Keyboard connected! VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_FS), TM_USBH_GetPID(TM_USB_FS)); /* Set flag */ FS_Printed = 1; } /* Read pressed button if any */ if (TM_USBH_HID_GetKeyboard(TM_USB_FS, &KbdInfo) == TM_USBH_HID_Keyboard) { /* Something pressed on keyboard */ /* Print on LCD if character is valid */ if (KbdInfo.C) { printf("Character: %c\n", KbdInfo.C); } /* Print others */ printf("LS: %d ", KbdInfo.Special.S.LShift); printf("LC: %d ", KbdInfo.Special.S.LCtrl); printf("LA: %d ", KbdInfo.Special.S.LAlt); printf("LG: %d ", KbdInfo.Special.S.LGUI); printf("\n"); } } else if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_Mouse) { /* Mouse is connected on FS port */ /* If not printed yet */ if (!FS_Printed) { /* Print to LCD */ printf("USB FS: Mouse connected! VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_FS), TM_USBH_GetPID(TM_USB_FS)); /* Turn on green LED */ TM_DISCO_LedOn(LED_GREEN); /* Set flag */ FS_Printed = 1; } /* Read mouse if any */ if (TM_USBH_HID_GetMouse(TM_USB_FS, &MouseInfo) == TM_USBH_HID_Mouse) { /* Something pressed on keyboard */ printf("Abs X: %d; Abs Y: %d; Rel X: %d; Rel Y %d\n", MouseInfo.AbsoluteX, MouseInfo.AbsoluteY, MouseInfo.RelativeX, MouseInfo.RelativeY); printf("Btn1: %d; Btn2: %d; Btn3: %d\n", MouseInfo.Buttons[0], MouseInfo.Buttons[1], MouseInfo.Buttons[2]); } } } else if (FS_Printed) { /* Check if no device connected */ if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_None) { /* Mouse is connected */ /* Print to LCD */ printf("USB FS: Device disconnected\n"); /* Clear flag */ FS_Printed = 0; /* Turn off green LED */ TM_DISCO_LedOff(LED_GREEN); } } /* Check MSC host on HS port */ if ( TM_USBH_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok && /*!< Check if any device connected to USB HS port */ TM_USBH_MSC_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok && /*!< Device connected to USB port is MSC type */ TM_USBH_MSC_IsReady(TM_USB_HS) == TM_USBH_Result_Ok /*!< Device is ready */ ) { /* Device is connected on HS port */ /* Connected device is MSC type */ /* If not printed already */ if (!HS_Printed) { /* Print to LCD */ printf("--------------------------\n"); printf("USB HS: USB MSC device connected with VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_HS), TM_USBH_GetPID(TM_USB_HS)); /* Set flag */ HS_Printed = 1; } /* If not mounted already */ if (!mounted) { /* Try to mount and write using FATFS */ if ((fres = f_mount(&FATFS_USB, "USBHS:", 1)) == FR_OK) { /* Mounted OK */ printf("USB HS: Mounted OK!\n"); /* Try to open file */ if ((fres = f_open(&fil, "USBHS:usb_hs_file.txt", FA_OPEN_ALWAYS | FA_WRITE | FA_READ)) == FR_OK) { /* File opened OK */ printf("USB HS: File opened!\n"); /* Go to end of file */ f_lseek(&fil, f_size(&fil)); /* Print string */ if (f_puts("USB HS: File written using USB HS port\n", &fil)) { /* Written OK */ printf("USB HS: File written OK!\n"); /* Set flag */ mounted = 1; /* Turn on red LED */ TM_DISCO_LedOn(LED_RED); } else { printf("USB HS: File writing error!\n"); } /* Close file */ f_close(&fil); printf("USB HS: File closed!\n"); if ((fres = f_open(&fil, "USBHS:usb_hs_file.txt", FA_WRITE | FA_READ)) == FR_OK) { printf("USB HS: File reopened OK and closed again!\n"); f_close(&fil); } else { printf("USB HS: File reopen ERROR! FRES: %d\n", fres); } } else { /* File not opened */ printf("USB HS: Failed to open file!\n"); } /* Unmount USB */ f_mount(NULL, "USBHS:", 1); } else { /* Mounting error! */ printf("USB HS: Failed to mount!\n"); } } } else { /* Clear flag */ mounted = 0; /* Print disconnection */ if (HS_Printed) { /* Print to LCD */ printf("USB HS: USB MSC device disconnected!\n"); /* Clear flag */ HS_Printed = 0; /* Turn off red LED */ TM_DISCO_LedOff(LED_RED); } } } }
TM_LCD_Result_t TM_LCD_Init(void) { TM_DMA2DGRAPHIC_INT_Conf_t DMA2DConf; /* Init SDRAM */ if (!TM_SDRAM_Init()) { /* Return error */ return TM_LCD_Result_SDRAM_Error; } /* Fill default structure */ LCD.Width = LCD_PIXEL_WIDTH; LCD.Height = LCD_PIXEL_HEIGHT; LCD.CurrentFrameBuffer = LCD_FRAME_BUFFER; LCD.FrameStart = LCD_FRAME_BUFFER; LCD.FrameOffset = LCD_BUFFER_OFFSET; LCD.CurrentFont = &TM_Font_11x18; LCD.ForegroundColor = 0x0000; LCD.BackgroundColor = 0xFFFF; LCD.Orientation = 1; /* Set orientation */ TM_LCD_SetOrientation(LCD.Orientation); /* Set configrations for DMA2D */ DMA2DConf.BufferStart = LCD_FRAME_BUFFER; DMA2DConf.BufferOffset = LCD_BUFFER_OFFSET; DMA2DConf.BytesPerPixel = LCD_PIXEL_SIZE; DMA2DConf.Width = LCD_PIXEL_WIDTH; DMA2DConf.Height = LCD_PIXEL_HEIGHT; DMA2DConf.Orientation = 1; /* Init LCD pins */ TM_LCD_INT_InitPins(); /* Init LCD dependant settings */ TM_LCD_INT_InitLCD(); /* Init LTDC peripheral */ TM_LCD_INT_InitLTDC(); /* Init LTDC layers */ TM_LCD_INT_InitLayers(); /* Init DMA2D GRAPHICS */ TM_DMA2DGRAPHIC_Init(); /* Set settings */ TM_INT_DMA2DGRAPHIC_SetConf(&DMA2DConf); /* Enable LCD */ TM_LCD_DisplayOn(); /* Set layer 1 as active layer */ TM_LCD_SetLayer1(); TM_LCD_Fill(LCD_COLOR_WHITE); TM_LCD_SetLayer2(); TM_LCD_Fill(LCD_COLOR_WHITE); TM_LCD_SetLayer1(); /* Set layer 1 as active layer */ TM_LCD_SetLayer1Opacity(255); TM_LCD_SetLayer2Opacity(0); /* Return OK */ return TM_LCD_Result_Ok; }
int main(void) { /* Init system */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay */ TM_DELAY_Init(); #if defined(STM32F429_DISCOVERY) || defined(STM32F7_DISCOVERY) || defined(STM32F439_EVAL) /* Init LCD */ TM_LCD_Init(); TM_LCD_SetFont(&TM_Font_7x10); TM_LCD_SetXY(5, 5); #if defined(STM32F7_DISCOVERY) /* Rotate LCD */ TM_LCD_SetOrientation(2); #endif #endif /* Init USB peripheral */ TM_USB_Init(); /* Init HOST on HS mode */ TM_USBH_Init(TM_USB_HS); /* Init USB CDC DEVICE on FS port */ TM_USBD_CDC_Init(TM_USB_FS); /* Send debug */ printf("USB FS configured as CDC device!\n"); /* Init USB HOST HID on HS port */ TM_USBH_HID_Init(TM_USB_HS); /* Send debug */ printf("USB HS configured as HID host!\n"); /* Start USB CDC device */ TM_USBD_Start(TM_USB_FS); /* Send debug */ printf("USB FS started!\n"); /* Start USB HID host */ TM_USBH_Start(TM_USB_HS); /* Send debug */ printf("USB HS started!\n"); while (1) { /* Process USB CDC device, send remaining data if needed */ /* It is better if you call this in periodic timer, like each ms in SYSTICK handler */ TM_USBD_CDC_Process(TM_USB_FS); /* Process USB HID Host */ TM_USBH_Process(TM_USB_HS); /* Check if CDC device is ready, if drivers are installed if needed */ if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) { /* Turn ON led */ TM_DISCO_LedOn(LED_GREEN); /* Print if needed */ if (!FS_Printed) { printf("FS: CDC ready to use!\n"); FS_Printed = 1; } } else { /* Turn OFF led */ TM_DISCO_LedOff(LED_GREEN); /* Print if needed */ if (FS_Printed) { printf("FS: CDC not ready to use!\n"); FS_Printed = 0; } } /* Check if anything received on FS port */ if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) { /* One character received */ /* Send it back */ TM_USBD_CDC_Putc(TM_USB_FS, ch); } /* Check HS port if anything connected */ if ( TM_USBH_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok && TM_USBH_IsDeviceReady(TM_USB_HS) == TM_USBH_Result_Ok ) { /* Something is connected */ /* Check for HID */ if (TM_USBH_HID_GetConnected(TM_USB_HS) == TM_USBH_HID_Keyboard) { if (!HS_Printed) { printf("HS: Keyboard connected!\n"); HS_Printed = 1; } } else if (TM_USBH_HID_GetConnected(TM_USB_HS) == TM_USBH_HID_Mouse) { if (!HS_Printed) { printf("HS: Mouse connected!\n"); HS_Printed = 1; } } else { /* No HID connected */ if (!HS_Printed) { printf("HS: Unknown connected!\n"); HS_Printed = 1; } } } else { /* Device not connected */ if (HS_Printed) { printf("HS: Device disconnected!\n"); HS_Printed = 0; } } } }
int main(void) { uint32_t i = 0, freq = 0; /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init LCD */ TM_LCD_Init(); #if defined(STM32F429_DISCOVERY) /* Rotate LCD to landscape mode */ TM_LCD_SetOrientation(2); #endif /* Print on LCD */ TM_LCD_SetXY(10, 10); TM_LCD_Puts("FFT Library example"); TM_LCD_SetXY(10, 30); TM_LCD_Puts("with software generated"); TM_LCD_SetXY(10, 50); TM_LCD_Puts("SINE wave"); /* Print "logo" */ TM_LCD_SetFont(&TM_Font_7x10); TM_LCD_SetXY(30, TM_LCD_GetHeight() - 15); TM_LCD_Puts("stm32f4-discovery.net"); /* Init FFT, FFT_SIZE define is used for FFT_SIZE, samples count is FFT_SIZE * 2, don't use malloc for memory allocation */ TM_FFT_Init_F32(&FFT, FFT_SIZE, 0); /* We didn't used malloc for allocation, so we have to set pointers ourself */ /* Input buffer must be 2 * FFT_SIZE in length because of real and imaginary part */ /* Output buffer must be FFT_SIZE in length */ TM_FFT_SetBuffers_F32(&FFT, Input, Output); while (1) { /* Let's fake sinus signal with 5, 15 and 30Hz frequencies */ do { /* Calculate sinus value */ sin_val = 0; sin_val += (float)0.5 * (float)sin((float)2 * (float)3.14159265359 * (float)1 * (float)freq * (float)i / (float)(FFT_SIZE / 2)); sin_val += (float)0.3 * (float)sin((float)2 * (float)3.14159265359 * (float)2 * (float)freq * (float)i / (float)(FFT_SIZE / 2)); sin_val += (float)0.1 * (float)sin((float)2 * (float)3.14159265359 * (float)3 * (float)freq * (float)i / (float)(FFT_SIZE / 2)); i++; } while (!TM_FFT_AddToBuffer(&FFT, sin_val)); /* Do FFT on signal, values at each bin and calculate max value and index where max value happened */ TM_FFT_Process_F32(&FFT); /* Display data on LCD, only single sided spectrum of FFT */ for (i = 0; i < (TM_FFT_GetFFTSize(&FFT) / 2); i++) { /* Draw FFT results */ DrawBar(30 + 2 * i, TM_LCD_GetHeight() - 30, FFT_BAR_MAX_HEIGHT, TM_FFT_GetMaxValue(&FFT), TM_FFT_GetFromBuffer(&FFT, i), 0x1234, 0xFFFF ); } /* Increase frequency */ freq++; /* Check value */ if (freq > 100) { freq = 0; } /* Little delay */ Delayms(50); } }