diff options
author | H. Nikolaus Schaller <hns@goldelico.com> | 2011-01-17 11:55:14 +0100 |
---|---|---|
committer | H. Nikolaus Schaller <hns@goldelico.com> | 2011-01-17 11:55:14 +0100 |
commit | df3931f8429a58b199597b084a66fbbee751c0e6 (patch) | |
tree | f93ece2d46fadbbf286b1ad134044239282b99bf /board | |
parent | 30edeb21ebfc731ec1656c7a8727617f5a08438c (diff) | |
download | bootable_bootloader_goldelico_gta04-df3931f8429a58b199597b084a66fbbee751c0e6.zip bootable_bootloader_goldelico_gta04-df3931f8429a58b199597b084a66fbbee751c0e6.tar.gz bootable_bootloader_goldelico_gta04-df3931f8429a58b199597b084a66fbbee751c0e6.tar.bz2 |
fixed some issues with different versions; select I2C1 for halt command
Diffstat (limited to 'board')
-rw-r--r-- | board/goldelico/gta04/TD028TTEC1.c | 16 | ||||
-rw-r--r-- | board/goldelico/gta04/TD028TTEC1.h | 1 | ||||
-rw-r--r-- | board/goldelico/gta04/backlight.c | 13 | ||||
-rw-r--r-- | board/goldelico/gta04/commands.c | 56 | ||||
-rw-r--r-- | board/goldelico/gta04/dssfb.c | 2 | ||||
-rw-r--r-- | board/goldelico/gta04/i2c1-fix.c | 2 | ||||
-rw-r--r-- | board/goldelico/gta04/shutdown.c | 5 | ||||
-rw-r--r-- | board/goldelico/gta04/status.c | 107 | ||||
-rw-r--r-- | board/goldelico/gta04/systest.c | 29 | ||||
-rw-r--r-- | board/goldelico/gta04/tsc2007.c | 59 |
10 files changed, 196 insertions, 94 deletions
diff --git a/board/goldelico/gta04/TD028TTEC1.c b/board/goldelico/gta04/TD028TTEC1.c index 167bebc..066362e 100644 --- a/board/goldelico/gta04/TD028TTEC1.c +++ b/board/goldelico/gta04/TD028TTEC1.c @@ -197,8 +197,10 @@ int jbt_check(void) int failed=0; int cnt0 = 0; int cnt1 = 0; - + +#if 0 printf("jbt_reg_init()\n"); +#endif err = omap_request_gpio(GPIO_CS); SPI_CS(1); // unselect err |= omap_request_gpio(GPIO_SCL); @@ -228,7 +230,7 @@ int jbt_check(void) int bit=i&1; SPI_SDA(bit); // write bit SPI_DELAY(); -#if 1 +#if 0 printf("bit: %d out: %d in: %d (%d)\n", bit, omap_get_gpio_datain(GPIO_DOUT), omap_get_gpio_datain(GPIO_DIN), SPI_READ()); #endif if(SPI_READ() != bit) // did not read back @@ -240,11 +242,13 @@ int jbt_check(void) } if(failed > 0) { - printf("jbt_reg_init() - no correct response, assuming no connection between GPIO_%d and GPIO_%d\n", GPIO_DOUT, GPIO_DIN); + printf("DISPLAY: "); if(cnt0 == 0) - printf(" DIN stuck at 0\n"); - if(cnt1 == 0) - printf(" DIN stuck at 1\n"); + printf("DIN (GPIO%d) stuck at 0\n", GPIO_DIN); + else if(cnt1 == 0) + printf("DIN (GPIO%d) stuck at 1\n", GPIO_DIN); + else + printf("DIN-DOUT (GPIO%d- (GPIO%d)) connetion broken\n", GPIO_DIN, GPIO_DOUT); return 1; } #endif diff --git a/board/goldelico/gta04/TD028TTEC1.h b/board/goldelico/gta04/TD028TTEC1.h index be97640..19bcc07 100644 --- a/board/goldelico/gta04/TD028TTEC1.h +++ b/board/goldelico/gta04/TD028TTEC1.h @@ -17,5 +17,6 @@ int jbt_reg_init(void); int jbt_reg_write_nodata(struct jbt_info *jbt, u_int8_t reg); int jbt_reg_write(struct jbt_info *jbt, u_int8_t reg, u_int8_t data); int jbt_reg_write16(struct jbt_info *jbt, u_int8_t reg, u_int16_t data); +int jbt_check(void); #endif diff --git a/board/goldelico/gta04/backlight.c b/board/goldelico/gta04/backlight.c index 4bd6619..3cb976c 100644 --- a/board/goldelico/gta04/backlight.c +++ b/board/goldelico/gta04/backlight.c @@ -30,9 +30,12 @@ #include <asm/mach-types.h> #include "backlight.h" -#ifdef CONFIG_OMAP3_GTA04 +#if defined(CONFIG_OMAP3_GTA04) #define GPIO_BACKLIGHT 57 /* = GPT11_PWM */ #define GPT_BACKLIGHT OMAP34XX_GPT11 +#elif defined(CONFIG_OMAP3_BEAGLE_EXPANDER) +#define GPIO_BACKLIGHT 146 /* = GPT11_PWM (instead of UART2-TX) */ +#define GPT_BACKLIGHT OMAP34XX_GPT11 #else /* Beagle Hybrid */ #define GPIO_BACKLIGHT 145 /* = GPT10_PWM */ #define GPT_BACKLIGHT OMAP34XX_GPT10 @@ -56,8 +59,10 @@ int backlight_init(void) { #if USE_PWM struct gptimer *gpt_base = (struct gptimer *)GPT_BACKLIGHT; -#ifdef CONFIG_OMAP3_GTA04 +#if defined(CONFIG_OMAP3_GTA04) MUX_VAL(CP(GPMC_NCS6), (IEN | PTD | DIS | M3)) /* GPT_11 - Backlight enable*/\ +#elif defined(CONFIG_OMAP3_BEAGLE_EXPANDER) + MUX_VAL(CP(UART2_TX), (IEN | PTD | DIS | M2)) /* switch to GPT11 */ #else MUX_VAL(CP(UART2_RTS), (IEN | PTD | DIS | M2)) /* switch to GPT10 */ #endif @@ -69,8 +74,10 @@ int backlight_init(void) #error todo #else -#ifdef CONFIG_OMAP3_GTA04 +#if defined(CONFIG_OMAP3_GTA04) MUX_VAL(CP(GPMC_NCS6), (IEN | PTD | DIS | M4)) /*GPIO_57 - Backlight enable*/ +#elif defined(CONFIG_OMAP3_BEAGLE_EXPANDER) + MUX_VAL(CP(UART2_TX), (IEN | PTD | DIS | M4)) /*GPIO_146*/ #else MUX_VAL(CP(UART2_RTS), (IEN | PTD | DIS | M4)) /*GPIO_145*/ #endif diff --git a/board/goldelico/gta04/commands.c b/board/goldelico/gta04/commands.c index d2bfb17..cb85b4c 100644 --- a/board/goldelico/gta04/commands.c +++ b/board/goldelico/gta04/commands.c @@ -108,6 +108,16 @@ static int do_lcd_init(int argc, char *const argv[]) return board_video_init(NULL); } +static int do_lcd_start(int argc, char *const argv[]) +{ + if(board_video_init(NULL)) + return 1; + jbt6k74_enter_state(2); + jbt6k74_display_onoff(1); + backlight_set_level(255); + return 0; +} + static int do_lcd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { int len; @@ -132,6 +142,8 @@ static int do_lcd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) return do_lcd_color (argc, argv); } else if (strncmp ("fb", argv[1], 2) == 0) { return do_lcd_framebuffer (argc, argv); + } else if (strncmp ("st", argv[1], 2) == 0) { + return do_lcd_start (argc, argv); } else { printf ("lcm: unknown operation: %s\n", argv[1]); } @@ -145,6 +157,7 @@ U_BOOT_CMD(lcm, 3, 0, do_lcd, "LCM sub-system", "off - switch off\n" "on - switch on\n" "power mode - set power mode\n" + "start - initialize, switch on power and enable backlight\n" "color hhhhhh - switch color (can be used without init)\n" "fb address - set framebuffer address (can be used without init)\n" ); @@ -168,16 +181,46 @@ static int do_tsc_loop(int argc, char *const argv[]) { printf("permanently reading ADCs of TSC.\n" "Press any key to stop\n\n"); - while (!tstc()) + while (!tstc() && (led_get_buttons()&0x09) == 0) { print_adc(); printf("\r"); } - getc(); + if(tstc()) + getc(); + printf("\n"); + return 0; +} + +static int do_tsc_gloop(int argc, char *const argv[]) +{ + unsigned short *fb=0x81000000; // RGB16 + printf("permanently reading ADCs of TSC to framebuffer.\n" + "Press any key to stop\n\n"); + omap3_dss_set_fb(fb); + while (!tstc() && (led_get_buttons()&0x09) == 0) + { + int i; + for(i=0; i<8; i++) + { + int val=(480*read_adc(i))/4096; + int x, y; + printf("%d: %d\n", i, val); + for(y=16*i; y<16*i+16; y++) + { // draw colored bar depending on current value + for(x=0; x<480; x++) + fb[x+480*y]=(x < val)?0xfc00:0x03ff; + } + } + } + if(tstc()) + getc(); printf("\n"); return 0; } + + static int tsc_choice=0; static int do_tsc_selection(int argc, char *const argv[]) @@ -259,7 +302,8 @@ static int do_tsc_choose(int argc, char *const argv[]) return 0; } } - getc(); + if(tstc()) + getc(); return 0; } @@ -277,6 +321,8 @@ static int do_tsc(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) return do_tsc_get (argc, argv); } else if (strncmp ("lo", argv[1], 2) == 0) { return do_tsc_loop (argc, argv); + } else if (strncmp ("gl", argv[1], 2) == 0) { + return do_tsc_gloop (argc, argv); } else if (strncmp ("ch", argv[1], 2) == 0) { return do_tsc_choose (argc, argv); } else if (strncmp ("se", argv[1], 2) == 0) { @@ -295,6 +341,7 @@ U_BOOT_CMD(tsc, 4, 0, do_tsc, "TSC2007 sub-system", "in[it] - initialize TSC2007\n" "ge[t] - read ADCs\n" "lo[op] - loop and display x/y coordinates\n" + "gl[oop] - loop and draw to framebuffer\n" "ch[oose] cols rows - choose item\n" "se[lection] p - check if item p (1 .. cols*rows) was selected\n" ); @@ -327,7 +374,7 @@ static int do_led_check(int argc, char *const argv[]) static int do_led_get(int argc, char *const argv[]) { int status=led_get_buttons(); - printf("button status: %01x\n", status); + printf("button status: %02x\n", status); print_buttons(status); printf("\n"); return 0; @@ -508,7 +555,6 @@ static int do_mux(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) printf("PADCONF [0:15] [16:31]\n"); while(addr < (char *) 0x48002A28) { u16 mux=*(u16 *) addr; - int i; if(cols == 0) printf("%08x", (unsigned int) addr); printf(" %c%d%c", (mux&8)?((mux&0x10?'U':'D')):' ', (mux&7), (mux&0x100)?'I':'O'); diff --git a/board/goldelico/gta04/dssfb.c b/board/goldelico/gta04/dssfb.c index b25c759..9ad530c 100644 --- a/board/goldelico/gta04/dssfb.c +++ b/board/goldelico/gta04/dssfb.c @@ -260,7 +260,7 @@ void dssfb_init(void) { #ifdef CONFIG_OMAP3_GTA04A2 /* delayed on GTA04A2 */ struct prcm *prcm_base = (struct prcm *)PRCM_BASE; - printf("prcm base = %08x\n", prcm_base); + printf("prcm base = %08x\n", (void *) prcm_base); printf("ick_dss_on\n"); sr32(&prcm_base->iclken_dss, 0, 32, ICK_DSS_ON); sdelay(1000); diff --git a/board/goldelico/gta04/i2c1-fix.c b/board/goldelico/gta04/i2c1-fix.c index 3b4363c..6a3da07 100644 --- a/board/goldelico/gta04/i2c1-fix.c +++ b/board/goldelico/gta04/i2c1-fix.c @@ -192,7 +192,7 @@ static int write_byte(struct i2c *base, int byte) static int read_byte(struct i2c *base) { int i; - u8 byte; + u8 byte=0; for (i=7; i>=0; i--) byte = (byte << 1) | read_bit(base); diff --git a/board/goldelico/gta04/shutdown.c b/board/goldelico/gta04/shutdown.c index 4348b60..f4e3aee 100644 --- a/board/goldelico/gta04/shutdown.c +++ b/board/goldelico/gta04/shutdown.c @@ -34,6 +34,11 @@ void shutdown(void) { u8 val = 0; + if(i2c_set_bus_num(0)) + { + printf ("could not select I2C1\n"); + return 1; + } printf("shutting down by writing DEVOFF register of TPS65950\n"); if (twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER, &val, TWL4030_PM_MASTER_P1_SW_EVENTS)) { diff --git a/board/goldelico/gta04/status.c b/board/goldelico/gta04/status.c index db2a5c2..afb4488 100644 --- a/board/goldelico/gta04/status.c +++ b/board/goldelico/gta04/status.c @@ -32,10 +32,19 @@ #include <twl4030.h> #include "status.h" -#ifdef CONFIG_OMAP3_GTA04 -static int isGTA04 = 1; -#define TCA6507 2 // I2C2 -#define TCA6507_ADDRESS 0x45 +#if defined(CONFIG_OMAP3_GTA04) + +// no need to probe for LED controller (compiler should optimize unnecessary code) +#define hasTCA6507 (1==1) + +#else + +static int hasTCA6507=0; + +#endif + +#define TCA6507_BUS 2 // I2C2 +#define TCA6507_ADDRESS 0x45 /* register numbers */ #define TCA6507_SELECT0 0 @@ -52,10 +61,6 @@ static int isGTA04 = 1; #define TCA6507_AUTO_INCREMENT 16 -#else -static int isGTA04 = 0; -#endif - // we can't include "beagle.h" /* BeagleBoard revisions */ extern int get_board_revision(void); @@ -66,8 +71,28 @@ extern int get_board_revision(void); static int isXM = 0; -// Note: on GTA04 the LEDs will be connected to TCA8418 and controlled through I2C -// Note: BB-XM has scrambled DSS assignment +#if defined(CONFIG_OMAP3_GTA04) + +#define GPIO_AUX 7 // AUX/User button +#define GPIO_POWER -1 // N/A on GTA04 (access through TPS65950) +#define GPIO_GPSEXT 144 // external GPS antenna is plugged in +#define GPIO_PENIRQ 160 // TSC must be set up to provide PENIRQ + +#elif defined(CONFIG_OMAP3_BEAGLE_EXPANDER) + +#define GPIO_AUX 136 // AUX/User button +#define GPIO_POWER 137 // POWER button +#define GPIO_GPSEXT 138 // external GPS antenna is plugged in +#define GPIO_PENIRQ 157 // TSC must be set up to provide PENIRQ + +#else + +#define GPIO_AUX 136 // AUX/User button +#define GPIO_POWER 137 // N/A on GTA04 +#define GPIO_GPSEXT 138 // external GPS antenna is plugged in +#define GPIO_PENIRQ 157 // TSC must be set up to provide PENIRQ + +#endif #define GPIO_LED_AUX_RED (isXM?88:70) // AUX #define GPIO_LED_AUX_GREEN (isXM?89:71) // AUX @@ -76,16 +101,9 @@ static int isXM = 0; #define GPIO_LED_VIBRA (isXM?2:88) // Vibracall motor #define GPIO_LED_UNUSED (isXM?3:89) // unused -// Note: on GTA04 the GPIOs will be assigned differently and the state of the POWER button is only available through the TPS65950 - -#define GPIO_AUX (isGTA04?7:136) // AUX/User button -#define GPIO_POWER (isGTA04?-1:137) // N/A on GTA04 -#define GPIO_GPSEXT (isGTA04?144:138) // external GPS antenna is plugged in -#define GPIO_PENIRQ (isGTA04?160:157) // TSC must be set up to provide PENIRQ - void led_set_led(int value) { - if(!isGTA04) { + if(!hasTCA6507) { omap_set_gpio_dataout(GPIO_LED_AUX_RED, (value&(1 << 0))); omap_set_gpio_dataout(GPIO_LED_AUX_GREEN, (value&(1 << 1))); omap_set_gpio_dataout(GPIO_LED_POWER_RED, (value&(1 << 3))); @@ -106,27 +124,42 @@ void led_set_led(int value) int led_get_buttons(void) { // convert button state into led state - if(isGTA04) { - u8 val; - i2c_set_bus_num(0); // read I2C1 - twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER, &val, TWL4030_PM_MASTER_STS_HW_CONDITIONS); // read state of power button (bit 0) from TPS65950 - return ((omap_get_gpio_datain(GPIO_AUX)) << 0) | - ((omap_get_gpio_datain(GPIO_GPSEXT)) << 1) | - (((val&0x01) != 0) << 3) | - ((omap_get_gpio_datain(GPIO_PENIRQ)) << 4); - } +#if defined(CONFIG_OMAP3_GTA04) + u8 val; + i2c_set_bus_num(0); // read I2C1 + twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER, &val, TWL4030_PM_MASTER_STS_HW_CONDITIONS); // read state of power button (bit 0) from TPS65950 + return ((omap_get_gpio_datain(GPIO_AUX)) << 0) | + ((omap_get_gpio_datain(GPIO_GPSEXT)) << 1) | + (((val&0x01) != 0) << 3) | + ((omap_get_gpio_datain(GPIO_PENIRQ)) << 4); +#elif defined(CONFIG_OMAP3_BEAGLE_EXPANDER) + return + ((omap_get_gpio_datain(GPIO_AUX)) << 0) | + ((0) << 1) | + ((!omap_get_gpio_datain(GPIO_POWER)) << 3) | + ((omap_get_gpio_datain(GPIO_PENIRQ)) << 4); +#else return ((!omap_get_gpio_datain(GPIO_AUX)) << 0) | ((omap_get_gpio_datain(GPIO_GPSEXT)) << 1) | ((!omap_get_gpio_datain(GPIO_POWER)) << 3) | ((omap_get_gpio_datain(GPIO_PENIRQ)) << 4); +#endif } int led_init(void) { isXM = (get_board_revision() == REVISION_XM); +#if !defined(CONFIG_OMAP3_GTA04) + if(i2c_set_bus_num(TCA6507_BUS-1)) + { + printf ("could not select I2C2\n"); + return 1; + } + hasTCA6507 = !i2c_probe(TCA6507_ADDRESS); +#endif - if(!isGTA04) { + if(!hasTCA6507) { if(isXM) { // XM has scrambled dss assignment with respect to default ball name MUX_VAL(CP(DSS_DATA18), (IEN | PTD | EN | M4)); /*GPIO */ MUX_VAL(CP(DSS_DATA19), (IEN | PTD | EN | M4)); /*GPIO */ @@ -154,19 +187,13 @@ int led_init(void) } else { // initialize I2C controller - if(i2c_set_bus_num(TCA6507-1)) - { - printf ("could not select I2C2\n"); - return 1; - } - // send init command? } omap_request_gpio(GPIO_AUX); omap_request_gpio(GPIO_GPSEXT); omap_request_gpio(GPIO_PENIRQ); - if(!isGTA04) { + if(!hasTCA6507) { omap_set_gpio_direction(GPIO_LED_AUX_GREEN, 0); // output omap_set_gpio_direction(GPIO_LED_AUX_RED, 0); // output omap_set_gpio_direction(GPIO_LED_POWER_GREEN, 0); // output @@ -177,11 +204,13 @@ int led_init(void) } omap_set_gpio_direction(GPIO_AUX, 1); // input - omap_set_gpio_direction(GPIO_AUX, 1); // input - omap_set_gpio_direction(GPIO_GPSEXT, 1); // input +#ifndef CONFIG_OMAP3_GTA04 + omap_set_gpio_direction(GPIO_POWER, 1); // input +#endif + omap_set_gpio_direction(GPIO_GPSEXT, 1); // input - // when sould we do omap_free_gpio(GPIO_LED_AUX_GREEN); - printf("did led_init()\n"); + // when sould we do omap_free_gpio(GPIO_LED_AUX_GREEN); ? + printf("did init LED driver for %s\n", hasTCA6507?"TCA6507":"GPIOs"); return 0; } diff --git a/board/goldelico/gta04/systest.c b/board/goldelico/gta04/systest.c index 10dd93e..480fcb4 100644 --- a/board/goldelico/gta04/systest.c +++ b/board/goldelico/gta04/systest.c @@ -31,12 +31,13 @@ #include <i2c.h> #include <twl4030.h> #include "systest.h" +#include "TD028TTEC1.h" int systest(void) { // do mixture of gps_echo, tsc_loop, status mirror status blink int r; i2c_set_bus_num(0); // I2C1 - printf("TPS65950: %s\n", (r=i2c_probe(TWL4030_CHIP_USB))?"-":"found"); // responds on 4 addresses 0x48..0x4b + printf("TPS65950: %s\n", (r=!i2c_probe(TWL4030_CHIP_USB))?"found":"-"); // responds on 4 addresses 0x48..0x4b if(!r) { // was ok, ask for details u8 val; @@ -80,16 +81,16 @@ int systest(void) printf(" VBAT: %d\n", (val2<<2)+(val>>6)); } i2c_set_bus_num(1); // I2C2 - printf("TSC2007: %s\n", i2c_probe(0x48)?"-":"found"); - printf("TCA6507: %s\n", i2c_probe(0x45)?"-":"found"); - printf("LIS302 TOP: %s\n", i2c_probe(0x1c)?"-":"found"); - printf("LIS302 BOTTOM: %s\n", i2c_probe(0x1d)?"-":"found"); - printf("LSM303: %s\n", i2c_probe(0x19)?"-":"found"); - printf("HMC5843: %s\n", i2c_probe(0x1e)?"-":"found"); - printf("BMP085: %s\n", i2c_probe(0x77)?"-":"found"); - printf("ITG3200: %s\n", i2c_probe(0x68)?"-":"found"); - printf("Si4721: %s\n", i2c_probe(0x21)?"-":"found"); - printf("TCA8418: %s\n", i2c_probe(0x64)?"-":"found"); + printf("TSC2007: %s\n", !i2c_probe(0x48)?"found":"-"); + printf("TCA6507: %s\n", !i2c_probe(0x45)?"found":"-"); + printf("LIS302 TOP: %s\n", !i2c_probe(0x1c)?"found":"-"); + printf("LIS302 BOTTOM: %s\n", !i2c_probe(0x1d)?"found":"-"); + printf("LSM303: %s\n", !i2c_probe(0x19)?"found":"-"); + printf("HMC5843: %s\n", !i2c_probe(0x1e)?"found":"-"); + printf("BMP085: %s\n", !i2c_probe(0x77)?"found":"-"); + printf("ITG3200: %s\n", !i2c_probe(0x68)?"found":"-"); + printf("Si4721: %s\n", !i2c_probe(0x21)?"found":"-"); + printf("TCA8418: %s\n", !i2c_probe(0x64)?"found":"-"); i2c_set_bus_num(2); // I2C3 // LEDs // GPS UART @@ -98,10 +99,10 @@ int systest(void) // Buttons // Power // Display communication - if(jbt_check()) - printf("DISPLAY: failed\n"); + if(!jbt_check()) + printf("DISPLAY: ok\n"); else - printf("DISPLAY: ok\n"); + printf("DISPLAY: failed\n"); return (0); } diff --git a/board/goldelico/gta04/tsc2007.c b/board/goldelico/gta04/tsc2007.c index 543e74f..430ecbc 100644 --- a/board/goldelico/gta04/tsc2007.c +++ b/board/goldelico/gta04/tsc2007.c @@ -37,39 +37,41 @@ // command byte definitions: // channel selection and power down -#define TSC2007_TEMP0 0x00 -#define TSC2007_AUX 0x20 -#define TSC2007_TEMP1 0x40 -#define TSC2007_ACTX 0x80 -#define TSC2007_ACTY 0x90 -#define TSC2007_ACTXY 0xA0 -#define TSC2007_X 0xc0 -#define TSC2007_Y 0xd0 -#define TSC2007_Z1 0xe0 -#define TSC2007_Z2 0xf0 - -#define TSC2007_POWER_DOWN 0x00 // must be sent once after power up -#define TSC2007_ADC_ON 0x04 -#define TSC2007_ADC_OFF_PENIRQ 0x08 - -#define TSC2007_12Bit2MHz 0x00 -#define TSC2007_8Bit4MHz 0x02 +#define TSC2007_TEMP0 0x00 +#define TSC2007_AUX 0x20 +#define TSC2007_TEMP1 0x40 +#define TSC2007_ACTX 0x80 +#define TSC2007_ACTY 0x90 +#define TSC2007_ACTXY 0xA0 +#define TSC2007_X 0xc0 +#define TSC2007_Y 0xd0 +#define TSC2007_Z1 0xe0 +#define TSC2007_Z2 0xf0 + +#define TSC2007_POWER_DOWN 0x00 // must be sent once after power up +#define TSC2007_ADC_ON 0x04 +#define TSC2007_ADC_OFF_PENIRQ 0x08 + +#define TSC2007_12Bit2MHz 0x00 +#define TSC2007_8Bit4MHz 0x02 // setup command -#define TSC2007_SETUP 0xb0 +#define TSC2007_SETUP 0xb0 -#define TSC2007_USE_MAV 0x00 +#define TSC2007_USE_MAV 0x00 #define TSC2007_BYPASS_MAV 0x02 -#define TSC2007_50kPUP 0x00 -#define TSC2007_90kPUP 0x01 +#define TSC2007_50kPUP 0x00 +#define TSC2007_90kPUP 0x01 /* int i2c_read(u_int8_t chip, u_int32_t addr, int alen, u_int8_t *buf, int len) int i2c_write(u_int8_t chip, u_int32_t addr, int alen, u_int8_t *buf, int len) */ +static int didNotInit=1; + int tsc2007_cmd(int cmd) { // send command unsigned char buf[16]; @@ -84,17 +86,22 @@ int tsc2007_cmd(int cmd) int tsc2007_init(void) { - int rc=0; if(i2c_set_bus_num(TSC2007_BUS-1)) { printf ("could not select I2C2\n"); return 1; } - rc = tsc2007_cmd(TSC2007_SETUP|TSC2007_USE_MAV|TSC2007_50kPUP); - rc |= tsc2007_cmd(TSC2007_POWER_DOWN); + if(i2c_probe(TSC2007_ADDRESS)) + { + printf ("could not probe TSC2007\n"); + return 1; + } - if(rc) + didNotInit = tsc2007_cmd(TSC2007_SETUP|TSC2007_USE_MAV|TSC2007_50kPUP); + didNotInit |= tsc2007_cmd(TSC2007_POWER_DOWN); + + if(didNotInit) printf("did tsc2007_init() failed.\n"); else printf("did tsc2007_init()\n"); @@ -116,6 +123,8 @@ int read_adc(int adcnum) TSC2007_AUX, TSC2007_AUX }; + if(didNotInit) + return -1; if(i2c_get_bus_num() != TSC2007_BUS-1 && i2c_set_bus_num(TSC2007_BUS-1)) { printf ("could not select I2C2\n"); |