/*------------------------------------------------------------------------------ -- 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 -------------------------------------------------------------------------------*/ /* TODO: Add SPI slave mode Add interrupt interface */ #ifndef SPI_H #define SPI_H #include #include #ifdef __cplusplus extern "C" { #endif /* typedef struct spi_t { void* _dev; int cfg; int speed; }spi_t;*/ typedef int spi_t; #define spi1 0 #define spi2 1 #define spi3 2 #define spi4 3 #define spi5 4 #define spi6 5 #define spi7 6 #define spi8 7 #define spi9 8 typedef enum { spi4bits = 0x3, spi5bits = 0x4, spi6bits = 0x5, spi7bits = 0x6, spi8bits = 0x7, spi9bits = 0x8, spi10bits = 0x9, spi11bits = 0xA, spi12bits = 0xB, spi13bits = 0xC, spi14bits = 0xD, spi15bits = 0xE, spi16bits = 0xF }spibits_t; #define SPIBITSMASK 0xF typedef enum { spislave = 0x00, spimaster = 0x10 }spimode_t; #define SPIMODEMASK 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 spi_t spiopen(int count); extern spi_t spiopenandconfig(int count,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,uint32_t config,uint32_t speed); 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 //SPI_H