regi2c_ctrl.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include "sdkconfig.h"
  9. #include "esp_rom_regi2c.h"
  10. #include "soc/regi2c_defs.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define regi2c_read_reg_raw esp_rom_regi2c_read
  15. #define regi2c_read_reg_mask_raw esp_rom_regi2c_read_mask
  16. #define regi2c_write_reg_raw esp_rom_regi2c_write
  17. #define regi2c_write_reg_mask_raw esp_rom_regi2c_write_mask
  18. #ifdef BOOTLOADER_BUILD
  19. /**
  20. * If compiling for the bootloader, ROM functions can be called directly,
  21. * without the need of a lock.
  22. */
  23. #define regi2c_ctrl_read_reg regi2c_read_reg_raw
  24. #define regi2c_ctrl_read_reg_mask regi2c_read_reg_mask_raw
  25. #define regi2c_ctrl_write_reg regi2c_write_reg_raw
  26. #define regi2c_ctrl_write_reg_mask regi2c_write_reg_mask_raw
  27. #else
  28. /* Access internal registers, don't use in application */
  29. uint8_t regi2c_ctrl_read_reg(uint8_t block, uint8_t host_id, uint8_t reg_add);
  30. uint8_t regi2c_ctrl_read_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb);
  31. void regi2c_ctrl_write_reg(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t data);
  32. void regi2c_ctrl_write_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb, uint8_t data);
  33. /* enter the critical section that protects internal registers. Don't use it in SDK. Use the functions above. */
  34. void regi2c_enter_critical(void);
  35. void regi2c_exit_critical(void);
  36. #endif // BOOTLOADER_BUILD
  37. /* Convenience macros for the above functions, these use register definitions
  38. * from regi2c_xxx.h header files.
  39. */
  40. #define REGI2C_WRITE_MASK(block, reg_add, indata) \
  41. regi2c_ctrl_write_reg_mask(block, block##_HOSTID, reg_add, reg_add##_MSB, reg_add##_LSB, indata)
  42. #define REGI2C_READ_MASK(block, reg_add) \
  43. regi2c_ctrl_read_reg_mask(block, block##_HOSTID, reg_add, reg_add##_MSB, reg_add##_LSB)
  44. #define REGI2C_WRITE(block, reg_add, indata) \
  45. regi2c_ctrl_write_reg(block, block##_HOSTID, reg_add, indata)
  46. #define REGI2C_READ(block, reg_add) \
  47. regi2c_ctrl_read_reg(block, block##_HOSTID, reg_add)
  48. /**
  49. * Restore regi2c analog calibration related configuration registers.
  50. * This is a workaround, and is fixed on later chips
  51. */
  52. #if REGI2C_ANA_CALI_PD_WORKAROUND
  53. void regi2c_analog_cali_reg_read(void);
  54. void regi2c_analog_cali_reg_write(void);
  55. #endif //#if ADC_CALI_PD_WORKAROUND
  56. /* Enable/Disable regi2c_saradc with calling these two functions.
  57. With reference count protection inside.
  58. Internal use only.
  59. */
  60. void regi2c_saradc_enable(void);
  61. void regi2c_saradc_disable(void);
  62. #ifdef __cplusplus
  63. }
  64. #endif