mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 13:15:18 -05:00
Many more drivers for mini2440. Now the main binary compiles and runs.
Flyspray: FS#10725 Author: Bob Cousins git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23362 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6d20102a9c
commit
90b576f55e
19 changed files with 1215 additions and 92 deletions
|
|
@ -1,140 +0,0 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2006 by Wade Brown
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "cpu.h"
|
||||
#include "system.h"
|
||||
#include "adc.h"
|
||||
#include "adc-target.h"
|
||||
#include "kernel.h"
|
||||
|
||||
static unsigned short adc_readings[NUM_ADC_CHANNELS];
|
||||
|
||||
/* prototypes */
|
||||
static unsigned short __adc_read(int channel);
|
||||
static void adc_tick(void);
|
||||
|
||||
void adc_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Turn on the ADC PCLK */
|
||||
s3c_regset32(&CLKCON, 1<<15);
|
||||
|
||||
/* Set channel 0, normal mode, disable "start by read" */
|
||||
ADCCON &= ~(0x3F);
|
||||
|
||||
/* No start delay. Use normal conversion mode. */
|
||||
ADCDLY = 0x1;
|
||||
|
||||
/* Set and enable the prescaler */
|
||||
ADCCON = (ADCCON & ~(0xff<<6)) | (0x19<<6);
|
||||
ADCCON |= (1<<14);
|
||||
|
||||
/* prefill the adc channels */
|
||||
for (i = 0; i < NUM_ADC_CHANNELS; i++)
|
||||
{
|
||||
adc_readings[i] = __adc_read(i);
|
||||
}
|
||||
|
||||
/* start at zero so when the tick starts it is at zero */
|
||||
adc_readings[0] = __adc_read(0);
|
||||
|
||||
/* attach the adc reading to the tick */
|
||||
tick_add_task(adc_tick);
|
||||
}
|
||||
|
||||
/* Called to get the recent ADC reading */
|
||||
inline unsigned short adc_read(int channel)
|
||||
{
|
||||
return adc_readings[channel];
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the ADC by polling
|
||||
* @param channel The ADC channel to read
|
||||
* @return 10bit reading from ADC channel or ADC_READ_ERROR if timeout
|
||||
*/
|
||||
static unsigned short __adc_read(int channel)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Set the channel */
|
||||
ADCCON = (ADCCON & ~(0x7<<3)) | (channel<<3);
|
||||
|
||||
/* Start the conversion process */
|
||||
ADCCON |= 0x1;
|
||||
|
||||
/* Wait for a low Enable_start */
|
||||
for (i = 20000;;)
|
||||
{
|
||||
if(0 == (ADCCON & 0x1))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
i--;
|
||||
if (0 == i)
|
||||
{
|
||||
/* Ran out of time */
|
||||
return ADC_READ_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for high End_of_Conversion */
|
||||
for(i = 20000;;)
|
||||
{
|
||||
if(ADCCON & (1<<15))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
i--;
|
||||
if(0 == i)
|
||||
{
|
||||
/* Ran out of time */
|
||||
return ADC_READ_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ADCDAT0 & 0x3ff);
|
||||
}
|
||||
|
||||
/* add this to the tick so that the ADC converts are done in the background */
|
||||
static void adc_tick(void)
|
||||
{
|
||||
static unsigned channel;
|
||||
|
||||
/* Check if the End Of Conversion is set */
|
||||
if (ADCCON & (1<<15))
|
||||
{
|
||||
adc_readings[channel] = (ADCDAT0 & 0x3FF);
|
||||
if (++channel >= NUM_ADC_CHANNELS)
|
||||
{
|
||||
channel = 0;
|
||||
}
|
||||
|
||||
/* setup the next conversion and start it*/
|
||||
ADCCON = (ADCCON & ~(0x7<<3)) | (channel<<3) | 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,144 +0,0 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2007 by Michael Sevakis
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "system.h"
|
||||
#include "i2c-meg-fx.h"
|
||||
|
||||
static struct wakeup i2c_wake; /* Transfer completion signal */
|
||||
static struct mutex i2c_mtx; /* Mutual exclusion */
|
||||
static unsigned char *buf_ptr; /* Next byte to transfer */
|
||||
static int buf_count; /* Number of bytes remaining to transfer */
|
||||
|
||||
static void i2c_stop(void)
|
||||
{
|
||||
/* Generate STOP */
|
||||
IICSTAT = I2C_MODE_MASTER | I2C_MODE_TX | I2C_RXTX_ENB;
|
||||
|
||||
/* No more interrupts, clear pending interrupt to continue */
|
||||
IICCON &= ~(I2C_TXRX_INTPND | I2C_TXRX_INTENB);
|
||||
}
|
||||
|
||||
void i2c_write(int addr, const unsigned char *buf, int count)
|
||||
{
|
||||
if (count <= 0)
|
||||
return;
|
||||
|
||||
mutex_lock(&i2c_mtx);
|
||||
|
||||
/* Turn on I2C clock */
|
||||
s3c_regset32(&CLKCON, 1 << 16);
|
||||
|
||||
/* Set mode to master transmitter and enable lines */
|
||||
IICSTAT = I2C_MODE_MASTER | I2C_MODE_TX | I2C_RXTX_ENB;
|
||||
|
||||
/* Set buffer start and count */
|
||||
buf_ptr = (unsigned char *)buf;
|
||||
buf_count = count;
|
||||
|
||||
/* Send slave address and then data */
|
||||
SRCPND = IIC_MASK;
|
||||
INTPND = IIC_MASK;
|
||||
|
||||
IICCON |= I2C_TXRX_INTENB;
|
||||
|
||||
/* Load slave address into shift register */
|
||||
IICDS = addr & 0xfe;
|
||||
|
||||
/* Generate START */
|
||||
IICSTAT = I2C_MODE_MASTER | I2C_MODE_TX | I2C_START | I2C_RXTX_ENB;
|
||||
|
||||
if (wakeup_wait(&i2c_wake, HZ) != OBJ_WAIT_SUCCEEDED)
|
||||
{
|
||||
/* Something went wrong - stop transmission */
|
||||
int oldlevel = disable_irq_save();
|
||||
i2c_stop();
|
||||
restore_irq(oldlevel);
|
||||
}
|
||||
|
||||
/* Go back to slave receive mode and disable lines */
|
||||
IICSTAT = 0;
|
||||
|
||||
/* Turn off I2C clock */
|
||||
s3c_regclr32(&CLKCON, 1 << 16);
|
||||
|
||||
mutex_unlock(&i2c_mtx);
|
||||
}
|
||||
|
||||
void i2c_init(void)
|
||||
{
|
||||
/* Init kernel objects */
|
||||
wakeup_init(&i2c_wake);
|
||||
mutex_init(&i2c_mtx);
|
||||
|
||||
/* Clear pending source */
|
||||
SRCPND = IIC_MASK;
|
||||
INTPND = IIC_MASK;
|
||||
|
||||
/* Enable i2c interrupt in controller */
|
||||
s3c_regclr32(&INTMOD, IIC_MASK);
|
||||
s3c_regclr32(&INTMSK, IIC_MASK);
|
||||
|
||||
/* Turn on I2C clock */
|
||||
s3c_regset32(&CLKCON, 1 << 16);
|
||||
|
||||
/* Set GPE15 (IICSDA) and GPE14 (IICSCL) to IIC */
|
||||
GPECON = (GPECON & ~((3 << 30) | (3 << 28))) |
|
||||
((2 << 30) | (2 << 28));
|
||||
|
||||
/* Bus ACK, IICCLK: fPCLK / 16, Rx/Tx Int: Disable, Tx clock: IICCLK/8 */
|
||||
/* OF PCLK: 49.1568MHz / 16 / 8 = 384.0375 kHz */
|
||||
IICCON = (7 << 0);
|
||||
|
||||
/* SDA line delayed 0 PCLKs */
|
||||
IICLC = (0 << 0);
|
||||
|
||||
/* Turn off I2C clock */
|
||||
s3c_regclr32(&CLKCON, 1 << 16);
|
||||
}
|
||||
|
||||
void IIC(void)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
/* If ack was received from last byte and bytes are remaining */
|
||||
if (--buf_count >= 0 && (IICSTAT & I2C_ACK_L) == 0)
|
||||
{
|
||||
/* Write next byte to shift register */
|
||||
IICDS = *buf_ptr++;
|
||||
|
||||
/* Clear pending interrupt to continue */
|
||||
IICCON &= ~I2C_TXRX_INTPND;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Finished */
|
||||
|
||||
/* Generate STOP */
|
||||
i2c_stop();
|
||||
|
||||
/* Signal thread */
|
||||
wakeup_signal(&i2c_wake);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Ack */
|
||||
SRCPND = IIC_MASK;
|
||||
INTPND = IIC_MASK;
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2007 by Michael Sevakis
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* chip-specific i2c functions */
|
||||
|
||||
/* IICCON */
|
||||
#define I2C_ACKGEN (1 << 7)
|
||||
#define I2C_TXCLK_512 (1 << 6)
|
||||
#define I2C_TXRX_INTENB (1 << 5)
|
||||
#define I2C_TXRX_INTPND (1 << 4)
|
||||
|
||||
/* IICSTAT */
|
||||
#define I2C_MODE_MASTER (2 << 6)
|
||||
#define I2C_MODE_TX (1 << 6)
|
||||
#define I2C_BUSY (1 << 5)
|
||||
#define I2C_START (1 << 5)
|
||||
#define I2C_RXTX_ENB (1 << 4)
|
||||
#define I2C_BUS_ARB_FAILED (1 << 3)
|
||||
#define I2C_S_ADDR_STAT (1 << 2)
|
||||
#define I2C_S_ADDR_MATCH (1 << 1)
|
||||
#define I2C_ACK_L (1 << 0)
|
||||
|
||||
/* IICLC */
|
||||
#define I2C_FLT_ENB (1 << 2)
|
||||
|
||||
void i2c_init(void);
|
||||
void i2c_write(int addr, const unsigned char *data, int count);
|
||||
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
#include "cpu.h"
|
||||
#include "kernel.h"
|
||||
#include "sound.h"
|
||||
#include "i2c-meg-fx.h"
|
||||
#include "i2c-s3c2440.h"
|
||||
#include "system-target.h"
|
||||
#include "timer.h"
|
||||
#include "wmcodec.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue