summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-05-16 21:03:57 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-05-16 21:03:57 +0000
commita2b049006067e47880fae51ff637d5c8021d1683 (patch)
tree97a322bca0f6f0ee6dfcfaa822cc7443545aa8db
parent97531e8f6c9cffbbc28d71e575a52c34773f691e (diff)
downloadrockbox-a2b049006067e47880fae51ff637d5c8021d1683.tar.gz
rockbox-a2b049006067e47880fae51ff637d5c8021d1683.zip
First version
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@604 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/dac.c68
-rw-r--r--firmware/drivers/dac.h38
2 files changed, 106 insertions, 0 deletions
diff --git a/firmware/drivers/dac.c b/firmware/drivers/dac.c
new file mode 100644
index 0000000000..0ea47dac89
--- /dev/null
+++ b/firmware/drivers/dac.c
@@ -0,0 +1,68 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "i2c.h"
20#include "debug.h"
21#include "dac.h"
22
23int dac_volume(unsigned int volume)
24{
25 int i;
26 unsigned char buf[16];
27
28 if(volume > 0x38)
29 volume = 0x38;
30
31 i=0;
32 buf[i++] = DAC_REG_WRITE | DAC_AVOL;
33 buf[i++] = (volume & 0x3f) | 0x40; /* Deemphasis ON */
34 buf[i++] = volume & 0x3f;
35
36 /* send read command */
37 if (i2c_write(DAC_DEV_WRITE,buf,i))
38 {
39 return -1;
40 }
41 return 0;
42}
43
44/***************************************************
45** Bit6: 0 = 3V, 1 = 5V
46** Bit5: 0 = normal, 1 = low power
47** Bit4: 0 = AUX2 off, 1 = AUX2 on
48** Bit3: 0 = AUX1 off, 1 = AUX2 on
49** Bit2: 0 = DAC off, 1 = DAC on
50** Bit1: 0 = stereo, 1 = mono
51** Bit0: 0 = normal right amp, 1 = inverted right amp
52***************************************************/
53int dac_config(int value)
54{
55 int i;
56 unsigned char buf[16];
57
58 i=0;
59 buf[i++] = DAC_REG_WRITE | DAC_GCFG;
60 buf[i++] = value;
61
62 /* send read command */
63 if (i2c_write(DAC_DEV_WRITE,buf,i))
64 {
65 return -1;
66 }
67 return 0;
68}
diff --git a/firmware/drivers/dac.h b/firmware/drivers/dac.h
new file mode 100644
index 0000000000..c860538a24
--- /dev/null
+++ b/firmware/drivers/dac.h
@@ -0,0 +1,38 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _DAC_H_
20#define _DAC_H_
21
22/*
23 DAC I2C defs
24*/
25#define DAC_ADR 0x9a
26#define DAC_DEV_WRITE (DAC_ADR | 0x00)
27
28#define DAC_REG_WRITE 0xc0
29
30/* registers..*/
31#define DAC_SR_REG 1
32#define DAC_AVOL 2
33#define DAC_GCFG 3
34
35extern int dac_volume(unsigned int volume);
36extern int dac_config(int value);
37
38#endif