Add I2C never reset, SPI bugfix

This commit is contained in:
Hierophect 2019-12-03 16:18:49 -05:00
parent 83ecb1b65e
commit 012b3bdf18
2 changed files with 23 additions and 5 deletions

View File

@ -36,6 +36,7 @@
#include "common-hal/microcontroller/Pin.h" #include "common-hal/microcontroller/Pin.h"
STATIC bool reserved_i2c[3]; STATIC bool reserved_i2c[3];
STATIC bool never_reset[3];
void i2c_reset(void) { void i2c_reset(void) {
//Note: I2Cs are also forcibly reset in construct, due to silicon error //Note: I2Cs are also forcibly reset in construct, due to silicon error
@ -48,11 +49,24 @@ void i2c_reset(void) {
__HAL_RCC_I2C2_CLK_DISABLE(); __HAL_RCC_I2C2_CLK_DISABLE();
#endif #endif
#ifdef I2C3 #ifdef I2C3
reserved_i2c[3] = false; reserved_i2c[2] = false;
__HAL_RCC_I2C3_CLK_DISABLE(); __HAL_RCC_I2C3_CLK_DISABLE();
#endif #endif
} }
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
for (size_t i = 0 ; i < MP_ARRAY_SIZE(mcu_i2c_banks); i++) {
if (self->handle.Instance == mcu_i2c_banks[i]) {
never_reset[i] = true;
never_reset_pin_number(self->scl->pin->port, self->scl->pin->number);
never_reset_pin_number(self->sda->pin->port, self->scl->pin->number);
break;
}
}
}
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) { const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) {
@ -166,19 +180,22 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
} }
#ifdef I2C1 #ifdef I2C1
if(self->handle.Instance==I2C1) { if(self->handle.Instance==I2C1) {
reserved_i2c[0] = 0; never_reset[0] = false;
reserved_i2c[0] = false;
__HAL_RCC_I2C1_CLK_DISABLE(); __HAL_RCC_I2C1_CLK_DISABLE();
} }
#endif #endif
#ifdef I2C2 #ifdef I2C2
if(self->handle.Instance==I2C2) { if(self->handle.Instance==I2C2) {
reserved_i2c[1] = 0; never_reset[1] = false;
reserved_i2c[1] = false;
__HAL_RCC_I2C2_CLK_DISABLE(); __HAL_RCC_I2C2_CLK_DISABLE();
} }
#endif #endif
#ifdef I2C3 #ifdef I2C3
if(self->handle.Instance==I2C3) { if(self->handle.Instance==I2C3) {
reserved_i2c[3] = 0; never_reset[2] = false;
reserved_i2c[2] = false;
__HAL_RCC_I2C3_CLK_DISABLE(); __HAL_RCC_I2C3_CLK_DISABLE();
} }
#endif #endif

View File

@ -191,7 +191,8 @@ bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
spi_clock_disable(1<<(self->sck->spi_index - 1)); spi_clock_disable(1<<(self->sck->spi_index - 1));
reserved_spi[self->sck->spi_index - 1] = true; reserved_spi[self->sck->spi_index - 1] = false;
never_reset_spi[self->sck->spi_index - 1] = false;
reset_pin_number(self->sck->pin->port,self->sck->pin->number); reset_pin_number(self->sck->pin->port,self->sck->pin->number);
reset_pin_number(self->mosi->pin->port,self->mosi->pin->number); reset_pin_number(self->mosi->pin->port,self->mosi->pin->number);