i2c_hal_iram.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "hal/i2c_hal.h"
  7. void i2c_hal_master_handle_tx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
  8. {
  9. if (i2c_ll_get_intsts_mask(hal->dev) != 0) {
  10. // If intr status is 0, no need to handle it.
  11. i2c_ll_master_get_event(hal->dev, event);
  12. if ((*event < I2C_INTR_EVENT_END_DET) ||
  13. (*event == I2C_INTR_EVENT_TRANS_DONE)) {
  14. i2c_ll_master_disable_tx_it(hal->dev);
  15. i2c_ll_master_clr_tx_it(hal->dev);
  16. } else if (*event == I2C_INTR_EVENT_END_DET) {
  17. i2c_ll_master_clr_tx_it(hal->dev);
  18. }
  19. }
  20. }
  21. void i2c_hal_master_handle_rx_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
  22. {
  23. if (i2c_ll_get_intsts_mask(hal->dev) != 0) {
  24. i2c_ll_master_get_event(hal->dev, event);
  25. if ((*event < I2C_INTR_EVENT_END_DET) ||
  26. (*event == I2C_INTR_EVENT_TRANS_DONE)) {
  27. i2c_ll_master_disable_rx_it(hal->dev);
  28. i2c_ll_master_clr_rx_it(hal->dev);
  29. } else if (*event == I2C_INTR_EVENT_END_DET) {
  30. i2c_ll_master_clr_rx_it(hal->dev);
  31. }
  32. }
  33. }
  34. #if SOC_I2C_SUPPORT_SLAVE
  35. void i2c_hal_slave_handle_event(i2c_hal_context_t *hal, i2c_intr_event_t *event)
  36. {
  37. i2c_ll_slave_get_event(hal->dev, event);
  38. }
  39. void i2c_hal_disable_slave_tx_it(i2c_hal_context_t *hal)
  40. {
  41. i2c_ll_slave_disable_tx_it(hal->dev);
  42. }
  43. #endif // SOC_I2C_SUPPORT_SLAVE
  44. void i2c_hal_update_config(i2c_hal_context_t *hal)
  45. {
  46. i2c_ll_update(hal->dev);
  47. }
  48. void i2c_hal_get_rxfifo_cnt(i2c_hal_context_t *hal, uint32_t *len)
  49. {
  50. *len = i2c_ll_get_rxfifo_cnt(hal->dev);
  51. }
  52. void i2c_hal_get_txfifo_cnt(i2c_hal_context_t *hal, uint32_t *len)
  53. {
  54. *len = i2c_ll_get_txfifo_len(hal->dev);
  55. }