Browse Source

esp8266: Allow GPIO16 to be used as a pin in the uPy pin HAL.

Now I2C works with GPIO16 as the SCL or SDA pin.
pull/2031/head
Damien George 9 years ago
parent
commit
67a6d31955
  1. 10
      esp8266/esp_mphal.c
  2. 12
      esp8266/esp_mphal.h

10
esp8266/esp_mphal.c

@ -215,6 +215,16 @@ void mp_hal_signal_dupterm_input(void) {
void mp_hal_pin_config_od(mp_hal_pin_obj_t pin_id) {
const pyb_pin_obj_t *pin = &pyb_pin_obj[pin_id];
if (pin->phys_port == 16) {
// configure GPIO16 as input with output register holding 0
WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | 1);
WRITE_PERI_REG(RTC_GPIO_CONF, READ_PERI_REG(RTC_GPIO_CONF) & ~1);
WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); // input
WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) & ~1)); // out=0
return;
}
ETS_GPIO_INTR_DISABLE();
PIN_FUNC_SELECT(pin->periph, pin->func);
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port)),

12
esp8266/esp_mphal.h

@ -66,8 +66,14 @@ void ets_event_poll(void);
#define mp_hal_pin_obj_t uint32_t
#define mp_hal_get_pin_obj(o) mp_obj_get_pin(o)
void mp_hal_pin_config_od(mp_hal_pin_obj_t pin);
#define mp_hal_pin_low(p) gpio_output_set(0, 1 << (p), 1 << (p), 0)
#define mp_hal_pin_od_high(p) gpio_output_set(1 << (p), 0, 1 << (p), 0)
#define mp_hal_pin_read(p) GPIO_INPUT_GET(GPIO_ID_PIN((p)))
#define mp_hal_pin_low(p) do { \
if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1) | 1); } \
else { gpio_output_set(0, 1 << (p), 1 << (p), 0); } \
} while (0)
#define mp_hal_pin_od_high(p) do { \
if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); } \
else { gpio_output_set(1 << (p), 0, 1 << (p), 0); } \
} while (0)
#define mp_hal_pin_read(p) pin_get(p)
#endif // _INCLUDED_MPHAL_H_

Loading…
Cancel
Save