-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera interface esp32s3 #75331
Camera interface esp32s3 #75331
Changes from all commits
4841df0
4cb56a1
866c2c0
8ebcb45
045ad83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
config CLOCK_CONTROL_ESP32_CAM | ||
bool "master clock for esp32 camera interface" | ||
help | ||
This option enables the pheriphery and cam clock for the lcd_cam module. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spelling |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#define DT_DRV_COMPAT espressif_esp32_cam_clk | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(esp32_lcd_cam, CONFIG_CLOCK_CONTROL_LOG_LEVEL); | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/drivers/pinctrl.h> | ||
#include <zephyr/drivers/clock_control.h> | ||
#include <soc/lcd_cam_struct.h> | ||
#include <soc/lcd_cam_reg.h> | ||
|
||
#define ESP32_CAM_PLL_F160M 160000000UL | ||
uLipe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#define ESP32_CAM_PLL_F160M_SEL 3 | ||
#define ESP32_CAM_CLK_OFF_SEL 0 | ||
|
||
struct clock_control_esp32_cam_config { | ||
const struct pinctrl_dev_config *pcfg; | ||
const struct device *clk_dev; | ||
struct device *clk_subsys; | ||
uint32_t cam_clk; | ||
uint8_t clock_sel; | ||
}; | ||
|
||
static int enable_pheripheral_clock(const struct device *dev) | ||
{ | ||
const struct clock_control_esp32_cam_config *cfg = dev->config; | ||
int ret = 0; | ||
|
||
/* Enable peripheral */ | ||
if (!device_is_ready(cfg->clk_dev)) { | ||
return -ENODEV; | ||
} | ||
|
||
return clock_control_on(cfg->clk_dev, cfg->clk_subsys); | ||
} | ||
|
||
static int set_camera_clock(uint32_t cam_clk) | ||
{ | ||
int ret = 0; | ||
|
||
if (0 == cam_clk) { | ||
LCD_CAM.cam_ctrl.cam_clk_sel = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use HAL API here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left a comment in the hal/cam PR. |
||
ESP32_CAM_CLK_OFF_SEL; | ||
LOG_DBG("Disabled CAM_CLK"); | ||
Check notice on line 44 in drivers/clock_control/clock_control_esp32_cam.c GitHub Actions / Run compliance checks on patch series (PR)You may want to run clang-format on this change
|
||
return -EINVAL; | ||
} | ||
|
||
if (ESP32_CAM_PLL_F160M % cam_clk) { | ||
LOG_WRN("MCLK is not a devider of 160MHz"); | ||
} | ||
|
||
LCD_CAM.cam_ctrl.cam_clk_sel = ESP32_CAM_PLL_F160M_SEL; | ||
LCD_CAM.cam_ctrl.cam_clkm_div_num = ESP32_CAM_PLL_F160M / cam_clk; | ||
LCD_CAM.cam_ctrl.cam_clkm_div_b = 0; | ||
LCD_CAM.cam_ctrl.cam_clkm_div_a = 0; | ||
LOG_DBG("MCLK set to %ld", ESP32_CAM_PLL_F160M / LCD_CAM.cam_ctrl.cam_clkm_div_num); | ||
|
||
return ret; | ||
} | ||
|
||
static int clock_control_esp32_cam_init(const struct device *dev) | ||
{ | ||
const struct clock_control_esp32_cam_config *cfg = dev->config; | ||
int ret = 0; | ||
|
||
ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); | ||
if (ret < 0) { | ||
LOG_ERR("video pinctrl setup failed (%d)", ret); | ||
return ret; | ||
} | ||
|
||
ret = enable_pheripheral_clock(dev); | ||
if (ret < 0) { | ||
LOG_ERR("Failed to enable peripheral clock"); | ||
return ret; | ||
} | ||
|
||
ret = set_camera_clock(cfg->cam_clk); | ||
if (ret < 0) { | ||
LOG_ERR("Failed to set camera clock"); | ||
return ret; | ||
} | ||
|
||
LOG_DBG("cam clock initialized"); | ||
|
||
return 0; | ||
} | ||
|
||
PINCTRL_DT_INST_DEFINE(0); | ||
|
||
static const struct clock_control_esp32_cam_config clock_control_esp32_cam_config = { | ||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), | ||
.clk_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0)), | ||
.clk_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(0, offset), | ||
.cam_clk = DT_INST_PROP_OR(0, cam_clk, 0), | ||
}; | ||
|
||
DEVICE_DT_INST_DEFINE(0, &clock_control_esp32_cam_init, NULL, NULL, &clock_control_esp32_cam_config, | ||
PRE_KERNEL_1, CONFIG_CLOCK_CONTROL_INIT_PRIORITY, NULL); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
config VIDEO_ESP32S3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto: default y / DT_HAS_... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use just |
||
bool "Video interface driver" | ||
default n | ||
depends on DMA | ||
help | ||
This option enables the video interface for the esp32s3. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong, it should default to y and have a "depends on DT_HAS...". See Kconfig files for the other clock control drivers