/*------------------------------------------------------------------------------ -- This file is a part of the libuc, microcontroler library -- Copyright (C) 2012, 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@gmail.com -------------------------------------------------------------------------------*/ /* */ #ifndef ADC_H #define ADC_H #include #include #ifdef __cplusplus extern "C" { #endif typedef struct adc_t { void* _dev; int cfg; int rate; }adc_t; typedef enum { adc6bits = 0x1, adc7bits = 0x2, adc8bits = 0x3, adc9bits = 0x4, adc10bits = 0x5, adc11bits = 0x6, adc12bits = 0x7, adc13bits = 0x8, adc14bits = 0x9, adc15bits = 0xA, adc16bits = 0xB, adc17bits = 0xC, adc18bits = 0xD, adc19bits = 0xE, adc20bits = 0xF, adc21bits = 0x10, adc22bits = 0x11, adc23bits = 0x12, adc24bits = 0x13 }adcbits_t; #define ADCBITSMASK 0xF typedef enum { adcsingle = 0x00, adcmaster = 0x10 }adcconvmode_t; #define ADCCONVMODEMASK 0x10 typedef enum { spiclkinhlow = 0x00, spiclkinhhigh = 0x20 }spiclkinhlvl_t; #define SPICLKINHLVLMASK 0x20 typedef enum { spiclkfirstedge = 0x00, spiclksecondedge = 0x40 }spiclkphase_t; #define SPICLKPHASEMASK 0x40 typedef enum { spimsbfirst = 0x00, spilsbfirst = 0x80 }spibitorder_t; #define SPIBITORDERMASK 0x80 extern int spiopen(int count,spi_t* spidev); extern int spiopenandconfig(int count,spi_t* spidev,uint32_t cfg,uint32_t speed,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin); extern int spiclose(spi_t* spidev); extern int spisetpins(spi_t* spidev,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin); extern int spienable(spi_t* spidev); extern int spidisable(spi_t* spidev); extern int spisetconfig(spi_t* spidev); extern int spisetspeed(spi_t* spidev, uint32_t speed); extern int spisetbitorder(spi_t* spidev,spibitorder_t order); extern int spisetdatabits(spi_t* spidev,spibits_t bitscnt); extern int spisetclkinhlevel(spi_t* spidev,spiclkinhlvl_t level); extern int spisetclkphase(spi_t* spidev,spiclkphase_t phase); extern int spiputw(spi_t* spidev,uint16_t data); extern uint16_t spigetw(spi_t* spidev); extern int spiputs(spi_t* spidev,char* s); extern int spigets(spi_t* spidev,char* s); extern int spiputnw(spi_t* spidev,uint16_t* w,int n); extern int spigetnw(spi_t* spidev,uint16_t* w,int n); extern int spiputnc(spi_t* spidev,char* c,int n); extern int spigetnc(spi_t* spidev,char* c,int n); extern int spiavailiabledata(spi_t* spidev); #ifdef __cplusplus } #endif #endif //ADC_H