]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/source/isi.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained / libchip_samv7 / source / isi.c
diff --git a/FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/source/isi.c b/FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/source/isi.c
deleted file mode 100644 (file)
index 14e7e19..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-/* ----------------------------------------------------------------------------\r
- *         SAM Software Package License \r
- * ----------------------------------------------------------------------------\r
- * Copyright (c) 2013, Atmel Corporation\r
- *\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions are met:\r
- *\r
- * - Redistributions of source code must retain the above copyright notice,\r
- * this list of conditions and the disclaimer below.\r
- *\r
- * Atmel's name may not be used to endorse or promote products derived from\r
- * this software without specific prior written permission.\r
- *\r
- * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
- * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- * ----------------------------------------------------------------------------\r
- */\r
-\r
-\r
-/*----------------------------------------------------------------------------\r
- *        Headers\r
- *----------------------------------------------------------------------------*/\r
-\r
-#include "chip.h"\r
-\r
-/*----------------------------------------------------------------------------\r
- *        Export functions\r
- *----------------------------------------------------------------------------*/\r
-\r
-/**\r
- * \brief Enable ISI\r
- */\r
-void ISI_Enable(void)\r
-{\r
-    REG_ISI_CR |= ISI_CR_ISI_EN;\r
-    while( (REG_ISI_SR & ISI_CR_ISI_EN)!=ISI_CR_ISI_EN);\r
-    REG_ISI_DMA_CHER |= ISI_DMA_CHER_P_CH_EN | ISI_DMA_CHER_C_CH_EN;\r
-}\r
-\r
-\r
-/**\r
- * \brief Disable ISI\r
- */\r
-void ISI_Disable(void)\r
-{\r
-    REG_ISI_CR |= ISI_CR_ISI_DIS;\r
-    REG_ISI_DMA_CHDR |= ISI_DMA_CHDR_P_CH_DIS;\r
-}\r
-\r
-\r
-/**\r
- * \brief Enable ISI interrupt\r
- * \param  flag of interrupt to enable\r
- */\r
-void ISI_EnableInterrupt(uint32_t flag)\r
-{\r
-    REG_ISI_IER = flag;\r
-}\r
-\r
-\r
-/**\r
- * \brief Disable ISI interrupt\r
- * \param  flag of interrupt to disable\r
- */\r
-void ISI_DisableInterrupt(uint32_t flag)\r
-{\r
-    REG_ISI_IDR = flag;\r
-}\r
-\r
-\r
-\r
-/**\r
- * \brief Return ISI status register\r
- * \return Status of ISI register\r
- */\r
-uint32_t ISI_StatusRegister(void)\r
-{\r
-    return(REG_ISI_SR);\r
-}\r
-\r
-\r
-/**\r
- * \brief Enable Codec path for capture next frame\r
- */\r
-void ISI_CodecPathFull(void)\r
-{\r
-    // The codec path is enabled and the next frame is captured.\r
-    // Both codec and preview datapaths are working simultaneously\r
-    REG_ISI_CR |= ISI_CR_ISI_CDC;\r
-    REG_ISI_CFG1 |= ISI_CFG1_FULL;\r
-}\r
-\r
-\r
-/**\r
- * \brief Set frame rate\r
- * \param frate frame rate capture\r
- */\r
-void ISI_SetFrame(uint32_t frate)\r
-{\r
-    if( frate > 7 ) {\r
-        TRACE_ERROR("FRate too big\n\r");\r
-        frate = 7;\r
-    }\r
-    REG_ISI_CFG1 |= ISI_CFG1_FRATE(frate);\r
-}\r
-\r
-\r
-/**\r
- * \brief Get the number of byte per pixels\r
- * \param bmpRgb BMP type can be YUV or RGB\r
- */\r
-uint8_t ISI_BytesForOnePixel(uint8_t bmpRgb)\r
-{\r
-    uint8_t nbByte_Pixel;\r
-\r
-    if (bmpRgb == RGB) {\r
-        if ((REG_ISI_CFG2 & ISI_CFG2_RGB_MODE) == ISI_CFG2_RGB_MODE){\r
-            // RGB: 5:6:5 16bits/pixels\r
-            nbByte_Pixel = 2;\r
-        } \r
-        else {\r
-            // RGB: 8:8:8 24bits/pixels\r
-            nbByte_Pixel = 3;\r
-        }\r
-    } \r
-    else {\r
-        // YUV: 2 pixels for 4 bytes\r
-        nbByte_Pixel = 2;\r
-    }\r
-    return nbByte_Pixel;\r
-}\r
-\r
-\r
-/**\r
- * \brief Reset ISI\r
- */\r
-void ISI_Reset(void)\r
-{\r
-    uint32_t timeout=0;\r
-\r
-    // Resets the image sensor interface.\r
-    // Finish capturing the current frame and then shut down the module.\r
-    REG_ISI_CR = ISI_CR_ISI_SRST | ISI_CR_ISI_DIS;\r
-    // wait Software reset has completed successfully.\r
-    while( (!(REG_ISI_SR & ISI_SR_SRST))\r
-        && (timeout < 0x5000) ){\r
-        timeout++;\r
-    }\r
-    if( timeout == 0x5000 ) {\r
-        TRACE_ERROR("ISI-Reset timeout\n\r");\r
-    }\r
-}\r
-\r
-/**\r
- * \brief ISI initialize\r
- * \param pVideo structure of video driver\r
- */\r
-void ISI_Init(pIsi_Video pVideo)\r
-{\r
-    uint32_t hRatio, vRatio;\r
-    ISI_Reset();\r
-\r
-    // SLD pixel clock periods to wait before the beginning of a line.\r
-    // SFD lines are skipped at the beginning of the frame.\r
-    REG_ISI_CFG1 |= ISI_CFG1_SLD(pVideo->Hblank) + ISI_CFG1_SFD(pVideo->Vblank);\r
-    REG_ISI_CFG1 |=ISI_CFG1_DISCR;\r
-    TRACE_DEBUG("ISI_CFG1=0x%X\n\r", REG_ISI_CFG1);\r
-\r
-    // IM_VSIZE: Vertical size of the Image sensor [0..2047]\r
-    // Vertical size = IM_VSIZE + 1\r
-    // IM_HSIZE: Horizontal size of the Image sensor [0..2047]\r
-    // Horizontal size = IM_HSIZE + 1\r
-    // YCC_SWAP : YCC image data    \r
-    REG_ISI_CFG2 = ISI_CFG2_IM_VSIZE(pVideo->codec_vsize - 1)\r
-                 + ISI_CFG2_IM_HSIZE(pVideo->codec_hsize - 1);\r
-    \r
-    if (pVideo->rgb_or_yuv == RGB) {\r
-        REG_ISI_CFG2 |= ISI_CFG2_COL_SPACE | ISI_CFG2_RGB_MODE ;\r
-    }\r
-    else {\r
-         REG_ISI_CFG2|= ISI_CFG2_YCC_SWAP_MODE2 ;\r
-    }\r
-    TRACE_DEBUG("ISI_CFG2=0x%X\n\r", REG_ISI_CFG2);\r
-\r
-    // Vertical Preview size = PREV_VSIZE + 1 (480 max only in RGB mode).\r
-    // Horizontal Preview size = PREV_HSIZE + 1 (640 max only in RGB mode).\r
-\r
-    if( (pVideo->lcd_vsize > 480) || (pVideo->lcd_hsize > 640)) {\r
-        TRACE_ERROR("Size LCD bad define %d, %d\n\r",pVideo->lcd_vsize ,pVideo->lcd_hsize);\r
-        REG_ISI_PSIZE = ((480 - 1) ) + (((640-1) << 16) );\r
-    }\r
-    else {\r
-        REG_ISI_PSIZE = ((pVideo->lcd_vsize -1)) + (((pVideo->lcd_hsize -1) << 16) );\r
-    }\r
-    // DEC_FACTOR is 8-bit width, range is from 16 to 255. \r
-    // Values from 0 to 16 do not perform any decimation.\r
-    //REG_ISI_PDECF = (16 * pVideo->codec_hsize)/640;\r
-    hRatio = (16 * pVideo->codec_hsize)/(pVideo->lcd_hsize); \r
-    vRatio = (16 * pVideo->codec_vsize)/(pVideo->lcd_vsize); \r
-    REG_ISI_PDECF = (hRatio > vRatio )? vRatio: hRatio;\r
-\r
-    if (REG_ISI_PDECF < 16) REG_ISI_PDECF = 16;\r
-\r
-    REG_ISI_DMA_P_DSCR = pVideo->Isi_fbd_base;\r
-    REG_ISI_DMA_P_CTRL = ISI_DMA_P_CTRL_P_FETCH;\r
-    REG_ISI_DMA_P_ADDR = pVideo->lcd_fb_addr;\r
-\r
-    REG_ISI_DMA_C_DSCR = pVideo->codec_fbd_base;\r
-    REG_ISI_DMA_C_CTRL = ISI_DMA_C_CTRL_C_FETCH;\r
-    REG_ISI_DMA_C_ADDR = pVideo->codec_fb_addr;\r
-\r
-    // C0: Color Space Conversion Matrix Coefficient C0\r
-    // C1: Color Space Conversion Matrix Coefficient C1\r
-    // C2: Color Space Conversion Matrix Coefficient C2\r
-    // C3: Color Space Conversion Matrix Coefficient C3\r
-    REG_ISI_Y2R_SET0  = ISI_Y2R_SET0_C0(0x95)\r
-                      + ISI_Y2R_SET0_C1(0xFF)\r
-                      + ISI_Y2R_SET0_C2(0x68)\r
-                      + ISI_Y2R_SET0_C3(0x32);\r
-\r
-    // C4: Color Space Conversion Matrix coefficient C4\r
-    // Yoff: Color Space Conversion Luminance 128 offset\r
-    // Croff: Color Space Conversion Red Chrominance 16 offset\r
-    // Cboff: Color Space Conversion Blue Chrominance 16 offset\r
-    REG_ISI_Y2R_SET1  = ISI_Y2R_SET1_C4(0xCC)\r
-                      + ISI_Y2R_SET1_Yoff\r
-                      + ISI_Y2R_SET1_Croff\r
-                      + ISI_Y2R_SET1_Cboff;\r
-}\r
-\r