isp_hal.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <sys/param.h>
  7. #include "sdkconfig.h"
  8. #include "soc/soc_caps.h"
  9. #include "hal/assert.h"
  10. #include "hal/log.h"
  11. #include "hal/isp_hal.h"
  12. #include "hal/isp_ll.h"
  13. /**
  14. * ISP HAL layer
  15. */
  16. void isp_hal_init(isp_hal_context_t *hal, int isp_id)
  17. {
  18. //ISP hardware instance
  19. hal->hw = ISP_LL_GET_HW(isp_id);
  20. isp_ll_init(hal->hw);
  21. }
  22. /*---------------------------------------------------------------
  23. AF
  24. ---------------------------------------------------------------*/
  25. void isp_hal_af_window_config(const isp_hal_context_t *hal, int window_id, const isp_af_window_t *window)
  26. {
  27. isp_ll_af_set_window_range(hal->hw, window_id, window->top_left_x, window->top_left_y, window->bottom_right_x, window->bottom_right_y);
  28. }
  29. void isp_hal_af_get_oneshot_result(const isp_hal_context_t *hal, isp_af_result_t *out_res)
  30. {
  31. isp_ll_clear_intr(hal->hw, ISP_LL_EVENT_AF_FDONE);
  32. isp_ll_af_manual_update(hal->hw);
  33. while (!(isp_ll_get_intr_raw(hal->hw) & ISP_LL_EVENT_AF_FDONE)) {
  34. ;
  35. }
  36. for (int i = 0; i < SOC_ISP_AF_WINDOW_NUMS; i++) {
  37. out_res->definition[i] = isp_ll_af_get_window_sum(hal->hw, i);
  38. out_res->luminance[i] = isp_ll_af_get_window_lum(hal->hw, i);
  39. }
  40. }
  41. /*---------------------------------------------------------------
  42. INTR, put in iram
  43. ---------------------------------------------------------------*/
  44. uint32_t isp_hal_check_clear_intr_event(const isp_hal_context_t *hal, uint32_t mask)
  45. {
  46. uint32_t triggered_events = isp_ll_get_intr_status(hal->hw) & mask;
  47. if (triggered_events) {
  48. isp_ll_clear_intr(hal->hw, triggered_events);
  49. }
  50. return triggered_events;
  51. }