From 02184a242edd2e92f5305a29cadd6bc71448875a Mon Sep 17 00:00:00 2001 From: Dominik Wenger Date: Tue, 9 Dec 2008 17:21:16 +0000 Subject: make fmradio-i2c code from clip more generic, so it works for m200v4 and hopefully all other as3525 targets. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19370 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/as3525/fmradio-i2c-as3525.c | 156 +++++++++++++++++++++ .../arm/as3525/sansa-clip/fmradio-i2c-clip.c | 137 ------------------ 2 files changed, 156 insertions(+), 137 deletions(-) create mode 100644 firmware/target/arm/as3525/fmradio-i2c-as3525.c delete mode 100644 firmware/target/arm/as3525/sansa-clip/fmradio-i2c-clip.c (limited to 'firmware/target') diff --git a/firmware/target/arm/as3525/fmradio-i2c-as3525.c b/firmware/target/arm/as3525/fmradio-i2c-as3525.c new file mode 100644 index 0000000000..18f29dbc57 --- /dev/null +++ b/firmware/target/arm/as3525/fmradio-i2c-as3525.c @@ -0,0 +1,156 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Bertrik Sikken + * + * 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. + * + ****************************************************************************/ + +/* + This is the fmradio_i2c interface, used by the radio driver + to communicate with the radio tuner chip. + + It is implemented using the generic i2c driver, which does "bit-banged" + I2C with a couple of GPIO pins. + */ + +#include "as3525.h" +#include "generic_i2c.h" +#include "fmradio_i2c.h" + +#if defined(SANSA_CLIP) +#define I2C_GPIO(x) GPIOB_PIN(x) +#define I2C_GPIO_DIR GPIOB_DIR +#define I2C_SCL_PIN 4 +#define I2C_SDA_PIN 5 + +#elif defined(SANSA_M200V4) +#define I2C_GPIO(x) GPIOD_PIN(x) +#define I2C_GPIO_DIR GPIOD_DIR +#define I2C_SCL_PIN 7 +#define I2C_SDA_PIN 6 + +#elif +#error no FM I2C GPIOPIN defines +#endif + +static void fm_scl_hi(void) +{ + I2C_GPIO(I2C_SCL_PIN) = 1 << I2C_SCL_PIN; +} + +static void fm_scl_lo(void) +{ + I2C_GPIO(I2C_SCL_PIN) = 0; +} + +static void fm_sda_hi(void) +{ + I2C_GPIO(I2C_SDA_PIN) = 1 << I2C_SDA_PIN; +} + +static void fm_sda_lo(void) +{ + I2C_GPIO(I2C_SDA_PIN) = 0; +} + +static void fm_sda_input(void) +{ + I2C_GPIO_DIR &= ~(1 << I2C_SDA_PIN); +} + +static void fm_sda_output(void) +{ + I2C_GPIO_DIR |= 1 << I2C_SDA_PIN; +} + +static void fm_scl_input(void) +{ + I2C_GPIO_DIR &= ~(1 << I2C_SCL_PIN); +} + +static void fm_scl_output(void) +{ + I2C_GPIO_DIR |= 1 << I2C_SCL_PIN; +} + +static int fm_sda(void) +{ + return I2C_GPIO(I2C_SDA_PIN); +} + +static int fm_scl(void) +{ + return I2C_GPIO(I2C_SCL_PIN); +} + +/* simple and crude delay, used for all delays in the generic i2c driver */ +static void fm_delay(void) +{ + volatile int i; + + /* this loop is uncalibrated and could use more sophistication */ + for (i = 0; i < 100; i++) { + } +} + +/* interface towards the generic i2c driver */ +static struct i2c_interface fm_i2c_interface = { +#if defined(SANSA_CLIP) + .address = 0x10 << 1, +#elif defined(SANSA_M200V4) + .address = 0xC0, +#elif +#error no fm i2c address defined +#endif + + .scl_hi = fm_scl_hi, + .scl_lo = fm_scl_lo, + .sda_hi = fm_sda_hi, + .sda_lo = fm_sda_lo, + .sda_input = fm_sda_input, + .sda_output = fm_sda_output, + .scl_input = fm_scl_input, + .scl_output = fm_scl_output, + .scl = fm_scl, + .sda = fm_sda, + + .delay_hd_sta = fm_delay, + .delay_hd_dat = fm_delay, + .delay_su_dat = fm_delay, + .delay_su_sto = fm_delay, + .delay_su_sta = fm_delay, + .delay_thigh = fm_delay +}; + +/* initialise i2c for fmradio */ +void fmradio_i2c_init(void) +{ + i2c_add_node(&fm_i2c_interface); +} + +int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) +{ + return i2c_write_data(address, -1, buf, count); +} + +int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) +{ + return i2c_read_data(address, -1, buf, count); +} + + + diff --git a/firmware/target/arm/as3525/sansa-clip/fmradio-i2c-clip.c b/firmware/target/arm/as3525/sansa-clip/fmradio-i2c-clip.c deleted file mode 100644 index e3444b8acf..0000000000 --- a/firmware/target/arm/as3525/sansa-clip/fmradio-i2c-clip.c +++ /dev/null @@ -1,137 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Bertrik Sikken - * - * 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. - * - ****************************************************************************/ - -/* - This is the fmradio_i2c interface, used by the radio driver - to communicate with the radio tuner chip. - - It is implemented using the generic i2c driver, which does "bit-banged" - I2C with a couple of GPIO pins. - */ - -#include "as3525.h" -#include "generic_i2c.h" -#include "fmradio_i2c.h" - -#define I2C_SCL_PIN 4 -#define I2C_SDA_PIN 5 - -static void fm_scl_hi(void) -{ - GPIOB_PIN(I2C_SCL_PIN) = 1 << I2C_SCL_PIN; -} - -static void fm_scl_lo(void) -{ - GPIOB_PIN(I2C_SCL_PIN) = 0; -} - -static void fm_sda_hi(void) -{ - GPIOB_PIN(I2C_SDA_PIN) = 1 << I2C_SDA_PIN; -} - -static void fm_sda_lo(void) -{ - GPIOB_PIN(I2C_SDA_PIN) = 0; -} - -static void fm_sda_input(void) -{ - GPIOB_DIR &= ~(1 << I2C_SDA_PIN); -} - -static void fm_sda_output(void) -{ - GPIOB_DIR |= 1 << I2C_SDA_PIN; -} - -static void fm_scl_input(void) -{ - GPIOB_DIR &= ~(1 << I2C_SCL_PIN); -} - -static void fm_scl_output(void) -{ - GPIOB_DIR |= 1 << I2C_SCL_PIN; -} - -static int fm_sda(void) -{ - return GPIOB_PIN(I2C_SDA_PIN); -} - -static int fm_scl(void) -{ - return GPIOB_PIN(I2C_SCL_PIN); -} - -/* simple and crude delay, used for all delays in the generic i2c driver */ -static void fm_delay(void) -{ - volatile int i; - - /* this loop is uncalibrated and could use more sophistication */ - for (i = 0; i < 100; i++) { - } -} - -/* interface towards the generic i2c driver */ -static struct i2c_interface fm_i2c_interface = { - .address = 0x10 << 1, - - .scl_hi = fm_scl_hi, - .scl_lo = fm_scl_lo, - .sda_hi = fm_sda_hi, - .sda_lo = fm_sda_lo, - .sda_input = fm_sda_input, - .sda_output = fm_sda_output, - .scl_input = fm_scl_input, - .scl_output = fm_scl_output, - .scl = fm_scl, - .sda = fm_sda, - - .delay_hd_sta = fm_delay, - .delay_hd_dat = fm_delay, - .delay_su_dat = fm_delay, - .delay_su_sto = fm_delay, - .delay_su_sta = fm_delay, - .delay_thigh = fm_delay -}; - -/* initialise i2c for fmradio */ -void fmradio_i2c_init(void) -{ - i2c_add_node(&fm_i2c_interface); -} - -int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) -{ - return i2c_write_data(address, -1, buf, count); -} - -int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) -{ - return i2c_read_data(address, -1, buf, count); -} - - - -- cgit v1.2.3