libspiasm  0.5
SPI Driver
 All Data Structures Files Functions Variables Typedefs Macros
spiasm.h
Go to the documentation of this file.
1 
26 // -- In spi_in the number 2 is shifted left 16 bits, this is or'd with the address of the Dpin.
27 // -- In spi_out, the number 1 is shifted left 16 bits, and or'd with the address of the Dpin.
28 
29 #ifndef spiasm_H
30 #define spiasm_H
31 
32 #if defined(__cplusplus)
33 extern "C" {
34 #endif
35 
36 #include "simpletools.h" // Library includes
37 
38 #define _Title_ 0
39  // For receiving data from SPI device (spi_in)
40 
41 #define MPRE 0
42 #define LPRE 1
43 #define MPOST 2
44 #define LPOST 3
45 
46  // For sending data to SPI device (spi_out)
47 
48 #define LFIRST 4
49 #define MFIRST 5
50 
51 typedef struct spi_struct // Structure defines variable order in memory
52  { // each variable address is 1 long from previous
53  volatile int command;
54  int Dpin;
55  int Cpin;
56  volatile int Mode;
57  volatile int Bits;
58  volatile int Value;
59  volatile int Flag;
60  int cog;
61  } spia_t;
62 
63 // function prototypes
64 
65  // these prototypes go in library h file (spi.h)
80 spia_t *spi_start(int clockdelay_ns, int clockstate);
81 
86 void spi_stop(spia_t *device);
87 
97 void spi_out(spia_t *device, int DQ, int CLK, int MD, int BIT, int VLU);
98 
108 int spi_in(spia_t *device,int DQ, int CLK, int MD, int BIT);
109 
110 #if defined(__cplusplus)
111 }
112 #endif
113 /* __cplusplus */
114 #endif
115 
116 /* spiasm_H */
117 
volatile int Mode
SPI Mode (0 - 5).
Definition: spiasm.h:56
int spi_in(spia_t *device, int DQ, int CLK, int MD, int BIT)
Receive data from SPI device.
Definition: spiasm.c:64
void spi_stop(spia_t *device)
Stop and Release Cog.
Definition: spiasm.c:38
volatile int command
packed SHIFTIN/SHIFTOUT command and address of Dpin
Definition: spiasm.h:53
volatile int Flag
0 = Data shift to Prop complete, 1 = in progress
Definition: spiasm.h:59
volatile int Value
Data sent or received.
Definition: spiasm.h:58
volatile int Bits
Bits to send or receive.
Definition: spiasm.h:57
void spi_out(spia_t *device, int DQ, int CLK, int MD, int BIT, int VLU)
Send data to SPI device.
Definition: spiasm.c:51
spia_t * spi_start(int clockdelay_ns, int clockstate)
Starts the spi cog, loads ClockState and ClockDelay PASM variables.
Definition: spiasm.c:19
int Dpin
Propeller pin for Data-in or Data-out.
Definition: spiasm.h:54
int Cpin
Propeller pin for Clock.
Definition: spiasm.h:55
struct spi_struct spia_t
Data type for struct.
Definition: spiasm.h:51
int cog
Remembers cog for spi_stop.
Definition: spiasm.h:60