Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / mcu / libs / codec /

audio_codec.c

   1  /*******************************************************************************
   2     audio_codec.c: FITKit 2.0 codec control functions
   3     Copyright (C) 2009 Brno University of Technology,
   4                        Faculty of Information Technology
   5     Author(s): Karel Slany <slany AT fit.vutbr.cz>
   6  
   7     LICENSE TERMS
   8  
   9     Redistribution and use in source and binary forms, with or without
  10     modification, are permitted provided that the following conditions
  11     are met:
  12     1. Redistributions of source code must retain the above copyright
  13        notice, this list of conditions and the following disclaimer.
  14     2. Redistributions in binary form must reproduce the above copyright
  15        notice, this list of conditions and the following disclaimer in
  16        the documentation and/or other materials provided with the
  17        distribution.
  18     3. All advertising materials mentioning features or use of this software
  19        or firmware must display the following acknowledgement:
  20  
  21          This product includes software developed by the University of
  22          Technology, Faculty of Information Technology, Brno and its
  23          contributors.
  24  
  25     4. Neither the name of the Company nor the names of its contributors
  26        may be used to endorse or promote products derived from this
  27        software without specific prior written permission.
  28  
  29     This software or firmware is provided ``as is'', and any express or implied
  30     warranties, including, but not limited to, the implied warranties of
  31     merchantability and fitness for a particular purpose are disclaimed.
  32     In no event shall the company or contributors be liable for any
  33     direct, indirect, incidental, special, exemplary, or consequential
  34     damages (including, but not limited to, procurement of substitute
  35     goods or services; loss of use, data, or profits; or business
  36     interruption) however caused and on any theory of liability, whether
  37     in contract, strict liability, or tort (including negligence or
  38     otherwise) arising in any way out of the use of this software, even
  39     if advised of the possibility of such damage.
  40  
  41     $Id$
  42  
  43  
  44  *******************************************************************************/
  45  
  46  #include <fitkitlib.h>
  47  #include "audio_codec.h"
  48  
  49  /*******************************************************************************
  50   * function sends codec configuration data via SPI
  51   ******************************************************************************/
  52  void codec_SPI_write(unsigned int addr, unsigned int data)
  53  {
  54    char dataH, dataL;
  55    dataH = (addr << 1) | ((data >> 8) & 1);
  56    dataL = data & 0xFF;
  57  
  58    /*
  59    term_send_str("Sending to Codec: ");
  60    term_send_hex((addr << 9) | data);
  61    term_send_str(" H: ");
  62    term_send_hex(dataH);
  63    term_send_str(" L: ");
  64    term_send_hex(dataL);
  65    term_send_str(" addr: ");
  66    term_send_hex(addr);
  67    term_send_str(" reg: ");
  68    term_send_hex(data);
  69    term_send_crlf();
  70    */
  71  
  72  
  73    /* the ACLK pin acts as negCS */
  74    P5SEL &= ~ACLK;  /* disable ACLK on this pin */
  75    P5OUT &= ~ACLK;  /* set negCS signal to 0 */
  76  
  77    /* send high and low byte of the configuration word */
  78    SPI_TX_BUF = dataH;
  79    while (SPI_BUSY) WDG_reset();
  80    SPI_TX_BUF = dataL;
  81    while (SPI_BUSY) WDG_reset();
  82  
  83    P5OUT |= ACLK;  /* set negCS signal to 1 */
  84    /*
  85    delay_ms(1);
  86    */
  87  }
  88  
Zobrazeno: 154128x Naposledy: 18.11.2017 16:39:34