2
2
#include "extmod/network_cyw43.h"
3
3
#include "extmod/modnetwork.h"
4
4
#include "lib/cyw43-driver/src/cyw43.h"
5
+ #include "pico/unique_id.h"
5
6
6
7
void cyw43_irq_deinit (void );
7
8
void cyw43_irq_init (void );
@@ -16,6 +17,30 @@ extern int cyw43_set_pins_wl(uint pins[CYW43_PIN_INDEX_WL_COUNT]);
16
17
extern void cyw43_set_pio_clock_divisor (uint16_t clock_div_int , uint8_t clock_div_frac );
17
18
#endif
18
19
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
+
19
44
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 ) {
20
45
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 };
21
46
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
36
61
};
37
62
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
38
63
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 ();
39
65
40
66
// Set the pins
41
67
#if CYW43_PIN_WL_DYNAMIC
0 commit comments