regi2c_ctrl.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
  7. //
  8. // Licensed under the Apache License, Version 2.0 (the "License");
  9. // you may not use this file except in compliance with the License.
  10. // You may obtain a copy of the License at
  11. //
  12. // http://www.apache.org/licenses/LICENSE-2.0
  13. //
  14. // Unless required by applicable law or agreed to in writing, software
  15. // distributed under the License is distributed on an "AS IS" BASIS,
  16. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. // See the License for the specific language governing permissions and
  18. // limitations under the License.
  19. #pragma once
  20. #include <stdint.h>
  21. #include "regi2c_bbpll.h"
  22. #include "regi2c_lp_bias.h"
  23. #include "regi2c_dig_reg.h"
  24. #include "regi2c_bias.h"
  25. #include "regi2c_saradc.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /* Analog function control register */
  30. #define I2C_MST_ANA_CONF0_REG 0x6000E040
  31. #define I2C_MST_BBPLL_STOP_FORCE_HIGH (BIT(2))
  32. #define I2C_MST_BBPLL_STOP_FORCE_LOW (BIT(3))
  33. #define ANA_CONFIG_REG 0x6000E044
  34. #define ANA_CONFIG_S (8)
  35. #define ANA_CONFIG_M (0x3FF)
  36. #define ANA_I2C_SAR_FORCE_PD BIT(18)
  37. #define ANA_I2C_BBPLL_M BIT(17) /* Clear to enable BBPLL */
  38. #define ANA_I2C_APLL_M BIT(14) /* Clear to enable APLL */
  39. #define ANA_CONFIG2_REG 0x6000E048
  40. #define ANA_CONFIG2_M BIT(18)
  41. #define ANA_I2C_SAR_FORCE_PU BIT(16)
  42. /* ROM functions which read/write internal control bus */
  43. uint8_t rom_i2c_readReg(uint8_t block, uint8_t host_id, uint8_t reg_add);
  44. uint8_t rom_i2c_readReg_Mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb);
  45. void rom_i2c_writeReg(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t data);
  46. void rom_i2c_writeReg_Mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb, uint8_t data);
  47. #ifdef BOOTLOADER_BUILD
  48. /**
  49. * If compiling for the bootloader, ROM functions can be called directly,
  50. * without the need of a lock.
  51. */
  52. #define regi2c_ctrl_read_reg rom_i2c_readReg
  53. #define regi2c_ctrl_read_reg_mask rom_i2c_readReg_Mask
  54. #define regi2c_ctrl_write_reg rom_i2c_writeReg
  55. #define regi2c_ctrl_write_reg_mask rom_i2c_writeReg_Mask
  56. #else
  57. #define i2c_read_reg_raw rom_i2c_readReg
  58. #define i2c_read_reg_mask_raw rom_i2c_readReg_Mask
  59. #define i2c_write_reg_raw rom_i2c_writeReg
  60. #define i2c_write_reg_mask_raw rom_i2c_writeReg_Mask
  61. uint8_t regi2c_ctrl_read_reg(uint8_t block, uint8_t host_id, uint8_t reg_add);
  62. uint8_t regi2c_ctrl_read_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb);
  63. void regi2c_ctrl_write_reg(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t data);
  64. 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);
  65. #endif // BOOTLOADER_BUILD
  66. /* Convenience macros for the above functions, these use register definitions
  67. * from regi2c_bbpll.h/regi2c_dig_reg.h/regi2c_lp_bias.h/regi2c_bias.h header files.
  68. */
  69. #define REGI2C_WRITE_MASK(block, reg_add, indata) \
  70. regi2c_ctrl_write_reg_mask(block, block##_HOSTID, reg_add, reg_add##_MSB, reg_add##_LSB, indata)
  71. #define REGI2C_READ_MASK(block, reg_add) \
  72. regi2c_ctrl_read_reg_mask(block, block##_HOSTID, reg_add, reg_add##_MSB, reg_add##_LSB)
  73. #define REGI2C_WRITE(block, reg_add, indata) \
  74. regi2c_ctrl_write_reg(block, block##_HOSTID, reg_add, indata)
  75. #define REGI2C_READ(block, reg_add) \
  76. regi2c_ctrl_read_reg(block, block##_HOSTID, reg_add)
  77. #ifdef __cplusplus
  78. }
  79. #endif