diff --git a/apps/codecs.c b/apps/codecs.c index 3fa05be59a..88478e8566 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -36,7 +36,6 @@ #include "kernel.h" #include "screens.h" #include "misc.h" -#include "mas.h" #include "codecs.h" #include "lang.h" #include "keyboard.h" diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 2497b17826..bedc98ae10 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -61,7 +61,6 @@ #include "rtc.h" #include "storage.h" #include "fat.h" -#include "mas.h" #include "eeprom_24cxx.h" #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) #include "sdmmc.h" diff --git a/apps/menus/recording_menu.c b/apps/menus/recording_menu.c index 6a1c1d31e8..8eaeab699c 100644 --- a/apps/menus/recording_menu.c +++ b/apps/menus/recording_menu.c @@ -49,7 +49,6 @@ #endif #ifdef HAVE_RECORDING #include "peakmeter.h" -#include "mas.h" #endif #include "splash.h" #if CONFIG_CODEC == SWCODEC diff --git a/apps/mpeg.c b/apps/mpeg.c index 62fda5e3cb..583e4e2122 100644 --- a/apps/mpeg.c +++ b/apps/mpeg.c @@ -45,7 +45,7 @@ #include "settings.h" #ifndef SIMULATOR #include "i2c.h" -#include "mas.h" +#include "mas35xx.h" #include "system.h" #include "usb.h" #include "file.h" @@ -53,7 +53,7 @@ #endif /* !SIMULATOR */ #ifdef HAVE_LCD_BITMAP #include "lcd.h" -#endif +#endif /* CONFIG_CODEC != SWCODEC */ #define MPEG_SWAP_CHUNKSIZE 0x2000 #define MPEG_HIGH_WATER 2 /* We leave 2 bytes empty because otherwise we diff --git a/apps/plugin.h b/apps/plugin.h index 56e0bfcd04..0503980c1e 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -77,7 +77,7 @@ void* plugin_get_buffer(size_t *buffer_size); #include "recording.h" #endif #else -#include "mas.h" +#include "mas35xx.h" #endif /* CONFIG_CODEC == SWCODEC */ #include "settings.h" #include "timer.h" diff --git a/apps/radio/radio.c b/apps/radio/radio.c index 6f1903d79c..5fe1fabef0 100644 --- a/apps/radio/radio.c +++ b/apps/radio/radio.c @@ -23,7 +23,6 @@ #include #include #include -#include "mas.h" #include "settings.h" #include "button.h" #include "status.h" diff --git a/apps/recorder/peakmeter.c b/apps/recorder/peakmeter.c index 2450559b8d..aacfc23cee 100644 --- a/apps/recorder/peakmeter.c +++ b/apps/recorder/peakmeter.c @@ -22,7 +22,6 @@ #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC) #include /* sim uses rand for peakmeter simulation */ #endif -#include "mas.h" #include "thread.h" #include "kernel.h" #include "settings.h" diff --git a/apps/recorder/peakmeter.h b/apps/recorder/peakmeter.h index 308e5fb916..4abcc154f3 100644 --- a/apps/recorder/peakmeter.h +++ b/apps/recorder/peakmeter.h @@ -22,6 +22,7 @@ #define __PEAKMETER_H__ #define PEAK_METER_FPS 20 +#define MAX_PEAK 0x8000 /*#define PM_DEBUG */ #ifdef PM_DEBUG diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index 9adb3c1839..fdeae03f9b 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -42,7 +42,6 @@ #include "pcm_record.h" #include "recording.h" #include "mp3_playback.h" -#include "mas.h" #include "button.h" #include "kernel.h" #include "settings.h" diff --git a/firmware/SOURCES b/firmware/SOURCES index f118f6a396..5b7a582604 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -175,7 +175,7 @@ drivers/led.c drivers/button.c #if (CONFIG_PLATFORM & PLATFORM_NATIVE) #ifdef HAVE_DAC3550A -drivers/dac.c +drivers/audio/dac3550a.c #endif #ifdef HAVE_SERIAL drivers/serial.c @@ -289,9 +289,6 @@ drivers/tuner/rda5802.c #endif /* BOOTLOADER */ /* Sound */ -#if CONFIG_CODEC != SWCODEC -mp3_playback.c -#endif /* CONFIG_CODEC != SWCODEC */ sound.c #if CONFIG_CODEC == SWCODEC @@ -303,15 +300,6 @@ pcm.c enc_base.c #endif /* HAVE_RECORDING */ #endif /* BOOTLOADER */ - -#else /* !SWCODEC */ - -#ifndef BOOTLOADER -#ifndef SIMULATOR -drivers/mas.c -#endif /* SIMULATOR */ -#endif /* BOOTLOADER */ - #endif /* SWCODEC */ /* Audio codec */ @@ -574,6 +562,8 @@ target/sh/archos/player/lcd-player.c target/sh/archos/player/power-player.c target/sh/archos/player/powermgmt-player.c target/sh/archos/player/usb-player.c +target/sh/archos/mascodec-archos.c +target/sh/archos/audio-archos.c #endif /* SIMULATOR */ #endif /* ARCHOS_PLAYER */ @@ -588,6 +578,8 @@ target/sh/archos/recorder/button-recorder.c target/sh/archos/recorder/power-recorder.c target/sh/archos/recorder/powermgmt-recorder.c target/sh/archos/recorder/usb-recorder.c +target/sh/archos/mascodec-archos.c +target/sh/archos/audio-archos.c #endif /* SIMULATOR */ #endif /* ARCHOS_RECORDER */ @@ -602,6 +594,8 @@ target/sh/archos/fm_v2/button-fm_v2.c target/sh/archos/fm_v2/power-fm_v2.c target/sh/archos/fm_v2/powermgmt-fm_v2.c target/sh/archos/fm_v2/usb-fm_v2.c +target/sh/archos/mascodec-archos.c +target/sh/archos/audio-archos.c #endif /* SIMULATOR */ #endif /* ARCHOS_FMRECORDER || ARCHOS_RECORDERV2 */ @@ -614,6 +608,8 @@ target/sh/archos/ondio/button-ondio.c target/sh/archos/ondio/power-ondio.c target/sh/archos/ondio/powermgmt-ondio.c target/sh/archos/ondio/usb-ondio.c +target/sh/archos/mascodec-archos.c +target/sh/archos/audio-archos.c #if (CONFIG_TUNER & TEA5767) target/sh/archos/ondio/fmradio_i2c-ondio.c #endif diff --git a/firmware/drivers/dac.c b/firmware/drivers/audio/dac3550a.c similarity index 89% rename from firmware/drivers/dac.c rename to firmware/drivers/audio/dac3550a.c index f21ef9a802..e13602e481 100644 --- a/firmware/drivers/dac.c +++ b/firmware/drivers/audio/dac3550a.c @@ -5,7 +5,7 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id$ + * $Id: dac.c 17847 2008-06-28 18:10:04Z bagder $ * * Copyright (C) 2002 by Linus Nielsen Feltzing * @@ -22,13 +22,19 @@ #include "stdbool.h" #include "i2c.h" #include "debug.h" -#include "dac.h" - -#ifdef HAVE_DAC3550A +#include "dac3550a.h" static bool line_in_enabled = false; static bool dac_enabled = false; +/* convert tenth of dB volume (-780..+180) to dac3550 register value */ +int tenthdb2reg(int db) +{ + if (db < -540) /* 3 dB steps */ + return (db + 780) / 30; + else /* 1.5 dB steps */ + return (db + 660) / 15; +} int dac_volume(unsigned int left, unsigned int right, bool deemph) { @@ -116,4 +122,3 @@ void dac_init(void) i2c_end(); } -#endif diff --git a/firmware/drivers/audio/mas35xx.c b/firmware/drivers/audio/mas35xx.c index 342d8a3c2e..e6cc665109 100644 --- a/firmware/drivers/audio/mas35xx.c +++ b/firmware/drivers/audio/mas35xx.c @@ -23,8 +23,8 @@ ****************************************************************************/ #include "config.h" +#include "system.h" /* MAX MIN macros */ #include "audiohw.h" -#include "mas.h" const struct sound_settings_info audiohw_settings[] = { #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) @@ -56,10 +56,15 @@ const struct sound_settings_info audiohw_settings[] = { #endif }; - int channel_configuration = SOUND_CHAN_STEREO; int stereo_width = 100; +#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) +unsigned long mdb_shape_shadow = 0; +unsigned long loudness_shadow = 0; +unsigned long shadow_io_control_main; +#endif + static void set_channel_config(void) { @@ -181,13 +186,97 @@ void audiohw_set_treble(int val) } #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -void audiohw_set_volume(int val) { +void audiohw_set_volume(int val) +{ unsigned tmp = ((unsigned)(val + 115) & 0xff) << 8; mas_codec_writereg(MAS_REG_VOLUME_CONTROL, tmp); } -void audiohw_set_balance(int val) { +void audiohw_set_loudness(int value) +{ + loudness_shadow = (loudness_shadow & 0x04) | + (MAX(MIN(value * 4, 0x44), 0) << 8); + mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow); +} + +void audiohw_set_avc(int value) +{ + int tmp; + + static const uint16_t avc_vals[] = + { + (0x1 << 8) | (0x8 << 12), /* 20ms */ + (0x2 << 8) | (0x8 << 12), /* 2s */ + (0x4 << 8) | (0x8 << 12), /* 4s */ + (0x8 << 8) | (0x8 << 12), /* 8s */ + }; + switch (value) { + case 1: + case 2: + case 3: + case 4: + tmp = avc_vals[value -1]; + break; + case -1: /* turn off and then turn on again to decay quickly */ + tmp = mas_codec_readreg(MAS_REG_KAVC); + mas_codec_writereg(MAS_REG_KAVC, 0); + break; + default: /* off */ + tmp = 0; + break; + } + mas_codec_writereg(MAS_REG_KAVC, tmp); +} + +void audiohw_set_mdb_strength(int value) +{ + mas_codec_writereg(MAS_REG_KMDB_STR, (value & 0x7f) << 8); +} + +void audiohw_set_mdb_harmonics(int value) +{ + int tmp = value * 127 / 100; + mas_codec_writereg(MAS_REG_KMDB_HAR, (tmp & 0x7f) << 8); +} + +void audiohw_set_mdb_center(int value) +{ + mas_codec_writereg(MAS_REG_KMDB_FC, (value/10) << 8); +} + +void audiohw_set_mdb_shape(int value) +{ + mdb_shape_shadow = (mdb_shape_shadow & 0x02) | ((value/10) << 8); + mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow); +} + +void audiohw_set_mdb_enable(int value) +{ + mdb_shape_shadow = (mdb_shape_shadow & ~0x02) | (value?2:0); + mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow); +} + +void audiohw_set_superbass(int value) +{ + loudness_shadow = (loudness_shadow & ~0x04) | (value?4:0); + mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow); +} + +void audiohw_set_balance(int val) +{ unsigned tmp = ((unsigned)(val * 127 / 100) & 0xff) << 8; mas_codec_writereg(MAS_REG_BALANCE, tmp); } -#endif + +void audiohw_set_pitch(unsigned long val) +{ + mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1); + + /* We must tell the MAS that the frequency has changed. + * This will unfortunately cause a short silence. */ + + mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1); +} + +#endif /* CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F */ + diff --git a/firmware/drivers/tuner/s1a0903x01.c b/firmware/drivers/tuner/s1a0903x01.c index 3a417d73af..2c93ebdaad 100644 --- a/firmware/drivers/tuner/s1a0903x01.c +++ b/firmware/drivers/tuner/s1a0903x01.c @@ -27,7 +27,7 @@ #include "tuner.h" /* tuner abstraction interface */ #include "fmradio.h" /* physical interface driver */ #include "sound.h" -#include "mas.h" +#include "mas35xx.h" #include "power.h" #define DEFAULT_IN1 0x100003 /* Mute */ diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h index 56f4d3dbea..930c671c20 100644 --- a/firmware/export/audiohw.h +++ b/firmware/export/audiohw.h @@ -59,6 +59,9 @@ #include "as3514.h" #elif defined(HAVE_MAS35XX) #include "mas35xx.h" +#if defined(HAVE_DAC3550A) +#include "dac3550a.h" +#endif /* HAVE_DAC3550A */ #elif defined(HAVE_TSC2100) #include "tsc2100.h" #elif defined(HAVE_JZ4740_CODEC) diff --git a/firmware/drivers/dac.h b/firmware/export/dac3550a.h similarity index 88% rename from firmware/drivers/dac.h rename to firmware/export/dac3550a.h index 121ce74e9d..3744b221ed 100644 --- a/firmware/drivers/dac.h +++ b/firmware/export/dac3550a.h @@ -5,7 +5,7 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id$ + * $Id: dac.h 24158 2010-01-03 11:31:14Z Buschel $ * * Copyright (C) 2002 by Linus Nielsen Feltzing * @@ -18,13 +18,11 @@ * KIND, either express or implied. * ****************************************************************************/ -#ifndef _DAC_H_ -#define _DAC_H_ +#ifndef _DAC3550A_H_ +#define _DAC3550A_H_ #include "config.h" -#ifdef HAVE_DAC3550A - /* DAC I2C defs */ @@ -38,11 +36,12 @@ #define DAC_AVOL 2 #define DAC_GCFG 3 +/* function prototypes */ +extern int tenthdb2reg(int db); extern int dac_volume(unsigned int left, unsigned int right, bool deemph); extern void dac_enable(bool enable); extern void dac_line_in(bool enable); extern void dac_init(void); -#endif +#endif /* _DAC3550A_H_ */ -#endif diff --git a/firmware/export/mas.h b/firmware/export/mas.h deleted file mode 100644 index 9cbe970b94..0000000000 --- a/firmware/export/mas.h +++ /dev/null @@ -1,184 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Linus Nielsen Feltzing - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef _MAS_H_ -#define _MAS_H_ - -#define MAS_BANK_D0 0 -#define MAS_BANK_D1 1 - -#define MAX_PEAK 0x8000 - -/* - MAS I2C defs -*/ -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -#define MAS_ADR 0x3c -#define MAS_DEV_WRITE (MAS_ADR | 0x00) -#define MAS_DEV_READ (MAS_ADR | 0x01) - -#elif CONFIG_CODEC == MAS3507D -#define MAS_ADR 0x3a -#define MAS_DEV_WRITE (MAS_ADR | 0x00) -#define MAS_DEV_READ (MAS_ADR | 0x01) -#endif - -/* registers..*/ -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -#define MAS_DATA_WRITE 0x68 -#define MAS_DATA_READ 0x69 -#define MAS_CODEC_WRITE 0x6c -#define MAS_CODEC_READ 0x6d -#define MAS_CONTROL 0x6a -#define MAS_DCCF 0x76 -#define MAS_DCFR 0x77 - -#elif CONFIG_CODEC == MAS3507D -#define MAS_DATA_WRITE 0x68 -#define MAS_DATA_READ 0x69 -#define MAS_CONTROL 0x6a -#endif - -/* - * MAS register - */ -#define MAS_REG_DCCF 0x8e -#define MAS_REG_MUTE 0xaa -#define MAS_REG_PIODATA 0xc8 -#define MAS_REG_StartUpConfig 0xe6 -#define MAS_REG_KPRESCALE 0xe7 -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -#define MAS_REG_KMDB_SWITCH 0x21 -#define MAS_REG_KMDB_STR 0x22 -#define MAS_REG_KMDB_HAR 0x23 -#define MAS_REG_KMDB_FC 0x24 -#define MAS_REG_KLOUDNESS 0x1e -#define MAS_REG_QPEAK_L 0x0a -#define MAS_REG_QPEAK_R 0x0b -#define MAS_REG_DQPEAK_L 0x0c -#define MAS_REG_DQPEAK_R 0x0d -#define MAS_REG_VOLUME_CONTROL 0x10 -#define MAS_REG_BALANCE 0x11 -#define MAS_REG_KAVC 0x12 -#define MAS_REG_KBASS 0x14 -#define MAS_REG_KTREBLE 0x15 - -#elif CONFIG_CODEC == MAS3507D -#define MAS_REG_KBASS 0x6b -#define MAS_REG_KTREBLE 0x6f -#endif - -/* - * MAS commands - */ -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -#define MAS_CMD_READ_ANCILLARY 0x50 -#define MAS_CMD_FAST_PRG_DL 0x60 -#define MAS_CMD_READ_IC_VER 0x70 -#define MAS_CMD_READ_REG 0xa0 -#define MAS_CMD_WRITE_REG 0xb0 -#define MAS_CMD_READ_D0_MEM 0xc0 -#define MAS_CMD_READ_D1_MEM 0xd0 -#define MAS_CMD_WRITE_D0_MEM 0xe0 -#define MAS_CMD_WRITE_D1_MEM 0xf0 - -#elif CONFIG_CODEC == MAS3507D -#define MAS_CMD_READ_ANCILLARY 0x30 -#define MAS_CMD_WRITE_REG 0x90 -#define MAS_CMD_WRITE_D0_MEM 0xa0 -#define MAS_CMD_WRITE_D1_MEM 0xb0 -#define MAS_CMD_READ_REG 0xd0 -#define MAS_CMD_READ_D0_MEM 0xe0 -#define MAS_CMD_READ_D1_MEM 0xf0 -#endif - -/* - * MAS D0 memory cells (MAS3587F / MAS3539F) - */ -#if CONFIG_CODEC == MAS3587F -#define MAS_D0_APP_SELECT 0x7f6 -#define MAS_D0_APP_RUNNING 0x7f7 -#define MAS_D0_ENCODER_CONTROL 0x7f0 -#define MAS_D0_IO_CONTROL_MAIN 0x7f1 -#define MAS_D0_INTERFACE_CONTROL 0x7f2 -#define MAS_D0_OFREQ_CONTROL 0x7f3 -#define MAS_D0_OUT_CLK_CONFIG 0x7f4 -#define MAS_D0_SPD_OUT_BITS 0x7f8 -#define MAS_D0_SOFT_MUTE 0x7f9 -#define MAS_D0_OUT_LL 0x7fc -#define MAS_D0_OUT_LR 0x7fd -#define MAS_D0_OUT_RL 0x7fe -#define MAS_D0_OUT_RR 0x7ff -#define MAS_D0_MPEG_FRAME_COUNT 0xfd0 -#define MAS_D0_MPEG_STATUS_1 0xfd1 -#define MAS_D0_MPEG_STATUS_2 0xfd2 -#define MAS_D0_CRC_ERROR_COUNT 0xfd3 - -#elif CONFIG_CODEC == MAS3539F -#define MAS_D0_APP_SELECT 0x34b -#define MAS_D0_APP_RUNNING 0x34c -/* no encoder :( */ -#define MAS_D0_IO_CONTROL_MAIN 0x346 -#define MAS_D0_INTERFACE_CONTROL 0x347 -#define MAS_D0_OFREQ_CONTROL 0x348 -#define MAS_D0_OUT_CLK_CONFIG 0x349 -#define MAS_D0_SPD_OUT_BITS 0x351 -#define MAS_D0_SOFT_MUTE 0x350 -#define MAS_D0_OUT_LL 0x354 -#define MAS_D0_OUT_LR 0x355 -#define MAS_D0_OUT_RL 0x356 -#define MAS_D0_OUT_RR 0x357 -#define MAS_D0_MPEG_FRAME_COUNT 0xfd0 -#define MAS_D0_MPEG_STATUS_1 0xfd1 -#define MAS_D0_MPEG_STATUS_2 0xfd2 -#define MAS_D0_CRC_ERROR_COUNT 0xfd3 - -#elif CONFIG_CODEC == MAS3507D -#define MAS_D0_MPEG_FRAME_COUNT 0x300 -#define MAS_D0_MPEG_STATUS_1 0x301 -#define MAS_D0_MPEG_STATUS_2 0x302 -#define MAS_D0_CRC_ERROR_COUNT 0x303 -#define MAS_D0_OUT_LL 0x7f8 -#define MAS_D0_OUT_LR 0x7f9 -#define MAS_D0_OUT_RL 0x7fa -#define MAS_D0_OUT_RR 0x7fb - -#endif - -int mas_default_read(unsigned short *buf); -int mas_run(unsigned short address); -int mas_readmem(int bank, int addr, unsigned long* dest, int len); -int mas_writemem(int bank, int addr, const unsigned long* src, int len); -int mas_readreg(int reg); -int mas_writereg(int reg, unsigned int val); -void mas_reset(void); -int mas_direct_config_read(unsigned char reg); -int mas_direct_config_write(unsigned char reg, unsigned int val); -int mas_codec_writereg(int reg, unsigned int val); -int mas_codec_readreg(int reg); -unsigned long mas_readver(void); - -#endif - -#if CONFIG_TUNER & S1A0903X01 -void mas_store_pllfreq(int freq); -int mas_get_pllfreq(void); -#endif - diff --git a/firmware/export/mas35xx.h b/firmware/export/mas35xx.h index 1c50b7f02b..f75658fce1 100644 --- a/firmware/export/mas35xx.h +++ b/firmware/export/mas35xx.h @@ -25,28 +25,56 @@ #define _MAS35XX_H #include "config.h" +#include "mascodec.h" + +#define MAS_BANK_D0 0 +#define MAS_BANK_D1 1 + +/* registers common to all MAS35xx */ +#define MAS_REG_DCCF 0x8e +#define MAS_REG_MUTE 0xaa +#define MAS_REG_PIODATA 0xc8 +#define MAS_REG_StartUpConfig 0xe6 +#define MAS_REG_KPRESCALE 0xe7 #if CONFIG_CODEC == MAS3507D +/* I2C defines */ +#define MAS_ADR 0x3a +#define MAS_DEV_WRITE (MAS_ADR | 0x00) +#define MAS_DEV_READ (MAS_ADR | 0x01) + +/* MAS3507D registers */ +#define MAS_DATA_WRITE 0x68 +#define MAS_DATA_READ 0x69 +#define MAS_CONTROL 0x6a + +#define MAS_REG_KBASS 0x6b +#define MAS_REG_KTREBLE 0x6f + +/* MAS3507D commands */ +#define MAS_CMD_READ_ANCILLARY 0x30 +#define MAS_CMD_WRITE_REG 0x90 +#define MAS_CMD_WRITE_D0_MEM 0xa0 +#define MAS_CMD_WRITE_D1_MEM 0xb0 +#define MAS_CMD_READ_REG 0xd0 +#define MAS_CMD_READ_D0_MEM 0xe0 +#define MAS_CMD_READ_D1_MEM 0xf0 + +/* MAS3507D D0 memmory cells */ +#define MAS_D0_MPEG_FRAME_COUNT 0x300 +#define MAS_D0_MPEG_STATUS_1 0x301 +#define MAS_D0_MPEG_STATUS_2 0x302 +#define MAS_D0_CRC_ERROR_COUNT 0x303 +#define MAS_D0_OUT_LL 0x7f8 +#define MAS_D0_OUT_LR 0x7f9 +#define MAS_D0_OUT_RL 0x7fa +#define MAS_D0_OUT_RR 0x7fb + #define VOLUME_MIN -780 #define VOLUME_MAX 180 #define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP | PRESCALER_CAP) -#else /* CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F */ - -/* MAS3587F and MAS3539F handle clipping prevention internally so we do not need - * the prescaler -> CLIPPING_CAP - */ - -#define VOLUME_MIN -400 -#define VOLUME_MAX 600 -#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP | BALANCE_CAP | CLIPPING_CAP) - -#endif - - -#if CONFIG_CODEC == MAS3507D - static const unsigned int bass_table[] = { 0x9e400, /* -15dB */ @@ -136,6 +164,112 @@ static const unsigned int prescale_table[] = 0xe6800, /* 14dB */ 0xe9400 /* 15dB */ }; -#endif /*CONFIG_CODEC == MAS3507D*/ + +#else /* CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F */ + +/* I2C defines */ +#define MAS_ADR 0x3c +#define MAS_DEV_WRITE (MAS_ADR | 0x00) +#define MAS_DEV_READ (MAS_ADR | 0x01) + +/* MAS3587F/MAS3539F registers */ +#define MAS_DATA_WRITE 0x68 +#define MAS_DATA_READ 0x69 +#define MAS_CODEC_WRITE 0x6c +#define MAS_CODEC_READ 0x6d +#define MAS_CONTROL 0x6a +#define MAS_DCCF 0x76 +#define MAS_DCFR 0x77 + +#define MAS_REG_KMDB_SWITCH 0x21 +#define MAS_REG_KMDB_STR 0x22 +#define MAS_REG_KMDB_HAR 0x23 +#define MAS_REG_KMDB_FC 0x24 +#define MAS_REG_KLOUDNESS 0x1e +#define MAS_REG_QPEAK_L 0x0a +#define MAS_REG_QPEAK_R 0x0b +#define MAS_REG_DQPEAK_L 0x0c +#define MAS_REG_DQPEAK_R 0x0d +#define MAS_REG_VOLUME_CONTROL 0x10 +#define MAS_REG_BALANCE 0x11 +#define MAS_REG_KAVC 0x12 +#define MAS_REG_KBASS 0x14 +#define MAS_REG_KTREBLE 0x15 + +/* MAS3587F/MAS3539F commands */ +#define MAS_CMD_READ_ANCILLARY 0x50 +#define MAS_CMD_FAST_PRG_DL 0x60 +#define MAS_CMD_READ_IC_VER 0x70 +#define MAS_CMD_READ_REG 0xa0 +#define MAS_CMD_WRITE_REG 0xb0 +#define MAS_CMD_READ_D0_MEM 0xc0 +#define MAS_CMD_READ_D1_MEM 0xd0 +#define MAS_CMD_WRITE_D0_MEM 0xe0 +#define MAS_CMD_WRITE_D1_MEM 0xf0 + +/* MAS3587F D0 memory cells */ +#if CONFIG_CODEC == MAS3587F +#define MAS_D0_APP_SELECT 0x7f6 +#define MAS_D0_APP_RUNNING 0x7f7 +#define MAS_D0_ENCODER_CONTROL 0x7f0 +#define MAS_D0_IO_CONTROL_MAIN 0x7f1 +#define MAS_D0_INTERFACE_CONTROL 0x7f2 +#define MAS_D0_OFREQ_CONTROL 0x7f3 +#define MAS_D0_OUT_CLK_CONFIG 0x7f4 +#define MAS_D0_SPD_OUT_BITS 0x7f8 +#define MAS_D0_SOFT_MUTE 0x7f9 +#define MAS_D0_OUT_LL 0x7fc +#define MAS_D0_OUT_LR 0x7fd +#define MAS_D0_OUT_RL 0x7fe +#define MAS_D0_OUT_RR 0x7ff +#define MAS_D0_MPEG_FRAME_COUNT 0xfd0 +#define MAS_D0_MPEG_STATUS_1 0xfd1 +#define MAS_D0_MPEG_STATUS_2 0xfd2 +#define MAS_D0_CRC_ERROR_COUNT 0xfd3 + +/* MAS3539F D0 memory cells */ +#elif CONFIG_CODEC == MAS3539F +#define MAS_D0_APP_SELECT 0x34b +#define MAS_D0_APP_RUNNING 0x34c +/* no encoder :( */ +#define MAS_D0_IO_CONTROL_MAIN 0x346 +#define MAS_D0_INTERFACE_CONTROL 0x347 +#define MAS_D0_OFREQ_CONTROL 0x348 +#define MAS_D0_OUT_CLK_CONFIG 0x349 +#define MAS_D0_SPD_OUT_BITS 0x351 +#define MAS_D0_SOFT_MUTE 0x350 +#define MAS_D0_OUT_LL 0x354 +#define MAS_D0_OUT_LR 0x355 +#define MAS_D0_OUT_RL 0x356 +#define MAS_D0_OUT_RR 0x357 +#define MAS_D0_MPEG_FRAME_COUNT 0xfd0 +#define MAS_D0_MPEG_STATUS_1 0xfd1 +#define MAS_D0_MPEG_STATUS_2 0xfd2 +#define MAS_D0_CRC_ERROR_COUNT 0xfd3 +#endif + +/* MAS3587F and MAS3539F handle clipping prevention internally so we do not need + * the prescaler -> CLIPPING_CAP + */ + +#define VOLUME_MIN -400 +#define VOLUME_MAX 600 +#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP | BALANCE_CAP | CLIPPING_CAP) + +#endif /* CONFIG_CODEC */ + +/* Function prototypes */ +#if CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F +extern void audiohw_set_loudness(int value); +extern void audiohw_set_avc(int value); +extern void audiohw_set_mdb_strength(int value); +extern void audiohw_set_mdb_harmonics(int value); +extern void audiohw_set_mdb_center(int value); +extern void audiohw_set_mdb_shape(int value); +extern void audiohw_set_mdb_enable(int value); +extern void audiohw_set_superbass(int value); +extern void audiohw_set_balance(int val); +extern void audiohw_set_pitch(unsigned long val); +#endif #endif /* _MAS35XX_H */ diff --git a/firmware/export/mascodec.h b/firmware/export/mascodec.h new file mode 100644 index 0000000000..82a71e30c8 --- /dev/null +++ b/firmware/export/mascodec.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: mas.h 24154 2010-01-03 10:27:43Z Buschel $ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _MASCODEC_H_ +#define _MASCODEC_H_ + +int mas_default_read(unsigned short *buf); +int mas_run(unsigned short address); +int mas_readmem(int bank, int addr, unsigned long* dest, int len); +int mas_writemem(int bank, int addr, const unsigned long* src, int len); +int mas_readreg(int reg); +int mas_writereg(int reg, unsigned int val); +void mas_reset(void); +int mas_direct_config_read(unsigned char reg); +int mas_direct_config_write(unsigned char reg, unsigned int val); +int mas_codec_writereg(int reg, unsigned int val); +int mas_codec_readreg(int reg); +unsigned long mas_readver(void); + +#endif + +#if CONFIG_TUNER & S1A0903X01 +void mas_store_pllfreq(int freq); +int mas_get_pllfreq(void); +#endif + diff --git a/firmware/sound.c b/firmware/sound.c index bede18615a..82d5cdf47d 100644 --- a/firmware/sound.c +++ b/firmware/sound.c @@ -26,16 +26,17 @@ #include "logf.h" #include "system.h" #include "i2c.h" -#include "mas.h" #if (CONFIG_PLATFORM & PLATFORM_NATIVE) #if CONFIG_CPU == PNX0101 #include "pnx0101.h" -#endif -#include "dac.h" +#endif /* CONFIG_CPU == PNX101 */ #if CONFIG_CODEC == SWCODEC #include "pcm.h" +#else /* !CONFIG_CODEC == HWCODEC */ +#include "mas35xx.h" +#include "dac3550a.h" #endif -#endif +#endif /* !SIMULATOR */ /* TODO * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble @@ -162,18 +163,6 @@ void sound_set_dsp_callback(int (*func)(int, intptr_t)) } #endif -#if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR) -/* convert tenth of dB volume (-780..+180) to dac3550 register value */ -static int tenthdb2reg(int db) -{ - if (db < -540) /* 3 dB steps */ - return (db + 780) / 30; - else /* 1.5 dB steps */ - return (db + 660) / 15; -} -#endif - - #if !defined(AUDIOHW_HAVE_CLIPPING) /* * The prescaler compensates for any kind of boosts, to prevent clipping. @@ -282,12 +271,6 @@ static void set_prescaled_volume(void) } #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */ - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -static unsigned long mdb_shape_shadow = 0; -static unsigned long loudness_shadow = 0; -#endif - void sound_set_volume(int value) { if(!audio_is_initialized) @@ -620,86 +603,64 @@ void sound_set_loudness(int value) { if(!audio_is_initialized) return; - loudness_shadow = (loudness_shadow & 0x04) | - (MAX(MIN(value * 4, 0x44), 0) << 8); - mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow); + + audiohw_set_loudness(value); } void sound_set_avc(int value) { if(!audio_is_initialized) return; - int tmp; - static const uint16_t avc_vals[] = - { - (0x1 << 8) | (0x8 << 12), /* 20ms */ - (0x2 << 8) | (0x8 << 12), /* 2s */ - (0x4 << 8) | (0x8 << 12), /* 4s */ - (0x8 << 8) | (0x8 << 12), /* 8s */ - }; - switch (value) { - case 1: - case 2: - case 3: - case 4: - tmp = avc_vals[value -1]; - break; - case -1: /* turn off and then turn on again to decay quickly */ - tmp = mas_codec_readreg(MAS_REG_KAVC); - mas_codec_writereg(MAS_REG_KAVC, 0); - break; - default: /* off */ - tmp = 0; - break; - } - mas_codec_writereg(MAS_REG_KAVC, tmp); + audiohw_set_avc(value); } void sound_set_mdb_strength(int value) { if(!audio_is_initialized) return; - mas_codec_writereg(MAS_REG_KMDB_STR, (value & 0x7f) << 8); + + audiohw_set_mdb_strength(value); } void sound_set_mdb_harmonics(int value) { if(!audio_is_initialized) return; - int tmp = value * 127 / 100; - mas_codec_writereg(MAS_REG_KMDB_HAR, (tmp & 0x7f) << 8); + + audiohw_set_mdb_harmonics(value); } void sound_set_mdb_center(int value) { if(!audio_is_initialized) return; - mas_codec_writereg(MAS_REG_KMDB_FC, (value/10) << 8); + + audiohw_set_mdb_center(value); } void sound_set_mdb_shape(int value) { if(!audio_is_initialized) return; - mdb_shape_shadow = (mdb_shape_shadow & 0x02) | ((value/10) << 8); - mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow); + + audiohw_set_mdb_shape(value); } void sound_set_mdb_enable(int value) { if(!audio_is_initialized) return; - mdb_shape_shadow = (mdb_shape_shadow & ~0x02) | (value?2:0); - mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow); + + audiohw_set_mdb_enable(value); } void sound_set_superbass(int value) { if(!audio_is_initialized) return; - loudness_shadow = (loudness_shadow & ~0x04) | (value?4:0); - mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow); + + audiohw_set_superbass(value); } #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ @@ -847,11 +808,7 @@ void sound_set_pitch(int32_t pitch) /* Calculate the new (bogus) frequency */ val = 18432 * PITCH_SPEED_100 / pitch; - mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1); - - /* We must tell the MAS that the frequency has changed. - * This will unfortunately cause a short silence. */ - mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1); + audiohw_set_pitch(val); last_pitch = pitch; } diff --git a/firmware/mp3_playback.c b/firmware/target/sh/archos/audio-archos.c similarity index 93% rename from firmware/mp3_playback.c rename to firmware/target/sh/archos/audio-archos.c index 8e19829f56..e2d8b6f157 100644 --- a/firmware/mp3_playback.c +++ b/firmware/target/sh/archos/audio-archos.c @@ -28,12 +28,8 @@ #include #include "mp3_playback.h" #include "sound.h" -#ifndef SIMULATOR #include "i2c.h" -#include "mas.h" -#include "dac.h" #include "system.h" -#endif #include "audiohw.h" /* hacking into mpeg.c, recording is still there */ @@ -56,14 +52,12 @@ extern unsigned shadow_codec_reg0; static bool paused; /* playback is paused */ static bool playing; /* We are playing an MP3 stream */ -#ifndef SIMULATOR /* for measuring the play time */ static long playstart_tick; static long cumulative_ticks; /* the registered callback function to ask for more mp3 data */ static void (*callback_for_more)(unsigned char**, size_t*); -#endif /* #ifndef SIMULATOR */ /* list of tracks in memory */ #define MAX_ID3_TAGS (1<<4) /* Must be power of 2 */ @@ -77,8 +71,6 @@ bool audio_is_initialized = false; extern void playback_tick(void); extern void rec_tick(void); -#ifndef SIMULATOR - unsigned long mas_version_code; #if CONFIG_CODEC == MAS3507D @@ -133,7 +125,6 @@ static void postpone_dma_tick(void) } #endif - #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) void demand_irq_enable(bool on) { @@ -328,7 +319,6 @@ static void init_playback(void) DEBUGF("MAS Decoding application started\n"); } #endif /* #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ -#endif /* SIMULATOR */ void mp3_init(int volume, int bass, int treble, int balance, int loudness, int avc, int channel_config, int stereo_width, @@ -336,23 +326,6 @@ void mp3_init(int volume, int bass, int treble, int balance, int loudness, int mdb_center, int mdb_shape, bool mdb_enable, bool superbass) { -#ifdef SIMULATOR - (void)volume; - (void)bass; - (void)treble; - (void)balance; - (void)loudness; - (void)avc; - (void)channel_config; - (void)stereo_width; - (void)mdb_strength; - (void)mdb_harmonics; - (void)mdb_center; - (void)mdb_shape; - (void)mdb_enable; - (void)superbass; - audio_is_initialized = true; -#else #if CONFIG_CODEC == MAS3507D unsigned long val; (void)loudness; @@ -469,7 +442,6 @@ void mp3_init(int volume, int bass, int treble, int balance, int loudness, sound_set(SOUND_MDB_ENABLE, mdb_enable); sound_set(SOUND_SUPERBASS, superbass); #endif -#endif /* !SIMULATOR */ playing = false; paused = true; @@ -477,7 +449,6 @@ void mp3_init(int volume, int bass, int treble, int balance, int loudness, void mp3_shutdown(void) { -#ifndef SIMULATOR #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) unsigned long val = 1; mas_writemem(MAS_BANK_D0, MAS_D0_SOFT_MUTE, &val, 1); /* Mute */ @@ -486,14 +457,10 @@ void mp3_shutdown(void) #if CONFIG_CODEC == MAS3507D dac_volume(0, 0, false); #endif - -#endif } /* new functions, to be exported to plugin API */ -#ifndef SIMULATOR - void mp3_play_init(void) { #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) @@ -594,25 +561,3 @@ unsigned char* mp3_get_pos(void) { return (unsigned char*)SAR3; } -#else /* #ifndef SIMULATOR */ - -void mp3_play_pause(bool play) -{ - (void)play; -} -void mp3_play_stop(void) -{ -} - -unsigned char* mp3_get_pos(void) -{ - return NULL; -} - -void mp3_play_data(const unsigned char* start, int size, - void (*get_more)(unsigned char** start, size_t* size) /* callback fn */ -) -{ - (void)start; (void)size; (void)get_more; -} -#endif diff --git a/firmware/drivers/mas.c b/firmware/target/sh/archos/mascodec-archos.c similarity index 99% rename from firmware/drivers/mas.c rename to firmware/target/sh/archos/mascodec-archos.c index 4f384d3b98..3f932166eb 100644 --- a/firmware/drivers/mas.c +++ b/firmware/target/sh/archos/mascodec-archos.c @@ -5,7 +5,7 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id$ + * $Id: mas.c 18807 2008-10-14 11:12:20Z zagor $ * * Copyright (C) 2002 by Linus Nielsen Feltzing * @@ -23,7 +23,7 @@ #include "sh7034.h" #include "i2c.h" #include "debug.h" -#include "mas.h" +#include "mas35xx.h" #include "kernel.h" #include "system.h" #include "hwcompat.h" diff --git a/firmware/test/i2c/main.c b/firmware/test/i2c/main.c index ad0f8efcbd..7a2ff49fcb 100644 --- a/firmware/test/i2c/main.c +++ b/firmware/test/i2c/main.c @@ -46,9 +46,9 @@ #include "i2c.h" -#include "mas.h" +#include "mas35xx.h" -#include "dac.h" +#include "dac3550a.h" #include "sh7034.h" diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index a9011b9aa5..e0372d2683 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c @@ -40,7 +40,113 @@ void audio_set_buffer_margin(int seconds) { (void)seconds; } -#endif + +/* firmware/target/sh/archos/audio-archos.c */ + +/* list of tracks in memory */ +#define MAX_ID3_TAGS (1<<4) /* Must be power of 2 */ +#define MAX_ID3_TAGS_MASK (MAX_ID3_TAGS - 1) + +static bool paused; /* playback is paused */ +static bool playing; /* We are playing an MP3 stream */ + +bool audio_is_initialized = false; + +void mp3_init(int volume, int bass, int treble, int balance, int loudness, + int avc, int channel_config, int stereo_width, + int mdb_strength, int mdb_harmonics, + int mdb_center, int mdb_shape, bool mdb_enable, + bool superbass) +{ + (void)volume; + (void)bass; + (void)treble; + (void)balance; + (void)loudness; + (void)avc; + (void)channel_config; + (void)stereo_width; + (void)mdb_strength; + (void)mdb_harmonics; + (void)mdb_center; + (void)mdb_shape; + (void)mdb_enable; + (void)superbass; + audio_is_initialized = true; + + playing = false; + paused = true; +} + +void mp3_play_pause(bool play) +{ + (void)play; +} + +void mp3_play_stop(void) +{ +} + +unsigned char* mp3_get_pos(void) +{ + return NULL; +} + +void mp3_play_data(const unsigned char* start, int size, + void (*get_more)(unsigned char** start, size_t* size) /* callback fn */ +) +{ + (void)start; (void)size; (void)get_more; +} + +/* firmware/drivers/audio/mas35xx.c */ +#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) +void audiohw_set_loudness(int value) +{ + (void)value; +} + +void audiohw_set_avc(int value) +{ + (void)value; +} + +void audiohw_set_mdb_strength(int value) +{ + (void)value; +} + +void audiohw_set_mdb_harmonics(int value) +{ + (void)value; +} + +void audiohw_set_mdb_center(int value) +{ + (void)value; +} + +void audiohw_set_mdb_shape(int value) +{ + (void)value; +} + +void audiohw_set_mdb_enable(int value) +{ + (void)value; +} + +void audiohw_set_superbass(int value) +{ + (void)value; +} + +void audiohw_set_pitch(unsigned long value) +{ + (void)value; +} +#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ +#endif /* CODEC != SWCODEC */ int fat_startsector(void) {