now checks for proper pin in is_pin_free; initialize GPIO16 as input in reset_pins

This commit is contained in:
sommersoft 2018-04-25 03:57:09 +00:00
parent 8cadcc8e83
commit e70ece4c41

View File

@ -33,14 +33,18 @@
#include "eagle_soc.h" #include "eagle_soc.h"
extern volatile bool adc_in_use; extern volatile bool adc_in_use;
volatile bool gpio16_in_use __attribute__((aligned(4))) = false;
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) { bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) {
if (pin == &pin_TOUT) { if (pin == &pin_TOUT) {
return !adc_in_use; return !adc_in_use;
} }
if (pin->gpio_number == NO_GPIO || pin->gpio_number == SPECIAL_CASE) { if (pin->gpio_number == NO_GPIO) {
return false; return false;
} }
if (pin->gpio_number == 16) {
return !gpio16_in_use;
}
return (READ_PERI_REG(pin->peripheral) & return (READ_PERI_REG(pin->peripheral) &
(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S)) == 0 && (PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S)) == 0 &&
(GPIO_REG_READ(GPIO_ENABLE_ADDRESS) & (1 << pin->gpio_number)) == 0 && (GPIO_REG_READ(GPIO_ENABLE_ADDRESS) & (1 << pin->gpio_number)) == 0 &&
@ -48,7 +52,7 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) {
} }
void reset_pins(void) { void reset_pins(void) {
for (int i = 0; i < 17; i++) { for (int i = 0; i < 16; i++) {
// 5 is RXD, 6 is TXD // 5 is RXD, 6 is TXD
if ((i > 4 && i < 13) || i == 12) { if ((i > 4 && i < 13) || i == 12) {
continue; continue;
@ -59,4 +63,9 @@ void reset_pins(void) {
// Disable the pin. // Disable the pin.
gpio_output_set(0x0, 0x0, 0x0, 1 << i); gpio_output_set(0x0, 0x0, 0x0, 1 << i);
} }
// Set GPIO16 as input
WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | 1); // mux configuration for XPD_DCDC and rtc_gpio0 connection
WRITE_PERI_REG(RTC_GPIO_CONF, READ_PERI_REG(RTC_GPIO_CONF) & ~1); //mux configuration for out enable
WRITE_PERI_REG(RTC_GPIO_ENABLE, READ_PERI_REG(RTC_GPIO_ENABLE) & ~1); //out disable
gpio16_in_use = false;
} }