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
67void cyw43_irq_deinit (void );
78void cyw43_irq_init (void );
@@ -16,6 +17,30 @@ extern int cyw43_set_pins_wl(uint pins[CYW43_PIN_INDEX_WL_COUNT]);
1617extern 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+
1944mp_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