/*------------------------------------------------------------------------------ -- This file is a part of the libuc, microcontroler library -- Copyright (C) 2011, 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 -------------------------------------------------------------------------------*/ #include #include spi_t spiopen(int count) { return -1; } spi_t spiopenandconfig(int count, uint32_t cfg, uint32_t speed, uint32_t MOSIpin, uint32_t MISOpin, uint32_t SCKpin, uint32_t SCSpin) { spi_t dev = spiopen(count); if(dev!=-1) { spidisable(dev); spisetpins(dev,MOSIpin, MISOpin, SCKpin, SCSpin); spienable(dev); spisetconfig(dev,cfg,speed); } return dev; } int spiclose(spi_t spidev) { if((spidev<3)&&(spidev>=0)) { return 1; } return -1; } int spisetpins(spi_t spidev,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin) { if((spidev<3)&&(spidev>=0)) { return 1; } return -1; } int spienable(spi_t spidev) { if((spidev<3)&&(spidev>=0)) { return 1; } return -1; } int spidisable(spi_t spidev) { if((spidev<3)&&(spidev>=0)) { return 1; } return -1; } int spisetconfig(spi_t spidev, uint32_t config, uint32_t speed) { if((spidev<3)&&(spidev>=0)) { return 0; } return 1; } int spisetspeed(spi_t spidev, uint32_t speed) { if((spidev<3)&&(spidev>=0)) { return 1; } return -1; } uint32_t spigetspeed(spi_t spidev) { if((spidev<3)&&(spidev>=0)) { return 0; } return -1; } int spisetdatabits(spi_t spidev,spibits_t bitscnt) { if((spidev<3)&&(spidev>=0)) { return 0; } return -1; } int spisetbitorder(spi_t spidev,spibitorder_t order) { if((spidev<3)&&(spidev>=0)) { return 1; } return -1; } int spisetclkinhlevel(spi_t spidev,spiclkinhlvl_t level) { if((spidev<3)&&(spidev>=0)) { return 1; } return -1; } int spisetclkphase(spi_t spidev,spiclkphase_t phase) { if((spidev<3)&&(spidev>=0)) { return 1; } return -1; } int spiputw(spi_t spidev,uint16_t data) { if((spidev<3)&&(spidev>=0)) { return 0; } return -1; } uint16_t spigetw(spi_t spidev) { if((spidev<3)&&(spidev>=0)) { return 0; } return -1; } int spiputs(spi_t spidev,char* s) { while (*s) spiputw(spidev,*s++); return 1; } int spigets(spi_t spidev,char* s) { do { (*s) = spigetw(spidev); } while(*s++); return 1; } int spiputnw(spi_t spidev,uint16_t* w,int n) { while(n!=0) { spiputw(spidev,*w++); n--; } return 1; } int spigetnw(spi_t spidev,uint16_t* w,int n) { while(n!=0) { *w++=spigetw(spidev); n--; } return 1; } int spiputnc(spi_t spidev,char* c,int n) { while(n!=0) { spiputw(spidev,*c++); n--; } return 1; } int spigetnc(spi_t spidev,char* c,int n) { while(n!=0) { *c++=spigetw(spidev); n--; } return 1; } int spiavailiabledata(spi_t spidev) { return 0; } int spitransactionfinished(spi_t spidev) { if((spidev<3)&&(spidev>=0)) { return 1; } return 0; }