Skip to content

Commit cc00c33

Browse files
committed
rp2: Move cyw43 code from main.
The "init" code can now be added to rp2_network_cyw43_make_new. Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
1 parent 8f426fa commit cc00c33

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

ports/rp2/main.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,11 @@
4949

5050
#include "pico/stdlib.h"
5151
#include "pico/binary_info.h"
52-
#include "pico/unique_id.h"
5352
#include "hardware/structs/rosc.h"
5453
#if MICROPY_PY_LWIP
5554
#include "lwip/init.h"
5655
#include "lwip/apps/mdns.h"
5756
#endif
58-
#if MICROPY_PY_NETWORK_CYW43
59-
#include "lib/cyw43-driver/src/cyw43.h"
60-
#endif
6157
#if PICO_RP2040
6258
#include "RP2040.h" // cmsis, for PendSV_IRQn and SCB/SCB_SCR_SEVONPEND_Msk
6359
#elif PICO_RP2350 && PICO_ARM
@@ -131,28 +127,6 @@ int main(int argc, char **argv) {
131127
#endif
132128
#endif
133129

134-
#if MICROPY_PY_NETWORK_CYW43 || MICROPY_PY_BLUETOOTH_CYW43
135-
{
136-
cyw43_init(&cyw43_state);
137-
cyw43_irq_init();
138-
cyw43_post_poll_hook(); // enable the irq
139-
uint8_t buf[8];
140-
memcpy(&buf[0], "PICO", 4);
141-
142-
// MAC isn't loaded from OTP yet, so use unique id to generate the default AP ssid.
143-
const char hexchr[16] = "0123456789ABCDEF";
144-
pico_unique_board_id_t pid;
145-
pico_get_unique_board_id(&pid);
146-
buf[4] = hexchr[pid.id[7] >> 4];
147-
buf[5] = hexchr[pid.id[6] & 0xf];
148-
buf[6] = hexchr[pid.id[5] >> 4];
149-
buf[7] = hexchr[pid.id[4] & 0xf];
150-
cyw43_wifi_ap_set_ssid(&cyw43_state, 8, buf);
151-
cyw43_wifi_ap_set_auth(&cyw43_state, CYW43_AUTH_WPA2_AES_PSK);
152-
cyw43_wifi_ap_set_password(&cyw43_state, 8, (const uint8_t *)"picoW123");
153-
}
154-
#endif
155-
156130
// Hook for setting up anything that can wait until after other hardware features are initialised.
157131
MICROPY_BOARD_EARLY_INIT();
158132

ports/rp2/rp2_network_cyw43.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "extmod/network_cyw43.h"
33
#include "extmod/modnetwork.h"
44
#include "lib/cyw43-driver/src/cyw43.h"
5+
#include "pico/unique_id.h"
56

67
void cyw43_irq_deinit(void);
78
void cyw43_irq_init(void);
@@ -16,6 +17,30 @@ extern int cyw43_set_pins_wl(uint pins[CYW43_PIN_INDEX_WL_COUNT]);
1617
extern void cyw43_set_pio_clock_divisor(uint16_t clock_div_int, uint8_t clock_div_frac);
1718
#endif
1819

20+
static void rp2_network_cyw43_init(void) {
21+
static bool cyw43_init_done;
22+
if (!cyw43_init_done) {
23+
cyw43_init(&cyw43_state);
24+
cyw43_irq_init();
25+
cyw43_post_poll_hook(); // enable the irq
26+
cyw43_init_done = true;
27+
}
28+
uint8_t buf[8];
29+
memcpy(&buf[0], "PICO", 4);
30+
31+
// Use unique id to generate the default AP ssid.
32+
const char hexchr[16] = "0123456789ABCDEF";
33+
pico_unique_board_id_t pid;
34+
pico_get_unique_board_id(&pid);
35+
buf[4] = hexchr[pid.id[7] >> 4];
36+
buf[5] = hexchr[pid.id[6] & 0xf];
37+
buf[6] = hexchr[pid.id[5] >> 4];
38+
buf[7] = hexchr[pid.id[4] & 0xf];
39+
cyw43_wifi_ap_set_ssid(&cyw43_state, 8, buf);
40+
cyw43_wifi_ap_set_auth(&cyw43_state, CYW43_AUTH_WPA2_AES_PSK);
41+
cyw43_wifi_ap_set_password(&cyw43_state, 8, (const uint8_t *)"picoW123");
42+
}
43+
1944
mp_obj_t rp2_network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
2045
enum { ARG_interface, ARG_pin_on, ARG_pin_out, ARG_pin_in, ARG_pin_wake, ARG_pin_clock, ARG_pin_cs, ARG_pin_dat, ARG_div_int, ARG_div_frac };
2146
static const mp_arg_t allowed_args[] = {
@@ -36,6 +61,7 @@ mp_obj_t rp2_network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, si
3661
};
3762
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
3863
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
64+
rp2_network_cyw43_init();
3965

4066
// Set the pins
4167
#if CYW43_PIN_WL_DYNAMIC

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy