Skip to content

Commit e7fa222

Browse files
committed
Setup Yukon to use dynamic wireless pins
1 parent 1658744 commit e7fa222

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

examples/modules/rm2_wireless/cheerlights.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
import network
32
import requests
43
from pimoroni_yukon import Yukon
54
from pimoroni_yukon import SLOT2 as STRIP_SLOT
@@ -51,7 +50,7 @@
5150
yukon.register_with_slot(wireless, RM2_SLOT) # Register the RM2WirelessModule object with the slot
5251
yukon.verify_and_initialise() # Verify that the modules are attached to Yukon, and initialise them
5352

54-
wlan = network.WLAN(network.STA_IF) # Create a new network object for interacting with WiFi
53+
wlan = wireless.WLAN(wireless.STA_IF) # Create a new network object for interacting with WiFi
5554
wlan.active(True) # Turn on WLAN communications
5655

5756
# Connect to WLAN
@@ -98,9 +97,3 @@
9897
finally:
9998
# Put the board back into a safe state, regardless of how the program may have ended
10099
yukon.reset()
101-
102-
# Attempt to disconnect from WiFi
103-
try:
104-
wlan.disconnect()
105-
except Exception:
106-
pass

examples/modules/rm2_wireless/wifi_scan.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
import network
32
import binascii
43
from pimoroni_yukon import Yukon
54
from pimoroni_yukon import SLOT5 as SLOT
@@ -17,16 +16,16 @@
1716

1817
# Variables
1918
yukon = Yukon() # Create a new Yukon object, with a lower voltage limit set
20-
module = RM2WirelessModule() # Create a RM2WirelessModule object
19+
wireless = RM2WirelessModule() # Create a RM2WirelessModule object
2120

2221

2322
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt)
2423
try:
25-
yukon.register_with_slot(module, SLOT) # Register the RM2WirelessModule object with the slot
26-
yukon.verify_and_initialise() # Verify that a RM2WirelessModule is attached to Yukon, and initialise it
24+
yukon.register_with_slot(wireless, SLOT) # Register the RM2WirelessModule object with the slot
25+
yukon.verify_and_initialise() # Verify that a RM2WirelessModule is attached to Yukon, and initialise it
2726

28-
wlan = network.WLAN(network.STA_IF) # Create a new network object for interacting with WiFi
29-
wlan.active(True) # Turn on WLAN communications
27+
wlan = wireless.WLAN(wireless.STA_IF) # Create a new network object for interacting with WiFi
28+
wlan.active(True) # Turn on WLAN communications
3029

3130
while not yukon.is_boot_pressed():
3231
# Scan for nearby networks and print them out
@@ -41,9 +40,3 @@
4140
finally:
4241
# Put the board back into a safe state, regardless of how the program may have ended
4342
yukon.reset()
44-
45-
# Attempt to disconnect from WiFi
46-
try:
47-
wlan.disconnect()
48-
except Exception:
49-
pass

firmware/PIMORONI_YUKON_W/board.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,7 @@ void board_init() {
1616
}
1717

1818
void board_reset(void) {
19-
for (int i = 0; i < 16; ++i) {
20-
gpio_init(i);
21-
hw_clear_bits(&pads_bank0_hw->io[i], PADS_BANK0_GPIO0_IE_BITS |
22-
PADS_BANK0_GPIO0_PUE_BITS |
23-
PADS_BANK0_GPIO0_PDE_BITS);
24-
hw_set_bits(&pads_bank0_hw->io[i], PADS_BANK0_GPIO0_OD_BITS);
25-
}
26-
27-
// Skip over SLOT 5
28-
29-
for (int i = 20; i < 24; ++i) {
19+
for (int i = 0; i < 24; ++i) {
3020
gpio_init(i);
3121
hw_clear_bits(&pads_bank0_hw->io[i], PADS_BANK0_GPIO0_IE_BITS |
3222
PADS_BANK0_GPIO0_PUE_BITS |

firmware/PIMORONI_YUKON_W/pimoroni_yukon_w.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
#endif
7878

7979
// --- WIRELESS ---
80-
// cyw43 SPI pins can't be changed at runtime
80+
// cyw43 SPI pins can be changed at runtime
8181
#ifndef CYW43_PIN_WL_DYNAMIC
82-
#define CYW43_PIN_WL_DYNAMIC 0
82+
#define CYW43_PIN_WL_DYNAMIC 1
8383
#endif
8484

8585
// gpio pin to power up the cyw43 chip

lib/pimoroni_yukon/modules/rm2_wireless.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
class RM2WirelessModule(YukonModule):
99
NAME = "RM2 Wireless"
1010

11+
STA_IF = 0
12+
AP_IF = 1
13+
1114
# | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
1215
# |-------|-------|-------|-------|-------|----------------------|-----------------------------|
1316
# | LOW | FLOAT | 1 | 0 | 1 | RM2 Wireless | |
@@ -23,9 +26,30 @@ def __init__(self):
2326
except ImportError:
2427
raise RuntimeError("This build does not contain wireless networking support. Please flash your Yukon with a build that supports wireless in order to use this module.")
2528

29+
self.__network = network
30+
2631
def initialise(self, slot, adc1_func, adc2_func):
27-
if slot.ID != 5:
28-
raise RuntimeError("Currently the wireless module is only supported in Slot 5. Please relocate your module.")
32+
self.__wl_on = slot.FAST1
33+
self.__wl_cs = slot.FAST2
34+
self.__wl_sck = slot.FAST3
35+
self.__wl_dat = slot.FAST4
2936

3037
# Pass the slot and adc functions up to the parent now that module specific initialisation has finished
3138
super().initialise(slot, adc1_func, adc2_func)
39+
40+
def reset(self):
41+
# Attempt to disconnect from WiFi
42+
try:
43+
self.__wlan.disconnect()
44+
except Exception:
45+
pass
46+
47+
def WLAN(self, interface_id):
48+
self.__wlan = self.__network.WLAN(interface_id,
49+
pin_on=self.__wl_on,
50+
pin_out=self.__wl_dat,
51+
pin_in=self.__wl_dat,
52+
pin_wake=self.__wl_dat,
53+
pin_clock=self.__wl_sck,
54+
pin_cs=self.__wl_cs)
55+
return self.__wlan

0 commit comments

Comments
 (0)