|
@@ -564,7 +564,38 @@ static bool should_stay_in_bootloader()
|
564
|
564
|
return !gpio_get(BOOTLOADER_ENTRY_PIN) || wd_says_so;
|
565
|
565
|
}
|
566
|
566
|
|
567
|
|
-static void network_deinit()
|
|
567
|
+int __attribute__((weak)) picowota_network_init()
|
|
568
|
+{
|
|
569
|
+ if (cyw43_arch_init()) {
|
|
570
|
+ DBG_PRINTF("failed to initialise\n");
|
|
571
|
+ return 1;
|
|
572
|
+ }
|
|
573
|
+
|
|
574
|
+#if PICOWOTA_WIFI_AP == 1
|
|
575
|
+ cyw43_arch_enable_ap_mode(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK);
|
|
576
|
+ DBG_PRINTF("Enabled the WiFi AP.\n");
|
|
577
|
+
|
|
578
|
+ ip4_addr_t gw, mask;
|
|
579
|
+ IP4_ADDR(&gw, 192, 168, 4, 1);
|
|
580
|
+ IP4_ADDR(&mask, 255, 255, 255, 0);
|
|
581
|
+
|
|
582
|
+ dhcp_server_init(&dhcp_server, &gw, &mask);
|
|
583
|
+ DBG_PRINTF("Started the DHCP server.\n");
|
|
584
|
+#else
|
|
585
|
+ cyw43_arch_enable_sta_mode();
|
|
586
|
+
|
|
587
|
+ DBG_PRINTF("Connecting to WiFi...\n");
|
|
588
|
+ if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
|
|
589
|
+ DBG_PRINTF("failed to connect.\n");
|
|
590
|
+ return 1;
|
|
591
|
+ } else {
|
|
592
|
+ DBG_PRINTF("Connected.\n");
|
|
593
|
+ }
|
|
594
|
+#endif
|
|
595
|
+ return 0;
|
|
596
|
+}
|
|
597
|
+
|
|
598
|
+void __attribute__((weak)) picowota_network_deinit()
|
568
|
599
|
{
|
569
|
600
|
#if PICOWOTA_WIFI_AP == 1
|
570
|
601
|
dhcp_server_deinit(&dhcp_server);
|
|
@@ -593,34 +624,11 @@ int main()
|
593
|
624
|
|
594
|
625
|
queue_init(&event_queue, sizeof(struct event), EVENT_QUEUE_LENGTH);
|
595
|
626
|
|
596
|
|
- if (cyw43_arch_init()) {
|
597
|
|
- DBG_PRINTF("failed to initialise\n");
|
598
|
|
- return 1;
|
|
627
|
+ int n = picowota_network_init();
|
|
628
|
+ if (n != 0) {
|
|
629
|
+ return n;
|
599
|
630
|
}
|
600
|
631
|
|
601
|
|
-#if PICOWOTA_WIFI_AP == 1
|
602
|
|
- cyw43_arch_enable_ap_mode(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK);
|
603
|
|
- DBG_PRINTF("Enabled the WiFi AP.\n");
|
604
|
|
-
|
605
|
|
- ip4_addr_t gw, mask;
|
606
|
|
- IP4_ADDR(&gw, 192, 168, 4, 1);
|
607
|
|
- IP4_ADDR(&mask, 255, 255, 255, 0);
|
608
|
|
-
|
609
|
|
- dhcp_server_t dhcp_server;
|
610
|
|
- dhcp_server_init(&dhcp_server, &gw, &mask);
|
611
|
|
- DBG_PRINTF("Started the DHCP server.\n");
|
612
|
|
-#else
|
613
|
|
- cyw43_arch_enable_sta_mode();
|
614
|
|
-
|
615
|
|
- DBG_PRINTF("Connecting to WiFi...\n");
|
616
|
|
- if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
|
617
|
|
- DBG_PRINTF("failed to connect.\n");
|
618
|
|
- return 1;
|
619
|
|
- } else {
|
620
|
|
- DBG_PRINTF("Connected.\n");
|
621
|
|
- }
|
622
|
|
-#endif
|
623
|
|
-
|
624
|
632
|
critical_section_init(&critical_section);
|
625
|
633
|
|
626
|
634
|
const struct comm_command *cmds[] = {
|
|
@@ -655,13 +663,13 @@ int main()
|
655
|
663
|
break;
|
656
|
664
|
case EVENT_TYPE_REBOOT:
|
657
|
665
|
tcp_comm_server_close(tcp);
|
658
|
|
- network_deinit();
|
|
666
|
+ picowota_network_deinit();
|
659
|
667
|
picowota_reboot(ev.reboot.to_bootloader);
|
660
|
668
|
|
661
|
669
|
break;
|
662
|
670
|
case EVENT_TYPE_GO:
|
663
|
671
|
tcp_comm_server_close(tcp);
|
664
|
|
- network_deinit();
|
|
672
|
+ picowota_network_deinit();
|
665
|
673
|
disable_interrupts();
|
666
|
674
|
reset_peripherals();
|
667
|
675
|
jump_to_vtor(ev.go.vtor);
|
|
@@ -674,6 +682,6 @@ int main()
|
674
|
682
|
sleep_ms(5);
|
675
|
683
|
}
|
676
|
684
|
|
677
|
|
- network_deinit();
|
|
685
|
+ picowota_network_deinit();
|
678
|
686
|
return 0;
|
679
|
687
|
}
|