teste
Dependencies: mbed BSP_DISCO_F746NG FatFS
main.cpp@0:020195991898, 2018-02-03 (annotated)
- Committer:
- buyukesmeli
- Date:
- Sat Feb 03 14:39:39 2018 +0000
- Revision:
- 0:020195991898
- Child:
- 1:28e2f24b11b3
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
buyukesmeli | 0:020195991898 | 1 | #include "mbed.h" |
buyukesmeli | 0:020195991898 | 2 | #define USE_STM32746G_DISCOVERY |
buyukesmeli | 0:020195991898 | 3 | #include "stm32f7xx_hal.h" |
buyukesmeli | 0:020195991898 | 4 | #include "stm32746g_discovery.h" |
buyukesmeli | 0:020195991898 | 5 | #include "stm32746g_discovery_sd.h" |
buyukesmeli | 0:020195991898 | 6 | #include "string.h" |
buyukesmeli | 0:020195991898 | 7 | #include "stm32746g_discovery_lcd.h" |
buyukesmeli | 0:020195991898 | 8 | #include "ff_gen_drv.h" |
buyukesmeli | 0:020195991898 | 9 | #include "sd_diskio.h" |
buyukesmeli | 0:020195991898 | 10 | |
buyukesmeli | 0:020195991898 | 11 | #define FRAME_BUFFER 0xC0000000 |
buyukesmeli | 0:020195991898 | 12 | #define SD_IN_BUFFER 0xC0140000 |
buyukesmeli | 0:020195991898 | 13 | #define SD_OUT_BUFFER 0xC0280000 |
buyukesmeli | 0:020195991898 | 14 | |
buyukesmeli | 0:020195991898 | 15 | FATFS SDFatFs; |
buyukesmeli | 0:020195991898 | 16 | FIL MyFile; |
buyukesmeli | 0:020195991898 | 17 | |
buyukesmeli | 0:020195991898 | 18 | |
buyukesmeli | 0:020195991898 | 19 | |
buyukesmeli | 0:020195991898 | 20 | |
buyukesmeli | 0:020195991898 | 21 | static void LCD_LL_ConvertFrameToARGB8888(void *pSrc, void *pDst); |
buyukesmeli | 0:020195991898 | 22 | static void LCD_LL_ConvertFrameToRGB888(void *pSrc, void *pDst); |
buyukesmeli | 0:020195991898 | 23 | extern SD_HandleTypeDef uSdHandle; |
buyukesmeli | 0:020195991898 | 24 | DMA2D_HandleTypeDef hdma2d_disco; |
buyukesmeli | 0:020195991898 | 25 | |
buyukesmeli | 0:020195991898 | 26 | Serial pc(USBTX, USBRX); |
buyukesmeli | 0:020195991898 | 27 | uint32_t i = 0, image_width = 0, image_height = 0; |
buyukesmeli | 0:020195991898 | 28 | const char image_header[] = "P6\n# Generated by STM32\n272 480\n255\n"; |
buyukesmeli | 0:020195991898 | 29 | |
buyukesmeli | 0:020195991898 | 30 | char SDPath[4]; |
buyukesmeli | 0:020195991898 | 31 | char text [40]; |
buyukesmeli | 0:020195991898 | 32 | char c; |
buyukesmeli | 0:020195991898 | 33 | |
buyukesmeli | 0:020195991898 | 34 | int main(void) |
buyukesmeli | 0:020195991898 | 35 | { |
buyukesmeli | 0:020195991898 | 36 | FRESULT res; |
buyukesmeli | 0:020195991898 | 37 | uint32_t bytesread; |
buyukesmeli | 0:020195991898 | 38 | uint32_t line_cnt=0; |
buyukesmeli | 0:020195991898 | 39 | pc.baud(115200); |
buyukesmeli | 0:020195991898 | 40 | |
buyukesmeli | 0:020195991898 | 41 | BSP_LCD_Init(); |
buyukesmeli | 0:020195991898 | 42 | BSP_LCD_DisplayOff(); |
buyukesmeli | 0:020195991898 | 43 | BSP_LCD_LayerDefaultInit(0, FRAME_BUFFER); |
buyukesmeli | 0:020195991898 | 44 | BSP_LCD_SelectLayer(0); |
buyukesmeli | 0:020195991898 | 45 | BSP_LCD_DisplayOn(); |
buyukesmeli | 0:020195991898 | 46 | |
buyukesmeli | 0:020195991898 | 47 | FATFS_LinkDriver(&SD_Driver, SDPath); |
buyukesmeli | 0:020195991898 | 48 | |
buyukesmeli | 0:020195991898 | 49 | res = f_mount(&SDFatFs, (TCHAR const*)SDPath, 0); |
buyukesmeli | 0:020195991898 | 50 | if(res!= FR_OK) |
buyukesmeli | 0:020195991898 | 51 | pc.printf("Failed to mount SD\n"); |
buyukesmeli | 0:020195991898 | 52 | |
buyukesmeli | 0:020195991898 | 53 | res = f_open(&MyFile, "image.ppm", FA_READ); |
buyukesmeli | 0:020195991898 | 54 | if(res!= FR_OK) |
buyukesmeli | 0:020195991898 | 55 | pc.printf("Failed to open file\n"); |
buyukesmeli | 0:020195991898 | 56 | |
buyukesmeli | 0:020195991898 | 57 | while(1) { |
buyukesmeli | 0:020195991898 | 58 | |
buyukesmeli | 0:020195991898 | 59 | res = f_read(&MyFile, &c, 1, (UINT*)&bytesread); |
buyukesmeli | 0:020195991898 | 60 | if (c!='#') |
buyukesmeli | 0:020195991898 | 61 | line_cnt++; |
buyukesmeli | 0:020195991898 | 62 | if(line_cnt==2) { |
buyukesmeli | 0:020195991898 | 63 | text[0] = c; |
buyukesmeli | 0:020195991898 | 64 | res = f_read(&MyFile, &c, 1, (UINT*)&bytesread); |
buyukesmeli | 0:020195991898 | 65 | i = 1; |
buyukesmeli | 0:020195991898 | 66 | while(c!=' ') { |
buyukesmeli | 0:020195991898 | 67 | text[i]=c; |
buyukesmeli | 0:020195991898 | 68 | res = f_read(&MyFile, &c, 1, (UINT*)&bytesread); |
buyukesmeli | 0:020195991898 | 69 | i++; |
buyukesmeli | 0:020195991898 | 70 | } |
buyukesmeli | 0:020195991898 | 71 | text[i]=0; |
buyukesmeli | 0:020195991898 | 72 | image_width = atoi(text); |
buyukesmeli | 0:020195991898 | 73 | res = f_read(&MyFile, &c, 1, (UINT*)&bytesread); |
buyukesmeli | 0:020195991898 | 74 | i = 0; |
buyukesmeli | 0:020195991898 | 75 | while(c!='\n') { |
buyukesmeli | 0:020195991898 | 76 | text[i]=c; |
buyukesmeli | 0:020195991898 | 77 | res = f_read(&MyFile, &c, 1, (UINT*)&bytesread); |
buyukesmeli | 0:020195991898 | 78 | i++; |
buyukesmeli | 0:020195991898 | 79 | } |
buyukesmeli | 0:020195991898 | 80 | text[i]=0; |
buyukesmeli | 0:020195991898 | 81 | image_height = atoi(text); |
buyukesmeli | 0:020195991898 | 82 | } else { |
buyukesmeli | 0:020195991898 | 83 | while(c!='\n') |
buyukesmeli | 0:020195991898 | 84 | res = f_read(&MyFile, &c, 1, (UINT*)&bytesread); |
buyukesmeli | 0:020195991898 | 85 | } |
buyukesmeli | 0:020195991898 | 86 | if(line_cnt == 3) |
buyukesmeli | 0:020195991898 | 87 | break; |
buyukesmeli | 0:020195991898 | 88 | |
buyukesmeli | 0:020195991898 | 89 | } |
buyukesmeli | 0:020195991898 | 90 | pc.printf("w = %d \n",image_width); |
buyukesmeli | 0:020195991898 | 91 | pc.printf("h = %d \n",image_height); |
buyukesmeli | 0:020195991898 | 92 | |
buyukesmeli | 0:020195991898 | 93 | if(image_width != 480 || image_height != 272) |
buyukesmeli | 0:020195991898 | 94 | pc.printf("Image size should be 272x480"); |
buyukesmeli | 0:020195991898 | 95 | |
buyukesmeli | 0:020195991898 | 96 | for(i = 0; i < image_width*image_width*3; i = i + 512) { |
buyukesmeli | 0:020195991898 | 97 | res = f_read(&MyFile, (void *)(SD_IN_BUFFER+i) , 512, (UINT*)&bytesread); |
buyukesmeli | 0:020195991898 | 98 | } |
buyukesmeli | 0:020195991898 | 99 | f_close(&MyFile); |
buyukesmeli | 0:020195991898 | 100 | |
buyukesmeli | 0:020195991898 | 101 | LCD_LL_ConvertFrameToARGB8888((uint32_t *)(SD_IN_BUFFER), (uint32_t *)(FRAME_BUFFER)); |
buyukesmeli | 0:020195991898 | 102 | |
buyukesmeli | 0:020195991898 | 103 | |
buyukesmeli | 0:020195991898 | 104 | LCD_LL_ConvertFrameToRGB888((uint32_t *)(FRAME_BUFFER), (uint32_t *)(SD_OUT_BUFFER)); |
buyukesmeli | 0:020195991898 | 105 | |
buyukesmeli | 0:020195991898 | 106 | res = f_open(&MyFile, "image_ou.ppm", FA_CREATE_ALWAYS | FA_WRITE); |
buyukesmeli | 0:020195991898 | 107 | if(res!= FR_OK) |
buyukesmeli | 0:020195991898 | 108 | pc.printf("Failed to open file\n"); |
buyukesmeli | 0:020195991898 | 109 | |
buyukesmeli | 0:020195991898 | 110 | |
buyukesmeli | 0:020195991898 | 111 | res = f_write(&MyFile, image_header, 15, &bytesread); |
buyukesmeli | 0:020195991898 | 112 | if(res!= FR_OK) |
buyukesmeli | 0:020195991898 | 113 | pc.printf("Failed to write file 1\n"); |
buyukesmeli | 0:020195991898 | 114 | |
buyukesmeli | 0:020195991898 | 115 | for(i = 0; i < 480*272*3; i = i + 512) { |
buyukesmeli | 0:020195991898 | 116 | res = f_write(&MyFile, (uint8_t *)(SD_OUT_BUFFER+i), 512, &bytesread); |
buyukesmeli | 0:020195991898 | 117 | if(res!= FR_OK) |
buyukesmeli | 0:020195991898 | 118 | pc.printf("Failed to write file\n"); |
buyukesmeli | 0:020195991898 | 119 | } |
buyukesmeli | 0:020195991898 | 120 | f_close(&MyFile); |
buyukesmeli | 0:020195991898 | 121 | FATFS_UnLinkDriver(SDPath); |
buyukesmeli | 0:020195991898 | 122 | |
buyukesmeli | 0:020195991898 | 123 | while (1) { |
buyukesmeli | 0:020195991898 | 124 | } |
buyukesmeli | 0:020195991898 | 125 | } |
buyukesmeli | 0:020195991898 | 126 | extern "C" { |
buyukesmeli | 0:020195991898 | 127 | void BSP_SDMMC_IRQHandler(void) |
buyukesmeli | 0:020195991898 | 128 | { |
buyukesmeli | 0:020195991898 | 129 | HAL_SD_IRQHandler(&uSdHandle); |
buyukesmeli | 0:020195991898 | 130 | } |
buyukesmeli | 0:020195991898 | 131 | void BSP_SDMMC_DMA_Tx_IRQHandler(void) |
buyukesmeli | 0:020195991898 | 132 | { |
buyukesmeli | 0:020195991898 | 133 | HAL_DMA_IRQHandler(uSdHandle.hdmatx); |
buyukesmeli | 0:020195991898 | 134 | } |
buyukesmeli | 0:020195991898 | 135 | void BSP_SDMMC_DMA_Rx_IRQHandler(void) |
buyukesmeli | 0:020195991898 | 136 | { |
buyukesmeli | 0:020195991898 | 137 | HAL_DMA_IRQHandler(uSdHandle.hdmarx); |
buyukesmeli | 0:020195991898 | 138 | } |
buyukesmeli | 0:020195991898 | 139 | static void LCD_LL_ConvertFrameToARGB8888(void *pSrc, void *pDst) |
buyukesmeli | 0:020195991898 | 140 | { |
buyukesmeli | 0:020195991898 | 141 | /* Enable DMA2D clock */ |
buyukesmeli | 0:020195991898 | 142 | __HAL_RCC_DMA2D_CLK_ENABLE(); |
buyukesmeli | 0:020195991898 | 143 | |
buyukesmeli | 0:020195991898 | 144 | /* Configure the DMA2D Mode, Color Mode and output offset */ |
buyukesmeli | 0:020195991898 | 145 | hdma2d_disco.Init.Mode = DMA2D_M2M_PFC; |
buyukesmeli | 0:020195991898 | 146 | hdma2d_disco.Init.ColorMode = DMA2D_ARGB8888; |
buyukesmeli | 0:020195991898 | 147 | hdma2d_disco.Init.OutputOffset = 0; |
buyukesmeli | 0:020195991898 | 148 | |
buyukesmeli | 0:020195991898 | 149 | /* Foreground Configuration */ |
buyukesmeli | 0:020195991898 | 150 | hdma2d_disco.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
buyukesmeli | 0:020195991898 | 151 | hdma2d_disco.LayerCfg[1].InputAlpha = 0xFF; |
buyukesmeli | 0:020195991898 | 152 | hdma2d_disco.LayerCfg[1].InputColorMode = CM_RGB888; |
buyukesmeli | 0:020195991898 | 153 | hdma2d_disco.LayerCfg[1].InputOffset = 0; |
buyukesmeli | 0:020195991898 | 154 | |
buyukesmeli | 0:020195991898 | 155 | hdma2d_disco.Instance = DMA2D; |
buyukesmeli | 0:020195991898 | 156 | |
buyukesmeli | 0:020195991898 | 157 | /* DMA2D Initialization */ |
buyukesmeli | 0:020195991898 | 158 | if(HAL_DMA2D_Init(&hdma2d_disco) == HAL_OK) { |
buyukesmeli | 0:020195991898 | 159 | if(HAL_DMA2D_ConfigLayer(&hdma2d_disco, 1) == HAL_OK) { |
buyukesmeli | 0:020195991898 | 160 | if (HAL_DMA2D_Start(&hdma2d_disco, (uint32_t)pSrc, (uint32_t)pDst, 480, 272) == HAL_OK) { |
buyukesmeli | 0:020195991898 | 161 | /* Polling For DMA transfer */ |
buyukesmeli | 0:020195991898 | 162 | HAL_DMA2D_PollForTransfer(&hdma2d_disco, 10); |
buyukesmeli | 0:020195991898 | 163 | } |
buyukesmeli | 0:020195991898 | 164 | } |
buyukesmeli | 0:020195991898 | 165 | } else { |
buyukesmeli | 0:020195991898 | 166 | |
buyukesmeli | 0:020195991898 | 167 | } |
buyukesmeli | 0:020195991898 | 168 | } |
buyukesmeli | 0:020195991898 | 169 | static void LCD_LL_ConvertFrameToRGB888(void *pSrc, void *pDst) |
buyukesmeli | 0:020195991898 | 170 | { |
buyukesmeli | 0:020195991898 | 171 | /* Enable DMA2D clock */ |
buyukesmeli | 0:020195991898 | 172 | __HAL_RCC_DMA2D_CLK_ENABLE(); |
buyukesmeli | 0:020195991898 | 173 | |
buyukesmeli | 0:020195991898 | 174 | /* Configure the DMA2D Mode, Color Mode and output offset */ |
buyukesmeli | 0:020195991898 | 175 | hdma2d_disco.Init.Mode = DMA2D_M2M_PFC; |
buyukesmeli | 0:020195991898 | 176 | hdma2d_disco.Init.ColorMode = DMA2D_RGB888; |
buyukesmeli | 0:020195991898 | 177 | hdma2d_disco.Init.OutputOffset = 0; |
buyukesmeli | 0:020195991898 | 178 | |
buyukesmeli | 0:020195991898 | 179 | /* Foreground Configuration */ |
buyukesmeli | 0:020195991898 | 180 | hdma2d_disco.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
buyukesmeli | 0:020195991898 | 181 | hdma2d_disco.LayerCfg[1].InputAlpha = 0xFF; |
buyukesmeli | 0:020195991898 | 182 | hdma2d_disco.LayerCfg[1].InputColorMode = CM_ARGB8888; |
buyukesmeli | 0:020195991898 | 183 | hdma2d_disco.LayerCfg[1].InputOffset = 0; |
buyukesmeli | 0:020195991898 | 184 | |
buyukesmeli | 0:020195991898 | 185 | hdma2d_disco.Instance = DMA2D; |
buyukesmeli | 0:020195991898 | 186 | |
buyukesmeli | 0:020195991898 | 187 | /* DMA2D Initialization */ |
buyukesmeli | 0:020195991898 | 188 | if(HAL_DMA2D_Init(&hdma2d_disco) == HAL_OK) { |
buyukesmeli | 0:020195991898 | 189 | if(HAL_DMA2D_ConfigLayer(&hdma2d_disco, 1) == HAL_OK) { |
buyukesmeli | 0:020195991898 | 190 | if (HAL_DMA2D_Start(&hdma2d_disco, (uint32_t)pSrc, (uint32_t)pDst, 480, 272) == HAL_OK) { |
buyukesmeli | 0:020195991898 | 191 | /* Polling For DMA transfer */ |
buyukesmeli | 0:020195991898 | 192 | HAL_DMA2D_PollForTransfer(&hdma2d_disco, 10); |
buyukesmeli | 0:020195991898 | 193 | } |
buyukesmeli | 0:020195991898 | 194 | } |
buyukesmeli | 0:020195991898 | 195 | } else { |
buyukesmeli | 0:020195991898 | 196 | |
buyukesmeli | 0:020195991898 | 197 | } |
buyukesmeli | 0:020195991898 | 198 | } |
buyukesmeli | 0:020195991898 | 199 | |
buyukesmeli | 0:020195991898 | 200 | } |