Merge pull request #3754 from hierophect/esp-spi-pinclaim

ESP32S2: fix pin claiming bugs
This commit is contained in:
Scott Shawcroft 2020-11-25 15:11:29 -08:00 committed by GitHub
commit abff2615cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -204,6 +204,14 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
// hal->dummy_bits = 0;
// hal->addr = 0;
claim_pin(self->clock_pin);
if (self->MOSI_pin != NULL) {
claim_pin(self->MOSI_pin);
}
if (self->MISO_pin != NULL) {
claim_pin(self->MISO_pin);
}
hal->io_mode = SPI_LL_IO_MODE_NORMAL;
common_hal_busio_spi_configure(self, 250000, 0, 0, 8);

View File

@ -96,7 +96,7 @@ void reset_all_pins(void) {
}
void claim_pin(const mcu_pin_obj_t* pin) {
in_use[pin->number / 32] |= (1 << pin->number % 32);
in_use[pin->number / 32] |= (1 << (pin->number % 32));
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL) {
neopixel_in_use = true;
@ -116,7 +116,7 @@ bool pin_number_is_free(gpio_num_t pin_number) {
#endif
uint8_t offset = pin_number / 32;
uint8_t mask = 1 << pin_number % 32;
uint32_t mask = 1 << (pin_number % 32);
return (never_reset_pins[offset] & mask) == 0 && (in_use[offset] & mask) == 0;
}