/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2007 by Jonathan Gordon * * 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 "config.h" #include "cpu.h" #include "system.h" #include "spi.h" #include "tsc2100.h" /* adc_data contains the last readings from the tsc2100 */ static short adc_data[10]; static short adc_status; static long adc_last_read=0; static long adc_last_touch_read=0; static long adc_last_volt_read=0; void tsc2100_read_data(void) { int page = 0, address = 0; unsigned int i; unsigned short command = 0x8000|(page << 11)|(address << 5); unsigned char out[] = {command >> 8, command & 0xff}; unsigned char *p_adc_data=(unsigned char *)&adc_data; adc_status|=tsc2100_readreg(TSSTAT_PAGE, TSSTAT_ADDRESS); adc_last_read=current_tick; spi_block_transfer(SPI_target_TSC2100, out, sizeof(out), (char *)adc_data, sizeof(adc_data)); for(i=0; i>1]=(short)(p_adc_data[i]<<8|p_adc_data[i+1]); } /* Read X, Y, Z1, Z2 touchscreen coordinates. */ bool tsc2100_read_touch(short *x, short* y, short *z1, short *z2) { /* Note: This could cause problems if the current tick is not reset in ~1.3 * years. Noting this in the event that a suspend/resume function * is added. */ if( (adc_status&(3<<9)) && (adc_last_read - adc_last_touch_read>=0) ) { *x = adc_data[0]; *y = adc_data[1]; *z1 = adc_data[2]; *z2 = adc_data[3]; adc_status&=~(3<<9); adc_last_touch_read=current_tick; return true; } else { return false; } } bool tsc2100_read_volt(short *bat1, short *bat2, short *aux) { if( (adc_status&(7<<4)) && TIME_BEFORE(adc_last_volt_read, adc_last_read)) { *bat1 = adc_data[5]; *bat2 = adc_data[6]; *aux = adc_data[7]; adc_status&=~(7<<4); adc_last_volt_read=current_tick; return true; } else { return false; } } void tsc2100_set_mode(bool poweron, unsigned char scan_mode) { short tsadc=(scan_mode<> 8, command & 0xff}; unsigned char in[2]; spi_block_transfer(SPI_target_TSC2100, out, sizeof(out), in, sizeof(in)); return (in[0]<<8)|in[1]; } void tsc2100_writereg(int page, int address, short value) { unsigned short command = (page << 11)|(address << 5); unsigned char out[4] = {command >> 8, command & 0xff, value >> 8, value & 0xff}; spi_block_transfer(SPI_target_TSC2100, out, sizeof(out), NULL, 0); } void tsc2100_keyclick(void) { // 1100 0100 0001 0000 //short val = 0xC410; tsc2100_writereg(TSAC2_PAGE, TSAC2_ADDRESS, tsc2100_readreg(TSAC2_PAGE, TSAC2_ADDRESS)&0x8000); } #ifdef HAVE_HARDWARE_BEEP void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude) { tsc2100_keyclick(); } #endif