2015-01-22 17:34:16 -05:00
|
|
|
/*
|
2017-06-30 03:22:17 -04:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2015-01-22 17:34:16 -05:00
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 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
|
|
|
|
* 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 "py/gc.h"
|
|
|
|
#include "py/runtime.h"
|
2019-10-06 08:29:40 -04:00
|
|
|
#include "py/persistentcode.h"
|
2016-05-10 18:25:39 -04:00
|
|
|
#include "py/mperrno.h"
|
2016-05-02 17:23:54 -04:00
|
|
|
#include "py/mphal.h"
|
2016-05-26 12:11:43 -04:00
|
|
|
#include "drivers/dht/dht.h"
|
2016-04-05 17:12:58 -04:00
|
|
|
#include "uart.h"
|
2015-01-22 17:34:16 -05:00
|
|
|
#include "user_interface.h"
|
2016-05-02 17:35:11 -04:00
|
|
|
#include "mem.h"
|
2018-07-03 00:39:50 -04:00
|
|
|
#include "ets_alt_task.h"
|
2016-02-11 08:19:11 -05:00
|
|
|
#include "espneopixel.h"
|
2016-03-27 19:58:14 -04:00
|
|
|
#include "espapa102.h"
|
2016-11-05 18:30:19 -04:00
|
|
|
#include "modmachine.h"
|
2015-01-22 17:34:16 -05:00
|
|
|
|
2015-05-02 15:24:25 -04:00
|
|
|
#define MODESP_INCLUDE_CONSTANTS (1)
|
|
|
|
|
2015-06-12 10:26:10 -04:00
|
|
|
void error_check(bool status, const char *msg) {
|
2015-05-02 15:24:25 -04:00
|
|
|
if (!status) {
|
2019-11-04 19:33:03 -05:00
|
|
|
mp_raise_msg(&mp_type_OSError, msg);
|
2015-01-25 10:41:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-05 17:12:58 -04:00
|
|
|
STATIC mp_obj_t esp_osdebug(mp_obj_t val) {
|
|
|
|
if (val == mp_const_none) {
|
|
|
|
uart_os_config(-1);
|
|
|
|
} else {
|
|
|
|
uart_os_config(mp_obj_get_int(val));
|
|
|
|
}
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_osdebug_obj, esp_osdebug);
|
|
|
|
|
2017-08-29 20:59:58 -04:00
|
|
|
STATIC mp_obj_t esp_sleep_type(size_t n_args, const mp_obj_t *args) {
|
2015-05-15 06:00:39 -04:00
|
|
|
if (n_args == 0) {
|
|
|
|
return mp_obj_new_int(wifi_get_sleep_type());
|
|
|
|
} else {
|
|
|
|
wifi_set_sleep_type(mp_obj_get_int(args[0]));
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_sleep_type_obj, 0, 1, esp_sleep_type);
|
|
|
|
|
2017-08-29 20:59:58 -04:00
|
|
|
STATIC mp_obj_t esp_deepsleep(size_t n_args, const mp_obj_t *args) {
|
2016-06-03 11:21:26 -04:00
|
|
|
uint32_t sleep_us = n_args > 0 ? mp_obj_get_int(args[0]) : 0;
|
|
|
|
// prepare for RTC reset at wake up
|
|
|
|
rtc_prepare_deepsleep(sleep_us);
|
2016-04-17 11:28:47 -04:00
|
|
|
system_deep_sleep_set_option(n_args > 1 ? mp_obj_get_int(args[1]) : 0);
|
2016-06-03 11:21:26 -04:00
|
|
|
system_deep_sleep(sleep_us);
|
2015-05-15 06:00:39 -04:00
|
|
|
return mp_const_none;
|
|
|
|
}
|
2016-04-17 11:28:47 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_deepsleep_obj, 0, 2, esp_deepsleep);
|
2015-05-15 06:00:39 -04:00
|
|
|
|
|
|
|
STATIC mp_obj_t esp_flash_id() {
|
|
|
|
return mp_obj_new_int(spi_flash_get_id());
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_id_obj, esp_flash_id);
|
|
|
|
|
2016-03-27 08:34:35 -04:00
|
|
|
STATIC mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t len_or_buf_in) {
|
2015-11-24 16:28:20 -05:00
|
|
|
mp_int_t offset = mp_obj_get_int(offset_in);
|
2016-03-27 08:34:35 -04:00
|
|
|
|
|
|
|
mp_int_t len;
|
|
|
|
byte *buf;
|
2019-01-30 06:05:48 -05:00
|
|
|
bool alloc_buf = mp_obj_is_int(len_or_buf_in);
|
2016-03-27 08:34:35 -04:00
|
|
|
|
|
|
|
if (alloc_buf) {
|
|
|
|
len = mp_obj_get_int(len_or_buf_in);
|
|
|
|
buf = m_new(byte, len);
|
|
|
|
} else {
|
|
|
|
mp_buffer_info_t bufinfo;
|
|
|
|
mp_get_buffer_raise(len_or_buf_in, &bufinfo, MP_BUFFER_WRITE);
|
|
|
|
len = bufinfo.len;
|
|
|
|
buf = bufinfo.buf;
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:28:20 -05:00
|
|
|
// We know that allocation will be 4-byte aligned for sure
|
|
|
|
SpiFlashOpResult res = spi_flash_read(offset, (uint32_t*)buf, len);
|
|
|
|
if (res == SPI_FLASH_RESULT_OK) {
|
2016-03-27 08:34:35 -04:00
|
|
|
if (alloc_buf) {
|
|
|
|
return mp_obj_new_bytes(buf, len);
|
|
|
|
}
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
if (alloc_buf) {
|
|
|
|
m_del(byte, buf, len);
|
2015-11-24 16:28:20 -05:00
|
|
|
}
|
2016-10-06 23:00:51 -04:00
|
|
|
mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO);
|
2015-11-24 16:28:20 -05:00
|
|
|
}
|
2015-12-21 15:06:27 -05:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_read_obj, esp_flash_read);
|
2015-11-24 16:28:20 -05:00
|
|
|
|
2016-02-08 04:42:24 -05:00
|
|
|
STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) {
|
|
|
|
mp_int_t offset = mp_obj_get_int(offset_in);
|
|
|
|
mp_buffer_info_t bufinfo;
|
|
|
|
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
|
2016-03-27 08:32:58 -04:00
|
|
|
if (bufinfo.len & 0x3) {
|
2017-08-09 00:40:45 -04:00
|
|
|
mp_raise_ValueError("len must be multiple of 4");
|
2016-03-27 08:32:58 -04:00
|
|
|
}
|
2018-07-03 00:39:50 -04:00
|
|
|
ets_loop_iter(); // flash access takes time so run any pending tasks
|
2016-02-08 04:42:24 -05:00
|
|
|
SpiFlashOpResult res = spi_flash_write(offset, bufinfo.buf, bufinfo.len);
|
2018-07-03 00:39:50 -04:00
|
|
|
ets_loop_iter();
|
2016-02-08 04:42:24 -05:00
|
|
|
if (res == SPI_FLASH_RESULT_OK) {
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
2016-10-06 23:00:51 -04:00
|
|
|
mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO);
|
2016-02-08 04:42:24 -05:00
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_write_obj, esp_flash_write);
|
|
|
|
|
|
|
|
STATIC mp_obj_t esp_flash_erase(mp_obj_t sector_in) {
|
|
|
|
mp_int_t sector = mp_obj_get_int(sector_in);
|
2018-07-03 00:39:50 -04:00
|
|
|
ets_loop_iter(); // flash access takes time so run any pending tasks
|
2016-02-08 04:42:24 -05:00
|
|
|
SpiFlashOpResult res = spi_flash_erase_sector(sector);
|
2018-07-03 00:39:50 -04:00
|
|
|
ets_loop_iter();
|
2016-02-08 04:42:24 -05:00
|
|
|
if (res == SPI_FLASH_RESULT_OK) {
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
2016-10-06 23:00:51 -04:00
|
|
|
mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO);
|
2016-02-08 04:42:24 -05:00
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_flash_erase_obj, esp_flash_erase);
|
|
|
|
|
2016-04-18 10:12:57 -04:00
|
|
|
STATIC mp_obj_t esp_flash_size(void) {
|
|
|
|
extern char flashchip;
|
|
|
|
// For SDK 1.5.2, either address has shifted and not mirrored in
|
|
|
|
// eagle.rom.addr.v6.ld, or extra initial member was added.
|
|
|
|
SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
|
|
|
|
#if 0
|
|
|
|
printf("deviceId: %x\n", flash->deviceId);
|
|
|
|
printf("chip_size: %u\n", flash->chip_size);
|
|
|
|
printf("block_size: %u\n", flash->block_size);
|
|
|
|
printf("sector_size: %u\n", flash->sector_size);
|
|
|
|
printf("page_size: %u\n", flash->page_size);
|
|
|
|
printf("status_mask: %u\n", flash->status_mask);
|
|
|
|
#endif
|
|
|
|
return mp_obj_new_int_from_uint(flash->chip_size);
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size);
|
|
|
|
|
2017-01-02 16:02:00 -05:00
|
|
|
// If there's just 1 loadable segment at the start of flash,
|
|
|
|
// we assume there's a yaota8266 bootloader.
|
|
|
|
#define IS_OTA_FIRMWARE() ((*(uint32_t*)0x40200000 & 0xff00) == 0x100)
|
|
|
|
|
2017-05-12 08:58:19 -04:00
|
|
|
extern byte _firmware_size[];
|
|
|
|
|
2016-10-23 18:03:17 -04:00
|
|
|
STATIC mp_obj_t esp_flash_user_start(void) {
|
2017-05-12 08:58:19 -04:00
|
|
|
return MP_OBJ_NEW_SMALL_INT((uint32_t)_firmware_size);
|
2016-10-23 18:03:17 -04:00
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_user_start_obj, esp_flash_user_start);
|
|
|
|
|
2016-08-03 17:29:19 -04:00
|
|
|
STATIC mp_obj_t esp_check_fw(void) {
|
|
|
|
MD5_CTX ctx;
|
2017-01-02 16:02:00 -05:00
|
|
|
char *fw_start = (char*)0x40200000;
|
|
|
|
if (IS_OTA_FIRMWARE()) {
|
|
|
|
// Skip yaota8266 bootloader
|
|
|
|
fw_start += 0x3c000;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t size = *(uint32_t*)(fw_start + 0x8ffc);
|
|
|
|
printf("size: %d\n", size);
|
|
|
|
if (size > 1024 * 1024) {
|
2017-01-02 21:50:18 -05:00
|
|
|
printf("Invalid size\n");
|
2017-01-02 16:02:00 -05:00
|
|
|
return mp_const_false;
|
|
|
|
}
|
2016-08-03 17:29:19 -04:00
|
|
|
MD5Init(&ctx);
|
2017-01-02 16:02:00 -05:00
|
|
|
MD5Update(&ctx, fw_start + 4, size - 4);
|
2016-08-03 17:29:19 -04:00
|
|
|
unsigned char digest[16];
|
|
|
|
MD5Final(digest, &ctx);
|
|
|
|
printf("md5: ");
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
printf("%02x", digest[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
2017-01-02 16:02:00 -05:00
|
|
|
return mp_obj_new_bool(memcmp(digest, fw_start + size, sizeof(digest)) == 0);
|
2016-08-03 17:29:19 -04:00
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_check_fw_obj, esp_check_fw);
|
|
|
|
|
|
|
|
|
2016-02-11 08:19:11 -05:00
|
|
|
STATIC mp_obj_t esp_neopixel_write_(mp_obj_t pin, mp_obj_t buf, mp_obj_t is800k) {
|
|
|
|
mp_buffer_info_t bufinfo;
|
|
|
|
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
|
|
|
|
esp_neopixel_write(mp_obj_get_pin_obj(pin)->phys_port,
|
|
|
|
(uint8_t*)bufinfo.buf, bufinfo.len, mp_obj_is_true(is800k));
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
|
|
|
|
|
2016-07-31 17:03:55 -04:00
|
|
|
#if MICROPY_ESP8266_APA102
|
2016-03-27 19:58:14 -04:00
|
|
|
STATIC mp_obj_t esp_apa102_write_(mp_obj_t clockPin, mp_obj_t dataPin, mp_obj_t buf) {
|
|
|
|
mp_buffer_info_t bufinfo;
|
|
|
|
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
|
|
|
|
esp_apa102_write(mp_obj_get_pin_obj(clockPin)->phys_port,
|
|
|
|
mp_obj_get_pin_obj(dataPin)->phys_port,
|
|
|
|
(uint8_t*)bufinfo.buf, bufinfo.len);
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_apa102_write_obj, esp_apa102_write_);
|
2016-07-31 17:03:55 -04:00
|
|
|
#endif
|
2016-03-27 19:58:14 -04:00
|
|
|
|
2016-04-10 18:16:38 -04:00
|
|
|
STATIC mp_obj_t esp_freemem() {
|
|
|
|
return MP_OBJ_NEW_SMALL_INT(system_get_free_heap_size());
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_freemem_obj, esp_freemem);
|
|
|
|
|
|
|
|
STATIC mp_obj_t esp_meminfo() {
|
|
|
|
system_print_meminfo();
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_meminfo_obj, esp_meminfo);
|
|
|
|
|
2016-05-02 17:35:11 -04:00
|
|
|
STATIC mp_obj_t esp_malloc(mp_obj_t size_in) {
|
|
|
|
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)os_malloc(mp_obj_get_int(size_in)));
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_malloc_obj, esp_malloc);
|
|
|
|
|
|
|
|
STATIC mp_obj_t esp_free(mp_obj_t addr_in) {
|
|
|
|
os_free((void*)mp_obj_get_int(addr_in));
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_free_obj, esp_free);
|
|
|
|
|
2016-05-02 17:23:54 -04:00
|
|
|
STATIC mp_obj_t esp_esf_free_bufs(mp_obj_t idx_in) {
|
|
|
|
return MP_OBJ_NEW_SMALL_INT(ets_esf_free_bufs(mp_obj_get_int(idx_in)));
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_esf_free_bufs_obj, esp_esf_free_bufs);
|
|
|
|
|
2016-12-09 01:05:51 -05:00
|
|
|
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
|
2016-12-09 00:47:47 -05:00
|
|
|
|
|
|
|
// We provide here a way of committing executable data to a region from
|
|
|
|
// which it can be executed by the CPU. There are 2 such writable regions:
|
|
|
|
// - iram1, which may have some space left at the end of it
|
|
|
|
// - memory-mapped flash rom
|
|
|
|
//
|
|
|
|
// By default the iram1 region (the space at the end of it) is used. The
|
|
|
|
// user can select iram1 or a section of flash by calling the
|
|
|
|
// esp.set_native_code_location() function; see below. If flash is selected
|
|
|
|
// then it is erased as needed.
|
|
|
|
|
|
|
|
#define IRAM1_END (0x40108000)
|
|
|
|
#define FLASH_START (0x40200000)
|
|
|
|
#define FLASH_END (0x40300000)
|
|
|
|
#define FLASH_SEC_SIZE (4096)
|
|
|
|
|
|
|
|
#define ESP_NATIVE_CODE_IRAM1 (0)
|
|
|
|
#define ESP_NATIVE_CODE_FLASH (1)
|
|
|
|
|
|
|
|
extern uint32_t _lit4_end;
|
|
|
|
STATIC uint32_t esp_native_code_location;
|
|
|
|
STATIC uint32_t esp_native_code_start;
|
|
|
|
STATIC uint32_t esp_native_code_end;
|
|
|
|
STATIC uint32_t esp_native_code_cur;
|
|
|
|
STATIC uint32_t esp_native_code_erased;
|
|
|
|
|
|
|
|
void esp_native_code_init(void) {
|
|
|
|
esp_native_code_location = ESP_NATIVE_CODE_IRAM1;
|
|
|
|
esp_native_code_start = (uint32_t)&_lit4_end;
|
|
|
|
esp_native_code_end = IRAM1_END;
|
|
|
|
esp_native_code_cur = esp_native_code_start;
|
|
|
|
esp_native_code_erased = 0;
|
|
|
|
}
|
|
|
|
|
2019-10-06 08:29:40 -04:00
|
|
|
void *esp_native_code_commit(void *buf, size_t len, void *reloc) {
|
2016-12-09 00:47:47 -05:00
|
|
|
//printf("COMMIT(buf=%p, len=%u, start=%08x, cur=%08x, end=%08x, erased=%08x)\n", buf, len, esp_native_code_start, esp_native_code_cur, esp_native_code_end, esp_native_code_erased);
|
|
|
|
|
|
|
|
len = (len + 3) & ~3;
|
|
|
|
if (esp_native_code_cur + len > esp_native_code_end) {
|
2020-02-10 19:48:28 -05:00
|
|
|
mp_raise_msg_varg(&mp_type_MemoryError,
|
|
|
|
"memory allocation failed, allocating %u bytes for native code", (uint)len);
|
2016-12-09 00:47:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void *dest;
|
|
|
|
if (esp_native_code_location == ESP_NATIVE_CODE_IRAM1) {
|
|
|
|
dest = (void*)esp_native_code_cur;
|
2019-10-06 08:29:40 -04:00
|
|
|
} else {
|
|
|
|
dest = (void*)(FLASH_START + esp_native_code_cur);
|
|
|
|
}
|
|
|
|
if (reloc) {
|
|
|
|
mp_native_relocate(reloc, buf, (uintptr_t)dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esp_native_code_location == ESP_NATIVE_CODE_IRAM1) {
|
2016-12-09 00:47:47 -05:00
|
|
|
memcpy(dest, buf, len);
|
|
|
|
} else {
|
|
|
|
SpiFlashOpResult res;
|
|
|
|
while (esp_native_code_erased < esp_native_code_cur + len) {
|
2018-07-03 00:39:50 -04:00
|
|
|
ets_loop_iter(); // flash access takes time so run any pending tasks
|
2016-12-09 00:47:47 -05:00
|
|
|
res = spi_flash_erase_sector(esp_native_code_erased / FLASH_SEC_SIZE);
|
|
|
|
if (res != SPI_FLASH_RESULT_OK) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
esp_native_code_erased += FLASH_SEC_SIZE;
|
|
|
|
}
|
2018-07-03 00:39:50 -04:00
|
|
|
ets_loop_iter();
|
2016-12-09 00:47:47 -05:00
|
|
|
if (res == SPI_FLASH_RESULT_OK) {
|
|
|
|
res = spi_flash_write(esp_native_code_cur, buf, len);
|
2018-07-03 00:39:50 -04:00
|
|
|
ets_loop_iter();
|
2016-12-09 00:47:47 -05:00
|
|
|
}
|
|
|
|
if (res != SPI_FLASH_RESULT_OK) {
|
|
|
|
mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_native_code_cur += len;
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC mp_obj_t esp_set_native_code_location(mp_obj_t start_in, mp_obj_t len_in) {
|
|
|
|
if (start_in == mp_const_none && len_in == mp_const_none) {
|
|
|
|
// use end of iram1 region
|
|
|
|
esp_native_code_init();
|
|
|
|
} else {
|
|
|
|
// use flash; input params are byte offsets from start of flash
|
|
|
|
esp_native_code_location = ESP_NATIVE_CODE_FLASH;
|
|
|
|
esp_native_code_start = mp_obj_get_int(start_in);
|
|
|
|
esp_native_code_end = esp_native_code_start + mp_obj_get_int(len_in);
|
|
|
|
esp_native_code_cur = esp_native_code_start;
|
|
|
|
esp_native_code_erased = esp_native_code_start;
|
|
|
|
// memory-mapped flash is limited in extents to 1MByte
|
|
|
|
if (esp_native_code_end > FLASH_END - FLASH_START) {
|
|
|
|
mp_raise_ValueError("flash location must be below 1MByte");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_set_native_code_location_obj, esp_set_native_code_location);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-07-30 11:13:01 -04:00
|
|
|
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) },
|
2016-10-08 17:56:46 -04:00
|
|
|
#if MICROPY_ESP8266_NEOPIXEL
|
2017-07-30 11:13:01 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_neopixel_write), MP_ROM_PTR(&esp_neopixel_write_obj) },
|
2016-10-08 17:56:46 -04:00
|
|
|
#endif
|
2016-07-31 17:03:55 -04:00
|
|
|
#if MICROPY_ESP8266_APA102
|
2017-07-30 11:13:01 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_apa102_write), MP_ROM_PTR(&esp_apa102_write_obj) },
|
2016-07-31 17:03:55 -04:00
|
|
|
#endif
|
2017-07-30 11:13:01 -04:00
|
|
|
{ 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) },
|
2016-12-09 01:05:51 -05:00
|
|
|
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
|
2017-07-30 11:13:01 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_set_native_code_location), MP_ROM_PTR(&esp_set_native_code_location_obj) },
|
2016-12-09 00:47:47 -05:00
|
|
|
#endif
|
2015-04-30 15:36:02 -04:00
|
|
|
|
|
|
|
#if MODESP_INCLUDE_CONSTANTS
|
2017-07-30 11:13:01 -04:00
|
|
|
{ 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) },
|
2015-04-30 15:36:02 -04:00
|
|
|
#endif
|
2015-01-22 17:34:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table);
|
|
|
|
|
|
|
|
const mp_obj_module_t esp_module = {
|
|
|
|
.base = { &mp_type_module },
|
|
|
|
.globals = (mp_obj_dict_t*)&esp_module_globals,
|
|
|
|
};
|