File tree
27 files changed
+119
-152
lines changed- stmhal
- boards
- HYDRABUS
- NETDUINO_PLUS_2
- PYBV10
- PYBV3
- PYBV4
- STM32F4DISC
- cc3k
- inc
- src
27 files changed
+119
-152
lines changedLines changed: 22 additions & 19 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
22 | 22 |
| |
23 | 23 |
| |
24 | 24 |
| |
25 |
| - | |
26 | 25 |
| |
27 | 26 |
| |
28 | 27 |
| |
| |||
39 | 38 |
| |
40 | 39 |
| |
41 | 40 |
| |
42 |
| - | |
43 | 41 |
| |
44 | 42 |
| |
45 | 43 |
| |
| |||
119 | 117 |
| |
120 | 118 |
| |
121 | 119 |
| |
122 |
| - | |
123 |
| - | |
124 |
| - | |
125 | 120 |
| |
126 | 121 |
| |
127 | 122 |
| |
| |||
186 | 181 |
| |
187 | 182 |
| |
188 | 183 |
| |
189 |
| - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
190 | 206 |
| |
191 | 207 |
| |
192 | 208 |
| |
| |||
202 | 218 |
| |
203 | 219 |
| |
204 | 220 |
| |
205 |
| - | |
206 |
| - | |
207 |
| - | |
208 |
| - | |
209 |
| - | |
210 |
| - | |
211 |
| - | |
212 |
| - | |
213 |
| - | |
214 |
| - | |
215 |
| - | |
216 |
| - | |
217 | 221 |
| |
218 | 222 |
| |
219 | 223 |
| |
| |||
224 | 228 |
| |
225 | 229 |
| |
226 | 230 |
| |
227 |
| - | |
228 | 231 |
| |
229 | 232 |
| |
230 | 233 |
| |
|
Lines changed: 0 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
19 |
| - | |
20 | 19 |
| |
21 | 20 |
| |
22 | 21 |
| |
|
Lines changed: 0 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
23 |
| - | |
24 | 23 |
| |
25 | 24 |
| |
26 | 25 |
| |
|
Lines changed: 0 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
20 |
| - | |
21 | 20 |
| |
22 | 21 |
| |
23 | 22 |
| |
| |||
38 | 37 |
| |
39 | 38 |
| |
40 | 39 |
| |
41 |
| - | |
42 |
| - | |
43 |
| - | |
44 |
| - | |
45 |
| - | |
46 |
| - | |
47 |
| - |
Lines changed: 0 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
19 |
| - | |
20 | 19 |
| |
21 | 20 |
| |
22 | 21 |
| |
|
Lines changed: 0 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
19 |
| - | |
20 | 19 |
| |
21 | 20 |
| |
22 | 21 |
| |
|
Lines changed: 0 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
19 |
| - | |
20 | 19 |
| |
21 | 20 |
| |
22 | 21 |
| |
| |||
32 | 31 |
| |
33 | 32 |
| |
34 | 33 |
| |
35 |
| - | |
36 | - | ||
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
41 |
| - |
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
56 | 56 |
| |
57 | 57 |
| |
58 | 58 |
| |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 |
| |
60 | 64 |
| |
61 | 65 |
| |
|
Lines changed: 0 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
43 | 43 |
| |
44 | 44 |
| |
45 | 45 |
| |
46 |
| - | |
47 |
| - | |
48 | 46 |
| |
49 | 47 |
| |
50 | 48 |
| |
| |||
164 | 162 |
| |
165 | 163 |
| |
166 | 164 |
| |
167 |
| - |
Lines changed: 46 additions & 42 deletions
@@ -31,8 +31,6 @@
31
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
32
*
33
33
*****************************************************************************/
34
-#include "mpconfigport.h"
35
-#if MICROPY_HW_ENABLE_CC3K
36
34
37
35
#include <string.h>
38
36
@@ -44,7 +42,6 @@
44
42
#include "obj.h"
45
43
#include "runtime.h"
46
44
#include "pin.h"
47
-#include "genhdr/pins.h"
48
45
#include "led.h"
49
46
#include "extint.h"
50
47
#include "spi.h"
@@ -58,14 +55,14 @@
58
55
#define DEBUG_printf(args...) (void)0
59
56
#endif
60
57
61
-#define PIN_CS MICROPY_HW_WLAN_PIN_CS
62
-#define PIN_EN MICROPY_HW_WLAN_PIN_EN
63
-#define PIN_IRQ MICROPY_HW_WLAN_PIN_IRQ
64
-#define SPI_HANDLE MICROPY_HW_WLAN_SPI_HANDLE
65
-#define IRQ_LINE MICROPY_HW_WLAN_IRQ_LINE
58
+// these need to be set to valid values before anything in this file will work
59
+STATIC SPI_HandleTypeDef *SPI_HANDLE = NULL;
60
+STATIC const pin_obj_t *PIN_CS = NULL;
61
+STATIC const pin_obj_t *PIN_EN = NULL;
62
+STATIC const pin_obj_t *PIN_IRQ = NULL;
66
63
67
-#define CS_LOW() HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_RESET)
68
-#define CS_HIGH() HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_SET)
64
+#define CS_LOW() HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_RESET)
65
+#define CS_HIGH() HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET)
69
66
70
67
#define READ 3
71
68
#define WRITE 1
@@ -106,10 +103,19 @@ tSpiInformation sSpiInformation;
106
103
char spi_buffer[CC3000_RX_BUFFER_SIZE];
107
104
unsigned char wlan_tx_buffer[CC3000_TX_BUFFER_SIZE];
108
105
109
-static const mp_obj_fun_native_t irq_callback_obj;
106
+STATIC const mp_obj_fun_builtin_t irq_callback_obj;
110
107
void SpiWriteDataSynchronous(unsigned char *data, unsigned short size);
111
108
void SpiReadDataSynchronous(unsigned char *data, unsigned short size);
112
109
110
+// set the pins to use to communicate with the CC3000
111
+// the arguments must be of type pin_obj_t* and SPI_HandleTypeDef*
112
+void SpiInit(void *spi, const void *pin_cs, const void *pin_en, const void *pin_irq) {
113
+ SPI_HANDLE = spi;
114
+ PIN_CS = pin_cs;
115
+ PIN_EN = pin_en;
116
+ PIN_IRQ = pin_irq;
117
+}
118
+
113
119
void SpiClose(void)
114
120
{
115
121
if (sSpiInformation.pRxPacket) {
@@ -118,7 +124,7 @@ void SpiClose(void)
118
124
119
125
tSLInformation.WlanInterruptDisable();
120
126
121
- //HAL_SPI_DeInit(&SPI_HANDLE);
127
+ //HAL_SPI_DeInit(SPI_HANDLE);
122
128
}
123
129
124
130
void SpiOpen(gcSpiHandleRx pfRxHandler)
@@ -136,18 +142,18 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
136
142
wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
137
143
138
144
/* SPI configuration */
139
- SPI_HANDLE.Init.Mode = SPI_MODE_MASTER;
140
- SPI_HANDLE.Init.Direction = SPI_DIRECTION_2LINES;
141
- SPI_HANDLE.Init.DataSize = SPI_DATASIZE_8BIT;
142
- SPI_HANDLE.Init.CLKPolarity = SPI_POLARITY_LOW;
143
- SPI_HANDLE.Init.CLKPhase = SPI_PHASE_2EDGE;
144
- SPI_HANDLE.Init.NSS = SPI_NSS_SOFT;
145
- SPI_HANDLE.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
146
- SPI_HANDLE.Init.FirstBit = SPI_FIRSTBIT_MSB;
147
- SPI_HANDLE.Init.TIMode = SPI_TIMODE_DISABLED;
148
- SPI_HANDLE.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
149
- SPI_HANDLE.Init.CRCPolynomial = 7;
150
- spi_init(&SPI_HANDLE);
145
+ SPI_HANDLE->Init.Mode = SPI_MODE_MASTER;
146
+ SPI_HANDLE->Init.Direction = SPI_DIRECTION_2LINES;
147
+ SPI_HANDLE->Init.DataSize = SPI_DATASIZE_8BIT;
148
+ SPI_HANDLE->Init.CLKPolarity = SPI_POLARITY_LOW;
149
+ SPI_HANDLE->Init.CLKPhase = SPI_PHASE_2EDGE;
150
+ SPI_HANDLE->Init.NSS = SPI_NSS_SOFT;
151
+ SPI_HANDLE->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
152
+ SPI_HANDLE->Init.FirstBit = SPI_FIRSTBIT_MSB;
153
+ SPI_HANDLE->Init.TIMode = SPI_TIMODE_DISABLED;
154
+ SPI_HANDLE->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
155
+ SPI_HANDLE->Init.CRCPolynomial = 7;
156
+ spi_init(SPI_HANDLE);
151
157
152
158
// configure wlan CS and EN pins
153
159
GPIO_InitTypeDef GPIO_InitStructure;
@@ -156,48 +162,48 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
156
162
GPIO_InitStructure.Pull = GPIO_NOPULL;
157
163
GPIO_InitStructure.Alternate = 0;
158
164
159
- GPIO_InitStructure.Pin = PIN_CS.pin_mask;
160
- HAL_GPIO_Init(PIN_CS.gpio, &GPIO_InitStructure);
165
+ GPIO_InitStructure.Pin = PIN_CS->pin_mask;
166
+ HAL_GPIO_Init(PIN_CS->gpio, &GPIO_InitStructure);
161
167
162
- GPIO_InitStructure.Pin = PIN_EN.pin_mask;
163
- HAL_GPIO_Init(PIN_EN.gpio, &GPIO_InitStructure);
168
+ GPIO_InitStructure.Pin = PIN_EN->pin_mask;
169
+ HAL_GPIO_Init(PIN_EN->gpio, &GPIO_InitStructure);
164
170
165
- HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_SET);
166
- HAL_GPIO_WritePin(PIN_EN.gpio, PIN_EN.pin_mask, GPIO_PIN_RESET);
171
+ HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET);
172
+ HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask, GPIO_PIN_RESET);
167
173
168
174
/* do a dummy read, this ensures SCLK is low before
169
175
actual communications start, it might be required */
170
176
CS_LOW();
171
177
uint8_t buf[1];
172
- HAL_SPI_Receive(&SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
178
+ HAL_SPI_Receive(SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
173
179
CS_HIGH();
174
180
175
181
// register EXTI
176
- extint_register((mp_obj_t)&PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
177
- extint_enable(IRQ_LINE);
182
+ extint_register((mp_obj_t)PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
183
+ extint_enable(PIN_IRQ->pin);
178
184
179
- DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ.pin, IRQ_LINE);
185
+ DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ->pin, PIN_IRQ->pin);
180
186
}
181
187
182
188
183
189
void SpiPauseSpi(void)
184
190
{
185
- extint_disable(IRQ_LINE);
191
+ extint_disable(PIN_IRQ->pin);
186
192
}
187
193
188
194
void SpiResumeSpi(void)
189
195
{
190
- extint_enable(IRQ_LINE);
196
+ extint_enable(PIN_IRQ->pin);
191
197
}
192
198
193
199
long ReadWlanInterruptPin(void)
194
200
{
195
- return HAL_GPIO_ReadPin(PIN_IRQ.gpio, PIN_IRQ.pin_mask);
201
+ return HAL_GPIO_ReadPin(PIN_IRQ->gpio, PIN_IRQ->pin_mask);
196
202
}
197
203
198
204
void WriteWlanPin(unsigned char val)
199
205
{
200
- HAL_GPIO_WritePin(PIN_EN.gpio, PIN_EN.pin_mask,
206
+ HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask,
201
207
(WLAN_ENABLE)? GPIO_PIN_SET:GPIO_PIN_RESET);
202
208
}
203
209
@@ -306,7 +312,7 @@ void SpiWriteDataSynchronous(unsigned char *data, unsigned short size)
306
312
{
307
313
DEBUG_printf("SpiWriteDataSynchronous(data=%p [%x %x %x %x], size=%u)\n", data, data[0], data[1], data[2], data[3], size);
308
314
__disable_irq();
309
- if (HAL_SPI_TransmitReceive(&SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
315
+ if (HAL_SPI_TransmitReceive(SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
310
316
//BREAK();
311
317
}
312
318
__enable_irq();
@@ -317,7 +323,7 @@ void SpiReadDataSynchronous(unsigned char *data, unsigned short size)
317
323
{
318
324
memset(data, READ, size);
319
325
__disable_irq();
320
- if (HAL_SPI_TransmitReceive(&SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
326
+ if (HAL_SPI_TransmitReceive(SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
321
327
//BREAK();
322
328
}
323
329
__enable_irq();
@@ -453,5 +459,3 @@ STATIC mp_obj_t irq_callback(mp_obj_t line)
453
459
}
454
460
455
461
STATIC MP_DEFINE_CONST_FUN_OBJ_1(irq_callback_obj, irq_callback);
456
-
457
-#endif // MICROPY_HW_ENABLE_CC3K
Lines changed: 0 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
42 | 42 |
| |
43 | 43 |
| |
44 | 44 |
| |
45 |
| - | |
46 |
| - | |
47 | 45 |
| |
48 | 46 |
| |
49 | 47 |
| |
| |||
849 | 847 |
| |
850 | 848 |
| |
851 | 849 |
| |
852 |
| - |
Lines changed: 0 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
39 | 39 |
| |
40 | 40 |
| |
41 | 41 |
| |
42 |
| - | |
43 |
| - | |
44 | 42 |
| |
45 | 43 |
| |
46 | 44 |
| |
| |||
225 | 223 |
| |
226 | 224 |
| |
227 | 225 |
| |
228 |
| - |
0 commit comments