예제 #1
0
파일: usb_core.c 프로젝트: eisnerd/rockbox
static void set_serial_descriptor(void)
{
    unsigned char serial[16];
    /* Align 32 digits right in the 40-digit serial number */
    short* p = &usb_string_iSerial.wString[1];
    int i;

    ascodec_readbytes(AS3514_UID_0, 0x10, serial);
    for(i = 0; i < 16; i++) {
        *p++ = hex[(serial[i] >> 4) & 0xF];
        *p++ = hex[(serial[i] >> 0) & 0xF];
    }
    usb_string_iSerial.bLength = 68;
}
/* Read 10-bit channel data */
unsigned short adc_read(int channel)
{
    if ((unsigned)channel >= NUM_ADC_CHANNELS)
        return 0;

    /* Select channel */
    ascodec_write(AS3514_ADC_0, (channel << 4));
    unsigned char buf[2];

    /* Read data */
    if (ascodec_readbytes(AS3514_ADC_0, 2, buf) < 0)
        return 0;

    /* decode to 10-bit and return */
    return (((buf[0] & 0x3) << 8) | buf[1]);
}
예제 #3
0
파일: adc-as3514.c 프로젝트: 4nykey/rockbox
/* Read 10-bit channel data */
unsigned short adc_read(int channel)
{
    unsigned short data = 0;

    if ((unsigned)channel >= NUM_ADC_CHANNELS)
        return 0;

    ascodec_lock();

    /* Select channel */
    if (ascodec_write(AS3514_ADC_0, (channel << 4)) >= 0)
    {
        unsigned char buf[2];

        /*
         * The AS3514 ADC will trigger an interrupt when the conversion
         * is finished, if the corresponding enable bit in IRQ_ENRD2
         * is set.
         * Previously the code did not wait and this apparently did
         * not pose any problems, but this should be more correct.
         * Without the wait the data read back may be completely or
         * partially (first one of the two bytes) stale.
         */
        ascodec_wait_adc_finished();


        /* Read data */
        if (ascodec_readbytes(AS3514_ADC_0, 2, buf) >= 0)
        {
            data = (((buf[0] & 0x3) << 8) | buf[1]);
        }
    }

    ascodec_unlock();
    
    return data;
}
예제 #4
0
/*
 * Initialise the PP I2C and I2S.
 */
void audiohw_preinit(void)
{
    /* read all reg values */
    ascodec_readbytes(0x0, AS3514_NUM_AUDIO_REGS, as3514_regs);

#ifdef HAVE_AS3543

    as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_DAC_GAIN_on);
    as3514_write(AS3514_AUDIOSET2, AUDIOSET2_HPH_QUALITY_LOW_POWER);
    /* common ground on, delay playback unmuting when inserting headphones */
    as3514_write(AS3514_AUDIOSET3, AUDIOSET3_HPCM_on | AUDIOSET3_HP_LONGSTART);

    as3514_write(AS3543_DAC_IF, AS3543_DAC_INT_PLL);
    /* Select Line 2 for FM radio */
    as3514_set(AS3514_LINE_IN1_R, LINE_IN_R_LINE_SELECT);
    /* Output SUM of microphone/line/DAC */
    as3514_write(AS3514_HPH_OUT_R, HPH_OUT_R_HEADPHONES | HPH_OUT_R_HP_OUT_SUM);

#else
    /* as3514/as3515 */

#if defined(SANSA_E200V2) || defined(SANSA_FUZE)
    /* Set ADC off, mixer on, DAC on, line out on, line in off, mic off */
    /* Turn on SUM, DAC */
    as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_LOUT_on | 
        AUDIOSET1_SUM_on);
#else
    /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */
    /* Turn on SUM, DAC */
    as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_SUM_on);
#endif /* SANSA_E200V2 || SANSA_FUZE */

    /* Set BIAS on, DITH off, AGC off, IBR_DAC max reduction, LSP_LP on, 
       IBR_LSP max reduction (50%), taken from c200v2 OF
     */
    as3514_write(AS3514_AUDIOSET2, AUDIOSET2_IBR_LSP_50 | AUDIOSET2_LSP_LP |
            AUDIOSET2_IBR_DAC_50 | AUDIOSET2_AGC_off | AUDIOSET2_DITH_off );

    /* Mute and disable speaker */
    as3514_write(AS3514_LSP_OUT_R, LSP_OUT_R_SP_OVC_TO_256MS | 0x00);
    as3514_write(AS3514_LSP_OUT_L, LSP_OUT_L_SP_MUTE | 0x00);

#ifdef PHILIPS_SA9200
    /* LRCK 8-23kHz (there are audible clicks while reading the ADC otherwise) */
    as3514_write(AS3514_PLLMODE, PLLMODE_LRCK_8_23);
#else
    /* LRCK 24-48kHz */
    as3514_write(AS3514_PLLMODE, PLLMODE_LRCK_24_48);
#endif /* PHILIPS_SA9200 */

    /* Set headphone over-current to 0, Min volume */
    as3514_write(AS3514_HPH_OUT_R, HPH_OUT_R_HP_OVC_TO_0MS | 0x00);

/* AMS Sansas based on the AS3525 need HPCM enabled, otherwise they output the
   L-R signal on both L and R headphone outputs instead of normal stereo.
   Turning it off saves a little power on targets that don't need it. */
#if (CONFIG_CPU == AS3525)
    /* Set HPCM on, ZCU off, reduce bias current, settings taken from c200v2 OF
     */
    as3514_write(AS3514_AUDIOSET3, AUDIOSET3_IBR_HPH | AUDIOSET3_ZCU_off);
#else
    /* TODO: check if AS3525 settings save power on e200v1 or as3525v2 */
    /* Set HPCM off, ZCU on */
    as3514_write(AS3514_AUDIOSET3, AUDIOSET3_HPCM_off);
#endif /* CONFIG_CPU == AS3525 */

    /* M2_Sup_off */
    as3514_set(AS3514_MIC2_L, MIC2_L_M2_SUP_off);

#endif /* HAVE_AS3543 */

    /* registers identical on as3514/as3515 and as3543 */

    /* M1_Sup_off */
    as3514_set(AS3514_MIC1_L, MIC1_L_M1_SUP_off);

    /* Headphone ON, MUTE, Min volume */
    as3514_write(AS3514_HPH_OUT_L, HPH_OUT_L_HP_ON | HPH_OUT_L_HP_MUTE | 0x00);

#if defined(SANSA_E200V2) || defined(SANSA_FUZE)
    /* Line Out Stereo, MUTE, Min volume */
    as3514_write(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_SE_ST | 
        LINE_OUT_L_LO_SES_DM_MUTE | 0x00);
#endif /* SANSA_E200V2 || SANSA_FUZE */

    /* DAC_Mute_off */
    as3514_set(AS3514_DAC_L, DAC_L_DAC_MUTE_off);
}