vs1053.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /****************************************************************************
  2. * include/nuttx/audio/vs1053.h
  3. *
  4. * Copyright (C) 2013 Ken Pettit. All rights reserved.
  5. * Author: Ken Pettit <pettitkd@gmail.com>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __INCLUDE_NUTTX_AUDIO_VS1053_H
  36. #define __INCLUDE_NUTTX_AUDIO_VS1053_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <stdint.h>
  41. #include <stdbool.h>
  42. #include <nuttx/irq.h>
  43. /****************************************************************************
  44. * Pre-processor Definitions
  45. ****************************************************************************/
  46. /* VS1053 Configuration Settings:
  47. *
  48. * CONFIG_AUDIO_VS1053 - Enabled VS1053 support
  49. * CONFIG_VS1053_SPIMODE - Controls the SPI mode
  50. */
  51. /****************************************************************************
  52. * Public Types
  53. ****************************************************************************/
  54. /* The VS1053 provides Data Request (DREQ) interrupts to the MCU via a GPIO
  55. * pin and also has a chip reset GPIO. The following structure provides an
  56. * MCU-independent mechanism for controlling the VS1053 GPIOs.
  57. */
  58. struct vs1053_lower_s
  59. {
  60. int (*attach)(FAR const struct vs1053_lower_s *lower, xcpt_t handler,
  61. FAR void *arg);
  62. void (*enable)(FAR const struct vs1053_lower_s *lower);
  63. void (*disable)(FAR const struct vs1053_lower_s *lower);
  64. void (*reset)(FAR const struct vs1053_lower_s *lower, bool state);
  65. int (*read_dreq)(FAR const struct vs1053_lower_s *lower);
  66. int irq;
  67. };
  68. /****************************************************************************
  69. * Public Data
  70. ****************************************************************************/
  71. #ifdef __cplusplus
  72. #define EXTERN extern "C"
  73. extern "C"
  74. {
  75. #else
  76. #define EXTERN extern
  77. #endif
  78. /****************************************************************************
  79. * Public Function Prototypes
  80. ****************************************************************************/
  81. /****************************************************************************
  82. * Name: vs1053_initialize
  83. *
  84. * Description:
  85. * Initialize the VS1053 driver. This will perform a chip reset of the
  86. * device as part of initialization.
  87. *
  88. * Input Parameters:
  89. * spi - A reference to the platform's SPI driver for the VS1053
  90. * lower - The MCU-specific interrupt used to control low-level MCU
  91. * functions (i.e., VS1053 GPIO interrupts).
  92. * devno - If more than one VS1053 is supported, then this is the
  93. * zero based number that identifies the VS1053;
  94. *
  95. * Returned Value:
  96. * OK on success; Negated errno on failure.
  97. *
  98. * Assumptions:
  99. *
  100. ****************************************************************************/
  101. struct spi_dev_s; /* See nuttx/spi/spi.h */
  102. struct audio_lowerhalf_s; /* See nuttx/audio/audio.h */
  103. FAR struct audio_lowerhalf_s *vs1053_initialize(FAR struct spi_dev_s *spi,
  104. FAR const struct vs1053_lower_s *lower,
  105. unsigned int devno);
  106. #undef EXTERN
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif /* __INCLUDE_NUTTX_AUDIO_VS1053_H */