played around with different inputs to change the temperature display
[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
29 #define SETMOSI SPIOUT|=MOSI
30 #define CLRMOSI SPIOUT&=~MOSI
31 #define SETCLK SPIOUT|=SCK
32 #define CLRCLK SPIOUT&=~SCK
33 #define READMISO (SPIIN&MISO?1:0)
34
35 //FIXME this should be defined by the platform.
36 #if (platform == donbfet)
37 # define SETTST PORTA|=(1 << PA4);
38 # define CLRTST PORTA&=~(1 << PA4);
39 # define SETRST PORTA|=(1 << PA5);
40 # define CLRRST PORTA&=~(1 << PA5);
41 #else
42 # define SETTST P4OUT|=TST
43 # define CLRTST P4OUT&=~TST
44 # define SETRST P2OUT|=RST
45 # define CLRRST P2OUT&=~RST
46 #endif
47
48 //! Set up the pins for SPI mode.
49 void spisetup();
50
51 //! Read and write an SPI byte.
52 unsigned char spitrans8(unsigned char byte);
53
54 //! Read a block to a buffer.
55 void spiflash_peekblock(unsigned long adr,
56                         unsigned char *buf,
57                         unsigned int len);
58
59
60 //! Write many blocks to the SPI Flash.
61 void spiflash_pokeblocks(unsigned long adr,
62                          unsigned char *buf,
63                          unsigned int len);
64
65
66 //! Enable SPI writing
67 void spiflash_wrten();
68
69 //! Read and write an SPI byte.
70 unsigned char spitrans8(unsigned char byte);
71 //! Grab the SPI flash status byte.
72 unsigned char spiflash_status();
73 //! Erase a sector.
74 void spiflash_erasesector(unsigned long adr);
75
76 extern app_t const spi_app;
77
78 #endif