drv_ov2640.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-03-24 spaceman the first version
  9. */
  10. #ifndef __DRV_OV2640_H__
  11. #define __DRV_OV2640_H__
  12. #include <rtthread.h>
  13. #include <lcd_port.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @brief OV2640 ID
  19. */
  20. #define OV2640_ID1 0x2640U
  21. #define OV2640_ID2 0x2642U
  22. #define OV2640_Enable 1
  23. #define OV2640_Disable 0
  24. // 用于设置输出的格式,被 ov2640_set_pixformat() 引用
  25. #define Pixformat_RGB565 0
  26. #define Pixformat_JPEG 1
  27. // OV2640的特效模式,被 ov2640_set_effect() 引用
  28. #define OV2640_Effect_Normal 0 // 正常模式
  29. #define OV2640_Effect_Negative 1 // 负片模式,也就是颜色全部取反
  30. #define OV2640_Effect_BW 2 // 黑白模式
  31. #define OV2640_Effect_BW_Negative 3 // 黑白模式+负片模式
  32. // 1. 定义OV2640实际输出的图像大小,可以根据实际的应用或者显示屏进行调整(同时也要修改配置参数里的时钟分频)
  33. // 2. 这两个参数不会影响帧率,且不能超过对应模式的最大尺寸
  34. // 3. SVGA模式下,输出图像最大分辨率为 800*600, 最大帧率30帧
  35. // 4. UXGA模式下,输出图像最大分辨率为 1600*1200,最大帧率15帧
  36. // 5. 要设置的图像长、宽必须能被4整除!
  37. // 6. 要设置的图像长、宽比必须满足4:3,不然画面会被拉伸畸变
  38. #define OV2640_Width 400 // 图像长度
  39. #define OV2640_Height 300 // 图像宽度
  40. // 1. 定义要显示的画面大小,数值一定要能被4整除!!
  41. // 2. RGB565格式下,最终会由DCMI将OV2640输出的4:3图像裁剪为适应屏幕的比例
  42. // 3. 此处的分辨率不能超过 OV2640_Width 和 OV2640_Height
  43. // 4. 分辨率太高时,需要修改PCLK的时钟速度,详细计算说明可参考 dcmi_ov2640_cfg.h 里的 0xd3 寄存器配置
  44. #define Display_Width LCD_WIDTH
  45. #define Display_Height LCD_HEIGHT
  46. // 1.RGB565模式下,需要 图像分辨率*2 的大小
  47. // 2.JPG模式下,需要的缓冲区大小并不是固定的,例如 640*480分辨率,JPG图像大概要占30K,
  48. // 缓冲区预留2倍左右大小即可,用户可根据实际情况去设置,
  49. #define OV2640_BufferSize Display_Width *Display_Height * 2 / 4 // DMA传输数据大小(32位宽)
  50. // #define OV2640_BufferSize 100*1024/4 // DMA传输数据大小(32位宽)
  51. #define OV2640_SEL_Registers 0xFF // 寄存器组选择寄存器
  52. #define OV2640_SEL_DSP 0x00 // 设置为0x00时,选择 DSP 寄存器组
  53. #define OV2640_SEL_SENSOR 0x01 // 设置为0x01时,选择 SENSOR 寄存器组
  54. // DSP 寄存器组 (0xFF = 0x00)
  55. #define OV2640_DSP_RESET 0xE0 // 可选择复位 控制器、SCCB单元、JPEG单元、DVP接口单元等
  56. #define OV2640_DSP_BPADDR 0x7C // 间接寄存器访问:地址
  57. #define OV2640_DSP_BPDATA 0x7D // 间接寄存器访问:数据
  58. // SENSOR 寄存器组 (0xFF = 0x01)
  59. #define OV2640_SENSOR_COM7 0x12 // 公共控制,系统复位、摄像头分辨率选择、缩放模式、颜色彩条设置
  60. #define OV2640_SENSOR_REG04 0x04 // 寄存器组4,可设置摄像头扫描方向等
  61. #define OV2640_SENSOR_PIDH 0x0a // ID高字节
  62. #define OV2640_SENSOR_PIDL 0x0b // ID低字节
  63. void ov2640_set_pixformat(struct rt_i2c_bus_device *bus, rt_uint8_t pixformat);
  64. rt_err_t ov2640_set_framesize(struct rt_i2c_bus_device *bus, rt_uint16_t width, rt_uint16_t height);
  65. rt_err_t ov2640_set_horizontal_mirror(struct rt_i2c_bus_device *bus, rt_uint8_t configstate);
  66. rt_err_t ov2640_set_vertical_flip(struct rt_i2c_bus_device *bus, rt_uint8_t configstate);
  67. void ov2640_set_saturation(struct rt_i2c_bus_device *bus, rt_int8_t saturation);
  68. void ov2640_set_brightness(struct rt_i2c_bus_device *bus, rt_int8_t brightness);
  69. void ov2640_set_contrast(struct rt_i2c_bus_device *bus, rt_int8_t contrast);
  70. void ov2640_set_effect(struct rt_i2c_bus_device *bus, rt_uint8_t effect_mode);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif