turn ftdi driver into echo server
[goodfet] / firmware / include / spi.h
1 /*! \file spi.h
2   \author Travis Goodspeed
3   \brief Definitions for the SPI application.
4 */
5
6 #ifndef SPI_H
7 #define SPI_H
8
9 #include "app.h"
10
11 #define SPI 0x01
12
13 //Pins and I/O
14 #if (platform == donbfet)
15 # define MOSI (1 << PA2)
16 # define MISO (1 << PA1)
17 # define SCK  (1 << PA0)
18 # define SS   (1 << PA3)
19 # define TST  (1 << PA4)
20 # define XRST (1 << PA5)
21 #else
22 # define MOSI BIT1
23 # define MISO BIT2
24 # define SCK  BIT3
25 # define TST  BIT0
26 # define RST  BIT6
27 #endif
28 //Apimotev2 SET/CLRRST needs to be on pin 21, so 2.1 -- just redefine RST to BIT0
29
30 #define SETMOSI SPIOUT|=MOSI
31 #define CLRMOSI SPIOUT&=~MOSI
32 #define SETCLK SPIOUT|=SCK
33 #define CLRCLK SPIOUT&=~SCK
34 #define READMISO (SPIIN&MISO?1:0)
35
36 //FIXME this should be defined by the platform.
37 #if (platform == donbfet)
38 # define SETTST PORTA|=(1 << PA4);
39 # define CLRTST PORTA&=~(1 << PA4);
40 # define SETRST PORTA|=(1 << PA5);
41 # define CLRRST PORTA&=~(1 << PA5);
42 #else
43 # define SETTST P4OUT|=TST
44 # define CLRTST P4OUT&=~TST
45 # define SETRST P2OUT|=RST
46 # define CLRRST P2OUT&=~RST
47 #endif
48
49 //! Set up the pins for SPI mode.
50 void spisetup();
51
52 //! Read and write an SPI byte.
53 unsigned char spitrans8(unsigned char byte);
54
55 //! Read a block to a buffer.
56 void spiflash_peekblock(unsigned long adr,
57                         unsigned char *buf,
58                         unsigned int len);
59
60
61 //! Write many blocks to the SPI Flash.
62 void spiflash_pokeblocks(unsigned long adr,
63                          unsigned char *buf,
64                          unsigned int len);
65
66
67 //! Enable SPI writing
68 void spiflash_wrten();
69
70 //! Read and write an SPI byte.
71 unsigned char spitrans8(unsigned char byte);
72 //! Grab the SPI flash status byte.
73 unsigned char spiflash_status();
74 //! Erase a sector.
75 void spiflash_erasesector(unsigned long adr);
76
77 extern app_t const spi_app;
78
79 #endif