Skip to content

Commit 34eb6b8

Browse files
Duy VoKhiemNguyenT
authored andcommitted
hal: renesas: ra: initial support for CEU driver
Initial support for CEU driver Signed-off-by: Duy Vo <[email protected]>
1 parent 7abbf53 commit 34eb6b8

File tree

5 files changed

+817
-0
lines changed

5 files changed

+817
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,6 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_ETHER
158158

159159
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_CRC
160160
fsp/src/r_crc/r_crc.c)
161+
162+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_CEU
163+
fsp/src/r_ceu/r_ceu.c)
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @ingroup RENESAS_GRAPHICS_INTERFACES
9+
* @defgroup CAPTURE_API CAPTURE Interface
10+
* @brief Interface for CAPTURE functions.
11+
*
12+
* @section CAPTURE_API_SUMMARY Summary
13+
* The CAPTURE interface provides the functionality for capturing an image from an image sensor/camera.
14+
* When a capture is complete a capture complete interrupt is triggered.
15+
*
16+
*
17+
* @{
18+
**********************************************************************************************************************/
19+
20+
#ifndef R_CAPTURE_API_H
21+
#define R_CAPTURE_API_H
22+
23+
/***********************************************************************************************************************
24+
* Includes
25+
**********************************************************************************************************************/
26+
27+
/* Register definitions, common services and error codes. */
28+
#include "bsp_api.h"
29+
30+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
31+
FSP_HEADER
32+
33+
/**********************************************************************************************************************
34+
* Macro definitions
35+
**********************************************************************************************************************/
36+
37+
/**********************************************************************************************************************
38+
* Typedef definitions
39+
**********************************************************************************************************************/
40+
41+
/** CAPTURE states. */
42+
typedef enum e_capture_state
43+
{
44+
CAPTURE_STATE_IDLE = 0, ///< CAPTURE is idle
45+
CAPTURE_STATE_IN_PROGRESS = 1, ///< CAPTURE capture in progress
46+
CAPTURE_STATE_BUSY = 2, ///< CAPTURE reset in progress
47+
} capture_state_t;
48+
49+
/** CAPTURE status */
50+
typedef struct e_capture_status
51+
{
52+
capture_state_t state; ///< Current state
53+
uint32_t * p_buffer; ///< Pointer to active buffer
54+
uint32_t data_size; ///< Size of data written to provided buffer
55+
} capture_status_t;
56+
57+
/** CAPTURE callback event ID - see implimentation for details */
58+
typedef uint32_t capture_event_t;
59+
60+
/** CAPTURE callback function parameter data */
61+
typedef struct st_capture_callback_args
62+
{
63+
capture_event_t event; ///< Event causing the callback
64+
uint8_t * p_buffer; ///< Pointer to buffer that contains captured data
65+
void const * p_context; ///< Placeholder for user data. Set in @ref capture_api_t::open function in @ref capture_cfg_t.
66+
} capture_callback_args_t;
67+
68+
/** CAPTURE configuration parameters. */
69+
typedef struct st_capture_cfg
70+
{
71+
uint16_t x_capture_start_pixel; ///< Horizontal position to start capture
72+
uint16_t x_capture_pixels; ///< Number of horizontal pixels to capture
73+
uint16_t y_capture_start_pixel; ///< Vertical position to start capture
74+
uint16_t y_capture_pixels; ///< Number of vertical lines/pixels to capture
75+
uint8_t bytes_per_pixel; ///< Number of bytes per pixel
76+
void (* p_callback)(capture_callback_args_t * p_args); ///< Callback provided when a CAPTURE transfer ISR occurs
77+
void const * p_context; ///< User defined context passed to callback function
78+
void const * p_extend; ///< Extension parameter for hardware specific settings
79+
} capture_cfg_t;
80+
81+
/** CAPTURE control block. Allocate an instance specific control block to pass into the CAPTURE API calls.
82+
*/
83+
typedef void capture_ctrl_t;
84+
85+
/** CAPTURE functions implemented at the HAL layer will follow this API. */
86+
typedef struct st_capture_api
87+
{
88+
/** Initial configuration.
89+
*
90+
* @note To reconfigure after calling this function, call @ref capture_api_t::close first.
91+
* @param[in] p_ctrl Pointer to control structure.
92+
* @param[in] p_cfg Pointer to pin configuration structure.
93+
*/
94+
fsp_err_t (* open)(capture_ctrl_t * const p_ctrl, capture_cfg_t const * const p_cfg);
95+
96+
/** Closes the driver and allows reconfiguration. May reduce power consumption.
97+
*
98+
* @param[in] p_ctrl Pointer to control structure.
99+
*/
100+
fsp_err_t (* close)(capture_ctrl_t * const p_ctrl);
101+
102+
/** Start a capture.
103+
*
104+
* @param[in] p_ctrl Pointer to control structure.
105+
* @param[in] p_buffer New pointer to store captured image data.
106+
*/
107+
fsp_err_t (* captureStart)(capture_ctrl_t * const p_ctrl, uint8_t * const p_buffer);
108+
109+
/**
110+
* Specify callback function and optional context pointer and working memory pointer.
111+
*
112+
* @param[in] p_ctrl Pointer to the CAPTURE control block.
113+
* @param[in] p_callback Callback function
114+
* @param[in] p_context Pointer to send to callback function
115+
* @param[in] p_working_memory Pointer to volatile memory where callback structure can be allocated.
116+
* Callback arguments allocated here are only valid during the callback.
117+
*/
118+
fsp_err_t (* callbackSet)(capture_ctrl_t * const p_ctrl, void (* p_callback)(capture_callback_args_t *),
119+
void const * const p_context, capture_callback_args_t * const p_callback_memory);
120+
121+
/** Check scan status.
122+
*
123+
* @param[in] p_ctrl Pointer to control handle structure
124+
* @param[out] p_status Pointer to store current status in
125+
*/
126+
fsp_err_t (* statusGet)(capture_ctrl_t * const p_ctrl, capture_status_t * p_status);
127+
} capture_api_t;
128+
129+
/** This structure encompasses everything that is needed to use an instance of this interface. */
130+
typedef struct st_capture_instance
131+
{
132+
capture_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
133+
capture_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
134+
capture_api_t const * p_api; ///< Pointer to the API structure for this instance
135+
} capture_instance_t;
136+
137+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
138+
FSP_FOOTER
139+
140+
#endif // R_CAPTURE_H
141+
142+
/*******************************************************************************************************************//**
143+
* @} (end addtogroup CAPTURE_API)
144+
**********************************************************************************************************************/

drivers/ra/fsp/inc/instances/r_ceu.h

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @addtogroup CEU
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_CEU_H
13+
#define R_CEU_H
14+
15+
#include "bsp_api.h"
16+
#include "r_capture_api.h"
17+
#include "r_ceu.h"
18+
19+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
20+
FSP_HEADER
21+
22+
/***********************************************************************************************************************
23+
* Macro definitions
24+
**********************************************************************************************************************/
25+
26+
/***********************************************************************************************************************
27+
* Typedef definitions
28+
**********************************************************************************************************************/
29+
30+
/** Capture mode */
31+
typedef enum e_ceu_capture_mode
32+
{
33+
CEU_CAPTURE_MODE_SINGLE = 0U, ///< Single image capture
34+
CEU_CAPTURE_MODE_CONTINUOUS = 1U, ///< Continuous image capture
35+
} ceu_capture_mode_t;
36+
37+
/** Data bus width */
38+
typedef enum e_ceu_data_bus_size
39+
{
40+
CEU_DATA_BUS_SIZE_8_BIT = 0U, ///< Data bus is 8-bit
41+
CEU_DATA_BUS_SIZE_16_BIT = 1U, ///< Data bus is 16-bit
42+
} ceu_data_bus_size_t;
43+
44+
/** Polarity of input HSYNC signal */
45+
typedef enum e_ceu_hsync_polarity
46+
{
47+
CEU_HSYNC_POLARITY_HIGH = 0U, ///< HSYNC signal is active high
48+
CEU_HSYNC_POLARITY_LOW = 1U, ///< HSYNC signal is active low
49+
} ceu_hsync_polarity_t;
50+
51+
/** Polarity of input VSYNC signal */
52+
typedef enum e_ceu_vsync_polarity
53+
{
54+
CEU_VSYNC_POLARITY_HIGH = 0U, ///< VSYNC signal is active high
55+
CEU_VSYNC_POLARITY_LOW = 1U, ///< VSYNC signal is active low
56+
} ceu_vsync_polarity_t;
57+
58+
typedef enum e_ceu_burst_transfer_mode
59+
{
60+
CEU_BURST_TRANSFER_MODE_X1 = (0u), ///< Transferred to the bus in 32-byte units */
61+
CEU_BURST_TRANSFER_MODE_X2 = (1u), ///< Transferred to the bus in 64-byte units */
62+
CEU_BURST_TRANSFER_MODE_X4 = (2u), ///< Transferred to the bus in 128-byte units */
63+
CEU_BURST_TRANSFER_MODE_X8 = (3u) ///< Transferred to the bus in 256-byte units */
64+
} ceu_burst_transfer_mode_t;
65+
66+
typedef enum e_ceu_event
67+
{
68+
CEU_EVENT_NONE = 0x00000000, // No event, default state
69+
CEU_EVENT_FRAME_END = 0x00000001, ///< Frame end event (CPE)
70+
CEU_EVENT_HD = 0x00000100, ///< (Not Used) HD received (HD)
71+
CEU_EVENT_VD = 0x00000200, ///< VD received (VD)
72+
CEU_EVENT_CRAM_OVERFLOW = 0x00010000, ///< Data overflowed in the CRAM buffer (CDTOF)
73+
CEU_EVENT_HD_MISMATCH = 0x00020000, ///< HD mismatch (IGHS)
74+
CEU_EVENT_VD_MISMATCH = 0x00040000, ///< VD mismatch (IGVS)
75+
CEU_EVENT_VD_ERROR = 0x00100000, ///< Invalid VD condition (VBP)
76+
CEU_EVENT_FIREWALL = 0x00800000, ///< Data write address exceeds firewall (FWF)
77+
CEU_EVENT_HD_MISSING = 0x01000000, ///< HD was expected but not input (NHD)
78+
CEU_EVENT_VD_MISSING = 0x02000000, ///< VD was expected but not input (NVD)
79+
} ceu_event_t;
80+
81+
/** Capture mode for CEU. */
82+
typedef enum e_ceu_capture_format
83+
{
84+
CEU_CAPTURE_FORMAT_DATA_SYNCHRONOUS = 0x1, ///< Raw formatted data.
85+
CEU_CAPTURE_FORMAT_DATA_ENABLE = 0x2 ///< JPG formatted data
86+
} ceu_capture_format_t;
87+
88+
/** Swap bits configuration */
89+
typedef struct st_ceu_byte_swapping_t
90+
{
91+
uint8_t swap_8bit_units : 1; ///< Byte swapping in 8-bit units
92+
uint8_t swap_16bit_units : 1; ///< Byte swapping in 16-bit units
93+
uint8_t swap_32bit_units : 1; ///< Byte swapping in 32-bit units
94+
} ceu_byte_swapping_t;
95+
96+
/** Edge information for latching signals */
97+
typedef struct st_ceu_edge_info_t
98+
{
99+
uint8_t dsel : 1; ///< Sets the edge for fetching the image data (D15 to D0) from an external module.
100+
uint8_t hdsel : 1; ///< Sets the edge for capturing hd from external module.
101+
uint8_t vdsel : 1; ///< Sets the edge for capturing vd from external module.
102+
} ceu_edge_info_t;
103+
104+
/** Extended configuration structure for CEU. */
105+
typedef struct st_ceu_extended_cfg
106+
{
107+
ceu_capture_format_t capture_format; ///< Capture format for incoming data
108+
ceu_data_bus_size_t data_bus_width; ///< Size of camera data bus
109+
ceu_edge_info_t edge_info;
110+
ceu_hsync_polarity_t hsync_polarity; ///< Polarity of HSYNC input
111+
ceu_vsync_polarity_t vsync_polarity; ///< Polarity of VSYNC input
112+
uint32_t image_area_size; ///< Image capture size. Used when setting firewall address for Data Enable Fetch mode.
113+
ceu_byte_swapping_t byte_swapping; ///< Controls byte swapping in 8-bit, 16-bit and 32-bit units
114+
ceu_burst_transfer_mode_t burst_mode; ///< Bus transfer data size
115+
uint32_t interrupts_enabled; ///< Enabled interrupt events bit mask
116+
uint8_t ceu_ipl; ///< PDC interrupt priority
117+
IRQn_Type ceu_irq; ///< PDC IRQ number
118+
} ceu_extended_cfg_t;
119+
120+
/** CEU instance control block. DO NOT INITIALIZE. */
121+
typedef struct st_ceu_instance_ctrl
122+
{
123+
capture_cfg_t const * p_cfg; // Pointer to the configuration structure
124+
uint32_t open; // Indicates whether or not the driver is open called.
125+
uint8_t * p_buffer; // Pointer to buffer currently in use
126+
uint32_t image_area_size; // Size of capture area for image (Used for Data Enable Fetch)
127+
uint32_t interrupts_enabled; // Interrupts enabled bitmask
128+
void (* p_callback)(capture_callback_args_t *); // Pointer to callback that is called when an ceu_event_t occurs.
129+
capture_callback_args_t * p_callback_memory; // Pointer to non-secure memory that can be used to pass arguments to a callback in non-secure memory.
130+
void const * p_context; // Pointer to context to be passed into callback function
131+
} ceu_instance_ctrl_t;
132+
133+
/**********************************************************************************************************************
134+
* Exported global variables
135+
**********************************************************************************************************************/
136+
137+
/** @cond INC_HEADER_DEFS_SEC */
138+
/** Filled in Interface API structure for this Instance. */
139+
extern const capture_api_t g_ceu_on_capture;
140+
141+
/** @endcond */
142+
143+
/***********************************************************************************************************************
144+
* Public APIs
145+
**********************************************************************************************************************/
146+
fsp_err_t R_CEU_Open(capture_ctrl_t * const p_ctrl, capture_cfg_t const * const p_cfg);
147+
148+
fsp_err_t R_CEU_Close(capture_ctrl_t * const p_ctrl);
149+
150+
fsp_err_t R_CEU_CaptureStart(capture_ctrl_t * const p_ctrl, uint8_t * const p_buffer);
151+
152+
fsp_err_t R_CEU_CallbackSet(capture_ctrl_t * const p_ctrl,
153+
void ( * p_callback)(capture_callback_args_t *),
154+
void const * const p_context,
155+
capture_callback_args_t * const p_callback_memory);
156+
157+
fsp_err_t R_CEU_StatusGet(capture_ctrl_t * const p_ctrl, capture_status_t * p_status);
158+
159+
typedef uint32_t my_uint_t;
160+
161+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
162+
FSP_FOOTER
163+
164+
#endif // R_CEU_H
165+
166+
/*******************************************************************************************************************//**
167+
* @} (end defgroup CEU)
168+
**********************************************************************************************************************/

0 commit comments

Comments
 (0)