##// END OF EJS Templates
Sync
Sync

File last commit:

r71:608b7f0e27c2 dev_alexis
r102:988f7eae7e79 dev_alexis
Show More
ADS7843.c
103 lines | 2.6 KiB | text/x-c | CLexer
/*------------------------------------------------------------------------------
-- This file is a part of the libuc, microcontroler library
-- Copyright (C) 2013, Alexis Jeandet
--
-- 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 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------
-- Author : Alexis Jeandet
-- Mail : alexis.jeandet@member.fsf.org
-------------------------------------------------------------------------------*/
#include <ADS7843.h>
#include <core.h>
int ads7843init(ADS7843_t *dev, spi_t spidev,void (*setnCS)(char),int (*busy)())
{
dev->spidev = spidev;
dev->setnCS = setnCS;
dev->busy = busy;
dev->setnCS(1);
return 1;
}
int ads7843read(ADS7843_t *dev,int* x,int* y)
{
int data;
*x=0;
*y=0;
spiputw(dev->spidev,0x97);
// delay_100us(2);
while(dev->busy());
spigetw2(dev->spidev,0);
spigetw2(dev->spidev,0);
delay_100us(100);
for(int i=0;i<32;i++)
{
data=0;
dev->setnCS(0);
spiputw(dev->spidev,0x97);
//delay_100us(2);
while(dev->busy());
data= (0x0FF & spigetw2(dev->spidev,0))<<8;
data+= 0x0FF & spigetw2(dev->spidev,0);
*x+=data>>4;
dev->setnCS(1);
delay_100us(10);
}
spiputw(dev->spidev,0xd7);
// delay_100us(2);
while(dev->busy());
spigetw2(dev->spidev,0);
spigetw2(dev->spidev,0);
delay_100us(10);
for(int i=0;i<32;i++)
{
data=0;
dev->setnCS(0);
spiputw(dev->spidev,0xd7);
// delay_100us(2);
while(dev->busy());
data= (spigetw2(dev->spidev,0))<<8;
data+= spigetw2(dev->spidev,0);
*y+=data>>4;
dev->setnCS(1);
delay_100us(10);
}
*x/=32;
*y/=32;
return 1;
}