uda1380.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Copyright (c) 2016 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef UDA1380_H__
  41. #define UDA1380_H__
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. #include <stdint.h>
  46. #include "nrf_drv_twi.h"
  47. #define UDA1380_REG_CLK 0x00
  48. #define UDA1380_REG_I2S 0x01
  49. #define UDA1380_REG_PWR 0x02
  50. #define UDA1380_REG_AMIX 0x03
  51. #define UDA1380_REG_HPA 0x04
  52. #define UDA1380_REG_VOL 0x10
  53. #define UDA1380_REG_MIX_VOL 0x11
  54. #define UDA1380_REG_PPROC 0x12
  55. #define UDA1380_REG_DEEMP 0x13
  56. #define UDA1380_REG_MIXER 0x14
  57. #define UDA1380_REG_RESET 0x7F
  58. /**
  59. * @brief Default UDA1380 TWI configuration
  60. *
  61. * @param scl_pin SCL pin number
  62. * @param sda_pin SDA pin number
  63. */
  64. #define UDA1380_DEFAULT_TWI_CONFIG(scl_pin, sda_pin) { \
  65. .scl = scl_pin, \
  66. .sda = sda_pin, \
  67. .frequency = NRF_DRV_TWI_FREQ_100K, \
  68. .interrupt_priority = APP_IRQ_PRIORITY_HIGH, \
  69. .clear_bus_init = false, \
  70. .hold_bus_uninit = false \
  71. }
  72. /**
  73. * @brief UDA1380 register descriptor
  74. * */
  75. typedef struct {
  76. uint8_t addr; //!< Internal register address
  77. uint8_t val[2]; //!< Internal register value
  78. } uda1380_reg_t;
  79. #define UDA1380_REG_INIT(address, value) { \
  80. .addr = address, \
  81. .val = {(value) / 256, (value) & 0xFF}, \
  82. }
  83. /**
  84. * @brief UDA1380 TWI bus address*/
  85. #define UDA1380_TWI_ADDRESS (0x18)
  86. /**
  87. * @brief UDA1380 interface
  88. * */
  89. typedef struct {
  90. nrf_drv_twi_t twi; //!< TWI instance
  91. nrf_drv_twi_config_t twi_cfg; //!< TWI configuration
  92. uint8_t twi_addr; //!< UDA1380 TWI address
  93. } uda1380_iface_t;
  94. /**
  95. * @brief Initializes UDA1380 codec IC
  96. *
  97. * @param p_iface Communication interface
  98. * @param p_reg_config Configuration registers
  99. * @param reg_size Number of configuration registers
  100. *
  101. * @return Standard error code
  102. * */
  103. ret_code_t uda1380_init(uda1380_iface_t const * p_iface,
  104. uda1380_reg_t const * p_reg_config,
  105. size_t reg_size);
  106. /**
  107. * @brief Enable UDA1380 codec
  108. *
  109. * @return Standard error code
  110. * */
  111. ret_code_t uda1380_enable(uda1380_iface_t const * p_iface);
  112. /**
  113. * @brief Disable UDA1380 codec
  114. *
  115. * @return Standard error code
  116. * */
  117. ret_code_t uda1380_disable(uda1380_iface_t const * p_iface);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* UDA1380_H__ */