move some audio driver specific code to the correspoding files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11675 a1c6a512-1295-4272-9138-f99709370657
diff --git a/firmware/drivers/tlv320.c b/firmware/drivers/tlv320.c
index c9ab094..a88eae5 100644
--- a/firmware/drivers/tlv320.c
+++ b/firmware/drivers/tlv320.c
@@ -33,6 +33,22 @@
#include "i2c-coldfire.h"
#include "tlv320.h"
+/* convert tenth of dB volume (-840..0) to master volume register value */
+int tenthdb2master(int db)
+{
+ /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
+ /* 1111111 == +6dB (0x7f) */
+ /* 1111001 == 0dB (0x79) */
+ /* 0110000 == -73dB (0x30 */
+ /* 0101111 == mute (0x2f) */
+
+ if (db < VOLUME_MIN) {
+ return 0x2f;
+ } else {
+ return((db/10)+73+0x30);
+ }
+}
+
/* local functions and definations */
#define TLV320_ADDR 0x34
diff --git a/firmware/drivers/uda1380.c b/firmware/drivers/uda1380.c
index 841e7fb..0001914 100644
--- a/firmware/drivers/uda1380.c
+++ b/firmware/drivers/uda1380.c
@@ -35,6 +35,32 @@
#include "uda1380.h"
#include "pcf50606.h"
+/* convert tenth of dB volume (-840..0) to master volume register value */
+int tenthdb2master(int db)
+{
+ if (db < -720) /* 1.5 dB steps */
+ return (2940 - db) / 15;
+ else if (db < -660) /* 0.75 dB steps */
+ return (1110 - db) * 2 / 15;
+ else if (db < -520) /* 0.5 dB steps */
+ return (520 - db) / 5;
+ else /* 0.25 dB steps */
+ return -db * 2 / 5;
+}
+
+/* convert tenth of dB volume (-780..0) to mixer volume register value */
+int tenthdb2mixer(int db)
+{
+ if (db < -660) /* 1.5 dB steps */
+ return (2640 - db) / 15;
+ else if (db < -600) /* 0.75 dB steps */
+ return (990 - db) * 2 / 15;
+ else if (db < -460) /* 0.5 dB steps */
+ return (460 - db) / 5;
+ else /* 0.25 dB steps */
+ return -db * 2 / 5;
+}
+
/* ------------------------------------------------- */
/* Local functions and variables */
/* ------------------------------------------------- */
diff --git a/firmware/drivers/wm8731l.c b/firmware/drivers/wm8731l.c
index 4fc33f8..3052133 100644
--- a/firmware/drivers/wm8731l.c
+++ b/firmware/drivers/wm8731l.c
@@ -42,6 +42,34 @@
#define IPOD_PCM_LEVEL 0x65 /* -6dB */
+/* convert tenth of dB volume (-730..60) to master volume register value */
+int tenthdb2master(int db)
+{
+ /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
+ /* 1111111 == +6dB (0x7f) */
+ /* 1111001 == 0dB (0x79) */
+ /* 0110000 == -73dB (0x30 */
+ /* 0101111 == mute (0x2f) */
+
+ if (db < VOLUME_MIN) {
+ return 0x2f;
+ } else {
+ return((db/10)+0x30+73);
+ }
+}
+
+/* convert tenth of dB volume (-780..0) to mixer volume register value */
+int tenthdb2mixer(int db)
+{
+ if (db < -660) /* 1.5 dB steps */
+ return (2640 - db) / 15;
+ else if (db < -600) /* 0.75 dB steps */
+ return (990 - db) * 2 / 15;
+ else if (db < -460) /* 0.5 dB steps */
+ return (460 - db) / 5;
+ else /* 0.25 dB steps */
+ return -db * 2 / 5;
+}
int audiohw_mute(int mute)
{
diff --git a/firmware/drivers/wm8758.c b/firmware/drivers/wm8758.c
index 3a4256b..268df13 100644
--- a/firmware/drivers/wm8758.c
+++ b/firmware/drivers/wm8758.c
@@ -40,6 +40,37 @@
#include "wmcodec.h"
#include "wm8758.h"
+/* convert tenth of dB volume (-57..6) to master volume register value */
+int tenthdb2master(int db)
+{
+ /* +6 to -57dB in 1dB steps == 64 levels = 6 bits */
+ /* 0111111 == +6dB (0x3f) = 63) */
+ /* 0111001 == 0dB (0x39) = 57) */
+ /* 0000001 == -56dB (0x01) = */
+ /* 0000000 == -57dB (0x00) */
+
+ /* 1000000 == Mute (0x40) */
+
+ if (db < VOLUME_MIN) {
+ return 0x40;
+ } else {
+ return((db/10)+57);
+ }
+}
+
+/* convert tenth of dB volume (-780..0) to mixer volume register value */
+int tenthdb2mixer(int db)
+{
+ if (db < -660) /* 1.5 dB steps */
+ return (2640 - db) / 15;
+ else if (db < -600) /* 0.75 dB steps */
+ return (990 - db) * 2 / 15;
+ else if (db < -460) /* 0.5 dB steps */
+ return (460 - db) / 5;
+ else /* 0.25 dB steps */
+ return -db * 2 / 5;
+}
+
void audiohw_reset(void);
#define IPOD_PCM_LEVEL 0x65 /* -6dB */
diff --git a/firmware/drivers/wm8975.c b/firmware/drivers/wm8975.c
index 96a563b..7f2f2c4 100644
--- a/firmware/drivers/wm8975.c
+++ b/firmware/drivers/wm8975.c
@@ -40,6 +40,36 @@
#include "wmcodec.h"
#include "wm8975.h"
+/* convert tenth of dB volume (-730..60) to master volume register value */
+int tenthdb2master(int db)
+{
+ /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
+ /* 1111111 == +6dB (0x7f) */
+ /* 1111001 == 0dB (0x79) */
+ /* 0110000 == -73dB (0x30 */
+ /* 0101111 == mute (0x2f) */
+
+ if (db < VOLUME_MIN) {
+ return 0x0;
+ } else {
+ return((db/10)+73+0x30);
+ }
+}
+
+/* convert tenth of dB volume (-780..0) to mixer volume register value */
+int tenthdb2mixer(int db)
+{
+ if (db < -660) /* 1.5 dB steps */
+ return (2640 - db) / 15;
+ else if (db < -600) /* 0.75 dB steps */
+ return (990 - db) * 2 / 15;
+ else if (db < -460) /* 0.5 dB steps */
+ return (460 - db) / 5;
+ else /* 0.25 dB steps */
+ return -db * 2 / 5;
+}
+
+
void audiohw_reset(void);
#define IPOD_PCM_LEVEL 0x65 /* -6dB */
diff --git a/firmware/export/sound.h b/firmware/export/sound.h
index 33175e4..2cf2ad3 100644
--- a/firmware/export/sound.h
+++ b/firmware/export/sound.h
@@ -19,6 +19,18 @@
#ifndef SOUND_H
#define SOUND_H
+#ifdef HAVE_UDA1380
+#include "uda1380.h"
+#elif defined(HAVE_WM8975) || defined(HAVE_WM8751)
+#include "wm8975.h"
+#elif defined(HAVE_WM8758)
+#include "wm8758.h"
+#elif defined(HAVE_WM8731) || defined(HAVE_WM8721)
+#include "wm8731l.h"
+#elif defined(HAVE_TLV320)
+#include "tlv320.h"
+#endif
+
enum {
SOUND_VOLUME = 0,
SOUND_BASS,
diff --git a/firmware/export/tlv320.h b/firmware/export/tlv320.h
index dbb17e3..3cf5bd8 100644
--- a/firmware/export/tlv320.h
+++ b/firmware/export/tlv320.h
@@ -20,6 +20,11 @@
#ifndef _TLV320_H_
#define _TLV320_H_
+#define VOLUME_MIN -730
+#define VOLUME_MAX 60
+
+extern tenthdb2master(int db);
+
/*** definitions ***/
extern void audiohw_init(void);
diff --git a/firmware/export/uda1380.h b/firmware/export/uda1380.h
index 4b70e79..f8c8d6d 100644
--- a/firmware/export/uda1380.h
+++ b/firmware/export/uda1380.h
@@ -19,6 +19,14 @@
#ifndef _UDA1380_H
#define _UDA1380_H
+
+/* volume/balance/treble/bass interdependency */
+#define VOLUME_MIN -840
+#define VOLUME_MAX 0
+
+extern tenthdb2master(int db);
+extern tenthdb2mixer(int db);
+
extern void audiohw_reset(void);
extern int audiohw_init(void);
extern void audiohw_enable_output(bool enable);
diff --git a/firmware/export/wm8731l.h b/firmware/export/wm8731l.h
index 5783be1..b6fa13f 100644
--- a/firmware/export/wm8731l.h
+++ b/firmware/export/wm8731l.h
@@ -20,6 +20,13 @@
#ifndef _WM8731L_H
#define _WM8731L_H
+/* volume/balance/treble/bass interdependency */
+#define VOLUME_MIN -730
+#define VOLUME_MAX 60
+
+extern int tenthdb2master(int db);
+extern int tenthdb2mixer(int db);
+
extern void audiohw_reset(void);
extern int audiohw_init(void);
extern void audiohw_enable_output(bool enable);
diff --git a/firmware/export/wm8758.h b/firmware/export/wm8758.h
index ca70746..20b26dc 100644
--- a/firmware/export/wm8758.h
+++ b/firmware/export/wm8758.h
@@ -20,6 +20,13 @@
#ifndef _WM8758_H
#define _WM8758_H
+/* volume/balance/treble/bass interdependency */
+#define VOLUME_MIN -570
+#define VOLUME_MAX 60
+
+extern int tenthdb2master(int db);
+extern int tenthdb2mixer(int db);
+
extern void audiohw_reset(void);
extern int audiohw_init(void);
extern void audiohw_enable_output(bool enable);
diff --git a/firmware/export/wm8975.h b/firmware/export/wm8975.h
index 005535b..c00303a 100644
--- a/firmware/export/wm8975.h
+++ b/firmware/export/wm8975.h
@@ -20,6 +20,13 @@
#ifndef _WM8975_H
#define _WM8975_H
+/* volume/balance/treble/bass interdependency */
+#define VOLUME_MIN -730
+#define VOLUME_MAX 60
+
+extern int tenthdb2master(int db);
+extern int tenthdb2mixer(int db);
+
extern void audiohw_reset(void);
extern int audiohw_init(void);
extern void audiohw_enable_output(bool enable);
diff --git a/firmware/sound.c b/firmware/sound.c
index 0c4c153..09fa3da 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -24,17 +24,7 @@
#ifndef SIMULATOR
#include "i2c.h"
#include "mas.h"
-#ifdef HAVE_UDA1380
-#include "uda1380.h"
-#elif defined(HAVE_WM8975) || defined(HAVE_WM8751)
-#include "wm8975.h"
-#elif defined(HAVE_WM8758)
-#include "wm8758.h"
-#elif defined(HAVE_WM8731) || defined(HAVE_WM8721)
-#include "wm8731l.h"
-#elif defined(HAVE_TLV320)
-#include "tlv320.h"
-#elif CONFIG_CPU == PNX0101
+#if CONFIG_CPU == PNX0101
#include "pnx0101.h"
#endif
#include "dac.h"
@@ -269,161 +259,7 @@
}
#endif
-#ifdef HAVE_UDA1380 /* volume/balance/treble/bass interdependency */
-#define VOLUME_MIN -840
-#define VOLUME_MAX 0
-
-/* convert tenth of dB volume (-840..0) to master volume register value */
-static int tenthdb2master(int db)
-{
- if (db < -720) /* 1.5 dB steps */
- return (2940 - db) / 15;
- else if (db < -660) /* 0.75 dB steps */
- return (1110 - db) * 2 / 15;
- else if (db < -520) /* 0.5 dB steps */
- return (520 - db) / 5;
- else /* 0.25 dB steps */
- return -db * 2 / 5;
-}
-
-/* convert tenth of dB volume (-780..0) to mixer volume register value */
-static int tenthdb2mixer(int db)
-{
- if (db < -660) /* 1.5 dB steps */
- return (2640 - db) / 15;
- else if (db < -600) /* 0.75 dB steps */
- return (990 - db) * 2 / 15;
- else if (db < -460) /* 0.5 dB steps */
- return (460 - db) / 5;
- else /* 0.25 dB steps */
- return -db * 2 / 5;
-}
-
-#elif defined(HAVE_TLV320)
-#define VOLUME_MIN -730
-#define VOLUME_MAX 60
-
-/* convert tenth of dB volume (-840..0) to master volume register value */
-static int tenthdb2master(int db)
-{
- /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
- /* 1111111 == +6dB (0x7f) */
- /* 1111001 == 0dB (0x79) */
- /* 0110000 == -73dB (0x30 */
- /* 0101111 == mute (0x2f) */
-
- if (db < VOLUME_MIN) {
- return 0x2f;
- } else {
- return((db/10)+73+0x30);
- }
-}
-
-#elif defined(HAVE_WM8975) || defined(HAVE_WM8751)
-/* volume/balance/treble/bass interdependency */
-#define VOLUME_MIN -730
-#define VOLUME_MAX 60
-
-/* convert tenth of dB volume (-730..60) to master volume register value */
-static int tenthdb2master(int db)
-{
- /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
- /* 1111111 == +6dB (0x7f) */
- /* 1111001 == 0dB (0x79) */
- /* 0110000 == -73dB (0x30 */
- /* 0101111 == mute (0x2f) */
-
- if (db < VOLUME_MIN) {
- return 0x0;
- } else {
- return((db/10)+73+0x30);
- }
-}
-
-/* convert tenth of dB volume (-780..0) to mixer volume register value */
-static int tenthdb2mixer(int db)
-{
- if (db < -660) /* 1.5 dB steps */
- return (2640 - db) / 15;
- else if (db < -600) /* 0.75 dB steps */
- return (990 - db) * 2 / 15;
- else if (db < -460) /* 0.5 dB steps */
- return (460 - db) / 5;
- else /* 0.25 dB steps */
- return -db * 2 / 5;
-}
-
-#elif defined(HAVE_WM8758)
-/* volume/balance/treble/bass interdependency */
-#define VOLUME_MIN -570
-#define VOLUME_MAX 60
-
-/* convert tenth of dB volume (-57..6) to master volume register value */
-static int tenthdb2master(int db)
-{
- /* +6 to -57dB in 1dB steps == 64 levels = 6 bits */
- /* 0111111 == +6dB (0x3f) = 63) */
- /* 0111001 == 0dB (0x39) = 57) */
- /* 0000001 == -56dB (0x01) = */
- /* 0000000 == -57dB (0x00) */
-
- /* 1000000 == Mute (0x40) */
-
- if (db < VOLUME_MIN) {
- return 0x40;
- } else {
- return((db/10)+57);
- }
-}
-
-/* convert tenth of dB volume (-780..0) to mixer volume register value */
-static int tenthdb2mixer(int db)
-{
- if (db < -660) /* 1.5 dB steps */
- return (2640 - db) / 15;
- else if (db < -600) /* 0.75 dB steps */
- return (990 - db) * 2 / 15;
- else if (db < -460) /* 0.5 dB steps */
- return (460 - db) / 5;
- else /* 0.25 dB steps */
- return -db * 2 / 5;
-}
-
-#elif defined(HAVE_WM8731) || defined(HAVE_WM8721)
-/* volume/balance/treble/bass interdependency */
-#define VOLUME_MIN -730
-#define VOLUME_MAX 60
-
-/* convert tenth of dB volume (-730..60) to master volume register value */
-static int tenthdb2master(int db)
-{
- /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
- /* 1111111 == +6dB (0x7f) */
- /* 1111001 == 0dB (0x79) */
- /* 0110000 == -73dB (0x30 */
- /* 0101111 == mute (0x2f) */
-
- if (db < VOLUME_MIN) {
- return 0x2f;
- } else {
- return((db/10)+0x30+73);
- }
-}
-
-/* convert tenth of dB volume (-780..0) to mixer volume register value */
-static int tenthdb2mixer(int db)
-{
- if (db < -660) /* 1.5 dB steps */
- return (2640 - db) / 15;
- else if (db < -600) /* 0.75 dB steps */
- return (990 - db) * 2 / 15;
- else if (db < -460) /* 0.5 dB steps */
- return (460 - db) / 5;
- else /* 0.25 dB steps */
- return -db * 2 / 5;
-}
-
-#elif defined(HAVE_PP5024_CODEC)
+#if defined(HAVE_PP5024_CODEC)
/* TODO: Work out volume/balance/treble/bass interdependency */
#define VOLUME_MIN 0
#define VOLUME_MAX 1