max9850.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * Copyright (c) 2016 - 2018, 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 MAX9850_H__
  41. #define MAX9850_H__
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. #include <stdint.h>
  46. #include "nrf_drv_twi.h"
  47. /**
  48. * @brief Default MAX9850 TWI configuration
  49. *
  50. * @param scl_pin SCL pin number
  51. * @param sda_pin SDA pin number
  52. */
  53. #define MAX9850_DEFAULT_TWI_CONFIG(scl_pin, sda_pin) { \
  54. .scl = scl_pin, \
  55. .sda = sda_pin, \
  56. .frequency = NRF_DRV_TWI_FREQ_100K, \
  57. .interrupt_priority = APP_IRQ_PRIORITY_HIGH, \
  58. .clear_bus_init = false, \
  59. .hold_bus_uninit = false \
  60. }
  61. /**
  62. * @brief Internal MAX9850 register map
  63. * */
  64. typedef struct {
  65. uint8_t status_a; //!< Status register A (R)
  66. uint8_t status_b; //!< Status register B (R)
  67. uint8_t volume; //!< Volume control (RW)
  68. uint8_t general_purpose; //!< General purpose register (RW)
  69. uint8_t interrupt_enable; //!< Interrupt enable (RW)
  70. uint8_t enable; //!< Enable register (RW)
  71. uint8_t clock; //!< Clock control (RW)
  72. uint8_t charge_pump; //!< Charge pump (RW)
  73. uint8_t lrclk_msb; //!< LRCLK MSB register (RW)
  74. uint8_t lrclk_lsb; //!< LRCLK LSB register (RW)
  75. uint8_t digital_audio; //!< Digital audio (RW)
  76. } max9850_regmap_t;
  77. /**
  78. * @brief MAX9850 register map after reset
  79. * */
  80. #define MAX9850_DEFAULT_REGMAP() { \
  81. .status_a = 0, \
  82. .status_b = 0, \
  83. .volume = 0x0C, \
  84. .general_purpose = 0, \
  85. .interrupt_enable = 0, \
  86. .enable = 0, \
  87. .clock = 0, \
  88. .charge_pump = 0, \
  89. .lrclk_msb = 0, \
  90. .lrclk_lsb = 0, \
  91. .digital_audio = 0, \
  92. }
  93. /**
  94. * @brief Helper macro for creating MAX9850 TWI address
  95. * */
  96. #define MAX9850_TWI_ADDR(v) (0x10 + (v))
  97. /**
  98. * @brief MAX9850 configuration
  99. * */
  100. typedef struct {
  101. nrf_drv_twi_t twi; //!< TWI instance
  102. nrf_drv_twi_config_t twi_cfg; //!< TWI configuration
  103. max9850_regmap_t regmap; //!< MAX9850 register map
  104. uint8_t twi_addr; //!< MAX9850 TWI address
  105. } max9850_config_t;
  106. /**
  107. * @brief Initializes MAX9850 IC
  108. *
  109. * @param p_max9850 MAX9850 configuration
  110. *
  111. * @return Standard error code
  112. * */
  113. ret_code_t max9850_init(max9850_config_t const * p_max9850);
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif /* MAX9850_H__ */