romapi_adc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * @brief ADC ROM API declarations and functions
  3. * These are the public ROM APIs and functions of the ADC ROM
  4. * driver.
  5. *
  6. * @note
  7. * Copyright(C) NXP Semiconductors, 2014
  8. * All rights reserved.
  9. *
  10. * @par
  11. * Software that is described herein is for illustrative purposes only
  12. * which provides customers with programming information regarding the
  13. * LPC products. This software is supplied "AS IS" without any warranties of
  14. * any kind, and NXP Semiconductors and its licensor disclaim any and
  15. * all warranties, express or implied, including all implied warranties of
  16. * merchantability, fitness for a particular purpose and non-infringement of
  17. * intellectual property rights. NXP Semiconductors assumes no responsibility
  18. * or liability for the use of the software, conveys no license or rights under any
  19. * patent, copyright, mask work right, or any other intellectual property rights in
  20. * or to any products. NXP Semiconductors reserves the right to make changes
  21. * in the software without notification. NXP Semiconductors also makes no
  22. * representation or warranty that such application will be suitable for the
  23. * specified use without further testing or modification.
  24. *
  25. * @par
  26. * Permission to use, copy, modify, and distribute this software and its
  27. * documentation is hereby granted, under NXP Semiconductors' and its
  28. * licensor's relevant copyrights in the software, without fee, provided that it
  29. * is used in conjunction with NXP Semiconductors microcontrollers. This
  30. * copyright, permission, and disclaimer notice must appear in all copies of
  31. * this code.
  32. */
  33. #include "romapi_5410x.h"
  34. /* Get memory size in bytes needed for ADC driver context */
  35. uint32_t ROM_ADC_GetMemSize(void)
  36. {
  37. #if defined(ROMDRIVERSV2_PRESENT)
  38. return ROMAPI_ADC_API->GetMemSize();
  39. #else
  40. return adcrom_api.GetMemSize();
  41. #endif
  42. }
  43. /* Initialize the ADC ROM driver */
  44. ADC_HANDLE_T ROM_ADC_Init(void *pMem, uint32_t baseAddr, void *pUserData)
  45. {
  46. #if defined(ROMDRIVERSV2_PRESENT)
  47. return ROMAPI_ADC_API->Init(pMem, baseAddr, pUserData);
  48. #else
  49. return adcrom_api.Init(pMem, baseAddr, pUserData);
  50. #endif
  51. }
  52. /* Configure the ADC peripheral */
  53. ErrorCode_t ROM_ADC_Configure(ADC_HANDLE_T hADC, const ADC_CFG_T *pCfg)
  54. {
  55. #if defined(ROMDRIVERSV2_PRESENT)
  56. return ROMAPI_ADC_API->Configure(hADC, pCfg);
  57. #else
  58. return adcrom_api.Configure(hADC, pCfg);
  59. #endif
  60. }
  61. /* Calibrate the ADC */
  62. ErrorCode_t ROM_ADC_Calibrate(ADC_HANDLE_T hADC, uint32_t sysclk_freq)
  63. {
  64. #if defined(ROMDRIVERSV2_PRESENT)
  65. return ROMAPI_ADC_API->Calibrate(hADC, sysclk_freq);
  66. #else
  67. return adcrom_api.Calibrate(hADC, sysclk_freq);
  68. #endif
  69. }
  70. /* Start the conversion on given SEQ */
  71. ErrorCode_t ROM_ADC_StartConversion(ADC_HANDLE_T hADC, ADC_SEQ_INDEX_T seqIndex, void *pBuf, size_t bufCount)
  72. {
  73. #if defined(ROMDRIVERSV2_PRESENT)
  74. /* Correct index adjust bug */
  75. uint32_t *ptr = &((uint32_t *)hADC)[9 + seqIndex * 6];
  76. if (*ptr != 2) *(ptr - 1) = 0;
  77. return ROMAPI_ADC_API->StartConversion(hADC, seqIndex, pBuf, bufCount);
  78. #else
  79. return adcrom_api.StartConversion(hADC, seqIndex, pBuf, bufCount);
  80. #endif
  81. }
  82. /* ADC Event handler */
  83. ErrorCode_t ROM_ADC_Handler(ADC_HANDLE_T hADC, ADC_HEVENT_T hEvent)
  84. {
  85. #if defined(ROMDRIVERSV2_PRESENT)
  86. return ROMAPI_ADC_API->Handler(hADC, hEvent);
  87. #else
  88. return adcrom_api.Handler(hADC, hEvent);
  89. #endif
  90. }
  91. /* ADC Callback register */
  92. ErrorCode_t ROM_ADC_RegisterCB(ADC_HANDLE_T hADC, ADC_CBINDEX_T cbIndex, void (*pCbFunc)(ADC_HANDLE_T,
  93. ADC_CBINDEX_T,
  94. void *))
  95. {
  96. #if defined(ROMDRIVERSV2_PRESENT)
  97. return ROMAPI_ADC_API->RegisterCB(hADC, cbIndex, pCbFunc);
  98. #else
  99. return adcrom_api.RegisterCB(hADC, cbIndex, pCbFunc);
  100. #endif
  101. }
  102. /* Set Threshold register values */
  103. void ROM_ADC_SetThreshold(ADC_HANDLE_T hADC, uint32_t valThr0, uint32_t valThr1)
  104. {
  105. #if defined(ROMDRIVERSV2_PRESENT)
  106. ROMAPI_ADC_API->SetThreshold(hADC, valThr0, valThr1);
  107. #else
  108. adcrom_api.SetThreshold(hADC, valThr0, valThr1);
  109. #endif
  110. }
  111. /* Configure ADC channel */
  112. ErrorCode_t ROM_ADC_ConfigureCh(ADC_HANDLE_T hADC, uint32_t chanNum, uint32_t chanOpts)
  113. {
  114. #if defined(ROMDRIVERSV2_PRESENT)
  115. return ROMAPI_ADC_API->ConfigureCh(hADC, chanNum, chanOpts);
  116. #else
  117. return adcrom_api.ConfigureCh(hADC, chanNum, chanOpts);
  118. #endif
  119. }
  120. /* Stop conversion of Analog samples */
  121. ErrorCode_t ROM_ADC_StopConversion(ADC_HANDLE_T hADC, ADC_SEQ_INDEX_T seqIndex)
  122. {
  123. #if defined(ROMDRIVERSV2_PRESENT)
  124. return ROMAPI_ADC_API->StopConversion(hADC, seqIndex);
  125. #else
  126. return adcrom_api.StopConversion(hADC, seqIndex);
  127. #endif
  128. }
  129. /* Generate a software trigger */
  130. ErrorCode_t ROM_ADC_SwTrigger(ADC_HANDLE_T hADC, ADC_SEQ_INDEX_T seqIndex)
  131. {
  132. #if defined(ROMDRIVERSV2_PRESENT)
  133. return ROMAPI_ADC_API->SwTrigger(hADC, seqIndex);
  134. #else
  135. return adcrom_api.SwTrigger(hADC, seqIndex);
  136. #endif
  137. }
  138. /* Get Current verion of the driver */
  139. uint16_t ROM_ADC_GetDriverVersion(void)
  140. {
  141. #if defined(ROMDRIVERSV2_PRESENT)
  142. return ROMAPI_ADC_API->GetDriverVersion();
  143. #else
  144. return adcrom_api.GetDriverVersion();
  145. #endif
  146. }