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.
37 * \author Francesco Sacchi <batt@develer.com>
41 #include <cfg/module.h>
44 #include <drv/timer.h>
46 #include "hw/hw_tas5706a.h"
47 #include "cfg/cfg_tas5706a.h"
51 typedef uint8_t tas_addr_t;
53 static bool tas5706a_send(tas_addr_t addr, const void *buf, size_t len)
55 bool ret = i2c_start_w(TAS_ADDR) && i2c_put(addr) && i2c_send(buf, len);
60 INLINE bool tas5706a_putc(tas_addr_t addr, uint8_t ch)
62 return tas5706a_send(addr, &ch, sizeof(ch));
65 static bool tas5706a_recv(tas_addr_t addr, void *buf, size_t len)
67 bool ret = i2c_start_w(TAS_ADDR) && i2c_put(addr) && i2c_start_r(TAS_ADDR) && i2c_recv(buf, len);
72 INLINE int tas5706a_getc(tas_addr_t addr)
75 if (tas5706a_recv(addr, &ch, sizeof(ch)))
76 return (int)(uint8_t)ch;
83 #define VOLUME_REG 0x07
86 #define DB_TO_REG(db) ((24 - (db)) * 2)
88 void tas5706a_init(void)
94 TAS5706A_SETPOWERDOWN(false);
95 TAS5706A_SETMUTE(false);
98 TAS5706A_SETRESET(false);
100 tas5706a_putc(TRIM_REG, 0x00);
102 tas5706a_putc(VOLUME_REG, DB_TO_REG(CONFIG_TAS_MAX_VOL));
105 tas5706a_putc(SYS_REG2, 0);
108 #define CH1_VOL_REG 0x08
109 #define CH2_VOL_REG 0x09
110 #define CH3_VOL_REG 0x0A
111 #define CH4_VOL_REG 0x0B
113 void tas5706a_setVolume(Tas5706aCh ch, tas5706a_vol_t vol)
115 ASSERT(ch < TAS_CNT);
116 ASSERT(vol <= TAS_VOL_MAX);
118 tas_addr_t addr1, addr2;
135 uint8_t vol_att = 0xff - ((vol * 0xff) / TAS_VOL_MAX);
137 tas5706a_putc(addr1, vol_att);
138 tas5706a_putc(addr2, vol_att);
141 void tas5706a_setLowPower(bool val)
143 TAS5706A_SETPOWERDOWN(val);
144 TAS5706A_SETMUTE(val);