4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
33 * \brief TAS5706A Power DAC i2c driver.
36 * \author Francesco Sacchi <batt@develer.com>
37 * \author Daniele Basile <asterix@develer.com>
42 #include "hw/hw_tas5706a.h"
44 #include "cfg/cfg_tas5706a.h"
45 #include "cfg/cfg_i2c.h"
47 #include <cfg/module.h>
50 #include <drv/timer.h>
52 typedef uint8_t tas_addr_t;
58 #define VOLUME_REG 0x07
61 #define DB_TO_REG(db) ((24 - (db)) * 2)
63 #define CH1_VOL_REG 0x08
64 #define CH2_VOL_REG 0x09
65 #define CH3_VOL_REG 0x0A
66 #define CH4_VOL_REG 0x0B
69 INLINE bool tas5706a_putc(I2c *i2c, tas_addr_t addr, uint8_t ch)
71 i2c_start_w(i2c, TAS_ADDR, 2, I2C_STOP);
81 INLINE int tas5706a_getc(I2c *i2c, tas_addr_t addr)
85 i2c_start_w(i2c, TAS_ADDR, 2, I2C_NOSTOP);
87 i2c_start_r(i2c, TAS_ADDR, 1, I2C_STOP);
88 ch = (int)(uint8_t)i2c_getc(i2c);
96 void tas5706a_setVolume_3(I2c *i2c, Tas5706aCh ch, tas5706a_vol_t vol)
99 ASSERT(vol <= TAS_VOL_MAX);
101 tas_addr_t addr1, addr2;
118 uint8_t vol_att = 0xff - ((vol * 0xff) / TAS_VOL_MAX);
120 tas5706a_putc(i2c, addr1, vol_att);
121 tas5706a_putc(i2c, addr2, vol_att);
124 void tas5706a_setLowPower_2(I2c *i2c, bool val)
128 TAS5706A_SETPOWERDOWN(val);
129 TAS5706A_SETMUTE(val);
133 void tas5706a_init_1(I2c *i2c)
140 TAS5706A_SETPOWERDOWN(false);
141 TAS5706A_SETMUTE(false);
142 TAS5706A_MCLK_INIT();
144 TAS5706A_SETRESET(false);
146 tas5706a_putc(i2c, TRIM_REG, 0x00);
148 tas5706a_putc(i2c, VOLUME_REG, DB_TO_REG(CONFIG_TAS_MAX_VOL));
151 tas5706a_putc(i2c, SYS_REG2, 0);