summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266
diff options
context:
space:
mode:
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/Makefile32
-rw-r--r--esp8266/README.md11
-rw-r--r--esp8266/esp8266_common.ld2
-rw-r--r--esp8266/esp_mphal.c24
-rw-r--r--esp8266/esp_mphal.h7
-rw-r--r--esp8266/espapa102.h4
-rw-r--r--esp8266/espneopixel.h5
-rw-r--r--esp8266/esponewire.c99
-rw-r--r--esp8266/esponewire.h36
-rw-r--r--esp8266/esppwm.h6
-rw-r--r--esp8266/ets_alt_task.h5
-rw-r--r--esp8266/etshal.h6
-rw-r--r--esp8266/fatfs_port.c2
-rw-r--r--esp8266/gccollect.c2
-rw-r--r--esp8266/gccollect.h6
-rw-r--r--esp8266/hspi.c6
-rw-r--r--esp8266/hspi_register.h2
-rw-r--r--esp8266/machine_adc.c8
-rw-r--r--esp8266/machine_hspi.c6
-rw-r--r--esp8266/machine_pin.c62
-rw-r--r--esp8266/machine_pwm.c2
-rw-r--r--esp8266/machine_rtc.c29
-rw-r--r--esp8266/machine_uart.c6
-rw-r--r--esp8266/machine_wdt.c8
-rw-r--r--esp8266/main.c4
-rw-r--r--esp8266/modesp.c66
-rw-r--r--esp8266/modmachine.c17
-rw-r--r--esp8266/modmachine.h6
-rw-r--r--esp8266/modnetwork.c98
-rw-r--r--esp8266/modonewire.c121
-rw-r--r--esp8266/modpyb.c2
l---------[-rw-r--r--]esp8266/modules/ds18x20.py52
l---------[-rw-r--r--]esp8266/modules/onewire.py92
-rw-r--r--esp8266/moduos.c2
-rw-r--r--esp8266/modutime.c2
-rw-r--r--esp8266/mpconfigport.h33
-rw-r--r--esp8266/mpconfigport_512k.h3
-rw-r--r--esp8266/qstrdefsport.h2
-rw-r--r--esp8266/uart.h12
-rw-r--r--esp8266/xtirq.h7
40 files changed, 240 insertions, 655 deletions
diff --git a/esp8266/Makefile b/esp8266/Makefile
index ff35689f4d..fce11a7d41 100644
--- a/esp8266/Makefile
+++ b/esp8266/Makefile
@@ -8,11 +8,11 @@ MICROPY_SSL_AXTLS = 1
MICROPY_FATFS = 1
MICROPY_PY_BTREE = 1
-FROZEN_DIR = scripts
-FROZEN_MPY_DIR = modules
+FROZEN_DIR ?= scripts
+FROZEN_MPY_DIR ?= modules
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
FWBIN = $(BUILD)/firmware-combined.bin
PORT ?= /dev/ttyACM0
@@ -23,8 +23,7 @@ CROSS_COMPILE = xtensa-lx106-elf-
ESP_SDK = $(shell $(CC) -print-sysroot)/usr
INC += -I.
-INC += -I..
-INC += -I../stmhal
+INC += -I$(TOP)
INC += -I$(BUILD)
INC += -I$(ESP_SDK)/include
@@ -68,7 +67,6 @@ SRC_C = \
lexerstr32.c \
uart.c \
esppwm.c \
- esponewire.c \
espneopixel.c \
espapa102.c \
intr.c \
@@ -85,19 +83,15 @@ SRC_C = \
modnetwork.c \
modutime.c \
moduos.c \
- modonewire.c \
ets_alt_task.c \
fatfs_port.c \
axtls_helpers.c \
hspi.c \
$(SRC_MOD)
-STM_SRC_C = $(addprefix stmhal/,\
- pybstdio.c \
- )
-
EXTMOD_SRC_C = $(addprefix extmod/,\
modlwip.c \
+ modonewire.c \
)
LIB_SRC_C = $(addprefix lib/,\
@@ -125,6 +119,7 @@ LIB_SRC_C = $(addprefix lib/,\
timeutils/timeutils.c \
utils/pyexec.c \
utils/interrupt_char.c \
+ utils/sys_stdio_mphal.c \
)
ifeq ($(MICROPY_FATFS), 1)
@@ -144,14 +139,13 @@ OBJ =
OBJ += $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
-OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
#OBJ += $(BUILD)/pins_$(BOARD).o
# List of sources for qstr extraction
-SRC_QSTR += $(SRC_C) $(STM_SRC_C) $(EXTMOD_SRC_C) $(DRIVERS_SRC_C)
+SRC_QSTR += $(SRC_C) $(EXTMOD_SRC_C) $(LIB_SRC_C) $(DRIVERS_SRC_C)
# Append any auto-generated sources that are needed by sources listed in SRC_QSTR
SRC_QSTR_AUTO_DEPS +=
@@ -226,16 +220,16 @@ ota:
#$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c
# $(call compile_c)
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
axtls: $(BUILD)/libaxtls.a
$(BUILD)/libaxtls.a:
- cd ../lib/axtls; cp config/upyconfig config/.config
- cd ../lib/axtls; $(MAKE) oldconfig -B
- cd ../lib/axtls; $(MAKE) clean
- cd ../lib/axtls; $(MAKE) all CC="$(CC)" LD="$(LD)" AR="$(AR)" CFLAGS_EXTRA="$(CFLAGS_XTENSA) -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=3072"
- cp ../lib/axtls/_stage/libaxtls.a $@
+ cd $(TOP)/lib/axtls; cp config/upyconfig config/.config
+ cd $(TOP)/lib/axtls; $(MAKE) oldconfig -B
+ cd $(TOP)/lib/axtls; $(MAKE) clean
+ cd $(TOP)/lib/axtls; $(MAKE) all CC="$(CC)" LD="$(LD)" AR="$(AR)" CFLAGS_EXTRA="$(CFLAGS_XTENSA) -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096"
+ cp $(TOP)/lib/axtls/_stage/libaxtls.a $@
clean-modules:
git clean -f -d modules
diff --git a/esp8266/README.md b/esp8266/README.md
index d717d26fed..252e195d83 100644
--- a/esp8266/README.md
+++ b/esp8266/README.md
@@ -114,8 +114,13 @@ Python prompt over WiFi, connecting through a browser.
Please follow the instructions there.
-More detailed instructions can be found at
-http://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
+Documentation
+-------------
+
+More detailed documentation and instructions can be found at
+http://docs.micropython.org/en/latest/esp8266/ , which includes Quick
+Reference, Tutorial, General Information related to ESP8266 port, and
+to MicroPython in general.
Troubleshooting
---------------
@@ -132,3 +137,5 @@ experience strange bootloops, crashes, lockups, here's a list to check against:
Please consult dedicated ESP8266 forums/resources for hardware-related
problems.
+
+Additional information may be available by the documentation links above.
diff --git a/esp8266/esp8266_common.ld b/esp8266/esp8266_common.ld
index bc983df700..de5268c8fe 100644
--- a/esp8266/esp8266_common.ld
+++ b/esp8266/esp8266_common.ld
@@ -125,8 +125,6 @@ SECTIONS
*lib/timeutils/*.o*(.literal*, .text*)
*lib/utils/*.o*(.literal*, .text*)
- *stmhal/pybstdio.o(.literal*, .text*)
-
build/main.o(.literal* .text*)
*gccollect.o(.literal* .text*)
*gchelper.o(.literal* .text*)
diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c
index 7ecc7776aa..61848fd343 100644
--- a/esp8266/esp_mphal.c
+++ b/esp8266/esp_mphal.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -208,28 +208,6 @@ void mp_hal_signal_dupterm_input(void) {
system_os_post(DUPTERM_TASK_ID, 0, 0);
}
-void mp_hal_pin_open_drain(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)),
- GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->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 << pin->phys_port));
- ETS_GPIO_INTR_ENABLE();
-}
-
// Get pointer to esf_buf bookkeeping structure
void *ets_get_esf_buf_ctlblk(void) {
// Get literal ptr before start of esf_rx_buf_alloc func
diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h
index d783f1f09a..913bd70dc9 100644
--- a/esp8266/esp_mphal.h
+++ b/esp8266/esp_mphal.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,9 +24,6 @@
* THE SOFTWARE.
*/
-#ifndef _INCLUDED_MPHAL_H_
-#define _INCLUDED_MPHAL_H_
-
#include "py/ringbuf.h"
#include "lib/utils/interrupt_char.h"
#include "xtirq.h"
@@ -96,5 +93,3 @@ void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin);
void *ets_get_esf_buf_ctlblk(void);
int ets_esf_free_bufs(int idx);
-
-#endif // _INCLUDED_MPHAL_H_
diff --git a/esp8266/espapa102.h b/esp8266/espapa102.h
index 82c92025d3..dd7c5ab729 100644
--- a/esp8266/espapa102.h
+++ b/esp8266/espapa102.h
@@ -23,5 +23,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_ESP8266_ESPAPA102_H
+#define MICROPY_INCLUDED_ESP8266_ESPAPA102_H
void esp_apa102_write(uint8_t clockPin, uint8_t dataPin, uint8_t *pixels, uint32_t numBytes);
+
+#endif // MICROPY_INCLUDED_ESP8266_ESPAPA102_H
diff --git a/esp8266/espneopixel.h b/esp8266/espneopixel.h
index 4b20afda58..c444740ff9 100644
--- a/esp8266/espneopixel.h
+++ b/esp8266/espneopixel.h
@@ -1 +1,6 @@
+#ifndef MICROPY_INCLUDED_ESP8266_ESPNEOPIXEL_H
+#define MICROPY_INCLUDED_ESP8266_ESPNEOPIXEL_H
+
void esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz);
+
+#endif // MICROPY_INCLUDED_ESP8266_ESPNEOPIXEL_H
diff --git a/esp8266/esponewire.c b/esp8266/esponewire.c
deleted file mode 100644
index 22bb45b158..0000000000
--- a/esp8266/esponewire.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2015-2016 Damien P. George
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include <stdint.h>
-
-#include "etshal.h"
-#include "user_interface.h"
-#include "modmachine.h"
-#include "esponewire.h"
-
-#define TIMING_RESET1 (0)
-#define TIMING_RESET2 (1)
-#define TIMING_RESET3 (2)
-#define TIMING_READ1 (3)
-#define TIMING_READ2 (4)
-#define TIMING_READ3 (5)
-#define TIMING_WRITE1 (6)
-#define TIMING_WRITE2 (7)
-#define TIMING_WRITE3 (8)
-
-uint16_t esp_onewire_timings[9] = {480, 40, 420, 5, 5, 40, 10, 50, 10};
-
-static uint32_t disable_irq(void) {
- ets_intr_lock();
- return 0;
-}
-
-static void enable_irq(uint32_t i) {
- ets_intr_unlock();
-}
-
-static void mp_hal_delay_us_no_irq(uint32_t us) {
- uint32_t start = system_get_time();
- while (system_get_time() - start < us) {
- }
-}
-
-#define DELAY_US mp_hal_delay_us_no_irq
-
-int esp_onewire_reset(uint pin) {
- pin_set(pin, 0);
- DELAY_US(esp_onewire_timings[TIMING_RESET1]);
- uint32_t i = disable_irq();
- pin_set(pin, 1);
- DELAY_US(esp_onewire_timings[TIMING_RESET2]);
- int status = !pin_get(pin);
- enable_irq(i);
- DELAY_US(esp_onewire_timings[TIMING_RESET3]);
- return status;
-}
-
-int esp_onewire_readbit(uint pin) {
- pin_set(pin, 1);
- uint32_t i = disable_irq();
- pin_set(pin, 0);
- DELAY_US(esp_onewire_timings[TIMING_READ1]);
- pin_set(pin, 1);
- DELAY_US(esp_onewire_timings[TIMING_READ2]);
- int value = pin_get(pin);
- enable_irq(i);
- DELAY_US(esp_onewire_timings[TIMING_READ3]);
- return value;
-}
-
-void esp_onewire_writebit(uint pin, int value) {
- uint32_t i = disable_irq();
- pin_set(pin, 0);
- DELAY_US(esp_onewire_timings[TIMING_WRITE1]);
- if (value) {
- pin_set(pin, 1);
- }
- DELAY_US(esp_onewire_timings[TIMING_WRITE2]);
- pin_set(pin, 1);
- DELAY_US(esp_onewire_timings[TIMING_WRITE3]);
- enable_irq(i);
-}
diff --git a/esp8266/esponewire.h b/esp8266/esponewire.h
deleted file mode 100644
index da0a1d3880..0000000000
--- a/esp8266/esponewire.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2016 Damien P. George
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef __MICROPY_INCLUDED_ESP8266_ESPONEWIRE_H__
-#define __MICROPY_INCLUDED_ESP8266_ESPONEWIRE_H__
-
-extern uint16_t esp_onewire_timings[9];
-
-int esp_onewire_reset(uint pin);
-int esp_onewire_readbit(uint pin);
-void esp_onewire_writebit(uint pin, int value);
-
-#endif // __MICROPY_INCLUDED_ESP8266_ESPONEWIRE_H__
diff --git a/esp8266/esppwm.h b/esp8266/esppwm.h
index 242a9a2a6f..1ee4a2f55a 100644
--- a/esp8266/esppwm.h
+++ b/esp8266/esppwm.h
@@ -1,5 +1,5 @@
-#ifndef __ESPPWM_H__
-#define __ESPPWM_H__
+#ifndef MICROPY_INCLUDED_ESP8266_ESPPWM_H
+#define MICROPY_INCLUDED_ESP8266_ESPPWM_H
#include <stdbool.h>
#include <stdint.h>
@@ -14,4 +14,4 @@ uint16_t pwm_get_freq(uint8_t channel);
int pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func);
bool pwm_delete(uint8_t channel);
-#endif
+#endif // MICROPY_INCLUDED_ESP8266_ESPPWM_H
diff --git a/esp8266/ets_alt_task.h b/esp8266/ets_alt_task.h
index dba0c5fa64..33a9d3a002 100644
--- a/esp8266/ets_alt_task.h
+++ b/esp8266/ets_alt_task.h
@@ -1,4 +1,9 @@
+#ifndef MICROPY_INCLUDED_ESP8266_ETS_ALT_TASK_H
+#define MICROPY_INCLUDED_ESP8266_ETS_ALT_TASK_H
+
extern int ets_loop_iter_disable;
extern uint32_t system_time_high_word;
bool ets_loop_iter(void);
+
+#endif // MICROPY_INCLUDED_ESP8266_ETS_ALT_TASK_H
diff --git a/esp8266/etshal.h b/esp8266/etshal.h
index 90af63ba2d..34787779f9 100644
--- a/esp8266/etshal.h
+++ b/esp8266/etshal.h
@@ -1,5 +1,5 @@
-#ifndef _INCLUDED_ETSHAL_H_
-#define _INCLUDED_ETSHAL_H_
+#ifndef MICROPY_INCLUDED_ESP8266_ETSHAL_H
+#define MICROPY_INCLUDED_ESP8266_ETSHAL_H
#include <os_type.h>
@@ -42,4 +42,4 @@ uint32_t SPIRead(uint32_t offset, void *buf, uint32_t len);
uint32_t SPIWrite(uint32_t offset, const void *buf, uint32_t len);
uint32_t SPIEraseSector(int sector);
-#endif // _INCLUDED_ETSHAL_H_
+#endif // MICROPY_INCLUDED_ESP8266_ETSHAL_H
diff --git a/esp8266/fatfs_port.c b/esp8266/fatfs_port.c
index 02384f6055..a8865c817e 100644
--- a/esp8266/fatfs_port.c
+++ b/esp8266/fatfs_port.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/gccollect.c b/esp8266/gccollect.c
index 1b9349f574..cd5d4932c5 100644
--- a/esp8266/gccollect.c
+++ b/esp8266/gccollect.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/gccollect.h b/esp8266/gccollect.h
index d81cba12c4..5735d8a390 100644
--- a/esp8266/gccollect.h
+++ b/esp8266/gccollect.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -23,6 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_ESP8266_GCCOLLECT_H
+#define MICROPY_INCLUDED_ESP8266_GCCOLLECT_H
extern uint32_t _text_start;
extern uint32_t _text_end;
@@ -39,3 +41,5 @@ extern uint32_t _heap_end;
void gc_collect(void);
void esp_native_code_gc_collect(void);
+
+#endif // MICROPY_INCLUDED_ESP8266_GCCOLLECT_H
diff --git a/esp8266/hspi.c b/esp8266/hspi.c
index 436fb4f6f4..554a50460f 100644
--- a/esp8266/hspi.c
+++ b/esp8266/hspi.c
@@ -28,7 +28,7 @@
/*
Wrapper to setup HSPI/SPI GPIO pins and default SPI clock
spi_no - SPI (0) or HSPI (1)
-Not used in Micropython.
+Not used in MicroPython.
*/
void spi_init(uint8_t spi_no) {
spi_init_gpio(spi_no, SPI_CLK_USE_DIV);
@@ -48,7 +48,7 @@ Configures SPI mode parameters for clock edge and clock polarity.
(1) Data is valid on clock trailing edge
spi_cpol - (0) Clock is low when inactive
(1) Clock is high when inactive
-For Micropython this version is different from original.
+For MicroPython this version is different from original.
*/
void spi_mode(uint8_t spi_no, uint8_t spi_cpha, uint8_t spi_cpol) {
if (spi_cpol) {
@@ -99,7 +99,7 @@ void spi_init_gpio(uint8_t spi_no, uint8_t sysclk_as_spiclk) {
// GPIO14 is HSPI CLK pin (Clock)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);
// GPIO15 is HSPI CS pin (Chip Select / Slave Select)
- // In Micropython, we are handling CS ourself in drivers.
+ // In MicroPython, we are handling CS ourself in drivers.
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);
}
}
diff --git a/esp8266/hspi_register.h b/esp8266/hspi_register.h
index 30a5ff5884..4dd335b400 100644
--- a/esp8266/hspi_register.h
+++ b/esp8266/hspi_register.h
@@ -3,7 +3,7 @@
* Modified by David Ogilvy (MetalPhreak)
* Based on original file included in SDK 1.0.0
*
- * Missing defines from previous SDK versions have
+ * Missing defines from previous SDK versions have
* been added and are noted with comments. The
* names of these defines are likely to change.
*/
diff --git a/esp8266/machine_adc.c b/esp8266/machine_adc.c
index f1fb5be315..c8c08695bd 100644
--- a/esp8266/machine_adc.c
+++ b/esp8266/machine_adc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -70,8 +70,8 @@ STATIC mp_obj_t pyb_adc_read(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_adc_read_obj, pyb_adc_read);
-STATIC const mp_map_elem_t pyb_adc_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&pyb_adc_read_obj }
+STATIC const mp_rom_map_elem_t pyb_adc_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&pyb_adc_read_obj) }
};
STATIC MP_DEFINE_CONST_DICT(pyb_adc_locals_dict, pyb_adc_locals_dict_table);
@@ -79,5 +79,5 @@ const mp_obj_type_t pyb_adc_type = {
{ &mp_type_type },
.name = MP_QSTR_ADC,
.make_new = pyb_adc_make_new,
- .locals_dict = (mp_obj_t)&pyb_adc_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&pyb_adc_locals_dict,
};
diff --git a/esp8266/machine_hspi.c b/esp8266/machine_hspi.c
index 1be342b526..eaabbab7ea 100644
--- a/esp8266/machine_hspi.c
+++ b/esp8266/machine_hspi.c
@@ -122,15 +122,13 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
spi_init_gpio(HSPI, SPI_CLK_80MHZ_NODIV);
spi_clock(HSPI, 0, 0);
} else if (self->baudrate > 40000000L) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "impossible baudrate"));
+ mp_raise_ValueError("impossible baudrate");
} else {
uint32_t divider = 40000000L / self->baudrate;
uint16_t prediv = MIN(divider, SPI_CLKDIV_PRE + 1);
uint16_t cntdiv = (divider / prediv) * 2; // cntdiv has to be even
if (cntdiv > SPI_CLKCNT_N + 1 || cntdiv == 0 || prediv == 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "impossible baudrate"));
+ mp_raise_ValueError("impossible baudrate");
}
self->baudrate = 80000000L / (prediv * cntdiv);
spi_init_gpio(HSPI, SPI_CLK_USE_DIV);
diff --git a/esp8266/machine_pin.c b/esp8266/machine_pin.c
index 385551578e..673082065b 100644
--- a/esp8266/machine_pin.c
+++ b/esp8266/machine_pin.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -125,7 +125,7 @@ void pin_intr_handler(uint32_t status) {
pyb_pin_obj_t *mp_obj_get_pin_obj(mp_obj_t pin_in) {
if (mp_obj_get_type(pin_in) != &pyb_pin_type) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "expecting a pin"));
+ mp_raise_ValueError("expecting a pin");
}
pyb_pin_obj_t *self = pin_in;
return self;
@@ -163,6 +163,28 @@ void mp_hal_pin_output(mp_hal_pin_obj_t pin_id) {
}
}
+void mp_hal_pin_open_drain(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)),
+ GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->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 << pin->phys_port));
+ ETS_GPIO_INTR_ENABLE();
+}
+
int pin_get(uint pin) {
if (pin == 16) {
return READ_PERI_REG(RTC_GPIO_IN_DATA) & 1;
@@ -258,7 +280,7 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, c
// only pull-down seems to be supported by the hardware, and
// we only expose pull-up behaviour in software
if (pull != GPIO_PULL_NONE) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin(16) doesn't support pull"));
+ mp_raise_ValueError("Pin(16) doesn't support pull");
}
} else {
PIN_FUNC_SELECT(self->periph, self->func);
@@ -297,7 +319,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
pin = (pyb_pin_obj_t*)&pyb_pin_obj[wanted_pin];
}
if (pin == NULL || pin->base.type == NULL) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid pin"));
+ mp_raise_ValueError("invalid pin");
}
if (n_args > 1 || n_kw > 0) {
@@ -404,24 +426,24 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i
return -1;
}
-STATIC const mp_map_elem_t pyb_pin_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_pin_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_pin_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pyb_pin_value_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&pyb_pin_off_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&pyb_pin_on_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_pin_irq_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_pin_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_pin_value_obj) },
+ { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&pyb_pin_off_obj) },
+ { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&pyb_pin_on_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_pin_irq_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_IN), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_INPUT) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OUT), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_OUTPUT) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OPEN_DRAIN), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_OPEN_DRAIN) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PULL_UP), MP_OBJ_NEW_SMALL_INT(GPIO_PULL_UP) },
- //{ MP_OBJ_NEW_QSTR(MP_QSTR_PULL_DOWN), MP_OBJ_NEW_SMALL_INT(GPIO_PULL_DOWN) },
-
- // IRG triggers, can be or'd together
- { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_RISING), MP_OBJ_NEW_SMALL_INT(GPIO_PIN_INTR_POSEDGE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_FALLING), MP_OBJ_NEW_SMALL_INT(GPIO_PIN_INTR_NEGEDGE) },
+ { MP_ROM_QSTR(MP_QSTR_IN), MP_ROM_INT(GPIO_MODE_INPUT) },
+ { MP_ROM_QSTR(MP_QSTR_OUT), MP_ROM_INT(GPIO_MODE_OUTPUT) },
+ { MP_ROM_QSTR(MP_QSTR_OPEN_DRAIN), MP_ROM_INT(GPIO_MODE_OPEN_DRAIN) },
+ { MP_ROM_QSTR(MP_QSTR_PULL_UP), MP_ROM_INT(GPIO_PULL_UP) },
+ //{ MP_ROM_QSTR(MP_QSTR_PULL_DOWN), MP_ROM_INT(GPIO_PULL_DOWN) },
+
+ // IRQ triggers, can be or'd together
+ { MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(GPIO_PIN_INTR_POSEDGE) },
+ { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_PIN_INTR_NEGEDGE) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_pin_locals_dict, pyb_pin_locals_dict_table);
@@ -437,7 +459,7 @@ const mp_obj_type_t pyb_pin_type = {
.make_new = mp_pin_make_new,
.call = pyb_pin_call,
.protocol = &pin_pin_p,
- .locals_dict = (mp_obj_t)&pyb_pin_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&pyb_pin_locals_dict,
};
/******************************************************************************/
diff --git a/esp8266/machine_pwm.c b/esp8266/machine_pwm.c
index 5d30f09656..8d73e6bb17 100644
--- a/esp8266/machine_pwm.c
+++ b/esp8266/machine_pwm.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/machine_rtc.c b/esp8266/machine_rtc.c
index b17bcb2616..c5d04e0cfa 100644
--- a/esp8266/machine_rtc.c
+++ b/esp8266/machine_rtc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -173,7 +173,7 @@ STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
// read RTC memory
system_rtc_mem_read(MEM_USER_LEN_ADDR, &len, sizeof(len));
- system_rtc_mem_read(MEM_USER_DATA_ADDR, rtcram, len + (4 - len % 4));
+ system_rtc_mem_read(MEM_USER_DATA_ADDR, rtcram, (len + 3) & ~3);
return mp_obj_new_bytes(rtcram, len);
} else {
@@ -183,8 +183,7 @@ STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
if (bufinfo.len > MEM_USER_MAXLEN) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "buffer too long"));
+ mp_raise_ValueError("buffer too long");
}
len = bufinfo.len;
@@ -195,7 +194,7 @@ STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
rtcram[i] = ((uint8_t *)bufinfo.buf)[i];
}
- system_rtc_mem_write(MEM_USER_DATA_ADDR, rtcram, len + (4 - len % 4));
+ system_rtc_mem_write(MEM_USER_DATA_ADDR, rtcram, (len + 3) & ~3);
return mp_const_none;
}
@@ -208,7 +207,7 @@ STATIC mp_obj_t pyb_rtc_alarm(mp_obj_t self_in, mp_obj_t alarm_id, mp_obj_t time
// check we want alarm0
if (mp_obj_get_int(alarm_id) != 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid alarm"));
+ mp_raise_ValueError("invalid alarm");
}
// set expiry time (in microseconds)
@@ -245,7 +244,7 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
// check we want alarm0
if (args[ARG_trigger].u_int != 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid alarm"));
+ mp_raise_ValueError("invalid alarm");
}
// set the wake value
@@ -255,13 +254,13 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq);
-STATIC const mp_map_elem_t pyb_rtc_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_datetime), (mp_obj_t)&pyb_rtc_datetime_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_memory), (mp_obj_t)&pyb_rtc_memory_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_alarm), (mp_obj_t)&pyb_rtc_alarm_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_left), (mp_obj_t)&pyb_rtc_alarm_left_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_rtc_irq_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ALARM0), MP_OBJ_NEW_SMALL_INT(0) },
+STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&pyb_rtc_datetime_obj) },
+ { MP_ROM_QSTR(MP_QSTR_memory), MP_ROM_PTR(&pyb_rtc_memory_obj) },
+ { MP_ROM_QSTR(MP_QSTR_alarm), MP_ROM_PTR(&pyb_rtc_alarm_obj) },
+ { MP_ROM_QSTR(MP_QSTR_alarm_left), MP_ROM_PTR(&pyb_rtc_alarm_left_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_rtc_irq_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(0) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
@@ -269,5 +268,5 @@ const mp_obj_type_t pyb_rtc_type = {
{ &mp_type_type },
.name = MP_QSTR_RTC,
.make_new = pyb_rtc_make_new,
- .locals_dict = (mp_obj_t)&pyb_rtc_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&pyb_rtc_locals_dict,
};
diff --git a/esp8266/machine_uart.c b/esp8266/machine_uart.c
index 4d9f343db1..e8be5e538c 100644
--- a/esp8266/machine_uart.c
+++ b/esp8266/machine_uart.c
@@ -104,7 +104,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
self->bits = 8;
break;
default:
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid data bits"));
+ mp_raise_ValueError("invalid data bits");
break;
}
@@ -140,7 +140,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
self->stop = 2;
break;
default:
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid stop bits"));
+ mp_raise_ValueError("invalid stop bits");
break;
}
@@ -215,7 +215,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->uart_id == 1) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "UART(1) can't read"));
+ mp_raise_msg(&mp_type_OSError, "UART(1) can't read");
}
// make sure we want at least 1 char
diff --git a/esp8266/machine_wdt.c b/esp8266/machine_wdt.c
index 83b5e8f322..5e23ff7826 100644
--- a/esp8266/machine_wdt.c
+++ b/esp8266/machine_wdt.c
@@ -71,9 +71,9 @@ STATIC mp_obj_t machine_wdt_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_deinit_obj, machine_wdt_deinit);
-STATIC const mp_map_elem_t machine_wdt_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&machine_wdt_feed_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&machine_wdt_deinit_obj },
+STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_feed), MP_ROM_PTR(&machine_wdt_feed_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_wdt_deinit_obj) },
};
STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table);
@@ -81,5 +81,5 @@ const mp_obj_type_t esp_wdt_type = {
{ &mp_type_type },
.name = MP_QSTR_WDT,
.make_new = machine_wdt_make_new,
- .locals_dict = (mp_obj_t)&machine_wdt_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&machine_wdt_locals_dict,
};
diff --git a/esp8266/main.c b/esp8266/main.c
index e3188dfe40..957198aa05 100644
--- a/esp8266/main.c
+++ b/esp8266/main.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -122,7 +122,7 @@ mp_import_stat_t mp_import_stat(const char *path) {
return MP_IMPORT_STAT_NO_EXIST;
}
-mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
+mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index 5eaae27d6a..6ddca0733b 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -118,7 +118,7 @@ STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len & 0x3) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "len must be multiple of 4"));
+ mp_raise_ValueError("len must be multiple of 4");
}
SpiFlashOpResult res = spi_flash_write(offset, bufinfo.buf, bufinfo.len);
if (res == SPI_FLASH_RESULT_OK) {
@@ -347,50 +347,40 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_set_native_code_location_obj, esp_set_nativ
#endif
-STATIC const mp_map_elem_t esp_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_esp) },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_osdebug), (mp_obj_t)&esp_osdebug_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_id), (mp_obj_t)&esp_flash_id_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_read), (mp_obj_t)&esp_flash_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_write), (mp_obj_t)&esp_flash_write_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_erase), (mp_obj_t)&esp_flash_erase_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_size), (mp_obj_t)&esp_flash_size_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_user_start), (mp_obj_t)&esp_flash_user_start_obj },
+STATIC const mp_rom_map_elem_t esp_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) },
+
+ { MP_ROM_QSTR(MP_QSTR_osdebug), MP_ROM_PTR(&esp_osdebug_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep_type), MP_ROM_PTR(&esp_sleep_type_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&esp_deepsleep_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_id), MP_ROM_PTR(&esp_flash_id_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_read), MP_ROM_PTR(&esp_flash_read_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_write), MP_ROM_PTR(&esp_flash_write_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_erase), MP_ROM_PTR(&esp_flash_erase_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&esp_flash_size_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_user_start), MP_ROM_PTR(&esp_flash_user_start_obj) },
#if MICROPY_ESP8266_NEOPIXEL
- { MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write), (mp_obj_t)&esp_neopixel_write_obj },
+ { MP_ROM_QSTR(MP_QSTR_neopixel_write), MP_ROM_PTR(&esp_neopixel_write_obj) },
#endif
#if MICROPY_ESP8266_APA102
- { MP_OBJ_NEW_QSTR(MP_QSTR_apa102_write), (mp_obj_t)&esp_apa102_write_obj },
+ { MP_ROM_QSTR(MP_QSTR_apa102_write), MP_ROM_PTR(&esp_apa102_write_obj) },
#endif
- { MP_OBJ_NEW_QSTR(MP_QSTR_dht_readinto), (mp_obj_t)&dht_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_freemem), (mp_obj_t)&esp_freemem_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_meminfo), (mp_obj_t)&esp_meminfo_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_check_fw), (mp_obj_t)&esp_check_fw_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj }, // TODO delete/rename/move elsewhere
- { MP_OBJ_NEW_QSTR(MP_QSTR_malloc), (mp_obj_t)&esp_malloc_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_free), (mp_obj_t)&esp_free_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_esf_free_bufs), (mp_obj_t)&esp_esf_free_bufs_obj },
+ { MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_freemem), MP_ROM_PTR(&esp_freemem_obj) },
+ { MP_ROM_QSTR(MP_QSTR_meminfo), MP_ROM_PTR(&esp_meminfo_obj) },
+ { MP_ROM_QSTR(MP_QSTR_check_fw), MP_ROM_PTR(&esp_check_fw_obj) },
+ { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&pyb_info_obj) }, // TODO delete/rename/move elsewhere
+ { MP_ROM_QSTR(MP_QSTR_malloc), MP_ROM_PTR(&esp_malloc_obj) },
+ { MP_ROM_QSTR(MP_QSTR_free), MP_ROM_PTR(&esp_free_obj) },
+ { MP_ROM_QSTR(MP_QSTR_esf_free_bufs), MP_ROM_PTR(&esp_esf_free_bufs_obj) },
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
- { MP_OBJ_NEW_QSTR(MP_QSTR_set_native_code_location), (mp_obj_t)&esp_set_native_code_location_obj },
+ { MP_ROM_QSTR(MP_QSTR_set_native_code_location), MP_ROM_PTR(&esp_set_native_code_location_obj) },
#endif
#if MODESP_INCLUDE_CONSTANTS
- { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_NONE),
- MP_OBJ_NEW_SMALL_INT(NONE_SLEEP_T) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_LIGHT),
- MP_OBJ_NEW_SMALL_INT(LIGHT_SLEEP_T) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_MODEM),
- MP_OBJ_NEW_SMALL_INT(MODEM_SLEEP_T) },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_STA_MODE),
- MP_OBJ_NEW_SMALL_INT(STATION_MODE)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_AP_MODE),
- MP_OBJ_NEW_SMALL_INT(SOFTAP_MODE)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STA_AP_MODE),
- MP_OBJ_NEW_SMALL_INT(STATIONAP_MODE)},
+ { MP_ROM_QSTR(MP_QSTR_SLEEP_NONE), MP_ROM_INT(NONE_SLEEP_T) },
+ { MP_ROM_QSTR(MP_QSTR_SLEEP_LIGHT), MP_ROM_INT(LIGHT_SLEEP_T) },
+ { MP_ROM_QSTR(MP_QSTR_SLEEP_MODEM), MP_ROM_INT(MODEM_SLEEP_T) },
#endif
};
diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c
index c26c633967..98bc495586 100644
--- a/esp8266/modmachine.c
+++ b/esp8266/modmachine.c
@@ -59,8 +59,7 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
// set
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
if (freq != 80 && freq != 160) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "frequency can only be either 80Mhz or 160MHz"));
+ mp_raise_ValueError("frequency can only be either 80Mhz or 160MHz");
}
system_update_cpu_freq(freq);
return mp_const_none;
@@ -193,12 +192,12 @@ STATIC mp_obj_t esp_timer_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_timer_deinit_obj, esp_timer_deinit);
-STATIC const mp_map_elem_t esp_timer_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&esp_timer_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&esp_timer_init_obj },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&esp_timer_callback_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ONE_SHOT), MP_OBJ_NEW_SMALL_INT(false) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PERIODIC), MP_OBJ_NEW_SMALL_INT(true) },
+STATIC const mp_rom_map_elem_t esp_timer_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&esp_timer_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&esp_timer_init_obj) },
+// { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&esp_timer_callback_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(false) },
+ { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(true) },
};
STATIC MP_DEFINE_CONST_DICT(esp_timer_locals_dict, esp_timer_locals_dict_table);
@@ -207,7 +206,7 @@ const mp_obj_type_t esp_timer_type = {
.name = MP_QSTR_Timer,
.print = esp_timer_print,
.make_new = esp_timer_make_new,
- .locals_dict = (mp_obj_t)&esp_timer_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&esp_timer_locals_dict,
};
// this bit is unused in the Xtensa PS register
diff --git a/esp8266/modmachine.h b/esp8266/modmachine.h
index 414aaa85b0..eae351f68d 100644
--- a/esp8266/modmachine.h
+++ b/esp8266/modmachine.h
@@ -1,5 +1,5 @@
-#ifndef __MICROPY_INCLUDED_ESP8266_MODPYB_H__
-#define __MICROPY_INCLUDED_ESP8266_MODPYB_H__
+#ifndef MICROPY_INCLUDED_ESP8266_MODMACHINE_H
+#define MICROPY_INCLUDED_ESP8266_MODMACHINE_H
#include "py/obj.h"
@@ -38,4 +38,4 @@ void pyb_rtc_set_us_since_2000(uint64_t nowus);
uint64_t pyb_rtc_get_us_since_2000();
void rtc_prepare_deepsleep(uint64_t sleep_us);
-#endif // __MICROPY_INCLUDED_ESP8266_MODPYB_H__
+#endif // MICROPY_INCLUDED_ESP8266_MODMACHINE_H
diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c
index eb9d75e284..b893209c65 100644
--- a/esp8266/modnetwork.c
+++ b/esp8266/modnetwork.c
@@ -1,9 +1,9 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
- * Copyright (c) 2015 Paul Sokolovsky
+ * Copyright (c) 2015-2016 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -275,8 +275,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig)
STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
if (n_args != 1 && kwargs->used != 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
- "either pos or kw args are allowed"));
+ mp_raise_TypeError("either pos or kw args are allowed");
}
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
@@ -303,8 +302,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(kwargs->table[i].value, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len != 6) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "invalid buffer length"));
+ mp_raise_ValueError("invalid buffer length");
}
wifi_set_macaddr(self->if_id, bufinfo.buf);
break;
@@ -374,8 +372,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
// Get config
if (n_args != 2) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
- "can query only one param"));
+ mp_raise_TypeError("can query only one param");
}
mp_obj_t val;
@@ -422,20 +419,19 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
return val;
unknown:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "unknown config param"));
+ mp_raise_ValueError("unknown config param");
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);
-STATIC const mp_map_elem_t wlan_if_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_active), (mp_obj_t)&esp_active_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&esp_connect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)&esp_disconnect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&esp_status_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&esp_scan_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_isconnected), (mp_obj_t)&esp_isconnected_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_config), (mp_obj_t)&esp_config_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ifconfig), (mp_obj_t)&esp_ifconfig_obj },
+STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&esp_active_obj) },
+ { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&esp_connect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&esp_disconnect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&esp_status_obj) },
+ { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&esp_scan_obj) },
+ { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&esp_isconnected_obj) },
+ { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
};
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
@@ -443,7 +439,7 @@ STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
const mp_obj_type_t wlan_if_type = {
{ &mp_type_type },
.name = MP_QSTR_WLAN,
- .locals_dict = (mp_obj_t)&wlan_if_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&wlan_if_locals_dict,
};
STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) {
@@ -456,47 +452,31 @@ STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_phy_mode_obj, 0, 1, esp_phy_mode);
-STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&get_wlan_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_phy_mode), (mp_obj_t)&esp_phy_mode_obj },
+STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
+ { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&get_wlan_obj) },
+ { MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_phy_mode_obj) },
#if MODNETWORK_INCLUDE_CONSTANTS
- { MP_OBJ_NEW_QSTR(MP_QSTR_STA_IF),
- MP_OBJ_NEW_SMALL_INT(STATION_IF)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_AP_IF),
- MP_OBJ_NEW_SMALL_INT(SOFTAP_IF)},
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_IDLE),
- MP_OBJ_NEW_SMALL_INT(STATION_IDLE)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_CONNECTING),
- MP_OBJ_NEW_SMALL_INT(STATION_CONNECTING)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_WRONG_PASSWORD),
- MP_OBJ_NEW_SMALL_INT(STATION_WRONG_PASSWORD)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_NO_AP_FOUND),
- MP_OBJ_NEW_SMALL_INT(STATION_NO_AP_FOUND)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_CONNECT_FAIL),
- MP_OBJ_NEW_SMALL_INT(STATION_CONNECT_FAIL)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_GOT_IP),
- MP_OBJ_NEW_SMALL_INT(STATION_GOT_IP)},
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11B),
- MP_OBJ_NEW_SMALL_INT(PHY_MODE_11B) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11G),
- MP_OBJ_NEW_SMALL_INT(PHY_MODE_11G) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11N),
- MP_OBJ_NEW_SMALL_INT(PHY_MODE_11N) },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_OPEN),
- MP_OBJ_NEW_SMALL_INT(AUTH_OPEN) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WEP),
- MP_OBJ_NEW_SMALL_INT(AUTH_WEP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA_PSK),
- MP_OBJ_NEW_SMALL_INT(AUTH_WPA_PSK) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA2_PSK),
- MP_OBJ_NEW_SMALL_INT(AUTH_WPA2_PSK) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK),
- MP_OBJ_NEW_SMALL_INT(AUTH_WPA_WPA2_PSK) },
+ { MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(STATION_IF)},
+ { MP_ROM_QSTR(MP_QSTR_AP_IF), MP_ROM_INT(SOFTAP_IF)},
+
+ { MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(STATION_IDLE)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(STATION_CONNECTING)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(STATION_WRONG_PASSWORD)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(STATION_NO_AP_FOUND)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_CONNECT_FAIL), MP_ROM_INT(STATION_CONNECT_FAIL)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STATION_GOT_IP)},
+
+ { MP_ROM_QSTR(MP_QSTR_MODE_11B), MP_ROM_INT(PHY_MODE_11B) },
+ { MP_ROM_QSTR(MP_QSTR_MODE_11G), MP_ROM_INT(PHY_MODE_11G) },
+ { MP_ROM_QSTR(MP_QSTR_MODE_11N), MP_ROM_INT(PHY_MODE_11N) },
+
+ { MP_ROM_QSTR(MP_QSTR_AUTH_OPEN), MP_ROM_INT(AUTH_OPEN) },
+ { MP_ROM_QSTR(MP_QSTR_AUTH_WEP), MP_ROM_INT(AUTH_WEP) },
+ { MP_ROM_QSTR(MP_QSTR_AUTH_WPA_PSK), MP_ROM_INT(AUTH_WPA_PSK) },
+ { MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_PSK), MP_ROM_INT(AUTH_WPA2_PSK) },
+ { MP_ROM_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK), MP_ROM_INT(AUTH_WPA_WPA2_PSK) },
#endif
};
diff --git a/esp8266/modonewire.c b/esp8266/modonewire.c
deleted file mode 100644
index 1bf7722409..0000000000
--- a/esp8266/modonewire.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2015 Damien P. George
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdint.h>
-
-#include "py/obj.h"
-#include "py/mphal.h"
-#include "modmachine.h"
-#include "esponewire.h"
-
-STATIC mp_obj_t onewire_timings(mp_obj_t timings_in) {
- mp_obj_t *items;
- mp_obj_get_array_fixed_n(timings_in, 9, &items);
- for (int i = 0; i < 9; ++i) {
- esp_onewire_timings[i] = mp_obj_get_int(items[i]);
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_timings_obj, onewire_timings);
-
-STATIC mp_obj_t onewire_reset(mp_obj_t pin_in) {
- return mp_obj_new_bool(esp_onewire_reset(mp_obj_get_pin(pin_in)));
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_reset_obj, onewire_reset);
-
-STATIC mp_obj_t onewire_readbit(mp_obj_t pin_in) {
- return MP_OBJ_NEW_SMALL_INT(esp_onewire_readbit(mp_obj_get_pin(pin_in)));
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_readbit_obj, onewire_readbit);
-
-STATIC mp_obj_t onewire_readbyte(mp_obj_t pin_in) {
- uint pin = mp_obj_get_pin(pin_in);
- uint8_t value = 0;
- for (int i = 0; i < 8; ++i) {
- value |= esp_onewire_readbit(pin) << i;
- }
- return MP_OBJ_NEW_SMALL_INT(value);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_readbyte_obj, onewire_readbyte);
-
-STATIC mp_obj_t onewire_writebit(mp_obj_t pin_in, mp_obj_t value_in) {
- esp_onewire_writebit(mp_obj_get_pin(pin_in), mp_obj_get_int(value_in));
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(onewire_writebit_obj, onewire_writebit);
-
-STATIC mp_obj_t onewire_writebyte(mp_obj_t pin_in, mp_obj_t value_in) {
- uint pin = mp_obj_get_pin(pin_in);
- int value = mp_obj_get_int(value_in);
- for (int i = 0; i < 8; ++i) {
- esp_onewire_writebit(pin, value & 1);
- value >>= 1;
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(onewire_writebyte_obj, onewire_writebyte);
-
-STATIC mp_obj_t onewire_crc8(mp_obj_t data) {
- mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
- uint8_t crc = 0;
- for (size_t i = 0; i < bufinfo.len; ++i) {
- uint8_t byte = ((uint8_t*)bufinfo.buf)[i];
- for (int b = 0; b < 8; ++b) {
- uint8_t fb_bit = (crc ^ byte) & 0x01;
- if (fb_bit == 0x01) {
- crc = crc ^ 0x18;
- }
- crc = (crc >> 1) & 0x7f;
- if (fb_bit == 0x01) {
- crc = crc | 0x80;
- }
- byte = byte >> 1;
- }
- }
- return MP_OBJ_NEW_SMALL_INT(crc);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_crc8_obj, onewire_crc8);
-
-STATIC const mp_map_elem_t onewire_module_globals_table[] = {
- { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_onewire) },
-
- { MP_ROM_QSTR(MP_QSTR_timings), MP_ROM_PTR((mp_obj_t)&onewire_timings_obj) },
- { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR((mp_obj_t)&onewire_reset_obj) },
- { MP_ROM_QSTR(MP_QSTR_readbit), MP_ROM_PTR((mp_obj_t)&onewire_readbit_obj) },
- { MP_ROM_QSTR(MP_QSTR_readbyte), MP_ROM_PTR((mp_obj_t)&onewire_readbyte_obj) },
- { MP_ROM_QSTR(MP_QSTR_writebit), MP_ROM_PTR((mp_obj_t)&onewire_writebit_obj) },
- { MP_ROM_QSTR(MP_QSTR_writebyte), MP_ROM_PTR((mp_obj_t)&onewire_writebyte_obj) },
- { MP_ROM_QSTR(MP_QSTR_crc8), MP_ROM_PTR((mp_obj_t)&onewire_crc8_obj) },
-};
-
-STATIC MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table);
-
-const mp_obj_module_t onewire_module = {
- .base = { &mp_type_module },
- .globals = (mp_obj_dict_t*)&onewire_module_globals,
-};
diff --git a/esp8266/modpyb.c b/esp8266/modpyb.c
index 9fe8039bc6..e977191ee6 100644
--- a/esp8266/modpyb.c
+++ b/esp8266/modpyb.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/modules/ds18x20.py b/esp8266/modules/ds18x20.py
index bf06094835..faae59d909 100644..120000
--- a/esp8266/modules/ds18x20.py
+++ b/esp8266/modules/ds18x20.py
@@ -1,51 +1 @@
-# DS18x20 temperature sensor driver for MicroPython.
-# MIT license; Copyright (c) 2016 Damien P. George
-
-from micropython import const
-
-_CONVERT = const(0x44)
-_RD_SCRATCH = const(0xbe)
-_WR_SCRATCH = const(0x4e)
-
-class DS18X20:
- def __init__(self, onewire):
- self.ow = onewire
- self.buf = bytearray(9)
-
- def scan(self):
- return [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28]
-
- def convert_temp(self):
- self.ow.reset(True)
- self.ow.writebyte(self.ow.SKIP_ROM)
- self.ow.writebyte(_CONVERT)
-
- def read_scratch(self, rom):
- self.ow.reset(True)
- self.ow.select_rom(rom)
- self.ow.writebyte(_RD_SCRATCH)
- self.ow.readinto(self.buf)
- if self.ow.crc8(self.buf):
- raise Exception('CRC error')
- return self.buf
-
- def write_scratch(self, rom, buf):
- self.ow.reset(True)
- self.ow.select_rom(rom)
- self.ow.writebyte(_WR_SCRATCH)
- self.ow.write(buf)
-
- def read_temp(self, rom):
- buf = self.read_scratch(rom)
- if rom[0] == 0x10:
- if buf[1]:
- t = buf[0] >> 1 | 0x80
- t = -((~t + 1) & 0xff)
- else:
- t = buf[0] >> 1
- return t - 0.25 + (buf[7] - buf[6]) / buf[7]
- else:
- t = buf[1] << 8 | buf[0]
- if t & 0x8000: # sign bit set
- t = -((t ^ 0xffff) + 1)
- return t / 16
+../../drivers/onewire/ds18x20.py \ No newline at end of file
diff --git a/esp8266/modules/onewire.py b/esp8266/modules/onewire.py
index 83318d1a47..f6ec745e85 100644..120000
--- a/esp8266/modules/onewire.py
+++ b/esp8266/modules/onewire.py
@@ -1,91 +1 @@
-# 1-Wire driver for MicroPython on ESP8266
-# MIT license; Copyright (c) 2016 Damien P. George
-
-from micropython import const
-import _onewire as _ow
-
-class OneWireError(Exception):
- pass
-
-class OneWire:
- SEARCH_ROM = const(0xf0)
- MATCH_ROM = const(0x55)
- SKIP_ROM = const(0xcc)
-
- def __init__(self, pin):
- self.pin = pin
- self.pin.init(pin.OPEN_DRAIN)
-
- def reset(self, required=False):
- reset = _ow.reset(self.pin)
- if required and not reset:
- raise OneWireError
- return reset
-
- def readbit(self):
- return _ow.readbit(self.pin)
-
- def readbyte(self):
- return _ow.readbyte(self.pin)
-
- def readinto(self, buf):
- for i in range(len(buf)):
- buf[i] = _ow.readbyte(self.pin)
-
- def writebit(self, value):
- return _ow.writebit(self.pin, value)
-
- def writebyte(self, value):
- return _ow.writebyte(self.pin, value)
-
- def write(self, buf):
- for b in buf:
- _ow.writebyte(self.pin, b)
-
- def select_rom(self, rom):
- self.reset()
- self.writebyte(MATCH_ROM)
- self.write(rom)
-
- def scan(self):
- devices = []
- diff = 65
- rom = False
- for i in range(0xff):
- rom, diff = self._search_rom(rom, diff)
- if rom:
- devices += [rom]
- if diff == 0:
- break
- return devices
-
- def _search_rom(self, l_rom, diff):
- if not self.reset():
- return None, 0
- self.writebyte(SEARCH_ROM)
- if not l_rom:
- l_rom = bytearray(8)
- rom = bytearray(8)
- next_diff = 0
- i = 64
- for byte in range(8):
- r_b = 0
- for bit in range(8):
- b = self.readbit()
- if self.readbit():
- if b: # there are no devices or there is an error on the bus
- return None, 0
- else:
- if not b: # collision, two devices with different bit meaning
- if diff > i or ((l_rom[byte] & (1 << bit)) and diff != i):
- b = 1
- next_diff = i
- self.writebit(b)
- if b:
- r_b |= 1 << bit
- i -= 1
- rom[byte] = r_b
- return rom, next_diff
-
- def crc8(self, data):
- return _ow.crc8(data)
+../../drivers/onewire/onewire.py \ No newline at end of file
diff --git a/esp8266/moduos.c b/esp8266/moduos.c
index 807d2e18a5..d0554096ed 100644
--- a/esp8266/moduos.c
+++ b/esp8266/moduos.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/modutime.c b/esp8266/modutime.c
index bdeb3bb453..afb14dfd6a 100644
--- a/esp8266/modutime.c
+++ b/esp8266/modutime.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h
index 483f93d02b..c45ed92c73 100644
--- a/esp8266/mpconfigport.h
+++ b/esp8266/mpconfigport.h
@@ -1,6 +1,6 @@
#include <stdint.h>
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
#define MICROPY_ALLOC_PATH_MAX (128)
@@ -17,6 +17,7 @@
#define MICROPY_DEBUG_PRINTER_DEST mp_debug_print
#define MICROPY_READER_VFS (MICROPY_VFS)
#define MICROPY_ENABLE_GC (1)
+#define MICROPY_ENABLE_FINALISER (1)
#define MICROPY_STACK_CHECK (1)
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
#define MICROPY_KBD_EXCEPTION (1)
@@ -148,7 +149,7 @@ void *esp_native_code_commit(void*, size_t);
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t esp_module;
@@ -157,24 +158,24 @@ extern const struct _mp_obj_module_t utime_module;
extern const struct _mp_obj_module_t uos_module;
extern const struct _mp_obj_module_t mp_module_lwip;
extern const struct _mp_obj_module_t mp_module_machine;
-extern const struct _mp_obj_module_t onewire_module;
+extern const struct _mp_obj_module_t mp_module_onewire;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_lwip }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_lwip }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&network_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&onewire_module }, \
+ { MP_ROM_QSTR(MP_QSTR_esp), MP_ROM_PTR(&esp_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_lwip) }, \
+ { MP_ROM_QSTR(MP_QSTR_network), MP_ROM_PTR(&network_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&utime_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&uos_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
+ { MP_ROM_QSTR(MP_QSTR__onewire), MP_ROM_PTR(&mp_module_onewire) }, \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&utime_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&uos_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
+ { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&utime_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&uos_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) }, \
+ { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \
+ { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_module_uselect) }, \
+ { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_module_lwip) }, \
#define MP_STATE_PORT MP_STATE_VM
diff --git a/esp8266/mpconfigport_512k.h b/esp8266/mpconfigport_512k.h
index 322fb4151a..b84c134792 100644
--- a/esp8266/mpconfigport_512k.h
+++ b/esp8266/mpconfigport_512k.h
@@ -5,6 +5,9 @@
#undef MICROPY_EMIT_INLINE_XTENSA
#define MICROPY_EMIT_INLINE_XTENSA (0)
+#undef MICROPY_ERROR_REPORTING
+#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
+
#undef MICROPY_VFS
#define MICROPY_VFS (0)
#undef MICROPY_VFS_FAT
diff --git a/esp8266/qstrdefsport.h b/esp8266/qstrdefsport.h
index 7610eb33da..8f301a69c5 100644
--- a/esp8266/qstrdefsport.h
+++ b/esp8266/qstrdefsport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/uart.h b/esp8266/uart.h
index f6850c42db..684689a0ec 100644
--- a/esp8266/uart.h
+++ b/esp8266/uart.h
@@ -1,5 +1,5 @@
-#ifndef _INCLUDED_UART_H_
-#define _INCLUDED_UART_H_
+#ifndef MICROPY_INCLUDED_ESP8266_UART_H
+#define MICROPY_INCLUDED_ESP8266_UART_H
#include <eagle_soc.h>
@@ -14,9 +14,9 @@ typedef enum {
} UartBitsNum4Char;
typedef enum {
- UART_ONE_STOP_BIT = 0,
- UART_ONE_HALF_STOP_BIT = BIT2,
- UART_TWO_STOP_BIT = BIT2
+ UART_ONE_STOP_BIT = 0x1,
+ UART_ONE_HALF_STOP_BIT = 0x2,
+ UART_TWO_STOP_BIT = 0x3
} UartStopBitsNum;
typedef enum {
@@ -103,4 +103,4 @@ void uart_setup(uint8 uart);
int uart_rx_any(uint8 uart);
int uart_tx_any_room(uint8 uart);
-#endif // _INCLUDED_UART_H_
+#endif // MICROPY_INCLUDED_ESP8266_UART_H
diff --git a/esp8266/xtirq.h b/esp8266/xtirq.h
index 856ff075ac..595052fc73 100644
--- a/esp8266/xtirq.h
+++ b/esp8266/xtirq.h
@@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-#ifndef __MICROPY_INCLUDED_ESP8266_XTIRQ_H__
-#define __MICROPY_INCLUDED_ESP8266_XTIRQ_H__
+#ifndef MICROPY_INCLUDED_ESP8266_XTIRQ_H
+#define MICROPY_INCLUDED_ESP8266_XTIRQ_H
#include <stdint.h>
@@ -57,4 +56,4 @@ static inline void enable_irq(uint32_t irq_state) {
restore_irq_pri(irq_state);
}
-#endif // __MICROPY_INCLUDED_ESP8266_XTIRQ_H__
+#endif // MICROPY_INCLUDED_ESP8266_XTIRQ_H