X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=inline;f=firmware%2Finclude%2Fspi.h;h=097510e1bc14ca2743ab04b9a909cbf078af5e7e;hb=86d2753c708b859cb622a4d10deee073e8a1fa92;hp=02e548ae5ed3f2f72da71417776ca9ccd2a0a7e9;hpb=ba4e9392ba615ed84d47576fe973057f89bb8998;p=goodfet diff --git a/firmware/include/spi.h b/firmware/include/spi.h index 02e548a..097510e 100644 --- a/firmware/include/spi.h +++ b/firmware/include/spi.h @@ -3,18 +3,65 @@ \brief Definitions for the SPI application. */ +#ifndef SPI_H +#define SPI_H + +#include "app.h" + +#define SPI 0x01 //Pins and I/O -//#define SS BIT0 -#define MOSI BIT1 -#define MISO BIT2 -#define SCK BIT3 +#if (platform == donbfet) +# define MOSI (1 << PA2) +# define MISO (1 << PA1) +# define SCK (1 << PA0) +# define SS (1 << PA3) +# define TST (1 << PA4) +# define XRST (1 << PA5) +#elif (platform == arduino) +// pin Arduini - nrf pin +// - nrf 1 GND +// - nrf 2 +3.3V +# define CE (1 << PB1) // pin 9 - nrf 3 CE +# define SS (1 << PB2) // pin 10 CS - nrf 4 CSN +# define MOSI (1 << PB3) // pin 11 MOSI - nrf 6 MOSI +# define MISO (1 << PB4) // pin 12 MISO - nrf 7 MISO +# define SCK (1 << PB5) // pin 13 SCL - nrf 5 CLK +// - nrf 8 IRQ +//# define TST (1 << PA4) +//# define XRST (1 << PA5) +#else +# define MOSI BIT1 +# define MISO BIT2 +# define SCK BIT3 +# define TST BIT0 +# define RST BIT6 +#endif +//Apimotev2 SET/CLRRST needs to be on pin 21, so 2.1 -- just redefine RST to BIT0 + +#define SETMOSI SPIOUT|=MOSI +#define CLRMOSI SPIOUT&=~MOSI +#define SETCLK SPIOUT|=SCK +#define CLRCLK SPIOUT&=~SCK +#define READMISO (SPIIN&MISO?1:0) -#define SETMOSI P5OUT|=MOSI -#define CLRMOSI P5OUT&=~MOSI -#define SETCLK P5OUT|=SCK -#define CLRCLK P5OUT&=~SCK -#define READMISO (P5IN&MISO?1:0) +//FIXME this should be defined by the platform. +#if (platform == donbfet) +# define SETTST PORTA|=(1 << PA4); +# define CLRTST PORTA&=~(1 << PA4); +# define SETRST PORTA|=(1 << PA5); +# define CLRRST PORTA&=~(1 << PA5); +#elif (platform == arduino) +//# define SETTST PORTA|=(1 << PA4); +//# define CLRTST PORTA&=~(1 << PA4); +//# define SETRST PORTA|=(1 << PA5); +//# define CLRRST PORTA&=~(1 << PA5); +#else +# define SETTST P4OUT|=TST +# define CLRTST P4OUT&=~TST +# define SETRST P2OUT|=RST +# define CLRRST P2OUT&=~RST +#endif //! Set up the pins for SPI mode. void spisetup(); @@ -43,3 +90,7 @@ unsigned char spitrans8(unsigned char byte); unsigned char spiflash_status(); //! Erase a sector. void spiflash_erasesector(unsigned long adr); + +extern app_t const spi_app; + +#endif