2 ******************************************************************************
3 * @file stm32f7xx_hal_jpeg.c
4 * @author MCD Application Team
7 * @brief JPEG HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the JPEG encoder/decoder peripheral:
10 * + Initialization and de-initialization functions
11 * + JPEG processing functions encoding and decoding
12 * + JPEG decoding Getting Info and encoding configuration setting
13 * + JPEG enable/disable header parsing functions (for decoding)
14 * + JPEG Input/Output Buffer configuration.
15 * + JPEG callback functions
16 * + JPEG Abort/Pause/Resume functions
17 * + JPEG custom quantization tables setting functions
18 * + IRQ handler management
19 * + Peripheral State and Error functions
22 ==============================================================================
23 ##### How to use this driver #####
24 ==============================================================================
26 (#) Initialize the JPEG peripheral using HAL_JPEG_Init : No initialization parameters are required.
27 Only the call to HAL_JPEG_Init is necessary to initialize the JPEG peripheral.
29 (#) If operation is JPEG encoding use function HAL_JPEG_ConfigEncoding to set
30 the encoding parameters (mandatory before calling the encoding function).
31 the application can change the encoding parameter "ImageQuality" from
32 1 to 100 to obtain a more or less quality (visual quality vs the original row image),
33 and inversely more or less jpg file size.
35 (#) Note that for decoding operation the JPEG peripheral output data are organized in
36 YCbCr blocks called MCU (Minimum Coded Unit) as defioned in the JPEG specification
37 ISO/IEC 10918-1 standard.
38 It is up to the application to transform these YCbCr blocks to RGB data that can be display.
40 Respectively, for Encoding operation the JPEG peripheral input should be organized
41 in YCbCr MCU blocks. It is up to the application to perform the necessary RGB to YCbCr
42 MCU blocks transformation before feeding the JPEG peripheral with data.
44 (#) Use functions HAL_JPEG_Encode and HAL_JPEG_Decode to start respectively
45 a JPEG encoding/decoding operation in polling method (blocking).
47 (#) Use functions HAL_JPEG_Encode_IT and HAL_JPEG_Decode_IT to start respectively
48 a JPEG encoding/decoding operation with Interrupt method (not blocking).
50 (#) Use functions HAL_JPEG_Encode_DMA and HAL_JPEG_Decode_DMA to start respectively
51 a JPEG encoding/decoding operation with DMA method (not blocking).
53 (#) Callback HAL_JPEG_InfoReadyCallback is asserted if the current operation
54 is a JPEG decoding to provide the application with JPEG image parameters.
55 This callback is asserted when the JPEG peripheral successfully parse the
58 (#) Callback HAL_JPEG_GetDataCallback is asserted for both encoding and decoding
59 operations to inform the application that the input buffer has been
60 consumed by the peripheral and to ask for a new data chunk if the operation
61 (encoding/decoding) has not been complete yet.
63 This CallBack should be implemented in the application side. It should
64 call the function HAL_JPEG_ConfigInputBuffer if new input data are available,
65 or call HAL_JPEG_Pause with parameter XferSelection set to "JPEG_PAUSE_RESUME_INPUT"
66 to inform the JPEG HAL driver that the ongoing operation shall pause waiting for the
67 application to provide a new input data chunk.
68 Once the application succeed getting new data and if the input has been paused,
69 the application can call the function HAL_JPEG_ConfigInputBuffer to set the new
70 input buffer and size, then resume the JPEG HAL input by calling new function HAL_JPEG_Resume.
71 If the application has ended feeding the HAL JPEG with input data (no more input data), the application
72 Should call the function \93HAL_JPEG_ConfigInputBuffer\94 (within the callback HAL_JPEG_GetDataCallback)
73 with the parameter \93InDataLength\94 set to zero.
75 The mechanism of HAL_JPEG_ConfigInputBuffer/HAL_JPEG_Pause/HAL_JPEG_Resume allows
76 to the application to provide the input data (for encoding or decoding) by chunks.
77 If the new input data chunk is not available (because data should be read from an input file
78 for example) the application can pause the JPEG input (using function HAL_JPEG_Pause)
79 Once the new input data chunk is available ( read from a file for example), the application
80 can call the function "HAL_JPEG_ConfigInputBuffer" to provide the HAL with the new chunk
81 then resume the JPEG HAL input by calling function "HAL_JPEG_Resume".
83 The application can call functions \93HAL_JPEG_ConfigInputBuffer \93 then "HAL_JPEG_Resume".
84 any time (outside the HAL_JPEG_GetDataCallback) Once the new input chunk data available.
85 However, to keep data coherency, the function \93HAL_JPEG_Pause\94 must be imperatively called
86 (if necessary) within the callback \93HAL_JPEG_GetDataCallback\94, i.e when the HAL JPEG has ended
87 Transferring the previous chunk buffer to the JPEG peripheral.
89 (#) Callback HAL_JPEG_DataReadyCallback is asserted when the HAL JPEG driver
90 has filled the given output buffer with the given size.
92 This CallBack should be implemented in the application side. It should
93 call the function HAL_JPEG_ConfigOutputBuffer to provide the HAL JPEG driver
94 with the new output buffer location and size to be used to store next data chunk.
95 if the application is not ready to provide the output chunk location then it can
96 call the function "HAL_JPEG_Pause" with parameter XferSelection set to "JPEG_PAUSE_RESUME_OUTPUT"
97 to inform the JPEG HAL driver that it shall pause output data. Once the application
98 is ready to receive the new data chunk (output buffer location free or available) it should call
99 the function "HAL_JPEG_ConfigOutputBuffer" to provide the HAL JPEG driver
100 with the new output chunk buffer location and size, then call "HAL_JPEG_Resume"
101 to inform the HAL that it shall resume outputting data in the given output buffer.
103 The mechanism of HAL_JPEG_ConfigOutputBuffer/HAL_JPEG_Pause/HAL_JPEG_Resume allows
104 the application to receive data from the JPEG peripheral by chunks. when a chunk
105 is received, the application can pause the HAL JPEG output data to be able to process
106 these received data (YCbCr to RGB conversion in case of decoding or data storage in case
109 The application can call functions \93HAL_JPEG_ ConfigOutputBuffer\93 then "HAL_JPEG_Resume".
110 any time (outside the HAL_JPEG_ DataReadyCallback) Once the output data buffer is free to use.
111 However, to keep data coherency, the function \93HAL_JPEG_Pause\94 must be imperatively called
112 (if necessary) within the callback \93HAL_JPEG_ DataReadyCallback\94, i.e when the HAL JPEG has ended
113 Transferring the previous chunk buffer from the JPEG peripheral to the application.
115 (#) Callback HAL_JPEG_EncodeCpltCallback is asserted when the HAL JPEG driver has
116 ended the current JPEG encoding operation, and all output data has been transmitted
119 (#) Callback HAL_JPEG_DecodeCpltCallback is asserted when the HAL JPEG driver has
120 ended the current JPEG decoding operation. and all output data has been transmitted
123 (#) Callback HAL_JPEG_ErrorCallback is asserted when an error occurred during
124 the current operation. the application can call the function "HAL_JPEG_GetError"
125 to retrieve the error codes.
127 (#) By default the HAL JPEG driver uses the default quantization tables
128 as provide in the JPEG specification (ISO/IEC 10918-1 standard) for encoding.
129 User can change these default tables if necessary using the function "HAL_JPEG_SetUserQuantTables"
130 Note that for decoding the quantization tables are automatically extracted from
133 (#) To control JPEG state you can use the following function: HAL_JPEG_GetState()
135 *** JPEG HAL driver macros list ***
136 =============================================
138 Below the list of most used macros in JPEG HAL driver.
140 (+) __HAL_JPEG_RESET_HANDLE_STATE : Reset JPEG handle state.
141 (+) __HAL_JPEG_ENABLE : Enable the JPEG peripheral.
142 (+) __HAL_JPEG_DISABLE : Disable the JPEG peripheral.
143 (+) __HAL_JPEG_GET_FLAG : Check the specified JPEG status flag.
144 (+) __HAL_JPEG_CLEAR_FLAG : Clear the specified JPEG status flag.
145 (+) __HAL_JPEG_ENABLE_IT : Enable the specified JPEG Interrupt.
146 (+) __HAL_JPEG_DISABLE_IT : Disable the specified JPEG Interrupt.
147 (+) __HAL_JPEG_GET_IT_SOURCE : returns the state of the specified JPEG Interrupt (Enabled or disabled).
151 ******************************************************************************
154 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
156 * Redistribution and use in source and binary forms, with or without modification,
157 * are permitted provided that the following conditions are met:
158 * 1. Redistributions of source code must retain the above copyright notice,
159 * this list of conditions and the following disclaimer.
160 * 2. Redistributions in binary form must reproduce the above copyright notice,
161 * this list of conditions and the following disclaimer in the documentation
162 * and/or other materials provided with the distribution.
163 * 3. Neither the name of STMicroelectronics nor the names of its contributors
164 * may be used to endorse or promote products derived from this software
165 * without specific prior written permission.
167 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
168 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
169 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
170 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
171 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
172 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
173 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
174 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
175 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
176 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
178 ******************************************************************************
181 /* Includes ------------------------------------------------------------------*/
182 #include "stm32f7xx_hal.h"
184 /** @addtogroup STM32F7xx_HAL_Driver
188 /** @defgroup JPEG JPEG
189 * @brief JPEG HAL module driver.
193 #ifdef HAL_JPEG_MODULE_ENABLED
195 #if defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx)
197 /* Private define ------------------------------------------------------------*/
198 /** @addtogroup JPEG_Private_Constants
201 #define JPEG_TIMEOUT_VALUE ((uint32_t)1000U) /* 1s */
202 #define JPEG_AC_HUFF_TABLE_SIZE ((uint32_t)162U) /* Huffman AC table size : 162 codes*/
203 #define JPEG_DC_HUFF_TABLE_SIZE ((uint32_t)12U) /* Huffman AC table size : 12 codes*/
205 #define JPEG_FIFO_SIZE ((uint32_t)8U) /* JPEG Input/Output HW FIFO size in words*/
207 #define JPEG_INTERRUPT_MASK ((uint32_t)0x0000007EU) /* JPEG Interrupt Mask*/
209 #define JPEG_DMA_MASK ((uint32_t)0x00001800U) /* JPEG DMA request Mask*/
210 #define JPEG_DMA_IDMA ((uint32_t)JPEG_CR_IDMAEN) /* DMA request for the input FIFO */
211 #define JPEG_DMA_ODMA ((uint32_t)JPEG_CR_ODMAEN) /* DMA request for the output FIFO */
213 #define JPEG_CONTEXT_ENCODE ((uint32_t)0x00000001U) /* JPEG context : operation is encoding*/
214 #define JPEG_CONTEXT_DECODE ((uint32_t)0x00000002U) /* JPEG context : operation is decoding*/
215 #define JPEG_CONTEXT_OPERATION_MASK ((uint32_t)0x00000003U) /* JPEG context : operation Mask */
217 #define JPEG_CONTEXT_POLLING ((uint32_t)0x00000004U) /* JPEG context : Transfer use Polling */
218 #define JPEG_CONTEXT_IT ((uint32_t)0x00000008U) /* JPEG context : Transfer use Interrupt */
219 #define JPEG_CONTEXT_DMA ((uint32_t)0x0000000CU) /* JPEG context : Transfer use DMA */
220 #define JPEG_CONTEXT_METHOD_MASK ((uint32_t)0x0000000CU) /* JPEG context : Transfer Mask */
223 #define JPEG_CONTEXT_CONF_ENCODING ((uint32_t)0x00000100U) /* JPEG context : encoding config done */
225 #define JPEG_CONTEXT_PAUSE_INPUT ((uint32_t)0x00001000U) /* JPEG context : Pause Input */
226 #define JPEG_CONTEXT_PAUSE_OUTPUT ((uint32_t)0x00002000U) /* JPEG context : Pause Output */
228 #define JPEG_CONTEXT_CUSTOM_TABLES ((uint32_t)0x00004000U) /* JPEG context : Use custom quantization tables */
230 #define JPEG_CONTEXT_ENDING_DMA ((uint32_t)0x00008000U) /* JPEG context : ending with DMA in progress */
232 #define JPEG_PROCESS_ONGOING ((uint32_t)0x00000000U) /* Process is on going */
233 #define JPEG_PROCESS_DONE ((uint32_t)0x00000001U) /* Process is done (ends) */
238 /* Private typedef -----------------------------------------------------------*/
239 /** @addtogroup JPEG_Private_Types
244 JPEG Huffman Table Structure definition :
245 This implementation of Huffman table structure is compliant with ISO/IEC 10918-1 standard , Annex C Huffman Table specification
249 /* These two fields directly represent the contents of a JPEG DHT marker */
250 uint8_t Bits
[16]; /*!< bits[k] = # of symbols with codes of length k bits, this parameter corresponds to BITS list in the Annex C */
252 uint8_t HuffVal
[162]; /*!< The symbols, in order of incremented code length, this parameter corresponds to HUFFVAL list in the Annex C */
255 }JPEG_ACHuffTableTypeDef
;
259 /* These two fields directly represent the contents of a JPEG DHT marker */
260 uint8_t Bits
[16]; /*!< bits[k] = # of symbols with codes of length k bits, this parameter corresponds to BITS list in the Annex C */
262 uint8_t HuffVal
[12]; /*!< The symbols, in order of incremented code length, this parameter corresponds to HUFFVAL list in the Annex C */
265 }JPEG_DCHuffTableTypeDef
;
269 uint8_t CodeLength
[JPEG_AC_HUFF_TABLE_SIZE
]; /*!< Code length */
271 uint32_t HuffmanCode
[JPEG_AC_HUFF_TABLE_SIZE
]; /*!< HuffmanCode */
273 }JPEG_AC_HuffCodeTableTypeDef
;
277 uint8_t CodeLength
[JPEG_DC_HUFF_TABLE_SIZE
]; /*!< Code length */
279 uint32_t HuffmanCode
[JPEG_DC_HUFF_TABLE_SIZE
]; /*!< HuffmanCode */
281 }JPEG_DC_HuffCodeTableTypeDef
;
286 /* Private macro -------------------------------------------------------------*/
287 /** @addtogroup JPEG_Private_Macros
290 #define JPEG_ENABLE_DMA(__HANDLE__,__DMA__) ((__HANDLE__)->Instance->CR |= ((__DMA__) & JPEG_DMA_MASK))
291 /*note : To disable a DMA request we must use MODIFY_REG macro to avoid writing "1" to the FIFO flush bits
292 located in the same DMA request enable register (CR register). */
293 #define JPEG_DISABLE_DMA(__HANDLE__,__DMA__) MODIFY_REG((__HANDLE__)->Instance->CR, ((__DMA__) & JPEG_DMA_MASK), 0)
299 /* Private variables ---------------------------------------------------------*/
300 /** @addtogroup JPEG_Private_Variables
304 static const JPEG_DCHuffTableTypeDef JPEG_DCLUM_HuffTable
=
306 { 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, /*Bits*/
308 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb } /*HUFFVAL */
312 static const JPEG_DCHuffTableTypeDef JPEG_DCCHROM_HuffTable
=
314 { 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, /*Bits*/
316 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb } /*HUFFVAL */
319 static const JPEG_ACHuffTableTypeDef JPEG_ACLUM_HuffTable
=
321 { 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }, /*Bits*/
323 { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, /*HUFFVAL */
324 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
325 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
326 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
327 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
328 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
329 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
330 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
331 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
332 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
333 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
334 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
335 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
336 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
337 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
338 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
339 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
340 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
341 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
342 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
346 static const JPEG_ACHuffTableTypeDef JPEG_ACCHROM_HuffTable
=
348 { 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }, /*Bits*/
350 { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, /*HUFFVAL */
351 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
352 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
353 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
354 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
355 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
356 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
357 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
358 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
359 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
360 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
361 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
362 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
363 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
364 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
365 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
366 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
367 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
368 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
369 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
375 These are the sample quantization tables given in JPEG spec ISO/IEC 10918-1 standard , section K.1.
377 static const uint8_t JPEG_LUM_QuantTable
[JPEG_QUANT_TABLE_SIZE
] =
379 16, 11, 10, 16, 24, 40, 51, 61,
380 12, 12, 14, 19, 26, 58, 60, 55,
381 14, 13, 16, 24, 40, 57, 69, 56,
382 14, 17, 22, 29, 51, 87, 80, 62,
383 18, 22, 37, 56, 68, 109, 103, 77,
384 24, 35, 55, 64, 81, 104, 113, 92,
385 49, 64, 78, 87, 103, 121, 120, 101,
386 72, 92, 95, 98, 112, 100, 103, 99
388 static const uint8_t JPEG_CHROM_QuantTable
[JPEG_QUANT_TABLE_SIZE
] =
390 17, 18, 24, 47, 99, 99, 99, 99,
391 18, 21, 26, 66, 99, 99, 99, 99,
392 24, 26, 56, 99, 99, 99, 99, 99,
393 47, 66, 99, 99, 99, 99, 99, 99,
394 99, 99, 99, 99, 99, 99, 99, 99,
395 99, 99, 99, 99, 99, 99, 99, 99,
396 99, 99, 99, 99, 99, 99, 99, 99,
397 99, 99, 99, 99, 99, 99, 99, 99
400 static const uint8_t JPEG_ZIGZAG_ORDER
[JPEG_QUANT_TABLE_SIZE
] =
402 0, 1, 8, 16, 9, 2, 3, 10,
403 17, 24, 32, 25, 18, 11, 4, 5,
404 12, 19, 26, 33, 40, 48, 41, 34,
405 27, 20, 13, 6, 7, 14, 21, 28,
406 35, 42, 49, 56, 57, 50, 43, 36,
407 29, 22, 15, 23, 30, 37, 44, 51,
408 58, 59, 52, 45, 38, 31, 39, 46,
409 53, 60, 61, 54, 47, 55, 62, 63
415 /* Private function prototypes -----------------------------------------------*/
416 /** @addtogroup JPEG_Private_Functions_Prototypes
420 static HAL_StatusTypeDef
JPEG_Bits_To_SizeCodes(uint8_t *Bits
, uint8_t *Huffsize
, uint32_t *Huffcode
, uint32_t *LastK
);
421 static HAL_StatusTypeDef
JPEG_DCHuff_BitsVals_To_SizeCodes(JPEG_DCHuffTableTypeDef
*DC_BitsValsTable
, JPEG_DC_HuffCodeTableTypeDef
*DC_SizeCodesTable
);
422 static HAL_StatusTypeDef
JPEG_ACHuff_BitsVals_To_SizeCodes(JPEG_ACHuffTableTypeDef
*AC_BitsValsTable
, JPEG_AC_HuffCodeTableTypeDef
*AC_SizeCodesTable
);
423 static HAL_StatusTypeDef
JPEG_Set_HuffDC_Mem(JPEG_HandleTypeDef
*hjpeg
, JPEG_DCHuffTableTypeDef
*HuffTableDC
, uint32_t *DCTableAddress
);
424 static HAL_StatusTypeDef
JPEG_Set_HuffAC_Mem(JPEG_HandleTypeDef
*hjpeg
, JPEG_ACHuffTableTypeDef
*HuffTableAC
, uint32_t *ACTableAddress
);
425 static HAL_StatusTypeDef
JPEG_Set_HuffEnc_Mem(JPEG_HandleTypeDef
*hjpeg
, JPEG_ACHuffTableTypeDef
*HuffTableAC0
, JPEG_DCHuffTableTypeDef
*HuffTableDC0
, JPEG_ACHuffTableTypeDef
*HuffTableAC1
, JPEG_DCHuffTableTypeDef
*HuffTableDC1
);
426 static void JPEG_Set_Huff_DHTMem(JPEG_HandleTypeDef
*hjpeg
, JPEG_ACHuffTableTypeDef
*HuffTableAC0
, JPEG_DCHuffTableTypeDef
*HuffTableDC0
, JPEG_ACHuffTableTypeDef
*HuffTableAC1
, JPEG_DCHuffTableTypeDef
*HuffTableDC1
);
427 static HAL_StatusTypeDef
JPEG_Set_Quantization_Mem(JPEG_HandleTypeDef
*hjpeg
, uint8_t *QTable
, uint32_t *QTableAddress
);
428 static void JPEG_SetColorYCBCR(JPEG_HandleTypeDef
*hjpeg
);
429 static void JPEG_SetColorGrayScale(JPEG_HandleTypeDef
*hjpeg
);
430 static void JPEG_SetColorCMYK(JPEG_HandleTypeDef
*hjpeg
);
432 static void JPEG_Init_Process(JPEG_HandleTypeDef
*hjpeg
);
433 static uint32_t JPEG_Process(JPEG_HandleTypeDef
*hjpeg
);
434 static void JPEG_ReadInputData(JPEG_HandleTypeDef
*hjpeg
, uint32_t nbRequestWords
);
435 static void JPEG_StoreOutputData(JPEG_HandleTypeDef
*hjpeg
, uint32_t nbOutputWords
);
436 static uint32_t JPEG_GetQuality(JPEG_HandleTypeDef
*hjpeg
);
438 static HAL_StatusTypeDef
JPEG_DMA_StartProcess(JPEG_HandleTypeDef
*hjpeg
);
439 static uint32_t JPEG_DMA_ContinueProcess(JPEG_HandleTypeDef
*hjpeg
);
440 static uint32_t JPEG_DMA_EndProcess(JPEG_HandleTypeDef
*hjpeg
);
441 static void JPEG_DMAOutCpltCallback(DMA_HandleTypeDef
*hdma
);
442 static void JPEG_DMAInCpltCallback(DMA_HandleTypeDef
*hdma
);
443 static void JPEG_DMAErrorCallback(DMA_HandleTypeDef
*hdma
);
444 static void JPEG_DMAOutAbortCallback(DMA_HandleTypeDef
*hdma
) ;
449 /** @defgroup JPEG_Exported_Functions JPEG Exported Functions
453 /** @defgroup JPEG_Exported_Functions_Group1 Initialization and de-initialization functions
454 * @brief Initialization and de-initialization functions.
457 ==============================================================================
458 ##### Initialization and de-initialization functions #####
459 ==============================================================================
460 [..] This section provides functions allowing to:
461 (+) Initialize the JPEG peripheral and creates the associated handle
462 (+) DeInitialize the JPEG peripheral
469 * @brief Initializes the JPEG according to the specified
470 * parameters in the JPEG_InitTypeDef and creates the associated handle.
471 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
472 * the configuration information for JPEG module
475 HAL_StatusTypeDef
HAL_JPEG_Init(JPEG_HandleTypeDef
*hjpeg
)
477 /*Note : these intermediate variables are used to avoid MISRA warning
478 regarding rule 11.5 */
479 uint32_t acLum_huffmanTableAddr
= (uint32_t)(&JPEG_ACLUM_HuffTable
);
480 uint32_t dcLum_huffmanTableAddr
= (uint32_t)(&JPEG_DCLUM_HuffTable
);
481 uint32_t acChrom_huffmanTableAddr
= (uint32_t)(&JPEG_ACCHROM_HuffTable
);
482 uint32_t dcChrom_huffmanTableAddr
= (uint32_t)(&JPEG_DCCHROM_HuffTable
);
484 /* Check the JPEG handle allocation */
490 if(hjpeg
->State
== HAL_JPEG_STATE_RESET
)
492 /* Allocate lock resource and initialize it */
493 hjpeg
->Lock
= HAL_UNLOCKED
;
495 /* Init the low level hardware : GPIO, CLOCK */
496 HAL_JPEG_MspInit(hjpeg
);
499 /* Change the JPEG state */
500 hjpeg
->State
= HAL_JPEG_STATE_BUSY
;
502 /* Start the JPEG Core*/
503 __HAL_JPEG_ENABLE(hjpeg
);
505 /* Stop the JPEG encoding/decoding process*/
506 hjpeg
->Instance
->CONFR0
&= ~JPEG_CONFR0_START
;
508 /* Disable All Interrupts */
509 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_INTERRUPT_MASK
);
511 /* Disable All DMA requests */
512 JPEG_DISABLE_DMA(hjpeg
,JPEG_DMA_MASK
);
514 /* Flush input and output FIFOs*/
515 hjpeg
->Instance
->CR
|= JPEG_CR_IFF
;
516 hjpeg
->Instance
->CR
|= JPEG_CR_OFF
;
518 /* Clear all flags */
519 __HAL_JPEG_CLEAR_FLAG(hjpeg
,JPEG_FLAG_ALL
);
521 hjpeg
->QuantTable0
= (uint8_t *)JPEG_LUM_QuantTable
;
522 hjpeg
->QuantTable1
= (uint8_t *)JPEG_CHROM_QuantTable
;
523 hjpeg
->QuantTable2
= NULL
;
524 hjpeg
->QuantTable3
= NULL
;
526 /* init the default Huffman tables*/
527 if(JPEG_Set_HuffEnc_Mem(hjpeg
, (JPEG_ACHuffTableTypeDef
*)acLum_huffmanTableAddr
, (JPEG_DCHuffTableTypeDef
*)dcLum_huffmanTableAddr
, (JPEG_ACHuffTableTypeDef
*)acChrom_huffmanTableAddr
, (JPEG_DCHuffTableTypeDef
*)dcChrom_huffmanTableAddr
) != HAL_OK
)
529 hjpeg
->ErrorCode
= HAL_JPEG_ERROR_HUFF_TABLE
;
534 /* Enable header processing*/
535 hjpeg
->Instance
->CONFR1
|= JPEG_CONFR1_HDR
;
537 /* Reset JpegInCount and JpegOutCount */
538 hjpeg
->JpegInCount
= 0;
539 hjpeg
->JpegOutCount
= 0;
541 /* Change the JPEG state */
542 hjpeg
->State
= HAL_JPEG_STATE_READY
;
544 /* Reset the JPEG ErrorCode */
545 hjpeg
->ErrorCode
= HAL_JPEG_ERROR_NONE
;
547 /*Clear the context filelds*/
550 /* Return function status */
555 * @brief DeInitializes the JPEG peripheral.
556 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
557 * the configuration information for JPEG module
560 HAL_StatusTypeDef
HAL_JPEG_DeInit(JPEG_HandleTypeDef
*hjpeg
)
562 /* Check the JPEG handle allocation */
568 /* DeInit the low level hardware: CLOCK, NVIC.*/
569 HAL_JPEG_MspDeInit(hjpeg
);
571 /* Change the JPEG state */
572 hjpeg
->State
= HAL_JPEG_STATE_BUSY
;
574 /* Reset the JPEG ErrorCode */
575 hjpeg
->ErrorCode
= HAL_JPEG_ERROR_NONE
;
577 /* Reset JpegInCount and JpegOutCount */
578 hjpeg
->JpegInCount
= 0;
579 hjpeg
->JpegOutCount
= 0;
581 /* Change the JPEG state */
582 hjpeg
->State
= HAL_JPEG_STATE_RESET
;
584 /*Clear the context fields*/
590 /* Return function status */
595 * @brief Initializes the JPEG MSP.
596 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
597 * the configuration information for JPEG module
600 __weak
void HAL_JPEG_MspInit(JPEG_HandleTypeDef
*hjpeg
)
602 /* Prevent unused argument(s) compilation warning */
605 /* NOTE : This function Should not be modified, when the callback is needed,
606 the HAL_JPEG_MspInit could be implemented in the user file
611 * @brief DeInitializes JPEG MSP.
612 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
613 * the configuration information for JPEG module
616 __weak
void HAL_JPEG_MspDeInit(JPEG_HandleTypeDef
*hjpeg
)
618 /* Prevent unused argument(s) compilation warning */
621 /* NOTE : This function Should not be modified, when the callback is needed,
622 the HAL_JPEG_MspDeInit could be implemented in the user file
630 /** @defgroup JPEG_Exported_Functions_Group2 Configuration functions
631 * @brief JPEG Configuration functions.
634 ==============================================================================
635 ##### Configuration functions #####
636 ==============================================================================
637 [..] This section provides functions allowing to:
638 (+) HAL_JPEG_ConfigEncoding() : JPEG encoding configuration
639 (+) HAL_JPEG_GetInfo() : Extract the image configuration from the JPEG header during the decoding
640 (+) HAL_JPEG_EnableHeaderParsing() : Enable JPEG Header parsing for decoding
641 (+) HAL_JPEG_DisableHeaderParsing() : Disable JPEG Header parsing for decoding
642 (+) HAL_JPEG_SetUserQuantTables : Modify the default Quantization tables used for JPEG encoding.
649 * @brief Set the JPEG encoding configuration.
650 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
651 * the configuration information for JPEG module
652 * @param pConf: pointer to a JPEG_ConfTypeDef structure that contains
653 * the encoding configuration
656 HAL_StatusTypeDef
HAL_JPEG_ConfigEncoding(JPEG_HandleTypeDef
*hjpeg
, JPEG_ConfTypeDef
*pConf
)
658 uint32_t error
= HAL_OK
;
659 uint32_t numberMCU
, hfactor
, vfactor
,hMCU
, vMCU
;
661 /* Check the JPEG handle allocation */
662 if( (hjpeg
== NULL
) || (pConf
== NULL
) )
668 /* Check the parameters */
669 assert_param(IS_JPEG_COLORSPACE(pConf
->ColorSpace
));
670 assert_param(IS_JPEG_CHROMASUBSAMPLING(pConf
->ChromaSubsampling
));
671 assert_param(IS_JPEG_IMAGE_QUALITY(pConf
->ImageQuality
));
676 if(hjpeg
->State
== HAL_JPEG_STATE_READY
)
678 hjpeg
->State
= HAL_JPEG_STATE_BUSY
;
680 hjpeg
->Conf
.ColorSpace
= pConf
->ColorSpace
;
681 hjpeg
->Conf
.ChromaSubsampling
= pConf
->ChromaSubsampling
;
682 hjpeg
->Conf
.ImageHeight
= pConf
->ImageHeight
;
683 hjpeg
->Conf
.ImageWidth
= pConf
->ImageWidth
;
684 hjpeg
->Conf
.ImageQuality
= pConf
->ImageQuality
;
686 /* Reset the Color Space : by default only one quantization table is used*/
687 hjpeg
->Instance
->CONFR1
&= ~JPEG_CONFR1_COLORSPACE
;
689 /* Set Number of color components*/
690 if(hjpeg
->Conf
.ColorSpace
== JPEG_GRAYSCALE_COLORSPACE
)
692 /*Gray Scale is only one component 8x8 blocks i.e 4:4:4*/
693 hjpeg
->Conf
.ChromaSubsampling
= JPEG_444_SUBSAMPLING
;
695 JPEG_SetColorGrayScale(hjpeg
);
696 /* Set quantization table 0*/
697 error
= JPEG_Set_Quantization_Mem(hjpeg
, hjpeg
->QuantTable0
, (uint32_t *)(hjpeg
->Instance
->QMEM0
));
699 else if(hjpeg
->Conf
.ColorSpace
== JPEG_YCBCR_COLORSPACE
)
702 Set the Color Space for YCbCr : 2 quantization tables are used
703 one for Luminance(Y) and one for both Chrominances (Cb & Cr)
705 hjpeg
->Instance
->CONFR1
|= JPEG_CONFR1_COLORSPACE_0
;
707 JPEG_SetColorYCBCR(hjpeg
);
709 /* Set quantization table 0*/
710 error
= JPEG_Set_Quantization_Mem(hjpeg
, hjpeg
->QuantTable0
, (uint32_t *)(hjpeg
->Instance
->QMEM0
));
711 /*By default quantization table 0 for component 0 and quantization table 1 for both components 1 and 2*/
712 error
|= JPEG_Set_Quantization_Mem(hjpeg
, hjpeg
->QuantTable1
, (uint32_t *)(hjpeg
->Instance
->QMEM1
));
714 if((hjpeg
->Context
& JPEG_CONTEXT_CUSTOM_TABLES
) != 0) /*Use user customized quantization tables , 1 table per component*/
716 /* use 3 quantization tables , one for each component*/
717 hjpeg
->Instance
->CONFR1
&= (~JPEG_CONFR1_COLORSPACE
);
718 hjpeg
->Instance
->CONFR1
|= JPEG_CONFR1_COLORSPACE_1
;
720 error
|= JPEG_Set_Quantization_Mem(hjpeg
, hjpeg
->QuantTable2
, (uint32_t *)(hjpeg
->Instance
->QMEM2
));
722 /*Use Quantization 1 table for component 1*/
723 hjpeg
->Instance
->CONFR5
&= (~JPEG_CONFR6_QT
);
724 hjpeg
->Instance
->CONFR5
|= JPEG_CONFR5_QT_0
;
726 /*Use Quantization 2 table for component 2*/
727 hjpeg
->Instance
->CONFR6
&= (~JPEG_CONFR6_QT
);
728 hjpeg
->Instance
->CONFR6
|= JPEG_CONFR6_QT_1
;
731 else if(hjpeg
->Conf
.ColorSpace
== JPEG_CMYK_COLORSPACE
)
733 JPEG_SetColorCMYK(hjpeg
);
735 /* Set quantization table 0*/
736 error
= JPEG_Set_Quantization_Mem(hjpeg
, hjpeg
->QuantTable0
, (uint32_t *)(hjpeg
->Instance
->QMEM0
));
737 /*By default quantization table 0 for All components*/
739 if((hjpeg
->Context
& JPEG_CONTEXT_CUSTOM_TABLES
) != 0) /*Use user customized quantization tables , 1 table per component*/
741 /* use 4 quantization tables , one for each component*/
742 hjpeg
->Instance
->CONFR1
|= JPEG_CONFR1_COLORSPACE
;
744 error
|= JPEG_Set_Quantization_Mem(hjpeg
, hjpeg
->QuantTable1
, (uint32_t *)(hjpeg
->Instance
->QMEM1
));
745 error
|= JPEG_Set_Quantization_Mem(hjpeg
, hjpeg
->QuantTable2
, (uint32_t *)(hjpeg
->Instance
->QMEM2
));
746 error
|= JPEG_Set_Quantization_Mem(hjpeg
, hjpeg
->QuantTable3
, (uint32_t *)(hjpeg
->Instance
->QMEM3
));
748 /*Use Quantization 1 table for component 1*/
749 hjpeg
->Instance
->CONFR5
|= JPEG_CONFR5_QT_0
;
751 /*Use Quantization 2 table for component 2*/
752 hjpeg
->Instance
->CONFR6
|= JPEG_CONFR6_QT_1
;
754 /*Use Quantization 3 table for component 3*/
755 hjpeg
->Instance
->CONFR7
|= JPEG_CONFR7_QT
;
761 hjpeg
->ErrorCode
= HAL_JPEG_ERROR_QUANT_TABLE
;
763 /* Process Unlocked */
766 /* Set the JPEG State to ready */
767 hjpeg
->State
= HAL_JPEG_STATE_READY
;
771 /* Set the image size*/
772 hjpeg
->Instance
->CONFR1
|= ((hjpeg
->Conf
.ImageHeight
& 0x0000FFFF) << 16); /* set the number of lines*/
773 hjpeg
->Instance
->CONFR3
|= ((hjpeg
->Conf
.ImageWidth
& 0x0000FFFF) << 16); /* set the number of pixels per line*/
775 if(hjpeg
->Conf
.ChromaSubsampling
== JPEG_420_SUBSAMPLING
) /* 4:2:0*/
780 else if(hjpeg
->Conf
.ChromaSubsampling
== JPEG_422_SUBSAMPLING
) /* 4:2:2*/
785 else /* Default is 8x8 MCU, 4:4:4*/
791 hMCU
= (hjpeg
->Conf
.ImageWidth
/ hfactor
);
792 if((hjpeg
->Conf
.ImageWidth
% hfactor
) != 0)
794 hMCU
++; /*+1 for horizontal incomplete MCU */
797 vMCU
= (hjpeg
->Conf
.ImageHeight
/ vfactor
);
798 if((hjpeg
->Conf
.ImageHeight
% vfactor
) != 0)
800 vMCU
++; /*+1 for vertical incomplete MCU */
803 numberMCU
= (hMCU
* vMCU
) - 1; /* Bit Field JPEG_CONFR2_NMCU shall be set to NB_MCU - 1*/
804 /* Set the number of MCU*/
805 hjpeg
->Instance
->CONFR2
= (numberMCU
& JPEG_CONFR2_NMCU
);
807 hjpeg
->Context
|= JPEG_CONTEXT_CONF_ENCODING
;
809 /* Process Unlocked */
812 /* Set the JPEG State to ready */
813 hjpeg
->State
= HAL_JPEG_STATE_READY
;
815 /* Return function status */
820 /* Process Unlocked */
823 /* Return function status */
830 * @brief Extract the image configuration from the JPEG header during the decoding
831 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
832 * the configuration information for JPEG module
833 * @param pInfo: pointer to a JPEG_ConfTypeDef structure that contains
834 * The JPEG decoded header informations
837 HAL_StatusTypeDef
HAL_JPEG_GetInfo(JPEG_HandleTypeDef
*hjpeg
, JPEG_ConfTypeDef
*pInfo
)
839 uint32_t yblockNb
, cBblockNb
, cRblockNb
;
841 /* Check the JPEG handle allocation */
842 if((hjpeg
== NULL
) || (pInfo
== NULL
))
847 /*Read the conf parameters */
848 if((hjpeg
->Instance
->CONFR1
& JPEG_CONFR1_NF
) == JPEG_CONFR1_NF_1
)
850 pInfo
->ColorSpace
= JPEG_YCBCR_COLORSPACE
;
852 else if((hjpeg
->Instance
->CONFR1
& JPEG_CONFR1_NF
) == 0)
854 pInfo
->ColorSpace
= JPEG_GRAYSCALE_COLORSPACE
;
856 else if((hjpeg
->Instance
->CONFR1
& JPEG_CONFR1_NF
) == JPEG_CONFR1_NF
)
858 pInfo
->ColorSpace
= JPEG_CMYK_COLORSPACE
;
861 pInfo
->ImageHeight
= (hjpeg
->Instance
->CONFR1
& 0xFFFF0000U
) >> 16;
862 pInfo
->ImageWidth
= (hjpeg
->Instance
->CONFR3
& 0xFFFF0000U
) >> 16;
864 if((pInfo
->ColorSpace
== JPEG_YCBCR_COLORSPACE
) || (pInfo
->ColorSpace
== JPEG_CMYK_COLORSPACE
))
866 yblockNb
= (hjpeg
->Instance
->CONFR4
& JPEG_CONFR4_NB
) >> 4;
867 cBblockNb
= (hjpeg
->Instance
->CONFR5
& JPEG_CONFR5_NB
) >> 4;
868 cRblockNb
= (hjpeg
->Instance
->CONFR6
& JPEG_CONFR6_NB
) >> 4;
870 if((yblockNb
== 1) && (cBblockNb
== 0) && (cRblockNb
== 0))
872 pInfo
->ChromaSubsampling
= JPEG_422_SUBSAMPLING
; /*16x8 block*/
874 else if((yblockNb
== 0) && (cBblockNb
== 0) && (cRblockNb
== 0))
876 pInfo
->ChromaSubsampling
= JPEG_444_SUBSAMPLING
;
878 else if((yblockNb
== 3) && (cBblockNb
== 0) && (cRblockNb
== 0))
880 pInfo
->ChromaSubsampling
= JPEG_420_SUBSAMPLING
;
882 else /*Default is 4:4:4*/
884 pInfo
->ChromaSubsampling
= JPEG_444_SUBSAMPLING
;
889 pInfo
->ChromaSubsampling
= JPEG_444_SUBSAMPLING
;
892 pInfo
->ImageQuality
= JPEG_GetQuality(hjpeg
);
894 /* Return function status */
899 * @brief Enable JPEG Header parsing for decoding
900 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
901 * the configuration information for the JPEG.
904 HAL_StatusTypeDef
HAL_JPEG_EnableHeaderParsing(JPEG_HandleTypeDef
*hjpeg
)
909 if(hjpeg
->State
== HAL_JPEG_STATE_READY
)
911 /* Change the JPEG state */
912 hjpeg
->State
= HAL_JPEG_STATE_BUSY
;
914 /* Enable header processing*/
915 hjpeg
->Instance
->CONFR1
|= JPEG_CONFR1_HDR
;
917 /* Process unlocked */
920 /* Change the JPEG state */
921 hjpeg
->State
= HAL_JPEG_STATE_READY
;
927 /* Process unlocked */
935 * @brief Disable JPEG Header parsing for decoding
936 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
937 * the configuration information for the JPEG.
940 HAL_StatusTypeDef
HAL_JPEG_DisableHeaderParsing(JPEG_HandleTypeDef
*hjpeg
)
945 if(hjpeg
->State
== HAL_JPEG_STATE_READY
)
947 /* Change the JPEG state */
948 hjpeg
->State
= HAL_JPEG_STATE_BUSY
;
950 /* Disable header processing*/
951 hjpeg
->Instance
->CONFR1
&= ~JPEG_CONFR1_HDR
;
953 /* Process unlocked */
956 /* Change the JPEG state */
957 hjpeg
->State
= HAL_JPEG_STATE_READY
;
963 /* Process unlocked */
971 * @brief Modify the default Quantization tables used for JPEG encoding.
972 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
973 * the configuration information for JPEG module
974 * @param QTable0 : pointer to uint8_t , define the user quantification table for color component 1.
975 * If NULL assume no need to update the table and no error return
976 * @param QTable1 : pointer to uint8_t , define the user quantification table for color component 2.
977 * If NULL assume no need to update the table and no error return.
978 * @param QTable2 : pointer to uint8_t , define the user quantification table for color component 3,
979 * If NULL assume no need to update the table and no error return.
980 * @param QTable3 : pointer to uint8_t , define the user quantification table for color component 4.
981 * If NULL assume no need to update the table and no error return.
987 HAL_StatusTypeDef
HAL_JPEG_SetUserQuantTables(JPEG_HandleTypeDef
*hjpeg
, uint8_t *QTable0
, uint8_t *QTable1
, uint8_t *QTable2
, uint8_t *QTable3
)
992 if(hjpeg
->State
== HAL_JPEG_STATE_READY
)
994 /* Change the DMA state */
995 hjpeg
->State
= HAL_JPEG_STATE_BUSY
;
997 hjpeg
->Context
|= JPEG_CONTEXT_CUSTOM_TABLES
;
999 hjpeg
->QuantTable0
= QTable0
;
1000 hjpeg
->QuantTable1
= QTable1
;
1001 hjpeg
->QuantTable2
= QTable2
;
1002 hjpeg
->QuantTable3
= QTable3
;
1004 /* Process Unlocked */
1005 __HAL_UNLOCK(hjpeg
);
1007 /* Change the DMA state */
1008 hjpeg
->State
= HAL_JPEG_STATE_READY
;
1010 /* Return function status */
1015 /* Process Unlocked */
1016 __HAL_UNLOCK(hjpeg
);
1026 /** @defgroup JPEG_Exported_Functions_Group3 encoding/decoding processing functions
1027 * @brief processing functions.
1030 ==============================================================================
1031 ##### JPEG processing functions #####
1032 ==============================================================================
1033 [..] This section provides functions allowing to:
1034 (+) HAL_JPEG_Encode() : JPEG encoding with polling process
1035 (+) HAL_JPEG_Decode() : JPEG decoding with polling process
1036 (+) HAL_JPEG_Encode_IT() : JPEG encoding with interrupt process
1037 (+) HAL_JPEG_Decode_IT() : JPEG decoding with interrupt process
1038 (+) HAL_JPEG_Encode_DMA() : JPEG encoding with DMA process
1039 (+) HAL_JPEG_Decode_DMA() : JPEG decoding with DMA process
1040 (+) HAL_JPEG_Pause() : Pause the Input/Output processing
1041 (+) HAL_JPEG_Resume() : Resume the JPEG Input/Output processing
1042 (+) HAL_JPEG_ConfigInputBuffer() : Config Encoding/Decoding Input Buffer
1043 (+) HAL_JPEG_ConfigOutputBuffer() : Config Encoding/Decoding Output Buffer
1044 (+) HAL_JPEG_Abort() : Aborts the JPEG Encoding/Decoding
1051 * @brief Starts JPEG encoding with polling processing
1052 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1053 * the configuration information for JPEG module
1054 * @param pDataInMCU: Pointer to the Input buffer
1055 * @param InDataLength: size in bytes Input buffer
1056 * @param pDataOut: Pointer to the jpeg output data buffer
1057 * @param OutDataLength: size in bytes of the Output buffer
1058 * @param Timeout: Specify Timeout value
1059 * @retval HAL status
1061 HAL_StatusTypeDef
HAL_JPEG_Encode(JPEG_HandleTypeDef
*hjpeg
, uint8_t *pDataInMCU
, uint32_t InDataLength
, uint8_t *pDataOut
, uint32_t OutDataLength
, uint32_t Timeout
)
1063 uint32_t tickstart
= 0;
1065 /* Check the parameters */
1066 assert_param((InDataLength
>= 4));
1067 assert_param((OutDataLength
>= 4));
1069 /* Check In/out buffer allocation and size */
1070 if((hjpeg
== NULL
) || (pDataInMCU
== NULL
) || (pDataOut
== NULL
) || \
1071 (InDataLength
== 0) || (OutDataLength
== 0))
1075 /* Process locked */
1078 if(hjpeg
->State
!= HAL_JPEG_STATE_READY
)
1080 /* Process Unlocked */
1081 __HAL_UNLOCK(hjpeg
);
1086 if(hjpeg
->State
== HAL_JPEG_STATE_READY
)
1088 if((hjpeg
->Context
& JPEG_CONTEXT_CONF_ENCODING
) == JPEG_CONTEXT_CONF_ENCODING
)
1090 /*Change JPEG state*/
1091 hjpeg
->State
= HAL_JPEG_STATE_BUSY_ENCODING
;
1093 /*Set the Context to Encode with Polling*/
1094 hjpeg
->Context
&= ~(JPEG_CONTEXT_OPERATION_MASK
| JPEG_CONTEXT_METHOD_MASK
);
1095 hjpeg
->Context
|= (JPEG_CONTEXT_ENCODE
| JPEG_CONTEXT_POLLING
);
1098 tickstart
= HAL_GetTick();
1099 /*In/Out Data length must be multiple of 4 Bytes (1 word)*/
1100 InDataLength
= InDataLength
- (InDataLength
% 4);
1101 OutDataLength
= OutDataLength
- (OutDataLength
% 4);
1103 /*Store In/out buffers pointers and size*/
1104 hjpeg
->pJpegInBuffPtr
= pDataInMCU
;
1105 hjpeg
->pJpegOutBuffPtr
= pDataOut
;
1106 hjpeg
->InDataLength
= InDataLength
;
1107 hjpeg
->OutDataLength
= OutDataLength
;
1109 /*Reset In/out data counter */
1110 hjpeg
->JpegInCount
= 0;
1111 hjpeg
->JpegOutCount
= 0;
1113 /*Init decoding process*/
1114 JPEG_Init_Process(hjpeg
);
1116 /*JPEG data processing : In/Out FIFO transfer*/
1117 while((JPEG_Process(hjpeg
) == JPEG_PROCESS_ONGOING
))
1119 if(Timeout
!= HAL_MAX_DELAY
)
1121 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
1124 /* Update error code */
1125 hjpeg
->ErrorCode
|= HAL_JPEG_ERROR_TIMEOUT
;
1127 /* Process Unlocked */
1128 __HAL_UNLOCK(hjpeg
);
1130 /*Change JPEG state*/
1131 hjpeg
->State
= HAL_JPEG_STATE_READY
;
1138 /* Process Unlocked */
1139 __HAL_UNLOCK(hjpeg
);
1141 /*Change JPEG state*/
1142 hjpeg
->State
= HAL_JPEG_STATE_READY
;
1146 /* Process Unlocked */
1147 __HAL_UNLOCK(hjpeg
);
1152 /* Return function status */
1157 * @brief Starts JPEG decoding with polling processing
1158 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1159 * the configuration information for JPEG module
1160 * @param pDataIn: Pointer to the input data buffer
1161 * @param InDataLength: size in bytes Input buffer
1162 * @param pDataOutMCU: Pointer to the Output data buffer
1163 * @param OutDataLength: size in bytes of the Output buffer
1164 * @param Timeout: Specify Timeout value
1165 * @retval HAL status
1167 HAL_StatusTypeDef
HAL_JPEG_Decode(JPEG_HandleTypeDef
*hjpeg
,uint8_t *pDataIn
,uint32_t InDataLength
,uint8_t *pDataOutMCU
,uint32_t OutDataLength
, uint32_t Timeout
)
1169 uint32_t tickstart
= 0;
1171 /* Check the parameters */
1172 assert_param((InDataLength
>= 4));
1173 assert_param((OutDataLength
>= 4));
1175 /* Check In/out buffer allocation and size */
1176 if((hjpeg
== NULL
) || (pDataIn
== NULL
) || (pDataOutMCU
== NULL
) || \
1177 (InDataLength
== 0) || (OutDataLength
== 0))
1182 /* Process Locked */
1186 tickstart
= HAL_GetTick();
1188 if(hjpeg
->State
== HAL_JPEG_STATE_READY
)
1190 /*Change JPEG state*/
1191 hjpeg
->State
= HAL_JPEG_STATE_BUSY_DECODING
;
1193 /*Set the Context to Decode with Polling*/
1194 /*Set the Context to Encode with Polling*/
1195 hjpeg
->Context
&= ~(JPEG_CONTEXT_OPERATION_MASK
| JPEG_CONTEXT_METHOD_MASK
);
1196 hjpeg
->Context
|= (JPEG_CONTEXT_DECODE
| JPEG_CONTEXT_POLLING
);
1198 /*In/Out Data length must be multiple of 4 Bytes (1 word)*/
1199 InDataLength
= InDataLength
- (InDataLength
% 4);
1200 OutDataLength
= OutDataLength
- (OutDataLength
% 4);
1202 /*Store In/out buffers pointers and size*/
1203 hjpeg
->pJpegInBuffPtr
= pDataIn
;
1204 hjpeg
->pJpegOutBuffPtr
= pDataOutMCU
;
1205 hjpeg
->InDataLength
= InDataLength
;
1206 hjpeg
->OutDataLength
= OutDataLength
;
1208 /*Reset In/out data counter */
1209 hjpeg
->JpegInCount
= 0;
1210 hjpeg
->JpegOutCount
= 0;
1212 /*Init decoding process*/
1213 JPEG_Init_Process(hjpeg
);
1215 /*JPEG data processing : In/Out FIFO transfer*/
1216 while((JPEG_Process(hjpeg
) == JPEG_PROCESS_ONGOING
))
1218 if(Timeout
!= HAL_MAX_DELAY
)
1220 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
1223 /* Update error code */
1224 hjpeg
->ErrorCode
|= HAL_JPEG_ERROR_TIMEOUT
;
1226 /* Process Unlocked */
1227 __HAL_UNLOCK(hjpeg
);
1229 /*Change JPEG state*/
1230 hjpeg
->State
= HAL_JPEG_STATE_READY
;
1237 /* Process Unlocked */
1238 __HAL_UNLOCK(hjpeg
);
1240 /*Change JPEG state*/
1241 hjpeg
->State
= HAL_JPEG_STATE_READY
;
1245 /* Process Unlocked */
1246 __HAL_UNLOCK(hjpeg
);
1250 /* Return function status */
1255 * @brief Starts JPEG encoding with interrupt processing
1256 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1257 * the configuration information for JPEG module
1258 * @param pDataInMCU: Pointer to the Input buffer
1259 * @param InDataLength: size in bytes Input buffer
1260 * @param pDataOut: Pointer to the jpeg output data buffer
1261 * @param OutDataLength: size in bytes of the Output buffer
1262 * @retval HAL status
1264 HAL_StatusTypeDef
HAL_JPEG_Encode_IT(JPEG_HandleTypeDef
*hjpeg
, uint8_t *pDataInMCU
, uint32_t InDataLength
, uint8_t *pDataOut
, uint32_t OutDataLength
)
1266 /* Check the parameters */
1267 assert_param((InDataLength
>= 4));
1268 assert_param((OutDataLength
>= 4));
1270 /* Check In/out buffer allocation and size */
1271 if((hjpeg
== NULL
) || (pDataInMCU
== NULL
) || (pDataOut
== NULL
) || \
1272 (InDataLength
== 0) || (OutDataLength
== 0))
1277 /* Process Locked */
1280 if(hjpeg
->State
!= HAL_JPEG_STATE_READY
)
1282 /* Process Unlocked */
1283 __HAL_UNLOCK(hjpeg
);
1289 if((hjpeg
->Context
& JPEG_CONTEXT_CONF_ENCODING
) == JPEG_CONTEXT_CONF_ENCODING
)
1291 /*Change JPEG state*/
1292 hjpeg
->State
= HAL_JPEG_STATE_BUSY_ENCODING
;
1294 /*Set the Context to Encode with IT*/
1295 hjpeg
->Context
&= ~(JPEG_CONTEXT_OPERATION_MASK
| JPEG_CONTEXT_METHOD_MASK
);
1296 hjpeg
->Context
|= (JPEG_CONTEXT_ENCODE
| JPEG_CONTEXT_IT
);
1298 /*In/Out Data length must be multiple of 4 Bytes (1 word)*/
1299 InDataLength
= InDataLength
- (InDataLength
% 4);
1300 OutDataLength
= OutDataLength
- (OutDataLength
% 4);
1302 /*Store In/out buffers pointers and size*/
1303 hjpeg
->pJpegInBuffPtr
= pDataInMCU
;
1304 hjpeg
->pJpegOutBuffPtr
= pDataOut
;
1305 hjpeg
->InDataLength
= InDataLength
;
1306 hjpeg
->OutDataLength
= OutDataLength
;
1308 /*Reset In/out data counter */
1309 hjpeg
->JpegInCount
= 0;
1310 hjpeg
->JpegOutCount
= 0;
1312 /*Init decoding process*/
1313 JPEG_Init_Process(hjpeg
);
1318 /* Process Unlocked */
1319 __HAL_UNLOCK(hjpeg
);
1324 /* Return function status */
1329 * @brief Starts JPEG decoding with interrupt processing
1330 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1331 * the configuration information for JPEG module
1332 * @param pDataIn: Pointer to the input data buffer
1333 * @param InDataLength: size in bytes Input buffer
1334 * @param pDataOutMCU: Pointer to the Output data buffer
1335 * @param OutDataLength: size in bytes of the Output buffer
1336 * @retval HAL status
1338 HAL_StatusTypeDef
HAL_JPEG_Decode_IT(JPEG_HandleTypeDef
*hjpeg
,uint8_t *pDataIn
,uint32_t InDataLength
,uint8_t *pDataOutMCU
,uint32_t OutDataLength
)
1340 /* Check the parameters */
1341 assert_param((InDataLength
>= 4));
1342 assert_param((OutDataLength
>= 4));
1344 /* Check In/out buffer allocation and size */
1345 if((hjpeg
== NULL
) || (pDataIn
== NULL
) || (pDataOutMCU
== NULL
) || \
1346 (InDataLength
== 0) || (OutDataLength
== 0))
1351 /* Process Locked */
1354 if(hjpeg
->State
== HAL_JPEG_STATE_READY
)
1356 /*Change JPEG state*/
1357 hjpeg
->State
= HAL_JPEG_STATE_BUSY_DECODING
;
1359 /*Set the Context to Decode with IT*/
1360 hjpeg
->Context
&= ~(JPEG_CONTEXT_OPERATION_MASK
| JPEG_CONTEXT_METHOD_MASK
);
1361 hjpeg
->Context
|= (JPEG_CONTEXT_DECODE
| JPEG_CONTEXT_IT
);
1363 /*In/Out Data length must be multiple of 4 Bytes (1 word)*/
1364 InDataLength
= InDataLength
- (InDataLength
% 4);
1365 OutDataLength
= OutDataLength
- (OutDataLength
% 4);
1367 /*Store In/out buffers pointers and size*/
1368 hjpeg
->pJpegInBuffPtr
= pDataIn
;
1369 hjpeg
->pJpegOutBuffPtr
= pDataOutMCU
;
1370 hjpeg
->InDataLength
= InDataLength
;
1371 hjpeg
->OutDataLength
= OutDataLength
;
1373 /*Reset In/out data counter */
1374 hjpeg
->JpegInCount
= 0;
1375 hjpeg
->JpegOutCount
= 0;
1377 /*Init decoding process*/
1378 JPEG_Init_Process(hjpeg
);
1383 /* Process Unlocked */
1384 __HAL_UNLOCK(hjpeg
);
1388 /* Return function status */
1393 * @brief Starts JPEG encoding with DMA processing
1394 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1395 * the configuration information for JPEG module
1396 * @param pDataInMCU: Pointer to the Input buffer
1397 * @param InDataLength: size in bytes Input buffer
1398 * @param pDataOut: Pointer to the jpeg output data buffer
1399 * @param OutDataLength: size in bytes of the Output buffer
1400 * @retval HAL status
1402 HAL_StatusTypeDef
HAL_JPEG_Encode_DMA(JPEG_HandleTypeDef
*hjpeg
, uint8_t *pDataInMCU
, uint32_t InDataLength
, uint8_t *pDataOut
, uint32_t OutDataLength
)
1404 /* Check the parameters */
1405 assert_param((InDataLength
>= 4));
1406 assert_param((OutDataLength
>= 4));
1408 /* Check In/out buffer allocation and size */
1409 if((hjpeg
== NULL
) || (pDataInMCU
== NULL
) || (pDataOut
== NULL
) || \
1410 (InDataLength
== 0) || (OutDataLength
== 0))
1415 /* Process Locked */
1418 if(hjpeg
->State
!= HAL_JPEG_STATE_READY
)
1420 /* Process Unlocked */
1421 __HAL_UNLOCK(hjpeg
);
1427 if((hjpeg
->Context
& JPEG_CONTEXT_CONF_ENCODING
) == JPEG_CONTEXT_CONF_ENCODING
)
1429 /*Change JPEG state*/
1430 hjpeg
->State
= HAL_JPEG_STATE_BUSY_ENCODING
;
1432 /*Set the Context to Encode with DMA*/
1433 hjpeg
->Context
&= ~(JPEG_CONTEXT_OPERATION_MASK
| JPEG_CONTEXT_METHOD_MASK
);
1434 hjpeg
->Context
|= (JPEG_CONTEXT_ENCODE
| JPEG_CONTEXT_DMA
);
1436 /*Store In/out buffers pointers and size*/
1437 hjpeg
->pJpegInBuffPtr
= pDataInMCU
;
1438 hjpeg
->pJpegOutBuffPtr
= pDataOut
;
1439 hjpeg
->InDataLength
= InDataLength
;
1440 hjpeg
->OutDataLength
= OutDataLength
;
1442 /*Reset In/out data counter */
1443 hjpeg
->JpegInCount
= 0;
1444 hjpeg
->JpegOutCount
= 0;
1446 /*Init decoding process*/
1447 JPEG_Init_Process(hjpeg
);
1449 /* JPEG encoding process using DMA */
1450 JPEG_DMA_StartProcess(hjpeg
);
1455 /* Process Unlocked */
1456 __HAL_UNLOCK(hjpeg
);
1461 /* Return function status */
1466 * @brief Starts JPEG decoding with DMA processing
1467 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1468 * the configuration information for JPEG module
1469 * @param pDataIn: Pointer to the input data buffer
1470 * @param InDataLength: size in bytes Input buffer
1471 * @param pDataOutMCU: Pointer to the Output data buffer
1472 * @param OutDataLength: size in bytes of the Output buffer
1473 * @retval HAL status
1475 HAL_StatusTypeDef
HAL_JPEG_Decode_DMA(JPEG_HandleTypeDef
*hjpeg
,uint8_t *pDataIn
,uint32_t InDataLength
,uint8_t *pDataOutMCU
,uint32_t OutDataLength
)
1477 /* Check the parameters */
1478 assert_param((InDataLength
>= 4));
1479 assert_param((OutDataLength
>= 4));
1481 /* Check In/out buffer allocation and size */
1482 if((hjpeg
== NULL
) || (pDataIn
== NULL
) || (pDataOutMCU
== NULL
) || \
1483 (InDataLength
== 0) || (OutDataLength
== 0))
1488 /* Process Locked */
1491 if(hjpeg
->State
== HAL_JPEG_STATE_READY
)
1493 /*Change JPEG state*/
1494 hjpeg
->State
= HAL_JPEG_STATE_BUSY_DECODING
;
1496 /*Set the Context to Decode with DMA*/
1497 hjpeg
->Context
&= ~(JPEG_CONTEXT_OPERATION_MASK
| JPEG_CONTEXT_METHOD_MASK
);
1498 hjpeg
->Context
|= (JPEG_CONTEXT_DECODE
| JPEG_CONTEXT_DMA
);
1500 /*Store In/out buffers pointers and size*/
1501 hjpeg
->pJpegInBuffPtr
= pDataIn
;
1502 hjpeg
->pJpegOutBuffPtr
= pDataOutMCU
;
1503 hjpeg
->InDataLength
= InDataLength
;
1504 hjpeg
->OutDataLength
= OutDataLength
;
1506 /*Reset In/out data counter */
1507 hjpeg
->JpegInCount
= 0;
1508 hjpeg
->JpegOutCount
= 0;
1510 /*Init decoding process*/
1511 JPEG_Init_Process(hjpeg
);
1513 /* JPEG decoding process using DMA */
1514 JPEG_DMA_StartProcess(hjpeg
);
1519 /* Process Unlocked */
1520 __HAL_UNLOCK(hjpeg
);
1524 /* Return function status */
1529 * @brief Pause the JPEG Input/Output processing
1530 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1531 * the configuration information for JPEG module
1532 * @param XferSelection: This parameter can be one of the following values :
1533 * JPEG_PAUSE_RESUME_INPUT : Pause Input processing
1534 * JPEG_PAUSE_RESUME_OUTPUT: Pause Output processing
1535 * JPEG_PAUSE_RESUME_INPUT_OUTPUT: Pause Input and Output processing
1536 * @retval HAL status
1538 HAL_StatusTypeDef
HAL_JPEG_Pause(JPEG_HandleTypeDef
*hjpeg
, uint32_t XferSelection
)
1542 assert_param(IS_JPEG_PAUSE_RESUME_STATE(XferSelection
));
1544 if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_DMA
)
1546 if((XferSelection
& JPEG_PAUSE_RESUME_INPUT
) == JPEG_PAUSE_RESUME_INPUT
)
1548 hjpeg
->Context
|= JPEG_CONTEXT_PAUSE_INPUT
;
1549 mask
|= JPEG_DMA_IDMA
;
1551 if((XferSelection
& JPEG_PAUSE_RESUME_OUTPUT
) == JPEG_PAUSE_RESUME_OUTPUT
)
1553 hjpeg
->Context
|= JPEG_CONTEXT_PAUSE_OUTPUT
;
1554 mask
|= JPEG_DMA_ODMA
;
1556 JPEG_DISABLE_DMA(hjpeg
,mask
);
1559 else if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_IT
)
1562 if((XferSelection
& JPEG_PAUSE_RESUME_INPUT
) == JPEG_PAUSE_RESUME_INPUT
)
1564 hjpeg
->Context
|= JPEG_CONTEXT_PAUSE_INPUT
;
1565 mask
|= (JPEG_IT_IFT
| JPEG_IT_IFNF
);
1567 if((XferSelection
& JPEG_PAUSE_RESUME_OUTPUT
) == JPEG_PAUSE_RESUME_OUTPUT
)
1569 hjpeg
->Context
|= JPEG_CONTEXT_PAUSE_OUTPUT
;
1570 mask
|= (JPEG_IT_OFT
| JPEG_IT_OFNE
| JPEG_IT_EOC
);
1572 __HAL_JPEG_DISABLE_IT(hjpeg
,mask
);
1576 /* Return function status */
1581 * @brief Resume the JPEG Input/Output processing
1582 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1583 * the configuration information for JPEG module
1584 * @param XferSelection: This parameter can be one of the following values :
1585 * JPEG_PAUSE_RESUME_INPUT : Resume Input processing
1586 * JPEG_PAUSE_RESUME_OUTPUT: Resume Output processing
1587 * JPEG_PAUSE_RESUME_INPUT_OUTPUT: Resume Input and Output processing
1588 * @retval HAL status
1590 HAL_StatusTypeDef
HAL_JPEG_Resume(JPEG_HandleTypeDef
*hjpeg
, uint32_t XferSelection
)
1594 assert_param(IS_JPEG_PAUSE_RESUME_STATE(XferSelection
));
1596 if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_DMA
)
1599 if((XferSelection
& JPEG_PAUSE_RESUME_INPUT
) == JPEG_PAUSE_RESUME_INPUT
)
1601 hjpeg
->Context
&= (~JPEG_CONTEXT_PAUSE_INPUT
);
1602 mask
|= JPEG_DMA_IDMA
;
1604 /*JPEG Input DMA transfer data number must be multiple of DMA buffer size
1605 as the destination is a 32 bits register */
1606 hjpeg
->InDataLength
= hjpeg
->InDataLength
- (hjpeg
->InDataLength
% 4);
1608 if(hjpeg
->InDataLength
> 0)
1610 /* Start DMA FIFO In transfer */
1611 HAL_DMA_Start_IT(hjpeg
->hdmain
, (uint32_t)hjpeg
->pJpegInBuffPtr
, (uint32_t)&hjpeg
->Instance
->DIR, hjpeg
->InDataLength
>> 2);
1615 if((XferSelection
& JPEG_PAUSE_RESUME_OUTPUT
) == JPEG_PAUSE_RESUME_OUTPUT
)
1617 hjpeg
->Context
&= (~JPEG_CONTEXT_PAUSE_OUTPUT
);
1618 mask
|= JPEG_DMA_ODMA
;
1620 /* Start DMA FIFO Out transfer */
1621 HAL_DMA_Start_IT(hjpeg
->hdmaout
, (uint32_t)&hjpeg
->Instance
->DOR
, (uint32_t)hjpeg
->pJpegOutBuffPtr
, hjpeg
->OutDataLength
>> 2);
1623 JPEG_ENABLE_DMA(hjpeg
,mask
);
1626 else if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_IT
)
1628 if((XferSelection
& JPEG_PAUSE_RESUME_INPUT
) == JPEG_PAUSE_RESUME_INPUT
)
1630 hjpeg
->Context
&= (~JPEG_CONTEXT_PAUSE_INPUT
);
1631 mask
|= (JPEG_IT_IFT
| JPEG_IT_IFNF
);
1633 if((XferSelection
& JPEG_PAUSE_RESUME_OUTPUT
) == JPEG_PAUSE_RESUME_OUTPUT
)
1635 hjpeg
->Context
&= (~JPEG_CONTEXT_PAUSE_OUTPUT
);
1636 mask
|= (JPEG_IT_OFT
| JPEG_IT_OFNE
| JPEG_IT_EOC
);
1638 __HAL_JPEG_ENABLE_IT(hjpeg
,mask
);
1642 /* Return function status */
1647 * @brief Config Encoding/Decoding Input Buffer.
1648 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1649 * the configuration information for JPEG module.
1650 * @param pNewInputBuffer: Pointer to the new input data buffer
1651 * @param InDataLength: Size in bytes of the new Input data buffer
1652 * @retval HAL status
1654 void HAL_JPEG_ConfigInputBuffer(JPEG_HandleTypeDef
*hjpeg
, uint8_t *pNewInputBuffer
, uint32_t InDataLength
)
1656 hjpeg
->pJpegInBuffPtr
= pNewInputBuffer
;
1657 hjpeg
->InDataLength
= InDataLength
;
1661 * @brief Config Encoding/Decoding Output Buffer.
1662 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1663 * the configuration information for JPEG module.
1664 * @param pNewOutputBuffer: Pointer to the new output data buffer
1665 * @param OutDataLength: Size in bytes of the new Output data buffer
1666 * @retval HAL status
1668 void HAL_JPEG_ConfigOutputBuffer(JPEG_HandleTypeDef
*hjpeg
, uint8_t *pNewOutputBuffer
, uint32_t OutDataLength
)
1670 hjpeg
->pJpegOutBuffPtr
= pNewOutputBuffer
;
1671 hjpeg
->OutDataLength
= OutDataLength
;
1675 * @brief Aborts the JPEG Encoding/Decoding.
1676 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1677 * the configuration information for JPEG module
1678 * @retval HAL status
1680 HAL_StatusTypeDef
HAL_JPEG_Abort(JPEG_HandleTypeDef
*hjpeg
)
1682 uint32_t tickstart
, tmpContext
;
1684 tmpContext
= hjpeg
->Context
;
1686 /*Reset the Context operation and method*/
1687 hjpeg
->Context
&= ~(JPEG_CONTEXT_OPERATION_MASK
| JPEG_CONTEXT_METHOD_MASK
| JPEG_CONTEXT_ENDING_DMA
);
1689 if((tmpContext
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_DMA
)
1691 /* Stop the DMA In/out Xfer*/
1692 HAL_DMA_Abort(hjpeg
->hdmaout
);
1693 HAL_DMA_Abort(hjpeg
->hdmain
);
1696 /* Stop the JPEG encoding/decoding process*/
1697 hjpeg
->Instance
->CONFR0
&= ~JPEG_CONFR0_START
;
1700 tickstart
= HAL_GetTick();
1702 /* Check if the JPEG Codec is effectively disabled */
1703 while(__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_COF
) != RESET
)
1705 /* Check for the Timeout */
1706 if((HAL_GetTick() - tickstart
) > JPEG_TIMEOUT_VALUE
)
1708 /* Update error code */
1709 hjpeg
->ErrorCode
|= HAL_JPEG_ERROR_TIMEOUT
;
1711 /* Change the DMA state */
1712 hjpeg
->State
= HAL_JPEG_STATE_TIMEOUT
;
1714 /* Process Unlocked */
1715 __HAL_UNLOCK(hjpeg
);
1721 /* Disable All Interrupts */
1722 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_INTERRUPT_MASK
);
1724 /* Disable All DMA requests */
1725 JPEG_DISABLE_DMA(hjpeg
,JPEG_DMA_MASK
);
1727 /* Flush input and output FIFOs*/
1728 hjpeg
->Instance
->CR
|= JPEG_CR_IFF
;
1729 hjpeg
->Instance
->CR
|= JPEG_CR_OFF
;
1731 /* Clear all flags */
1732 __HAL_JPEG_CLEAR_FLAG(hjpeg
,JPEG_FLAG_ALL
);
1734 /* Reset JpegInCount and JpegOutCount */
1735 hjpeg
->JpegInCount
= 0;
1736 hjpeg
->JpegOutCount
= 0;
1738 /*Reset the Context Pause*/
1739 hjpeg
->Context
&= ~(JPEG_CONTEXT_PAUSE_INPUT
| JPEG_CONTEXT_PAUSE_OUTPUT
);
1741 /* Change the DMA state*/
1742 hjpeg
->State
= HAL_JPEG_STATE_READY
;
1744 /* Process Unlocked */
1745 __HAL_UNLOCK(hjpeg
);
1747 /* Return function status */
1756 /** @defgroup JPEG_Exported_Functions_Group4 JPEG Decode/Encode callback functions
1757 * @brief JPEG process callback functions.
1760 ==============================================================================
1761 ##### JPEG Decode/Encode callback functions #####
1762 ==============================================================================
1763 [..] This section provides callback functions:
1764 (+) HAL_JPEG_InfoReadyCallback() : Decoding JPEG Info ready callback
1765 (+) HAL_JPEG_EncodeCpltCallback() : Encoding complete callback.
1766 (+) HAL_JPEG_DecodeCpltCallback() : Decoding complete callback.
1767 (+) HAL_JPEG_ErrorCallback() : JPEG error callback.
1768 (+) HAL_JPEG_GetDataCallback() : Get New Data chunk callback.
1769 (+) HAL_JPEG_DataReadyCallback() : Decoded/Encoded Data ready callback.
1776 * @brief Decoding JPEG Info ready callback.
1777 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1778 * the configuration information for JPEG module
1779 * @param pInfo: pointer to a JPEG_ConfTypeDef structure that contains
1780 * The JPEG decoded header informations
1783 __weak
void HAL_JPEG_InfoReadyCallback(JPEG_HandleTypeDef
*hjpeg
,JPEG_ConfTypeDef
*pInfo
)
1785 /* Prevent unused argument(s) compilation warning */
1789 /* NOTE : This function Should not be modified, when the callback is needed,
1790 the HAL_JPEG_HeaderParsingCpltCallback could be implemented in the user file
1795 * @brief Encoding complete callback.
1796 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1797 * the configuration information for JPEG module
1800 __weak
void HAL_JPEG_EncodeCpltCallback(JPEG_HandleTypeDef
*hjpeg
)
1802 /* Prevent unused argument(s) compilation warning */
1805 /* NOTE : This function Should not be modified, when the callback is needed,
1806 the HAL_JPEG_EncodeCpltCallback could be implemented in the user file
1811 * @brief Decoding complete callback.
1812 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1813 * the configuration information for JPEG module
1816 __weak
void HAL_JPEG_DecodeCpltCallback(JPEG_HandleTypeDef
*hjpeg
)
1818 /* Prevent unused argument(s) compilation warning */
1821 /* NOTE : This function Should not be modified, when the callback is needed,
1822 the HAL_JPEG_EncodeCpltCallback could be implemented in the user file
1827 * @brief JPEG error callback.
1828 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1829 * the configuration information for JPEG module
1832 __weak
void HAL_JPEG_ErrorCallback(JPEG_HandleTypeDef
*hjpeg
)
1834 /* Prevent unused argument(s) compilation warning */
1837 /* NOTE : This function Should not be modified, when the callback is needed,
1838 the HAL_JPEG_ErrorCallback could be implemented in the user file
1843 * @brief Get New Data chunk callback.
1844 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1845 * the configuration information for JPEG module
1846 * @param NbDecodedData: Number of consummed data in the previous chunk in bytes
1849 __weak
void HAL_JPEG_GetDataCallback(JPEG_HandleTypeDef
*hjpeg
, uint32_t NbDecodedData
)
1851 /* Prevent unused argument(s) compilation warning */
1853 UNUSED(NbDecodedData
);
1855 /* NOTE : This function Should not be modified, when the callback is needed,
1856 the HAL_JPEG_GetDataCallback could be implemented in the user file
1861 * @brief Decoded/Encoded Data ready callback.
1862 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1863 * the configuration information for JPEG module
1864 * @param pDataOut: pointer to the output data buffer
1865 * @param OutDataLength: number in bytes of data available in the specified output buffer
1868 __weak
void HAL_JPEG_DataReadyCallback (JPEG_HandleTypeDef
*hjpeg
, uint8_t *pDataOut
, uint32_t OutDataLength
)
1870 /* Prevent unused argument(s) compilation warning */
1873 UNUSED(OutDataLength
);
1875 /* NOTE : This function Should not be modified, when the callback is needed,
1876 the HAL_JPEG_DataReadyCallback could be implemented in the user file
1885 /** @defgroup JPEG_Exported_Functions_Group5 JPEG IRQ handler management
1886 * @brief JPEG IRQ handler.
1889 ==============================================================================
1890 ##### JPEG IRQ handler management #####
1891 ==============================================================================
1892 [..] This section provides JPEG IRQ handler function.
1893 (+) HAL_JPEG_IRQHandler() : handles JPEG interrupt request
1900 * @brief This function handles JPEG interrupt request.
1901 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1902 * the configuration information for JPEG module
1905 void HAL_JPEG_IRQHandler(JPEG_HandleTypeDef
*hjpeg
)
1907 switch(hjpeg
->State
)
1909 case HAL_JPEG_STATE_BUSY_ENCODING
:
1910 case HAL_JPEG_STATE_BUSY_DECODING
:
1911 /* continue JPEG data encoding/Decoding*/
1912 /* JPEG data processing : In/Out FIFO transfer*/
1913 if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_IT
)
1915 JPEG_Process(hjpeg
);
1917 else if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_DMA
)
1919 JPEG_DMA_ContinueProcess(hjpeg
);
1934 /** @defgroup JPEG_Exported_Functions_Group6 Peripheral State functions
1935 * @brief Peripheral State functions.
1938 ==============================================================================
1939 ##### Peripheral State and Error functions #####
1940 ==============================================================================
1941 [..] This section provides JPEG State and Errors function.
1942 (+) HAL_JPEG_GetState() : permits to get in run-time the JPEG state.
1943 (+) HAL_JPEG_GetError() : Returns the JPEG error code if any.
1950 * @brief Returns the JPEG state.
1951 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
1952 * the configuration information for JPEG module
1953 * @retval JPEG state
1955 HAL_JPEG_STATETypeDef
HAL_JPEG_GetState(JPEG_HandleTypeDef
*hjpeg
)
1957 return hjpeg
->State
;
1961 * @brief Return the JPEG error code
1962 * @param hjpeg : pointer to a JPEG_HandleTypeDef structure that contains
1963 * the configuration information for the specified JPEG.
1964 * @retval JPEG Error Code
1966 uint32_t HAL_JPEG_GetError(JPEG_HandleTypeDef
*hjpeg
)
1968 return hjpeg
->ErrorCode
;
1980 /** @addtogroup JPEG_Private_Functions
1985 * @brief Generates Huffman sizes/Codes Table from Bits/vals Table
1986 * @param Bits: pointer to bits table
1987 * @param Huffsize: pointer to sizes table
1988 * @param Huffcode: pointer to codes table
1989 * @param LastK: pointer to last Coeff (table dimmension)
1990 * @retval HAL status
1992 static HAL_StatusTypeDef
JPEG_Bits_To_SizeCodes(uint8_t *Bits
, uint8_t *Huffsize
, uint32_t *Huffcode
, uint32_t *LastK
)
1994 uint32_t i
, p
, l
, code
, si
;
1996 /* Figure C.1 \96 Generation of table of Huffman code sizes */
1998 for (l
= 0; l
< 16; l
++)
2000 i
= (uint32_t)Bits
[l
];
2002 { /* check for table overflow */
2007 Huffsize
[p
++] = (uint8_t) l
+1;
2014 /* Figure C.2 \96 Generation of table of Huffman codes */
2018 while (Huffsize
[p
] != 0)
2020 while (((uint32_t) Huffsize
[p
]) == si
)
2022 Huffcode
[p
++] = code
;
2025 /* code must fit in "size" bits (si), no code is allowed to be all ones*/
2026 if (((uint32_t) code
) >= (((uint32_t) 1) << si
))
2033 /* Return function status */
2038 * @brief Transform a Bits/Vals AC Huffman table to sizes/Codes huffman Table
2039 * that can programmed to the JPEG encoder registers
2040 * @param AC_BitsValsTable: pointer to AC huffman bits/vals table
2041 * @param AC_SizeCodesTable: pointer to AC huffman Sizes/Codes table
2042 * @retval HAL status
2044 static HAL_StatusTypeDef
JPEG_ACHuff_BitsVals_To_SizeCodes(JPEG_ACHuffTableTypeDef
*AC_BitsValsTable
, JPEG_AC_HuffCodeTableTypeDef
*AC_SizeCodesTable
)
2046 HAL_StatusTypeDef error
;
2047 uint8_t huffsize
[257];
2048 uint32_t huffcode
[257];
2050 uint32_t l
,lsb
, msb
;
2053 error
= JPEG_Bits_To_SizeCodes(AC_BitsValsTable
->Bits
, huffsize
, huffcode
, &lastK
);
2059 /* Figure C.3 \96 Ordering procedure for encoding procedure code tables */
2064 l
= AC_BitsValsTable
->HuffVal
[k
];
2067 l
= 160; /*l = 0x00 EOB code*/
2069 else if(l
== 0xF0)/* l = 0xF0 ZRL code*/
2075 msb
= (l
& 0xF0) >> 4;
2077 l
= (msb
* 10) + lsb
- 1;
2079 if(l
>= JPEG_AC_HUFF_TABLE_SIZE
)
2081 return HAL_ERROR
; /* Huffman Table overflow error*/
2085 AC_SizeCodesTable
->HuffmanCode
[l
] = huffcode
[k
];
2086 AC_SizeCodesTable
->CodeLength
[l
] = huffsize
[k
] - 1;
2091 /* Return function status */
2096 * @brief Transform a Bits/Vals DC Huffman table to sizes/Codes huffman Table
2097 * that can programmed to the JPEG encoder registers
2098 * @param DC_BitsValsTable: pointer to DC huffman bits/vals table
2099 * @param DC_SizeCodesTable: pointer to DC huffman Sizes/Codes table
2100 * @retval HAL status
2102 static HAL_StatusTypeDef
JPEG_DCHuff_BitsVals_To_SizeCodes(JPEG_DCHuffTableTypeDef
*DC_BitsValsTable
, JPEG_DC_HuffCodeTableTypeDef
*DC_SizeCodesTable
)
2104 HAL_StatusTypeDef error
;
2109 uint8_t huffsize
[257];
2110 uint32_t huffcode
[257];
2111 error
= JPEG_Bits_To_SizeCodes(DC_BitsValsTable
->Bits
, huffsize
, huffcode
, &lastK
);
2116 /* Figure C.3: ordering procedure for encoding procedure code tables */
2121 l
= DC_BitsValsTable
->HuffVal
[k
];
2122 if(l
>= JPEG_DC_HUFF_TABLE_SIZE
)
2124 return HAL_ERROR
; /* Huffman Table overflow error*/
2128 DC_SizeCodesTable
->HuffmanCode
[l
] = huffcode
[k
];
2129 DC_SizeCodesTable
->CodeLength
[l
] = huffsize
[k
] - 1;
2134 /* Return function status */
2139 * @brief Set the JPEG register with an DC huffman table at the given DC table address
2140 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2141 * the configuration information for JPEG module
2142 * @param HuffTableDC: pointer to DC huffman table
2143 * @param DCTableAddress: Encoder DC huffman table address it could be HUFFENC_DC0 or HUFFENC_DC1.
2144 * @retval HAL status
2146 static HAL_StatusTypeDef
JPEG_Set_HuffDC_Mem(JPEG_HandleTypeDef
*hjpeg
, JPEG_DCHuffTableTypeDef
*HuffTableDC
, uint32_t *DCTableAddress
)
2148 HAL_StatusTypeDef error
= HAL_OK
;
2149 JPEG_DC_HuffCodeTableTypeDef dcSizeCodesTable
;
2150 uint32_t i
, lsb
, msb
;
2151 __IO
uint32_t *address
, *addressDef
;
2153 if(DCTableAddress
== (uint32_t *)(hjpeg
->Instance
->HUFFENC_DC0
))
2155 address
= (hjpeg
->Instance
->HUFFENC_DC0
+ (JPEG_DC_HUFF_TABLE_SIZE
/2));
2157 else if (DCTableAddress
== (uint32_t *)(hjpeg
->Instance
->HUFFENC_DC1
))
2159 address
= (hjpeg
->Instance
->HUFFENC_DC1
+ (JPEG_DC_HUFF_TABLE_SIZE
/2));
2166 if(HuffTableDC
!= NULL
)
2168 error
= JPEG_DCHuff_BitsVals_To_SizeCodes(HuffTableDC
, &dcSizeCodesTable
);
2173 addressDef
= address
;
2174 *addressDef
= 0x0FFF0FFF;
2176 *addressDef
= 0x0FFF0FFF;
2178 i
= JPEG_DC_HUFF_TABLE_SIZE
;
2183 msb
= ((uint32_t)(((uint32_t)dcSizeCodesTable
.CodeLength
[i
] & 0xF) << 8 )) | ((uint32_t)dcSizeCodesTable
.HuffmanCode
[i
] & 0xFF);
2185 lsb
= ((uint32_t)(((uint32_t)dcSizeCodesTable
.CodeLength
[i
] & 0xF) << 8 )) | ((uint32_t)dcSizeCodesTable
.HuffmanCode
[i
] & 0xFF);
2187 *address
= lsb
| (msb
<< 16);
2191 /* Return function status */
2196 * @brief Set the JPEG register with an AC huffman table at the given AC table address
2197 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2198 * the configuration information for JPEG module
2199 * @param HuffTableAC: pointer to AC huffman table
2200 * @param ACTableAddress: Encoder AC huffman table address it could be HUFFENC_AC0 or HUFFENC_AC1.
2201 * @retval HAL status
2203 static HAL_StatusTypeDef
JPEG_Set_HuffAC_Mem(JPEG_HandleTypeDef
*hjpeg
, JPEG_ACHuffTableTypeDef
*HuffTableAC
, uint32_t *ACTableAddress
)
2205 HAL_StatusTypeDef error
= HAL_OK
;
2206 JPEG_AC_HuffCodeTableTypeDef acSizeCodesTable
;
2207 uint32_t i
, lsb
, msb
;
2208 __IO
uint32_t *address
, *addressDef
;
2210 if(ACTableAddress
== (uint32_t *)(hjpeg
->Instance
->HUFFENC_AC0
))
2212 address
= (hjpeg
->Instance
->HUFFENC_AC0
+ (JPEG_AC_HUFF_TABLE_SIZE
/2));
2214 else if (ACTableAddress
== (uint32_t *)(hjpeg
->Instance
->HUFFENC_AC1
))
2216 address
= (hjpeg
->Instance
->HUFFENC_AC1
+ (JPEG_AC_HUFF_TABLE_SIZE
/2));
2223 if(HuffTableAC
!= NULL
)
2225 error
= JPEG_ACHuff_BitsVals_To_SizeCodes(HuffTableAC
, &acSizeCodesTable
);
2230 /* Default values settings : 162\96167 FFFh , 168\96175 FD0h\96FD7h */
2231 /* Locations 162:175 of each AC table contain information used internally by the core */
2233 addressDef
= address
;
2236 *addressDef
= 0x0FFF0FFF;
2239 *addressDef
= 0x0FD10FD0;
2241 *addressDef
= 0x0FD30FD2;
2243 *addressDef
= 0x0FD50FD4;
2245 *addressDef
= 0x0FD70FD6;
2246 /* end of Locations 162:175 */
2249 i
= JPEG_AC_HUFF_TABLE_SIZE
;
2254 msb
= ((uint32_t)(((uint32_t)acSizeCodesTable
.CodeLength
[i
] & 0xF) << 8 )) | ((uint32_t)acSizeCodesTable
.HuffmanCode
[i
] & 0xFF);
2256 lsb
= ((uint32_t)(((uint32_t)acSizeCodesTable
.CodeLength
[i
] & 0xF) << 8 )) | ((uint32_t)acSizeCodesTable
.HuffmanCode
[i
] & 0xFF);
2258 *address
= lsb
| (msb
<< 16);
2262 /* Return function status */
2267 * @brief Configure the JPEG encoder register huffman tables to used during
2268 * the encdoing operation
2269 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2270 * the configuration information for JPEG module
2271 * @param HuffTableAC0: AC0 huffman table
2272 * @param HuffTableDC0: DC0 huffman table
2273 * @param HuffTableAC1: AC1 huffman table
2274 * @param HuffTableDC1: DC1 huffman table
2277 static HAL_StatusTypeDef
JPEG_Set_HuffEnc_Mem(JPEG_HandleTypeDef
*hjpeg
, JPEG_ACHuffTableTypeDef
*HuffTableAC0
, JPEG_DCHuffTableTypeDef
*HuffTableDC0
, JPEG_ACHuffTableTypeDef
*HuffTableAC1
, JPEG_DCHuffTableTypeDef
*HuffTableDC1
)
2279 HAL_StatusTypeDef error
= HAL_OK
;
2281 JPEG_Set_Huff_DHTMem(hjpeg
, HuffTableAC0
, HuffTableDC0
, HuffTableAC1
, HuffTableDC1
);
2283 if(HuffTableAC0
!= NULL
)
2285 error
= JPEG_Set_HuffAC_Mem(hjpeg
, HuffTableAC0
, (uint32_t *)(hjpeg
->Instance
->HUFFENC_AC0
));
2292 if(HuffTableAC1
!= NULL
)
2294 error
= JPEG_Set_HuffAC_Mem(hjpeg
, HuffTableAC1
, (uint32_t *)(hjpeg
->Instance
->HUFFENC_AC1
));
2301 if(HuffTableDC0
!= NULL
)
2303 error
= JPEG_Set_HuffDC_Mem(hjpeg
, HuffTableDC0
, (uint32_t *)hjpeg
->Instance
->HUFFENC_DC0
);
2310 if(HuffTableDC1
!= NULL
)
2312 error
= JPEG_Set_HuffDC_Mem(hjpeg
, HuffTableDC1
, (uint32_t *)hjpeg
->Instance
->HUFFENC_DC1
);
2318 /* Return function status */
2323 * @brief Configure the JPEG register huffman tables to be included in the JPEG
2324 * file header (used for encoding only)
2325 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2326 * the configuration information for JPEG module
2327 * @param HuffTableAC0: AC0 huffman table
2328 * @param HuffTableDC0: DC0 huffman table
2329 * @param HuffTableAC1: AC1 huffman table
2330 * @param HuffTableDC1: DC1 huffman table
2333 static void JPEG_Set_Huff_DHTMem(JPEG_HandleTypeDef
*hjpeg
, JPEG_ACHuffTableTypeDef
*HuffTableAC0
, JPEG_DCHuffTableTypeDef
*HuffTableDC0
, JPEG_ACHuffTableTypeDef
*HuffTableAC1
, JPEG_DCHuffTableTypeDef
*HuffTableDC1
)
2335 uint32_t value
, index
;
2336 __IO
uint32_t *address
;
2337 if(HuffTableDC0
!= NULL
)
2339 /* DC0 Huffman Table : BITS*/
2340 /* DC0 BITS is a 16 Bytes table i.e 4x32bits words from DHTMEM base address to DHTMEM + 3*/
2341 address
= (hjpeg
->Instance
->DHTMEM
+ 3);
2346 *address
= (((uint32_t)HuffTableDC0
->Bits
[index
-1] & 0xFF) << 24)|
2347 (((uint32_t)HuffTableDC0
->Bits
[index
-2] & 0xFF) << 16)|
2348 (((uint32_t)HuffTableDC0
->Bits
[index
-3] & 0xFF) << 8) |
2349 ((uint32_t)HuffTableDC0
->Bits
[index
-4] & 0xFF);
2354 /* DC0 Huffman Table : Val*/
2355 /* DC0 VALS is a 12 Bytes table i.e 3x32bits words from DHTMEM base address +4 to DHTMEM + 6 */
2356 address
= (hjpeg
->Instance
->DHTMEM
+ 6);
2360 *address
= (((uint32_t)HuffTableDC0
->HuffVal
[index
-1] & 0xFF) << 24)|
2361 (((uint32_t)HuffTableDC0
->HuffVal
[index
-2] & 0xFF) << 16)|
2362 (((uint32_t)HuffTableDC0
->HuffVal
[index
-3] & 0xFF) << 8) |
2363 ((uint32_t)HuffTableDC0
->HuffVal
[index
-4] & 0xFF);
2369 if(HuffTableAC0
!= NULL
)
2371 /* AC0 Huffman Table : BITS*/
2372 /* AC0 BITS is a 16 Bytes table i.e 4x32bits words from DHTMEM base address + 7 to DHTMEM + 10*/
2373 address
= (hjpeg
->Instance
->DHTMEM
+ 10);
2378 *address
= (((uint32_t)HuffTableAC0
->Bits
[index
-1] & 0xFF) << 24)|
2379 (((uint32_t)HuffTableAC0
->Bits
[index
-2] & 0xFF) << 16)|
2380 (((uint32_t)HuffTableAC0
->Bits
[index
-3] & 0xFF) << 8) |
2381 ((uint32_t)HuffTableAC0
->Bits
[index
-4] & 0xFF);
2386 /* AC0 Huffman Table : Val*/
2387 /* AC0 VALS is a 162 Bytes table i.e 41x32bits words from DHTMEM base address + 11 to DHTMEM + 51 */
2388 /* only Byte 0 and Byte 1 of the last word (@ DHTMEM + 51) belong to AC0 VALS table */
2389 address
= (hjpeg
->Instance
->DHTMEM
+ 51);
2390 value
= *address
& 0xFFFF0000U
;
2391 value
= value
| (((uint32_t)HuffTableAC0
->HuffVal
[161] & 0xFF) << 8) | ((uint32_t)HuffTableAC0
->HuffVal
[160] & 0xFF);
2394 /*continue setting 160 AC0 huffman values */
2395 address
--; /* address = hjpeg->Instance->DHTMEM + 50*/
2399 *address
= (((uint32_t)HuffTableAC0
->HuffVal
[index
-1] & 0xFF) << 24)|
2400 (((uint32_t)HuffTableAC0
->HuffVal
[index
-2] & 0xFF) << 16)|
2401 (((uint32_t)HuffTableAC0
->HuffVal
[index
-3] & 0xFF) << 8) |
2402 ((uint32_t)HuffTableAC0
->HuffVal
[index
-4] & 0xFF);
2408 if(HuffTableDC1
!= NULL
)
2410 /* DC1 Huffman Table : BITS*/
2411 /* DC1 BITS is a 16 Bytes table i.e 4x32bits words from DHTMEM + 51 base address to DHTMEM + 55*/
2412 /* only Byte 2 and Byte 3 of the first word (@ DHTMEM + 51) belong to DC1 Bits table */
2413 address
= (hjpeg
->Instance
->DHTMEM
+ 51);
2414 value
= *address
& 0x0000FFFFU
;
2415 value
= value
| (((uint32_t)HuffTableDC1
->Bits
[1] & 0xFF) << 24) | (((uint32_t)HuffTableDC1
->Bits
[0] & 0xFF) << 16);
2418 /* only Byte 0 and Byte 1 of the last word (@ DHTMEM + 55) belong to DC1 Bits table */
2419 address
= (hjpeg
->Instance
->DHTMEM
+ 55);
2420 value
= *address
& 0xFFFF0000U
;
2421 value
= value
| (((uint32_t)HuffTableDC1
->Bits
[15] & 0xFF) << 8) | ((uint32_t)HuffTableDC1
->Bits
[14] & 0xFF);
2424 /*continue setting 12 DC1 huffman Bits from DHTMEM + 54 down to DHTMEM + 52*/
2430 *address
= (((uint32_t)HuffTableDC1
->Bits
[index
+1] & 0xFF) << 24)|
2431 (((uint32_t)HuffTableDC1
->Bits
[index
] & 0xFF) << 16)|
2432 (((uint32_t)HuffTableDC1
->Bits
[index
-1] & 0xFF) << 8) |
2433 ((uint32_t)HuffTableDC1
->Bits
[index
-2] & 0xFF);
2438 /* DC1 Huffman Table : Val*/
2439 /* DC1 VALS is a 12 Bytes table i.e 3x32bits words from DHTMEM base address +55 to DHTMEM + 58 */
2440 /* only Byte 2 and Byte 3 of the first word (@ DHTMEM + 55) belong to DC1 Val table */
2441 address
= (hjpeg
->Instance
->DHTMEM
+ 55);
2442 value
= *address
& 0x0000FFFF;
2443 value
= value
| (((uint32_t)HuffTableDC1
->HuffVal
[1] & 0xFF) << 24) | (((uint32_t)HuffTableDC1
->HuffVal
[0] & 0xFF) << 16);
2446 /* only Byte 0 and Byte 1 of the last word (@ DHTMEM + 58) belong to DC1 Val table */
2447 address
= (hjpeg
->Instance
->DHTMEM
+ 58);
2448 value
= *address
& 0xFFFF0000U
;
2449 value
= value
| (((uint32_t)HuffTableDC1
->HuffVal
[11] & 0xFF) << 8) | ((uint32_t)HuffTableDC1
->HuffVal
[10] & 0xFF);
2452 /*continue setting 8 DC1 huffman val from DHTMEM + 57 down to DHTMEM + 56*/
2457 *address
= (((uint32_t)HuffTableDC1
->HuffVal
[index
+1] & 0xFF) << 24)|
2458 (((uint32_t)HuffTableDC1
->HuffVal
[index
] & 0xFF) << 16)|
2459 (((uint32_t)HuffTableDC1
->HuffVal
[index
-1] & 0xFF) << 8) |
2460 ((uint32_t)HuffTableDC1
->HuffVal
[index
-2] & 0xFF);
2466 if(HuffTableAC1
!= NULL
)
2468 /* AC1 Huffman Table : BITS*/
2469 /* AC1 BITS is a 16 Bytes table i.e 4x32bits words from DHTMEM base address + 58 to DHTMEM + 62*/
2470 /* only Byte 2 and Byte 3 of the first word (@ DHTMEM + 58) belong to AC1 Bits table */
2471 address
= (hjpeg
->Instance
->DHTMEM
+ 58);
2472 value
= *address
& 0x0000FFFFU
;
2473 value
= value
| (((uint32_t)HuffTableAC1
->Bits
[1] & 0xFF) << 24) | (((uint32_t)HuffTableAC1
->Bits
[0] & 0xFF) << 16);
2476 /* only Byte 0 and Byte 1 of the last word (@ DHTMEM + 62) belong to Bits Val table */
2477 address
= (hjpeg
->Instance
->DHTMEM
+ 62);
2478 value
= *address
& 0xFFFF0000U
;
2479 value
= value
| (((uint32_t)HuffTableAC1
->Bits
[15] & 0xFF) << 8) | ((uint32_t)HuffTableAC1
->Bits
[14] & 0xFF);
2482 /*continue setting 12 AC1 huffman Bits from DHTMEM + 61 down to DHTMEM + 59*/
2488 *address
= (((uint32_t)HuffTableAC1
->Bits
[index
+1] & 0xFF) << 24)|
2489 (((uint32_t)HuffTableAC1
->Bits
[index
] & 0xFF) << 16)|
2490 (((uint32_t)HuffTableAC1
->Bits
[index
-1] & 0xFF) << 8) |
2491 ((uint32_t)HuffTableAC1
->Bits
[index
-2] & 0xFF);
2496 /* AC1 Huffman Table : Val*/
2497 /* AC1 VALS is a 162 Bytes table i.e 41x32bits words from DHTMEM base address + 62 to DHTMEM + 102 */
2498 /* only Byte 2 and Byte 3 of the first word (@ DHTMEM + 62) belong to AC1 VALS table */
2499 address
= (hjpeg
->Instance
->DHTMEM
+ 62);
2500 value
= *address
& 0x0000FFFF;
2501 value
= value
| (((uint32_t)HuffTableAC1
->HuffVal
[1] & 0xFF) << 24) | (((uint32_t)HuffTableAC1
->HuffVal
[0] & 0xFF) << 16);
2504 /*continue setting 160 AC1 huffman values from DHTMEM + 63 to DHTMEM+102 */
2505 address
= (hjpeg
->Instance
->DHTMEM
+ 102);
2509 *address
= (((uint32_t)HuffTableAC1
->HuffVal
[index
+1] & 0xFF) << 24)|
2510 (((uint32_t)HuffTableAC1
->HuffVal
[index
] & 0xFF) << 16)|
2511 (((uint32_t)HuffTableAC1
->HuffVal
[index
-1] & 0xFF) << 8) |
2512 ((uint32_t)HuffTableAC1
->HuffVal
[index
-2] & 0xFF);
2520 * @brief Configure the JPEG registers with a given quantization table
2521 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2522 * the configuration information for JPEG module
2523 * @param QTable: pointer to an array of 64 bytes giving the quantization table
2524 * @param QTableAddress: destination quantization address in the JPEG peripheral
2525 * it could be QMEM0, QMEM1, QMEM2 or QMEM3
2528 static HAL_StatusTypeDef
JPEG_Set_Quantization_Mem(JPEG_HandleTypeDef
*hjpeg
, uint8_t *QTable
, uint32_t *QTableAddress
)
2530 uint32_t i
, j
, *tableAddress
, quantRow
, quantVal
, ScaleFactor
;
2532 if((QTableAddress
== ((uint32_t *)(hjpeg
->Instance
->QMEM0
))) ||
2533 (QTableAddress
== ((uint32_t *)(hjpeg
->Instance
->QMEM1
))) ||
2534 (QTableAddress
== ((uint32_t *)(hjpeg
->Instance
->QMEM2
))) ||
2535 (QTableAddress
== ((uint32_t *)(hjpeg
->Instance
->QMEM3
))))
2537 tableAddress
= QTableAddress
;
2544 if ((hjpeg
->Conf
.ImageQuality
>= 50) && (hjpeg
->Conf
.ImageQuality
<= 100))
2546 ScaleFactor
= 200 - (hjpeg
->Conf
.ImageQuality
* 2);
2548 else if (hjpeg
->Conf
.ImageQuality
> 0)
2550 ScaleFactor
= ((uint32_t) 5000) / ((uint32_t) hjpeg
->Conf
.ImageQuality
);
2557 /*Quantization_table = (Standard_quanization_table * ScaleFactor + 50) / 100*/
2559 while( i
< JPEG_QUANT_TABLE_SIZE
)
2564 /* Note that the quantization coefficients must be specified in the table in zigzag order */
2565 quantVal
= ((((uint32_t) QTable
[JPEG_ZIGZAG_ORDER
[i
+j
]]) * ScaleFactor
) + 50) / 100;
2571 else if (quantVal
> 255)
2576 quantRow
|= ((quantVal
& 0xFF) << (8 * j
));
2580 *tableAddress
= quantRow
;
2584 /* Return function status */
2589 * @brief Configure the JPEG registers for YCbCr color space
2590 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2591 * the configuration information for JPEG module
2594 static void JPEG_SetColorYCBCR(JPEG_HandleTypeDef
*hjpeg
)
2596 uint32_t ySamplingH
;
2597 uint32_t ySamplingV
;
2600 /*Set Number of color components to 3*/
2601 hjpeg
->Instance
->CONFR1
&= ~JPEG_CONFR1_NF
;
2602 hjpeg
->Instance
->CONFR1
|= JPEG_CONFR1_NF_1
;
2604 /* compute MCU block size and Y, Cb ,Cr sampling factors*/
2605 if(hjpeg
->Conf
.ChromaSubsampling
== JPEG_420_SUBSAMPLING
)
2607 ySamplingH
= JPEG_CONFR4_HSF_1
; /* Hs = 2*/
2608 ySamplingV
= JPEG_CONFR4_VSF_1
; /* Vs = 2*/
2610 yblockNb
= 0x30; /* 4 blocks of 8x8*/
2612 else if(hjpeg
->Conf
.ChromaSubsampling
== JPEG_422_SUBSAMPLING
)
2614 ySamplingH
= JPEG_CONFR4_HSF_1
; /* Hs = 2*/
2615 ySamplingV
= JPEG_CONFR4_VSF_0
; /* Vs = 1*/
2617 yblockNb
= 0x10; /* 2 blocks of 8x8*/
2619 else /*JPEG_444_SUBSAMPLING and default*/
2621 ySamplingH
= JPEG_CONFR4_HSF_0
; /* Hs = 1*/
2622 ySamplingV
= JPEG_CONFR4_VSF_0
; /* Vs = 1*/
2624 yblockNb
= 0; /* 1 block of 8x8*/
2627 hjpeg
->Instance
->CONFR1
&= ~(JPEG_CONFR1_NF
| JPEG_CONFR1_NS
);
2628 hjpeg
->Instance
->CONFR1
|= (JPEG_CONFR1_NF_1
| JPEG_CONFR1_NS_1
);
2630 /*Reset CONFR4 register*/
2631 hjpeg
->Instance
->CONFR4
= 0;
2632 /*Set Horizental and Vertical sampling factor , number of blocks , Quantization table and Huffman AC/DC tables for component 0*/
2633 hjpeg
->Instance
->CONFR4
|= (ySamplingH
| ySamplingV
| (yblockNb
& JPEG_CONFR4_NB
) );
2635 /*Reset CONFR5 register*/
2636 hjpeg
->Instance
->CONFR5
= 0;
2637 /*Set Horizental and Vertical sampling factor , number of blocks , Quantization table and Huffman AC/DC tables for component 1*/
2638 hjpeg
->Instance
->CONFR5
|= (JPEG_CONFR5_HSF_0
| JPEG_CONFR5_VSF_0
| JPEG_CONFR5_QT_0
| JPEG_CONFR5_HA
| JPEG_CONFR5_HD
);
2640 /*Reset CONFR6 register*/
2641 hjpeg
->Instance
->CONFR6
= 0;
2642 /*Set Horizental and Vertical sampling factor and number of blocks for component 2*/
2643 /* In YCBCR , by default, both chrominance components (component 1 and component 2) use the same Quantization table (table 1) */
2644 /* In YCBCR , both chrominance components (component 1 and component 2) use the same Huffman tables (table 1) */
2645 hjpeg
->Instance
->CONFR6
|= (JPEG_CONFR6_HSF_0
| JPEG_CONFR6_VSF_0
| JPEG_CONFR6_QT_0
| JPEG_CONFR6_HA
| JPEG_CONFR6_HD
);
2650 * @brief Configure the JPEG registers for GrayScale color space
2651 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2652 * the configuration information for JPEG module
2655 static void JPEG_SetColorGrayScale(JPEG_HandleTypeDef
*hjpeg
)
2657 /*Set Number of color components to 1*/
2658 hjpeg
->Instance
->CONFR1
&= ~(JPEG_CONFR1_NF
| JPEG_CONFR1_NS
);
2660 /*in GrayScale use 1 single Quantization table (Table 0)*/
2661 /*in GrayScale use only one couple of AC/DC huffman table (table 0)*/
2663 /*Reset CONFR4 register*/
2664 hjpeg
->Instance
->CONFR4
= 0;
2665 /*Set Horizental and Vertical sampling factor , number of blocks , Quantization table and Huffman AC/DC tables for component 0*/
2666 hjpeg
->Instance
->CONFR4
|= JPEG_CONFR4_HSF_0
| JPEG_CONFR4_VSF_0
;
2670 * @brief Configure the JPEG registers for CMYK color space
2671 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2672 * the configuration information for JPEG module
2675 static void JPEG_SetColorCMYK(JPEG_HandleTypeDef
*hjpeg
)
2677 uint32_t ySamplingH
;
2678 uint32_t ySamplingV
;
2681 /*Set Number of color components to 4*/
2682 hjpeg
->Instance
->CONFR1
|= (JPEG_CONFR1_NF
| JPEG_CONFR1_NS
);
2684 /* compute MCU block size and Y, Cb ,Cr sampling factors*/
2685 if(hjpeg
->Conf
.ChromaSubsampling
== JPEG_420_SUBSAMPLING
)
2687 ySamplingH
= JPEG_CONFR4_HSF_1
; /* Hs = 2*/
2688 ySamplingV
= JPEG_CONFR4_VSF_1
; /* Vs = 2*/
2690 yblockNb
= 0x30; /* 4 blocks of 8x8*/
2692 else if(hjpeg
->Conf
.ChromaSubsampling
== JPEG_422_SUBSAMPLING
)
2694 ySamplingH
= JPEG_CONFR4_HSF_1
; /* Hs = 2*/
2695 ySamplingV
= JPEG_CONFR4_VSF_0
; /* Vs = 1*/
2697 yblockNb
= 0x10; /* 2 blocks of 8x8*/
2699 else /*JPEG_444_SUBSAMPLING and default*/
2701 ySamplingH
= JPEG_CONFR4_HSF_0
; /* Hs = 1*/
2702 ySamplingV
= JPEG_CONFR4_VSF_0
; /* Vs = 1*/
2704 yblockNb
= 0; /* 1 block of 8x8*/
2707 /*Reset CONFR4 register*/
2708 hjpeg
->Instance
->CONFR4
= 0;
2709 /*Set Horizental and Vertical sampling factor , number of blocks , Quantization table and Huffman AC/DC tables for component 0*/
2710 hjpeg
->Instance
->CONFR4
|= (ySamplingH
| ySamplingV
| (yblockNb
& JPEG_CONFR4_NB
) );
2712 /*Reset CONFR5 register*/
2713 hjpeg
->Instance
->CONFR5
= 0;
2714 /*Set Horizental and Vertical sampling factor , number of blocks , Quantization table and Huffman AC/DC tables for component 1*/
2715 hjpeg
->Instance
->CONFR5
|= (JPEG_CONFR5_HSF_0
| JPEG_CONFR5_VSF_0
);
2717 /*Reset CONFR6 register*/
2718 hjpeg
->Instance
->CONFR6
= 0;
2719 /*Set Horizental and Vertical sampling factor , number of blocks , Quantization table and Huffman AC/DC tables for component 2*/
2720 hjpeg
->Instance
->CONFR6
|= (JPEG_CONFR6_HSF_0
| JPEG_CONFR6_VSF_0
);
2722 /*Reset CONFR7 register*/
2723 hjpeg
->Instance
->CONFR7
= 0;
2724 /*Set Horizental and Vertical sampling factor , number of blocks , Quantization table and Huffman AC/DC tables for component 3*/
2725 hjpeg
->Instance
->CONFR7
|= (JPEG_CONFR7_HSF_0
| JPEG_CONFR7_VSF_0
);
2729 * @brief Init the JPEG encoding/decoding process in case of Polling or Interrupt and DMA
2730 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2731 * the configuration information for JPEG module
2734 static void JPEG_Init_Process(JPEG_HandleTypeDef
*hjpeg
)
2737 hjpeg
->Context
&= (~(JPEG_CONTEXT_PAUSE_INPUT
| JPEG_CONTEXT_PAUSE_OUTPUT
));
2739 if((hjpeg
->Context
& JPEG_CONTEXT_OPERATION_MASK
) == JPEG_CONTEXT_DECODE
)
2741 /*Set JPEG Codec to Decoding mode */
2742 hjpeg
->Instance
->CONFR1
|= JPEG_CONFR1_DE
;
2744 else if((hjpeg
->Context
& JPEG_CONTEXT_OPERATION_MASK
) == JPEG_CONTEXT_ENCODE
)
2746 /*Set JPEG Codec to Encoding mode */
2747 hjpeg
->Instance
->CONFR1
&= ~JPEG_CONFR1_DE
;
2750 /*Stop JPEG processing */
2751 hjpeg
->Instance
->CONFR0
&= ~JPEG_CONFR0_START
;
2753 /* Disable All Interrupts */
2754 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_INTERRUPT_MASK
);
2756 /* Disable All DMA requests */
2757 JPEG_DISABLE_DMA(hjpeg
,JPEG_DMA_MASK
);
2759 /* Flush input and output FIFOs*/
2760 hjpeg
->Instance
->CR
|= JPEG_CR_IFF
;
2761 hjpeg
->Instance
->CR
|= JPEG_CR_OFF
;
2763 /* Clear all flags */
2764 __HAL_JPEG_CLEAR_FLAG(hjpeg
,JPEG_FLAG_ALL
);
2766 /*Start Encoding/Decoding*/
2767 hjpeg
->Instance
->CONFR0
|= JPEG_CONFR0_START
;
2769 if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_IT
)
2771 /*Enable IN/OUT, end of Conversation, and end of header parsing interruptions*/
2772 __HAL_JPEG_ENABLE_IT(hjpeg
, JPEG_IT_IFT
| JPEG_IT_IFNF
| JPEG_IT_OFT
| JPEG_IT_OFNE
| JPEG_IT_EOC
|JPEG_IT_HPD
);
2774 else if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_DMA
)
2776 /*Enable End Of Conversation, and End Of Header parsing interruptions*/
2777 __HAL_JPEG_ENABLE_IT(hjpeg
, JPEG_IT_EOC
|JPEG_IT_HPD
);
2783 * @brief JPEG encoding/decoding process in case of Polling or Interrupt
2784 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2785 * the configuration information for JPEG module
2786 * @retval JPEG_PROCESS_DONE if the process has ends else JPEG_PROCESS_ONGOING
2788 static uint32_t JPEG_Process(JPEG_HandleTypeDef
*hjpeg
)
2790 uint32_t tmpContext
;
2792 /*End of header processing flag rised*/
2793 if(((hjpeg
->Context
& JPEG_CONTEXT_OPERATION_MASK
) == JPEG_CONTEXT_DECODE
) && (__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_HPDF
) != RESET
))
2795 /*Call Header parsing complet callback */
2796 HAL_JPEG_GetInfo(hjpeg
, &hjpeg
->Conf
);
2797 /* Reset the ImageQuality */
2798 hjpeg
->Conf
.ImageQuality
= 0;
2799 /* Note : the image quality is only available at the end of the decoding operation */
2800 /* at the current stage the calculated image quality is not correct so reset it */
2802 /*Call Info Ready callback */
2803 HAL_JPEG_InfoReadyCallback(hjpeg
, &hjpeg
->Conf
);
2805 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_IT_HPD
);
2807 /* Clear header processing done flag */
2808 __HAL_JPEG_CLEAR_FLAG(hjpeg
,JPEG_FLAG_HPDF
);
2811 /*Input FIFO status handling*/
2812 if((hjpeg
->Context
& JPEG_CONTEXT_PAUSE_INPUT
) == 0)
2814 if(__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_IFTF
) != RESET
)
2816 /*Input FIFO threshold flag rised*/
2817 /*4 words (16 bytes) can be written in */
2818 JPEG_ReadInputData(hjpeg
,4);
2820 else if(__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_IFNFF
) != RESET
)
2822 /*Input FIFO Not Full flag rised*/
2823 /*32-bit value can be written in */
2824 JPEG_ReadInputData(hjpeg
,1);
2829 /*Output FIFO flag handling*/
2830 if((hjpeg
->Context
& JPEG_CONTEXT_PAUSE_OUTPUT
) == 0)
2832 if(__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_OFTF
) != RESET
)
2834 /*Output FIFO threshold flag rised*/
2835 /*4 words (16 bytes) can be read out */
2836 JPEG_StoreOutputData(hjpeg
, 4);
2838 else if(__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_OFNEF
) != RESET
)
2840 /*Output FIFO Not Empty flag rised*/
2841 /*32-bit value can be read out */
2842 JPEG_StoreOutputData(hjpeg
, 1);
2846 /*End of Conversion handling :i.e EOC flag is high and OFTF low and OFNEF low*/
2847 if(__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_EOCF
| JPEG_FLAG_OFTF
| JPEG_FLAG_OFNEF
) == JPEG_FLAG_EOCF
)
2849 /*Stop Encoding/Decoding*/
2850 hjpeg
->Instance
->CONFR0
&= ~JPEG_CONFR0_START
;
2852 if((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_IT
)
2854 /* Disable All Interrupts */
2855 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_INTERRUPT_MASK
);
2858 /* Clear all flags */
2859 __HAL_JPEG_CLEAR_FLAG(hjpeg
,JPEG_FLAG_ALL
);
2861 /*Call End of conversion callback */
2862 if(hjpeg
->JpegOutCount
> 0)
2864 /*Output Buffer is not empty, call DecodedDataReadyCallback*/
2865 HAL_JPEG_DataReadyCallback (hjpeg
, hjpeg
->pJpegOutBuffPtr
, hjpeg
->JpegOutCount
);
2866 hjpeg
->JpegOutCount
= 0;
2869 /*Reset Context Operation*/
2870 tmpContext
= hjpeg
->Context
;
2871 /*Clear all context fields execpt JPEG_CONTEXT_CONF_ENCODING and JPEG_CONTEXT_CUSTOM_TABLES*/
2872 hjpeg
->Context
&= (JPEG_CONTEXT_CONF_ENCODING
| JPEG_CONTEXT_CUSTOM_TABLES
);
2874 /* Process Unlocked */
2875 __HAL_UNLOCK(hjpeg
);
2877 /* Change the JPEG state */
2878 hjpeg
->State
= HAL_JPEG_STATE_READY
;
2880 /*Call End of Encoding/Decoding callback */
2881 if((tmpContext
& JPEG_CONTEXT_OPERATION_MASK
) == JPEG_CONTEXT_DECODE
)
2883 HAL_JPEG_DecodeCpltCallback(hjpeg
);
2885 else if((tmpContext
& JPEG_CONTEXT_OPERATION_MASK
) == JPEG_CONTEXT_ENCODE
)
2887 HAL_JPEG_EncodeCpltCallback(hjpeg
);
2890 return JPEG_PROCESS_DONE
;
2894 return JPEG_PROCESS_ONGOING
;
2898 * @brief Store some output data from the JPEG peripheral to the output buffer.
2899 * This function is used when the JPEG peripheral has new data to output
2900 * in case of Polling or Interrupt process
2901 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2902 * the configuration information for JPEG module
2903 * @param nbOutputWords: Number of output words (of 32 bits) ready from the JPEG peripheral
2906 static void JPEG_StoreOutputData(JPEG_HandleTypeDef
*hjpeg
, uint32_t nbOutputWords
)
2908 uint32_t index
, nBwords
, nbBytes
, dataword
, *pOutData
;
2910 pOutData
= (uint32_t *)(((uint32_t *)hjpeg
->pJpegOutBuffPtr
) + (hjpeg
->JpegOutCount
/4));
2912 if(hjpeg
->OutDataLength
>= (hjpeg
->JpegOutCount
+ (nbOutputWords
*4)))
2914 for(index
= 0; index
< nbOutputWords
; index
++)
2916 /*Transfer 32 bits from the JPEG output FIFO*/
2917 *pOutData
= hjpeg
->Instance
->DOR
;
2919 hjpeg
->JpegOutCount
+= 4;
2921 if(hjpeg
->OutDataLength
== hjpeg
->JpegOutCount
)
2923 /*Output Buffer is full, call DecodedDataReadyCallback*/
2924 HAL_JPEG_DataReadyCallback (hjpeg
, hjpeg
->pJpegOutBuffPtr
, hjpeg
->JpegOutCount
);
2925 hjpeg
->JpegOutCount
= 0;
2928 else if(hjpeg
->OutDataLength
> hjpeg
->JpegOutCount
)
2930 nBwords
= (hjpeg
->OutDataLength
- hjpeg
->JpegOutCount
)/4;
2931 for(index
= 0; index
< nBwords
; index
++)
2933 /*Transfer 32 bits from the JPEG output FIFO*/
2934 *pOutData
= hjpeg
->Instance
->DOR
;
2936 hjpeg
->JpegOutCount
+= 4;
2938 if(hjpeg
->OutDataLength
== hjpeg
->JpegOutCount
)
2940 /*Output Buffer is full, call DecodedDataReadyCallback*/
2941 HAL_JPEG_DataReadyCallback (hjpeg
, hjpeg
->pJpegOutBuffPtr
, hjpeg
->JpegOutCount
);
2942 hjpeg
->JpegOutCount
= 0;
2946 nbBytes
= hjpeg
->OutDataLength
- hjpeg
->JpegOutCount
;
2947 dataword
= hjpeg
->Instance
->DOR
;
2948 for(index
= 0; index
< nbBytes
; index
++)
2950 hjpeg
->pJpegOutBuffPtr
[hjpeg
->JpegOutCount
] = (dataword
>> (8*index
)) & 0xFF;
2951 hjpeg
->JpegOutCount
++;
2953 /*Output Buffer is full, call DecodedDataReadyCallback*/
2954 HAL_JPEG_DataReadyCallback (hjpeg
, hjpeg
->pJpegOutBuffPtr
, hjpeg
->JpegOutCount
);
2955 hjpeg
->JpegOutCount
= 0;
2957 nbBytes
= 4 - nbBytes
;
2958 for(index
= nbBytes
; index
< 4; index
++)
2960 hjpeg
->pJpegOutBuffPtr
[hjpeg
->JpegOutCount
] = (dataword
>> (8*index
)) & 0xFF;
2961 hjpeg
->JpegOutCount
++;
2968 * @brief Read some input Data from the input buffer.
2969 * This function is used when the JPEG peripheral needs new data
2970 * in case of Polling or Interrupt process
2971 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
2972 * the configuration information for JPEG module
2973 * @param nbRequestWords: Number of input words (of 32 bits) that the JPE peripheral request
2976 static void JPEG_ReadInputData(JPEG_HandleTypeDef
*hjpeg
, uint32_t nbRequestWords
)
2978 uint32_t nbBytes
= 0, nBwords
, index
, Dataword
;
2980 if((hjpeg
->InDataLength
== 0) || (nbRequestWords
== 0))
2982 /* No more Input data : nothing to do*/
2983 HAL_JPEG_Pause(hjpeg
, JPEG_PAUSE_RESUME_INPUT
);
2985 else if(hjpeg
->InDataLength
> hjpeg
->JpegInCount
)
2987 nbBytes
= hjpeg
->InDataLength
- hjpeg
->JpegInCount
;
2989 else if(hjpeg
->InDataLength
== hjpeg
->JpegInCount
)
2991 /*Call HAL_JPEG_GetDataCallback to get new data */
2992 HAL_JPEG_GetDataCallback(hjpeg
, hjpeg
->JpegInCount
);
2993 if(hjpeg
->InDataLength
> 4)
2995 hjpeg
->InDataLength
= hjpeg
->InDataLength
- (hjpeg
->InDataLength
% 4);
2997 hjpeg
->JpegInCount
= 0;
2998 nbBytes
= hjpeg
->InDataLength
;
3000 if((nbBytes
> 0) && ((hjpeg
->Context
& JPEG_CONTEXT_PAUSE_INPUT
) == 0))
3002 nBwords
= nbBytes
/ 4;
3003 if(nBwords
>= nbRequestWords
)
3005 for(index
= 0; index
< nbRequestWords
; index
++)
3007 hjpeg
->Instance
->DIR = *((uint32_t *)(((uint32_t *)hjpeg
->pJpegInBuffPtr
) + (hjpeg
->JpegInCount
/4)));
3009 hjpeg
->JpegInCount
+= 4;
3012 else /*nBwords < nbRequestWords*/
3016 for(index
= 0; index
< nBwords
; index
++)
3018 hjpeg
->Instance
->DIR = *((uint32_t *)(((uint32_t *)hjpeg
->pJpegInBuffPtr
) + (hjpeg
->JpegInCount
/4)));
3020 hjpeg
->JpegInCount
+= 4;
3027 for(index
=0; index
< nbBytes
; index
++)
3029 Dataword
|= (uint32_t)hjpeg
->pJpegInBuffPtr
[hjpeg
->JpegInCount
] << (8 * index
);
3030 hjpeg
->JpegInCount
++;
3032 hjpeg
->Instance
->DIR = Dataword
;
3039 * @brief Start the JPEG DMA process (encoding/decoding)
3040 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
3041 * the configuration information for JPEG module
3042 * @retval JPEG_PROCESS_DONE if process ends else JPEG_PROCESS_ONGOING
3044 static HAL_StatusTypeDef
JPEG_DMA_StartProcess(JPEG_HandleTypeDef
*hjpeg
)
3046 if((hjpeg
->InDataLength
< 4) || (hjpeg
->OutDataLength
< 4))
3050 /* Reset Ending DMA internal context flag*/
3051 hjpeg
->Context
&= ~JPEG_CONTEXT_ENDING_DMA
;
3053 /* Disable DMA In/Out Request*/
3054 JPEG_DISABLE_DMA(hjpeg
,JPEG_DMA_ODMA
| JPEG_DMA_IDMA
);
3056 /* Set the JPEG DMA In transfer complete callback */
3057 hjpeg
->hdmain
->XferCpltCallback
= JPEG_DMAInCpltCallback
;
3058 /* Set the DMA In error callback */
3059 hjpeg
->hdmain
->XferErrorCallback
= JPEG_DMAErrorCallback
;
3061 /* Set the JPEG DMA Out transfer complete callback */
3062 hjpeg
->hdmaout
->XferCpltCallback
= JPEG_DMAOutCpltCallback
;
3063 /* Set the DMA Out error callback */
3064 hjpeg
->hdmaout
->XferErrorCallback
= JPEG_DMAErrorCallback
;
3065 /* Set the DMA Out Abort callback */
3066 hjpeg
->hdmaout
->XferAbortCallback
= JPEG_DMAOutAbortCallback
;
3068 /*DMA transfer size must be a multiple of 4 bytes i.e mutliple of 32bits words*/
3069 hjpeg
->InDataLength
= hjpeg
->InDataLength
- (hjpeg
->InDataLength
% 4);
3071 /*DMA transfer size must be a multiple of 4 bytes i.e mutliple of 32bits words*/
3072 hjpeg
->OutDataLength
= hjpeg
->OutDataLength
- (hjpeg
->OutDataLength
% 4);
3074 /* Start DMA FIFO In transfer */
3075 HAL_DMA_Start_IT(hjpeg
->hdmain
, (uint32_t)hjpeg
->pJpegInBuffPtr
, (uint32_t)&hjpeg
->Instance
->DIR, hjpeg
->InDataLength
>> 2);
3077 /* Start DMA FIFO Out transfer */
3078 HAL_DMA_Start_IT(hjpeg
->hdmaout
, (uint32_t)&hjpeg
->Instance
->DOR
, (uint32_t)hjpeg
->pJpegOutBuffPtr
, hjpeg
->OutDataLength
>> 2);
3080 /* Enable JPEG In/Out DMA requests*/
3081 JPEG_ENABLE_DMA(hjpeg
,JPEG_DMA_IDMA
| JPEG_DMA_ODMA
);
3087 * @brief Continue the current JPEG DMA process (encoding/decoding)
3088 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
3089 * the configuration information for JPEG module
3090 * @retval JPEG_PROCESS_DONE if process ends else JPEG_PROCESS_ONGOING
3092 static uint32_t JPEG_DMA_ContinueProcess(JPEG_HandleTypeDef
*hjpeg
)
3094 /*End of header processing flag rises*/
3095 if(((hjpeg
->Context
& JPEG_CONTEXT_OPERATION_MASK
) == JPEG_CONTEXT_DECODE
) && (__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_HPDF
) != RESET
))
3097 /*Call Header parsing complete callback */
3098 HAL_JPEG_GetInfo(hjpeg
, &hjpeg
->Conf
);
3100 /* Reset the ImageQuality */
3101 hjpeg
->Conf
.ImageQuality
= 0;
3102 /* Note : the image quality is only available at the end of the decoding operation */
3103 /* at the current stage the calculated image quality is not correct so reset it */
3105 /*Call Info Ready callback */
3106 HAL_JPEG_InfoReadyCallback(hjpeg
, &hjpeg
->Conf
);
3108 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_IT_HPD
);
3110 /* Clear header processing done flag */
3111 __HAL_JPEG_CLEAR_FLAG(hjpeg
,JPEG_FLAG_HPDF
);
3114 /*End of Conversion handling*/
3115 if(__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_EOCF
) != RESET
)
3117 /*Disabkle JPEG In/Out DMA Requests*/
3118 JPEG_DISABLE_DMA(hjpeg
,JPEG_DMA_ODMA
| JPEG_DMA_IDMA
);
3120 hjpeg
->Context
|= JPEG_CONTEXT_ENDING_DMA
;
3122 /*Stop Encoding/Decoding*/
3123 hjpeg
->Instance
->CONFR0
&= ~JPEG_CONFR0_START
;
3125 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_INTERRUPT_MASK
);
3127 /* Clear all flags */
3128 __HAL_JPEG_CLEAR_FLAG(hjpeg
,JPEG_FLAG_ALL
);
3130 if(hjpeg
->hdmain
->State
== HAL_DMA_STATE_BUSY
)
3132 /* Stop the DMA In Xfer*/
3133 HAL_DMA_Abort_IT(hjpeg
->hdmain
);
3136 if(hjpeg
->hdmaout
->State
== HAL_DMA_STATE_BUSY
)
3138 /* Stop the DMA out Xfer*/
3139 HAL_DMA_Abort_IT(hjpeg
->hdmaout
);
3143 return JPEG_DMA_EndProcess(hjpeg
);
3147 return JPEG_PROCESS_ONGOING
;
3151 * @brief Finalize the current JPEG DMA process (encoding/decoding)
3152 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
3153 * the configuration information for JPEG module
3154 * @retval JPEG_PROCESS_DONE
3156 static uint32_t JPEG_DMA_EndProcess(JPEG_HandleTypeDef
*hjpeg
)
3158 uint32_t tmpContext
, count
= JPEG_FIFO_SIZE
, *pDataOut
;
3160 hjpeg
->JpegOutCount
= hjpeg
->OutDataLength
- ((hjpeg
->hdmaout
->Instance
->NDTR
& DMA_SxNDT
) << 2);
3162 /*if Output Buffer is full, call HAL_JPEG_DataReadyCallback*/
3163 if(hjpeg
->JpegOutCount
== hjpeg
->OutDataLength
)
3165 HAL_JPEG_DataReadyCallback (hjpeg
, hjpeg
->pJpegOutBuffPtr
, hjpeg
->JpegOutCount
);
3166 hjpeg
->JpegOutCount
= 0;
3169 pDataOut
= (uint32_t *)(hjpeg
->pJpegOutBuffPtr
+ hjpeg
->JpegOutCount
);
3171 while((__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_OFNEF
) != 0) && (count
> 0))
3175 *pDataOut
= hjpeg
->Instance
->DOR
;
3177 hjpeg
->JpegOutCount
+= 4;
3179 if(hjpeg
->JpegOutCount
== hjpeg
->OutDataLength
)
3181 /*Output Buffer is full, call HAL_JPEG_DataReadyCallback*/
3182 HAL_JPEG_DataReadyCallback (hjpeg
, hjpeg
->pJpegOutBuffPtr
, hjpeg
->JpegOutCount
);
3183 hjpeg
->JpegOutCount
= 0;
3187 /*Stop Encoding/Decoding*/
3188 hjpeg
->Instance
->CONFR0
&= ~JPEG_CONFR0_START
;
3190 if(hjpeg
->JpegOutCount
> 0)
3192 /*Output Buffer is not empty, call DecodedDataReadyCallback*/
3193 HAL_JPEG_DataReadyCallback (hjpeg
, hjpeg
->pJpegOutBuffPtr
, hjpeg
->JpegOutCount
);
3194 hjpeg
->JpegOutCount
= 0;
3197 tmpContext
= hjpeg
->Context
;
3198 /*Clear all context fileds execpt JPEG_CONTEXT_CONF_ENCODING and JPEG_CONTEXT_CUSTOM_TABLES*/
3199 hjpeg
->Context
&= (JPEG_CONTEXT_CONF_ENCODING
| JPEG_CONTEXT_CUSTOM_TABLES
);
3201 /* Process Unlocked */
3202 __HAL_UNLOCK(hjpeg
);
3204 /* Change the JPEG state */
3205 hjpeg
->State
= HAL_JPEG_STATE_READY
;
3207 /*Call End of Encoding/Decoding callback */
3208 if((tmpContext
& JPEG_CONTEXT_OPERATION_MASK
) == JPEG_CONTEXT_DECODE
)
3210 HAL_JPEG_DecodeCpltCallback(hjpeg
);
3212 else if((tmpContext
& JPEG_CONTEXT_OPERATION_MASK
) == JPEG_CONTEXT_ENCODE
)
3214 HAL_JPEG_EncodeCpltCallback(hjpeg
);
3218 return JPEG_PROCESS_DONE
;
3222 * @brief DMA input transfer complete callback
3223 * @param hdma: pointer to a DMA_HandleTypeDef structure.
3226 static void JPEG_DMAInCpltCallback(DMA_HandleTypeDef
*hdma
)
3228 JPEG_HandleTypeDef
* hjpeg
= (JPEG_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3230 /* Disable The JPEG IT so the DMA Input Callback can not be interrupted by the JPEG EOC IT or JPEG HPD IT */
3231 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_INTERRUPT_MASK
);
3233 if(((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_DMA
) && ((hjpeg
->Context
& JPEG_CONTEXT_ENDING_DMA
) == 0))
3235 JPEG_DISABLE_DMA(hjpeg
,JPEG_DMA_IDMA
);
3237 hjpeg
->JpegInCount
= hjpeg
->InDataLength
- ((hdma
->Instance
->NDTR
& DMA_SxNDT
) << 2);
3239 /*Call HAL_JPEG_GetDataCallback to get new data */
3240 HAL_JPEG_GetDataCallback(hjpeg
, hjpeg
->JpegInCount
);
3242 if(hjpeg
->InDataLength
>= 4)
3244 /*JPEG Input DMA transfer data number must be multiple of 32 bits word
3245 as the destination is a 32 bits (4 bytes) register */
3246 hjpeg
->InDataLength
= hjpeg
->InDataLength
- (hjpeg
->InDataLength
% 4);
3248 else if(hjpeg
->InDataLength
> 0)
3250 /*Transfer last data word (i.e last 4 bytes)*/
3251 hjpeg
->InDataLength
= 4;
3254 if(((hjpeg
->Context
& JPEG_CONTEXT_PAUSE_INPUT
) == 0) && (hjpeg
->InDataLength
> 0))
3256 /* Start DMA FIFO In transfer */
3257 HAL_DMA_Start_IT(hjpeg
->hdmain
, (uint32_t)hjpeg
->pJpegInBuffPtr
, (uint32_t)&hjpeg
->Instance
->DIR, hjpeg
->InDataLength
>> 2);
3258 JPEG_ENABLE_DMA(hjpeg
,JPEG_DMA_IDMA
);
3261 /* JPEG Conversion still on going : Enable the JPEG IT */
3262 __HAL_JPEG_ENABLE_IT(hjpeg
,JPEG_IT_EOC
|JPEG_IT_HPD
);
3267 * @brief DMA output transfer complete callback
3268 * @param hdma: pointer to a DMA_HandleTypeDef structure.
3271 static void JPEG_DMAOutCpltCallback(DMA_HandleTypeDef
*hdma
)
3273 JPEG_HandleTypeDef
* hjpeg
= (JPEG_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3275 /* Disable The JPEG IT so the DMA Output Callback can not be interrupted by the JPEG EOC IT or JPEG HPD IT */
3276 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_INTERRUPT_MASK
);
3278 if(((hjpeg
->Context
& JPEG_CONTEXT_METHOD_MASK
) == JPEG_CONTEXT_DMA
) && ((hjpeg
->Context
& JPEG_CONTEXT_ENDING_DMA
) == 0))
3280 if(__HAL_JPEG_GET_FLAG(hjpeg
, JPEG_FLAG_EOCF
) == 0)
3282 JPEG_DISABLE_DMA(hjpeg
,JPEG_DMA_ODMA
);
3283 hjpeg
->JpegOutCount
= hjpeg
->OutDataLength
- ((hdma
->Instance
->NDTR
& DMA_SxNDT
) << 2);
3285 /*Output Buffer is full, call HAL_JPEG_DataReadyCallback*/
3286 HAL_JPEG_DataReadyCallback (hjpeg
, hjpeg
->pJpegOutBuffPtr
, hjpeg
->JpegOutCount
);
3288 if((hjpeg
->Context
& JPEG_CONTEXT_PAUSE_OUTPUT
) == 0)
3290 /* Start DMA FIFO Out transfer */
3291 HAL_DMA_Start_IT(hjpeg
->hdmaout
, (uint32_t)&hjpeg
->Instance
->DOR
, (uint32_t)hjpeg
->pJpegOutBuffPtr
, hjpeg
->OutDataLength
>> 2);
3292 JPEG_ENABLE_DMA(hjpeg
,JPEG_DMA_ODMA
);
3296 /* JPEG Conversion still on going : Enable the JPEG IT */
3297 __HAL_JPEG_ENABLE_IT(hjpeg
,JPEG_IT_EOC
|JPEG_IT_HPD
);
3302 * @brief DMA Transfer error callback
3303 * @param hdma: pointer to a DMA_HandleTypeDef structure.
3306 static void JPEG_DMAErrorCallback(DMA_HandleTypeDef
*hdma
)
3308 JPEG_HandleTypeDef
* hjpeg
= (JPEG_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3310 /* if DMA error is FIFO error ignore it */
3311 if(HAL_DMA_GetError(hdma
) != HAL_DMA_ERROR_FE
)
3313 /*Stop Encoding/Decoding*/
3314 hjpeg
->Instance
->CONFR0
&= ~JPEG_CONFR0_START
;
3316 /* Disable All Interrupts */
3317 __HAL_JPEG_DISABLE_IT(hjpeg
,JPEG_INTERRUPT_MASK
);
3319 /* Disable All DMA requests */
3320 JPEG_DISABLE_DMA(hjpeg
,JPEG_DMA_MASK
);
3322 hjpeg
->State
= HAL_JPEG_STATE_READY
;
3323 hjpeg
->ErrorCode
|= HAL_JPEG_ERROR_DMA
;
3324 HAL_JPEG_ErrorCallback(hjpeg
);
3329 * @brief DMA output Abort callback
3330 * @param hdma: pointer to a DMA_HandleTypeDef structure.
3333 static void JPEG_DMAOutAbortCallback(DMA_HandleTypeDef
*hdma
)
3335 JPEG_HandleTypeDef
* hjpeg
= (JPEG_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3337 if((hjpeg
->Context
& JPEG_CONTEXT_ENDING_DMA
) != 0)
3339 JPEG_DMA_EndProcess(hjpeg
);
3344 * @brief Calculate the decoded image quality (from 1 to 100)
3345 * @param hjpeg: pointer to a JPEG_HandleTypeDef structure that contains
3346 * the configuration information for JPEG module
3347 * @retval JPEG image quality from 1 to 100.
3349 static uint32_t JPEG_GetQuality(JPEG_HandleTypeDef
*hjpeg
)
3351 uint32_t quality
= 0;
3352 uint32_t quantRow
, quantVal
,scale
, i
, j
;
3353 uint32_t *tableAddress
= (uint32_t *)hjpeg
->Instance
->QMEM0
;
3356 while( i
< JPEG_QUANT_TABLE_SIZE
)
3358 quantRow
= *tableAddress
;
3361 quantVal
= (quantRow
>> (8 * j
)) & 0xFF;
3364 /* if Quantization value = 1 then quality is 100%*/
3369 /* Note that the quantization coefficients must be specified in the table in zigzag order */
3370 scale
= (quantVal
*100)/((uint32_t) JPEG_LUM_QuantTable
[JPEG_ZIGZAG_ORDER
[i
+j
]]);
3374 quality
+= (200 - scale
)/2;
3378 quality
+= 5000/scale
;
3387 return (quality
/((uint32_t)64));
3393 #endif /* STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx */
3394 #endif /* HAL_JPEG_MODULE_ENABLED */
3403 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/