Skip to content

Commit

Permalink
Fix OLED initialization hanging on SDK 2.1.0 (#134)
Browse files Browse the repository at this point in the history
* Fix OLED initialization hanging on SDK 2.1.0
* Disable WiFi Power Management
  • Loading branch information
tjko authored Dec 6, 2024
1 parent 6e45f87 commit e2a7fa5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)


project(fanpico
VERSION 1.7.1
VERSION 1.7.2
DESCRIPTION "FanPico - Programmable PWM (PC) Fan Controller"
HOMEPAGE_URL https://kokkonen.net/fanpico/
LANGUAGES C CXX ASM
Expand Down
2 changes: 1 addition & 1 deletion libs/ss_oled-lib
Submodule ss_oled-lib updated 4 files
+19 −8 BitBang_I2C.c
+2 −1 BitBang_I2C.h
+2 −2 ss_oled.c
+1 −1 ss_oled.h
2 changes: 1 addition & 1 deletion src/display_oled.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void oled_display_init()
do {
sleep_ms(50);
res = oledInit(&oled, dtype, -1, flip, invert, I2C_HW,
SDA_PIN, SCL_PIN, LCD_RESET_PIN, 0);
SDA_PIN, SCL_PIN, LCD_RESET_PIN, cfg->i2c_speed, true);
} while (res == OLED_NOT_FOUND && retries++ < 10);

if (res == OLED_NOT_FOUND) {
Expand Down
75 changes: 38 additions & 37 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,15 @@ void wifi_init()
log_msg(LOG_NOTICE, "Initializing WiFi...");

/* If WiFi country is defined in configuratio, use it... */
if (cfg) {
const char *country = cfg->wifi_country;
if (strlen(country) > 1) {
uint rev = 0;
if (country[2] >= '0' && country[2] <= '9') {
rev = country[2] - '0';
}
country_code = CYW43_COUNTRY(country[0], country[1], rev);
log_msg(LOG_NOTICE, "WiFi country code: %06x (%s)",
country_code, country);
const char *country = cfg->wifi_country;
if (strlen(country) > 1) {
uint rev = 0;
if (country[2] >= '0' && country[2] <= '9') {
rev = country[2] - '0';
}
country_code = CYW43_COUNTRY(country[0], country[1], rev);
log_msg(LOG_NOTICE, "WiFi country code: %06x (%s)",
country_code, country);
}

if ((res = cyw43_arch_init_with_country(country_code))) {
Expand All @@ -109,6 +107,7 @@ void wifi_init()
}

cyw43_arch_enable_sta_mode();
cyw43_wifi_pm(&cyw43_state, CYW43_NONE_PM);

cyw43_arch_lwip_begin();

Expand Down Expand Up @@ -151,34 +150,36 @@ void wifi_init()
log_msg(LOG_NOTICE, "WiFi MAC: %s", mac_address_str(cyw43_mac));

/* Attempt to connect to a WiFi network... */
if (cfg) {
if (strlen(cfg->wifi_ssid) > 0 && strlen(cfg->wifi_passwd) > 0) {
log_msg(LOG_NOTICE, "WiFi connecting to network: %s", cfg->wifi_ssid);
if (cfg->wifi_mode == 0) {
/* Default is to initiate asynchronous connection. */
res = cyw43_arch_wifi_connect_async(cfg->wifi_ssid,
cfg->wifi_passwd,
CYW43_AUTH_WPA2_AES_PSK);
} else {
/* If "SYS:WIFI:MODE 1" has been used, attempt synchronous connection
as connection to some buggy(?) APs don't seem to always work with
asynchronouse connection... */
int retries = 2;

do {
res = cyw43_arch_wifi_connect_timeout_ms(cfg->wifi_ssid,
cfg->wifi_passwd,
CYW43_AUTH_WPA2_AES_PSK,
30000);
log_msg(LOG_INFO, "cyw43_arch_wifi_connect_timeout_ms(): %d", res);
} while (res != 0 && --retries > 0);
}
if (res != 0) {
log_msg(LOG_ERR, "WiFi connect failed: %d", res);
cyw43_arch_deinit();
return;
}
if (strlen(cfg->wifi_ssid) > 0 && strlen(cfg->wifi_passwd) > 0) {
log_msg(LOG_NOTICE, "WiFi connecting to network: %s", cfg->wifi_ssid);
if (cfg->wifi_mode == 0) {
/* Default is to initiate asynchronous connection. */
res = cyw43_arch_wifi_connect_async(cfg->wifi_ssid,
cfg->wifi_passwd,
CYW43_AUTH_WPA2_AES_PSK);
} else {
/* If "SYS:WIFI:MODE 1" has been used, attempt synchronous connection
as connection to some buggy(?) APs don't seem to always work with
asynchronouse connection... */
int retries = 2;

do {
res = cyw43_arch_wifi_connect_timeout_ms(cfg->wifi_ssid,
cfg->wifi_passwd,
CYW43_AUTH_WPA3_WPA2_AES_PSK,
30000);
log_msg(LOG_INFO, "cyw43_arch_wifi_connect_timeout_ms(): %d", res);
} while (res != 0 && --retries > 0);
}
if (res != 0) {
log_msg(LOG_ERR, "WiFi connect failed: %d", res);
cyw43_arch_deinit();
return;
}
} else {
log_msg(LOG_ERR, "No WiFi SSID configured");
cyw43_arch_deinit();
return;
}

wifi_initialized = true;
Expand Down

0 comments on commit e2a7fa5

Please sign in to comment.