goodfet needs SS not CS for nrf application
[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 #elif (platform == arduino)
22 // pin Arduini - nrf pin
23 //                                      - nrf 1 GND
24 //                                      - nrf 2 +3.3V
25 # define CE   (1 << PB1) // pin 9       - nrf 3 CE
26 # define SS   (1 << PB2) // pin 10 CS   - nrf 4 CSN
27 # define MOSI (1 << PB3) // pin 11 MOSI - nrf 6 MOSI
28 # define MISO (1 << PB4) // pin 12 MISO - nrf 7 MISO
29 # define SCK  (1 << PB5) // pin 13 SCL  - nrf 5 CLK
30 //                                      - nrf 8 IRQ
31 //# define TST  (1 << PA4)
32 //# define XRST (1 << PA5)
33 #else
34 # define MOSI BIT1
35 # define MISO BIT2
36 # define SCK  BIT3
37 # define TST  BIT0
38 # define RST  BIT6
39 #endif
40 //Apimotev2 SET/CLRRST needs to be on pin 21, so 2.1 -- just redefine RST to BIT0
41
42 #define SETMOSI SPIOUT|=MOSI
43 #define CLRMOSI SPIOUT&=~MOSI
44 #define SETCLK SPIOUT|=SCK
45 #define CLRCLK SPIOUT&=~SCK
46 #define READMISO (SPIIN&MISO?1:0)
47
48 //FIXME this should be defined by the platform.
49 #if (platform == donbfet)
50 # define SETTST PORTA|=(1 << PA4);
51 # define CLRTST PORTA&=~(1 << PA4);
52 # define SETRST PORTA|=(1 << PA5);
53 # define CLRRST PORTA&=~(1 << PA5);
54 #elif (platform == arduino)
55 //# define SETTST PORTA|=(1 << PA4);
56 //# define CLRTST PORTA&=~(1 << PA4);
57 //# define SETRST PORTA|=(1 << PA5);
58 //# define CLRRST PORTA&=~(1 << PA5);
59 #else
60 # define SETTST P4OUT|=TST
61 # define CLRTST P4OUT&=~TST
62 # define SETRST P2OUT|=RST
63 # define CLRRST P2OUT&=~RST
64 #endif
65
66 //! Set up the pins for SPI mode.
67 void spisetup();
68
69 //! Read and write an SPI byte.
70 unsigned char spitrans8(unsigned char byte);
71
72 //! Read a block to a buffer.
73 void spiflash_peekblock(unsigned long adr,
74                         unsigned char *buf,
75                         unsigned int len);
76
77
78 //! Write many blocks to the SPI Flash.
79 void spiflash_pokeblocks(unsigned long adr,
80                          unsigned char *buf,
81                          unsigned int len);
82
83
84 //! Enable SPI writing
85 void spiflash_wrten();
86
87 //! Read and write an SPI byte.
88 unsigned char spitrans8(unsigned char byte);
89 //! Grab the SPI flash status byte.
90 unsigned char spiflash_status();
91 //! Erase a sector.
92 void spiflash_erasesector(unsigned long adr);
93
94 extern app_t const spi_app;
95
96 #endif