Commit 68e222af authored by Damien George's avatar Damien George
Browse files

esp8266: Add mp_hal_pin_input() and mp_hal_pin_output() functions.

parent 20aa9c85
......@@ -68,6 +68,8 @@ void ets_event_poll(void);
#include "esp8266/modpyb.h"
#define mp_hal_pin_obj_t uint32_t
#define mp_hal_get_pin_obj(o) mp_obj_get_pin(o)
void mp_hal_pin_input(mp_hal_pin_obj_t pin);
void mp_hal_pin_output(mp_hal_pin_obj_t pin);
void mp_hal_pin_config_od(mp_hal_pin_obj_t pin);
#define mp_hal_pin_low(p) do { \
if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1) | 1); } \
......
......@@ -36,6 +36,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
#include "modpyb.h"
#define GET_TRIGGER(phys_port) \
......@@ -123,6 +124,34 @@ uint mp_obj_get_pin(mp_obj_t pin_in) {
return mp_obj_get_pin_obj(pin_in)->phys_port;
}
void mp_hal_pin_input(mp_hal_pin_obj_t pin_id) {
pin_mode[pin_id] = GPIO_MODE_INPUT;
if (pin_id == 16) {
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
} else {
const pyb_pin_obj_t *self = &pyb_pin_obj[pin_id];
PIN_FUNC_SELECT(self->periph, self->func);
PIN_PULLUP_DIS(self->periph);
gpio_output_set(0, 0, 0, 1 << self->phys_port);
}
}
void mp_hal_pin_output(mp_hal_pin_obj_t pin_id) {
pin_mode[pin_id] = GPIO_MODE_OUTPUT;
if (pin_id == 16) {
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) | 1); // output
} else {
const pyb_pin_obj_t *self = &pyb_pin_obj[pin_id];
PIN_FUNC_SELECT(self->periph, self->func);
PIN_PULLUP_DIS(self->periph);
gpio_output_set(0, 0, 1 << self->phys_port, 0);
}
}
int pin_get(uint pin) {
if (pin == 16) {
return READ_PERI_REG(RTC_GPIO_IN_DATA) & 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment