Skip to content

Commit 0aac3bc

Browse files
committed
Merge branch 'master' into pico2_w_changes
2 parents 34f936a + 594670e commit 0aac3bc

File tree

5 files changed

+70
-24
lines changed

5 files changed

+70
-24
lines changed

extmod/nimble/modbluetooth_nimble.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,24 +1911,21 @@ static int ble_secret_store_read(int obj_type, const union ble_store_key *key, u
19111911
// <type=peer,addr,*> (single)
19121912
// Find the entry for this specific peer.
19131913
assert(key->sec.idx == 0);
1914-
assert(!key->sec.ediv_rand_present);
19151914
key_data = (const uint8_t *)&key->sec.peer_addr;
19161915
key_data_len = sizeof(ble_addr_t);
19171916
} else {
19181917
// <type=peer,*> (with index)
19191918
// Iterate all known peers.
1920-
assert(!key->sec.ediv_rand_present);
19211919
key_data = NULL;
19221920
key_data_len = 0;
19231921
}
19241922
break;
19251923
}
19261924
case BLE_STORE_OBJ_TYPE_OUR_SEC: {
1927-
// <type=our,addr,ediv_rand>
1928-
// Find our secret for this remote device, matching this ediv/rand key.
1925+
// <type=our,addr,*>
1926+
// Find our secret for this remote device.
19291927
assert(ble_addr_cmp(&key->sec.peer_addr, BLE_ADDR_ANY)); // Must have address.
19301928
assert(key->sec.idx == 0);
1931-
assert(key->sec.ediv_rand_present);
19321929
key_data = (const uint8_t *)&key->sec.peer_addr;
19331930
key_data_len = sizeof(ble_addr_t);
19341931
break;
@@ -1958,10 +1955,6 @@ static int ble_secret_store_read(int obj_type, const union ble_store_key *key, u
19581955

19591956
DEBUG_printf("ble_secret_store_read: found secret\n");
19601957

1961-
if (obj_type == BLE_STORE_OBJ_TYPE_OUR_SEC) {
1962-
// TODO: Verify ediv_rand matches.
1963-
}
1964-
19651958
return 0;
19661959
}
19671960

@@ -1970,14 +1963,13 @@ static int ble_secret_store_write(int obj_type, const union ble_store_value *val
19701963
switch (obj_type) {
19711964
case BLE_STORE_OBJ_TYPE_PEER_SEC:
19721965
case BLE_STORE_OBJ_TYPE_OUR_SEC: {
1973-
// <type=peer,addr,edivrand>
1966+
// <type=peer,addr,*>
19741967

19751968
struct ble_store_key_sec key_sec;
19761969
const struct ble_store_value_sec *value_sec = &val->sec;
19771970
ble_store_key_from_value_sec(&key_sec, value_sec);
19781971

19791972
assert(ble_addr_cmp(&key_sec.peer_addr, BLE_ADDR_ANY)); // Must have address.
1980-
assert(key_sec.ediv_rand_present);
19811973

19821974
if (!mp_bluetooth_gap_on_set_secret(obj_type, (const uint8_t *)&key_sec.peer_addr, sizeof(ble_addr_t), (const uint8_t *)value_sec, sizeof(struct ble_store_value_sec))) {
19831975
DEBUG_printf("Failed to write key: type=%d\n", obj_type);
@@ -2005,9 +1997,7 @@ static int ble_secret_store_delete(int obj_type, const union ble_store_key *key)
20051997
case BLE_STORE_OBJ_TYPE_PEER_SEC:
20061998
case BLE_STORE_OBJ_TYPE_OUR_SEC: {
20071999
// <type=peer,addr,*>
2008-
20092000
assert(ble_addr_cmp(&key->sec.peer_addr, BLE_ADDR_ANY)); // Must have address.
2010-
// ediv_rand is optional (will not be present for delete).
20112001

20122002
if (!mp_bluetooth_gap_on_set_secret(obj_type, (const uint8_t *)&key->sec.peer_addr, sizeof(ble_addr_t), NULL, 0)) {
20132003
DEBUG_printf("Failed to delete key: type=%d\n", obj_type);

ports/esp32/machine_pwm.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@
3434
#include "py/mphal.h"
3535
#include "driver/ledc.h"
3636
#include "esp_err.h"
37-
#include "esp_clk_tree.h"
3837
#include "soc/gpio_sig_map.h"
3938

39+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
40+
#include "esp_clk_tree.h"
41+
#endif
42+
4043
#define PWM_DBG(...)
4144
// #define PWM_DBG(...) mp_printf(&mp_plat_print, __VA_ARGS__); mp_printf(&mp_plat_print, "\n");
4245

@@ -208,7 +211,41 @@ static void configure_channel(machine_pwm_obj_t *self) {
208211
}
209212
}
210213

214+
// Temporary workaround for ledc_find_suitable_duty_resolution function only being added in IDF V5.2
215+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
216+
static uint32_t ledc_find_suitable_duty_resolution(uint32_t src_clk_freq, uint32_t timer_freq) {
217+
// This implementation is based on the one used in Micropython v1.23
218+
219+
// Find the highest bit resolution for the requested frequency
220+
unsigned int freq = src_clk_freq;
221+
222+
int divider = (freq + timer_freq / 2) / timer_freq; // rounded
223+
if (divider == 0) {
224+
divider = 1;
225+
}
226+
float f = (float)freq / divider; // actual frequency
227+
if (f <= 1.0) {
228+
f = 1.0;
229+
}
230+
freq = (unsigned int)roundf((float)freq / f);
231+
232+
unsigned int res = 0;
233+
for (; freq > 1; freq >>= 1) {
234+
++res;
235+
}
236+
if (res == 0) {
237+
res = 1;
238+
} else if (res > HIGHEST_PWM_RES) {
239+
// Limit resolution to HIGHEST_PWM_RES to match units of our duty
240+
res = HIGHEST_PWM_RES;
241+
}
242+
243+
return res;
244+
}
245+
#endif
246+
211247
static void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_config_t *timer) {
248+
esp_err_t err;
212249
if (freq != timer->freq_hz) {
213250
// Configure the new frequency and resolution
214251
timer->freq_hz = freq;
@@ -228,10 +265,21 @@ static void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
228265
}
229266
#endif
230267
uint32_t src_clk_freq = 0;
231-
esp_err_t err = esp_clk_tree_src_get_freq_hz(timer->clk_cfg, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &src_clk_freq);
268+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
269+
err = esp_clk_tree_src_get_freq_hz(timer->clk_cfg, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &src_clk_freq);
232270
if (err != ESP_OK) {
233271
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("unable to query source clock frequency %d"), (int)timer->clk_cfg);
234272
}
273+
#else
274+
// Simplified fallback logic for IDF V5.0.x, for targets with APB only.
275+
src_clk_freq = APB_CLK_FREQ; // 80 MHz
276+
#if SOC_LEDC_SUPPORT_REF_TICK
277+
if (timer->clk_cfg == LEDC_USE_REF_TICK) {
278+
src_clk_freq = REF_CLK_FREQ; // 1 MHz
279+
}
280+
#endif // SOC_LEDC_SUPPORT_REF_TICK
281+
#endif // ESP_IDF_VERSION
282+
235283
timer->duty_resolution = ledc_find_suitable_duty_resolution(src_clk_freq, timer->freq_hz);
236284

237285
// Set frequency

ports/esp32/modnetwork_globals.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
{ MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_network_phy_mode_obj) },
1414
{ MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&esp_network_ipconfig_obj) },
1515

16-
#if MICROPY_PY_NETWORK_WLAN
16+
// These WLAN constants are now in the WLAN class and remain here only for backwards compatibility.
17+
#if !MICROPY_PREVIEW_VERSION_2 && MICROPY_PY_NETWORK_WLAN
1718
{ MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(WIFI_IF_STA)},
1819
{ MP_ROM_QSTR(MP_QSTR_AP_IF), MP_ROM_INT(WIFI_IF_AP)},
1920

ports/esp32/network_common.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,3 @@ static mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) {
337337
return mp_const_none;
338338
}
339339
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj, 0, 1, esp_phy_mode);
340-
341-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
342-
_Static_assert(WIFI_AUTH_MAX == 13, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
343-
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2)
344-
_Static_assert(WIFI_AUTH_MAX == 11, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
345-
#else
346-
_Static_assert(WIFI_AUTH_MAX == 10, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
347-
#endif

ports/esp32/network_wlan.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,28 @@ static const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
744744
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA2_WPA3), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) },
745745
{ MP_ROM_QSTR(MP_QSTR_SEC_WAPI), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) },
746746
{ MP_ROM_QSTR(MP_QSTR_SEC_OWE), MP_ROM_INT(WIFI_AUTH_OWE) },
747+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2)
748+
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_ENT_192), MP_ROM_INT(WIFI_AUTH_WPA3_ENT_192) },
749+
#endif
750+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
751+
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_EXT_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK) },
752+
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_EXT_PSK_MIXED_MODE), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE) },
753+
#endif
747754

748755
{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(WIFI_PS_NONE) },
749756
{ MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(WIFI_PS_MIN_MODEM) },
750757
{ MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(WIFI_PS_MAX_MODEM) },
751758
};
752759
static MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
753760

761+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
762+
_Static_assert(WIFI_AUTH_MAX == 13, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
763+
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2)
764+
_Static_assert(WIFI_AUTH_MAX == 11, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
765+
#else
766+
_Static_assert(WIFI_AUTH_MAX == 10, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
767+
#endif
768+
754769
MP_DEFINE_CONST_OBJ_TYPE(
755770
esp_network_wlan_type,
756771
MP_QSTR_WLAN,

0 commit comments

Comments
 (0)