X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Finclude%2Fspi.h;h=d940605657b9961a89031e9d31dd826cc4160ce7;hp=f5c0d8e418414a46a37fcdd772a91af4c89101c2;hb=f3480afd0970eb232b17070d8596e5d09aef2c7e;hpb=6dc88d2f1713d2bf9f2fabb5fbfb9f235a679b2f diff --git a/firmware/include/spi.h b/firmware/include/spi.h index f5c0d8e..d940605 100644 --- a/firmware/include/spi.h +++ b/firmware/include/spi.h @@ -3,21 +3,47 @@ \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) +#else +# define MOSI BIT1 +# define MISO BIT2 +# define SCK BIT3 +# define TST BIT0 +# define RST BIT6 +#endif -#define SETSS P5OUT|=SS -#define CLRSS P5OUT&=~SS +#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); +#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(); @@ -35,3 +61,18 @@ void spiflash_peekblock(unsigned long adr, void spiflash_pokeblocks(unsigned long adr, unsigned char *buf, unsigned int len); + + +//! Enable SPI writing +void spiflash_wrten(); + +//! Read and write an SPI byte. +unsigned char spitrans8(unsigned char byte); +//! Grab the SPI flash status byte. +unsigned char spiflash_status(); +//! Erase a sector. +void spiflash_erasesector(unsigned long adr); + +extern app_t const spi_app; + +#endif