summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-04-12 13:54:40 +0100
committerDamien George <damien.p.george@gmail.com>2016-04-12 14:06:54 +0100
commitac63ca7bc57e24008d25c0826c5c0c42abf38b13 (patch)
tree7e8e68bfa21d2d791756a99e4ec8f986a0402210 /esp8266
parent1a65ff1b72f4cccecc797902d9713bce57b17588 (diff)
downloadmicropython-ac63ca7bc57e24008d25c0826c5c0c42abf38b13.tar.gz
micropython-ac63ca7bc57e24008d25c0826c5c0c42abf38b13.zip
esp8266: Implement basic C-level pin HAL.
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/esp_mphal.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h
index 6713e42551..ec2ed5b61d 100644
--- a/esp8266/esp_mphal.h
+++ b/esp8266/esp_mphal.h
@@ -56,4 +56,24 @@ void dupterm_task_init();
void ets_event_poll(void);
#define ETS_POLL_WHILE(cond) { while (cond) ets_event_poll(); }
+// C-level pin HAL
+#include "etshal.h"
+#include "gpio.h"
+#include "esp8266/modpyb.h"
+#define mp_hal_pin_obj_t pyb_pin_obj_t
+#define mp_hal_get_pin_obj(o) mp_obj_get_pin_obj(o)
+#define mp_hal_pin_config_od(p) do { \
+ ETS_GPIO_INTR_DISABLE(); \
+ PIN_FUNC_SELECT((p)->periph, (p)->func); \
+ GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN((p)->phys_port)), \
+ GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN((p)->phys_port))) \
+ | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); /* open drain */ \
+ GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, \
+ GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << (p)->phys_port)); \
+ ETS_GPIO_INTR_ENABLE(); \
+ } while (0)
+#define mp_hal_pin_low(p) gpio_output_set(0, 1 << (p)->phys_port, 1 << (p)->phys_port, 0)
+#define mp_hal_pin_od_high(p) gpio_output_set(1 << (p)->phys_port, 0, 1 << (p)->phys_port, 0)
+#define mp_hal_pin_read(p) GPIO_INPUT_GET(GPIO_ID_PIN((p)->phys_port))
+
#endif // _INCLUDED_MPHAL_H_