auddac.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:4k
源码类别:

DVD

开发平台:

C/C++

  1. //
  2. // FILE
  3. // auddac.c
  4. //
  5. // DESCRIPTION
  6. // generic auddac control
  7. //
  8. #include "user_init.h"
  9. #if defined(PCM1742)
  10. #include "config.h"
  11. #include "regmap.h"
  12. #include "global.h"
  13. #include "func.h"
  14. #include "gpio.h"
  15. #include "audclk.h"
  16. #include "auddrv.h" //2004AUDDRV oliver 20041004 for using audio driver purpose
  17. //#include "audif.h"
  18. #include "gpio.h"
  19. #ifdef PCM1742
  20. #include "pcm1742.h"
  21. #endif
  22. //
  23. // DVD board version related gpio change
  24. //
  25. #define   GPN_MCDL_MC    3
  26. #define   GPN_MCDL_MD    4
  27. #define   GPN_MCDL_ML_1  2
  28. //
  29. /*
  30. #define GPN_MCDL_MC     3
  31. #define GPN_MCDL_MD     4
  32. #define GPN_MCDL_ML_1   2
  33. */
  34. /*
  35. #define GPN_MCDL_MC     3
  36. #define GPN_MCDL_MD     2
  37. #define GPN_MCDL_ML_1   4
  38. */
  39. #define MCDL_MC_SET(d)  GPIO_O_SET(GPN_MCDL_MC,d)
  40. #define MCDL_MD_SET(d)  GPIO_O_SET(GPN_MCDL_MD,d)
  41. #define MCDL_ML1_SET(d) GPIO_O_SET(GPN_MCDL_ML_1,d)
  42. #define MCDL_MC_OUT()   GPIO_E_SET(GPN_MCDL_MC,1)
  43. #define MCDL_MD_OUT()   GPIO_E_SET(GPN_MCDL_MD,1)
  44. #define MCDL_ML1_OUT()  GPIO_E_SET(GPN_MCDL_ML_1,1)
  45. #define delay_mcdl(i)   delay_1us(i)
  46. void    write_mcdl(unsigned data)
  47. {
  48.     int i;
  49.     MCDL_MC_SET(1);
  50.     MCDL_MD_SET(1);
  51.     MCDL_ML1_SET(0);
  52.   
  53.     MCDL_MC_OUT();
  54.     MCDL_MD_OUT();
  55.     MCDL_ML1_OUT();
  56.     for (i=15;i>=0;i--)
  57.     {
  58.         MCDL_MC_SET(0);             delay_mcdl(2);
  59.         MCDL_MD_SET((data>>i)&1);   delay_mcdl(2);
  60.         MCDL_MC_SET(1);             delay_mcdl(2);
  61.     }
  62.     MCDL_ML1_SET(1);
  63.     for (i=1;i>=0;i--)
  64.     {
  65.         MCDL_MC_SET(0);     delay_mcdl(2);
  66.         MCDL_MC_SET(1);     delay_mcdl(2);
  67.     }
  68. }
  69. // 
  70. // FUNTCION
  71. // dac_set_vol()
  72. //
  73. // vol=0: mute
  74. // vol=255: 0-dB attenuation
  75. //
  76. void
  77. dac_set_vol(unsigned vol)
  78. {
  79.     unsigned v;
  80. #if defined(PCM1742)
  81.     v = vol;
  82.     write_mcdl(v | (0x10<<8));        // load and set L volume
  83.     write_mcdl(v | (0x11<<8));        // load and set R volume
  84. #endif
  85. }
  86. //
  87. // FUNCTION
  88. // dac_turn_on()
  89. // DESCRIPTION
  90. // turn on dac
  91. //
  92. void    dac_turn_on()
  93. {
  94. #ifdef PCM1742
  95.     int i;
  96.     for (i=0; i<2; i++) {
  97.         delay_1ms(10);
  98.         //Register-18
  99.         write_mcdl(PCM1742_R18_MUTE_OFF | PCM1742_R18_OVER_SAMPLE_OFF | (0x12<<8));
  100.         delay_1ms(10);
  101.         //Register-19
  102.         write_mcdl(PCM1742_R19_SF_48 | (0x13<<8));
  103.         delay_1ms(10);
  104.         //Register-20
  105.         write_mcdl(
  106.                 PCM1742_R20_FMT_24RJ |
  107.                 //PCM1742_R20_FMT_I2S |
  108.                 (0x14<<8));
  109.     }
  110. #endif
  111.     dac_set_vol(0xff);
  112. }
  113. //Set DAC Sampling frequency
  114. //fs:44.1K/48k
  115. //xck:384fs/256fs
  116. void dac_set_fs(BYTE fs)
  117. {
  118. #ifdef PCM1742
  119.     switch(fs)
  120.     {
  121.         case FS_48K:
  122.             write_mcdl(PCM1742_R18_MUTE_OFF | PCM1742_R18_OVER_SAMPLE_OFF | (0x12<<8));
  123.             write_mcdl(PCM1742_R19_SF_48 | (0x13<<8));
  124.             break;
  125.         case FS_96K:
  126.             write_mcdl(PCM1742_R18_MUTE_OFF | PCM1742_R18_OVER_SAMPLE_ON | (0x12<<8));
  127.             write_mcdl(PCM1742_R19_SF_48 | (0x13<<8));
  128.             break;
  129.         case FS_44K:
  130.         case FS_88K:
  131.             write_mcdl(PCM1742_R18_MUTE_OFF | PCM1742_R18_OVER_SAMPLE_OFF | (0x12<<8));
  132.             write_mcdl(PCM1742_R19_SF_44 | (0x13<<8));
  133.             break;
  134.         case FS_32K:
  135.             write_mcdl(PCM1742_R18_MUTE_OFF | PCM1742_R18_OVER_SAMPLE_OFF | (0x12<<8));
  136.             write_mcdl(PCM1742_R19_SF_32 | (0x13<<8));
  137.             break;
  138.         default:
  139.             write_mcdl(PCM1742_R18_MUTE_OFF | PCM1742_R18_OVER_SAMPLE_OFF | (0x12<<8));
  140.             write_mcdl(PCM1742_R19_SF_44 | (0x13<<8));
  141.             break;
  142.     }
  143. #endif    
  144. }
  145. #endif //#if defined(PCM1742)