Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
esp32/util: fixed problem in antenna switch in newer esp32 chip models
  • Loading branch information
iwahdan88 committed Dec 13, 2018
commit 1d665391be0a6c034ee64a62b7310e66b56b59c4
11 changes: 11 additions & 0 deletions esp32/mods/machpin.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void pin_preinit(void) {
void pin_init0(void) {
// initialize all pins as inputs with pull downs enabled
mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)&pin_module_pins_locals_dict);

for (uint i = 0; i < named_map->used - 1; i++) {
pin_obj_t *self = (pin_obj_t *)named_map->table[i].value;
if (self != &PIN_MODULE_P1) { // temporal while we remove all the IDF logs
Expand All @@ -132,6 +133,16 @@ void pin_init0(void) {
continue;
}
#endif
/* exclude the antenna switch pin from initialization as it is already initialized */
if((micropy_hw_antenna_diversity_pin_num == MICROPY_SECOND_GEN_ANT_SELECT_PIN_NUM) && (self == &PIN_MODULE_P12))
{
continue;
}
/* exclude RGB led from initialization as it is already initialized by mperror */
if (self == &PIN_MODULE_P2)
{
continue;
}
pin_config(self, -1, -1, GPIO_MODE_INPUT, MACHPIN_PULL_DOWN, 0);
}
}
Expand Down
29 changes: 29 additions & 0 deletions esp32/util/antenna.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,44 @@ void antenna_init0(void) {
}

void antenna_select (antenna_type_t _antenna) {
static bool init_done = false;

if (micropy_hw_antenna_diversity_pin_num < 32) {
// set the pin value
if (_antenna == ANTENNA_TYPE_EXTERNAL) {
// config the pin for first time if is the second generation as it was already ulled down by default
if((micropy_hw_antenna_diversity_pin_num == MICROPY_SECOND_GEN_ANT_SELECT_PIN_NUM) && (!init_done))
{
gpio_config_t gpioconf = {.pin_bit_mask = 1ull << MICROPY_SECOND_GEN_ANT_SELECT_PIN_NUM,
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE};
if(ESP_OK == gpio_config(&gpioconf))
{
init_done = true;
}
}

GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, 1 << micropy_hw_antenna_diversity_pin_num);
} else if (_antenna == ANTENNA_TYPE_INTERNAL) {
GPIO_REG_WRITE(GPIO_OUT_W1TC_REG, 1 << micropy_hw_antenna_diversity_pin_num);
}
} else {
if (_antenna == ANTENNA_TYPE_EXTERNAL) {
// config the pin for first time if is the second generation as it was already ulled down by default
if((micropy_hw_antenna_diversity_pin_num == MICROPY_SECOND_GEN_ANT_SELECT_PIN_NUM) && (!init_done))
{
gpio_config_t gpioconf = {.pin_bit_mask = 1ull << (MICROPY_SECOND_GEN_ANT_SELECT_PIN_NUM & 31),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE};
if(ESP_OK == gpio_config(&gpioconf))
{
init_done = true;
}
}
GPIO_REG_WRITE(GPIO_OUT1_W1TS_REG, 1 << (micropy_hw_antenna_diversity_pin_num & 31));
} else if (_antenna == ANTENNA_TYPE_INTERNAL) {
GPIO_REG_WRITE(GPIO_OUT1_W1TC_REG, 1 << (micropy_hw_antenna_diversity_pin_num & 31));
Expand Down