@@ -13,7 +13,9 @@ extern "C" {
13
13
#define SLAVESELECT 10 // ss
14
14
#define SLAVEREADY 3
15
15
16
- #define DELAY_100NS asm volatile (" nop" )
16
+ #define DELAY_100NS do { asm volatile (" nop" ); }while (0 );
17
+ #define DELAY_SPI (X ) { int ii=0 ; do { asm volatile (" nop" ); }while (++ii<X);}
18
+ #define DELAY_TRANSFER () DELAY_SPI(10 )
17
19
18
20
void SpiDrv::begin ()
19
21
{
@@ -78,9 +80,8 @@ char SpiDrv::spiTransfer(volatile char data)
78
80
{
79
81
};
80
82
char result = SPDR;
81
- DELAY_100NS;
82
- DELAY_100NS;
83
- // delayMicroseconds(SPI_TX_DELAY);
83
+ DELAY_TRANSFER ();
84
+
84
85
return result; // return the received byte
85
86
}
86
87
@@ -99,25 +100,8 @@ int SpiDrv::waitSpiChar(unsigned char waitChar)
99
100
return (_readChar == waitChar);
100
101
}
101
102
102
- // int SpiDrv::waitSpiChar(char waitChar, char* readChar)
103
- // {
104
- // int timeout = TIMEOUT_CHAR;
105
- // do{
106
- // *readChar = spiTransfer(DUMMY_DATA); //get data byte
107
- // if (*readChar == WAIT_CMD)
108
- // {
109
- // INFO1("WAIT");
110
- // delayMicroseconds(WAIT_CHAR_DELAY);
111
- // }
112
- // }while((timeout-- > 0) && (*readChar != waitChar));
113
- //
114
- // return (*readChar == waitChar);
115
- // }
116
-
117
-
118
103
int SpiDrv::readAndCheckChar (char checkChar, char * readChar)
119
104
{
120
- // *readChar = spiTransfer(DUMMY_DATA); //get data byte
121
105
getParam ((uint8_t *)readChar);
122
106
123
107
return (*readChar == checkChar);
@@ -128,11 +112,8 @@ char SpiDrv::readChar()
128
112
uint8_t readChar = 0 ;
129
113
getParam (&readChar);
130
114
return readChar;
131
- // return spiTransfer(DUMMY_DATA); //get data byte
132
115
}
133
116
134
- // #define WAIT_START_CMD(x) waitSpiChar(START_CMD, &x)
135
- // #define WAIT_START_CMD(x) readAndCheckChar(START_CMD, &x)
136
117
#define WAIT_START_CMD (x ) waitSpiChar(START_CMD)
137
118
138
119
#define IF_CHECK_START_CMD (x ) \
@@ -171,10 +152,7 @@ void SpiDrv::getParam(uint8_t* param)
171
152
{
172
153
// Get Params data
173
154
*param = spiTransfer (DUMMY_DATA);
174
- DELAY_100NS;
175
- DELAY_100NS;
176
- DELAY_100NS;
177
- DELAY_100NS;
155
+ DELAY_TRANSFER ();
178
156
}
179
157
180
158
int SpiDrv::waitResponseCmd (uint8_t cmd, uint8_t numParam, uint8_t * param, uint8_t * param_len)
0 commit comments