Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 33e0dd9

Browse files
author
Craig Wm. Versek
committed
take their more conservative 96kB heap allocation
2 parents b60fc4f + f3913bf commit 33e0dd9

21 files changed

+464
-120
lines changed

esp32/Makefile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ ESPCOMP = $(ESPIDF)/components
2929
ESPTOOL ?= $(ESPCOMP)/esptool_py/esptool/esptool.py
3030

3131
# verify the ESP IDF version
32-
ESPIDF_SUPHASH := 13dfb5568dcc30aa43363c49f7a4505d04036424
33-
ESPIDF_CURHASH := $(shell git -C $(ESPIDF) show --pretty=format:'%H')
32+
ESPIDF_SUPHASH := c06cc31d85cc700e1dbddbe527d4282c4bc5845a
33+
ESPIDF_CURHASH := $(shell git -C $(ESPIDF) show -s --pretty=format:'%H')
3434
ifneq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH))
3535
$(info ** WARNING **)
3636
$(info The git hash of ESP IDF does not match the supported version)
@@ -116,6 +116,7 @@ SRC_C = \
116116
mphalport.c \
117117
fatfs_port.c \
118118
help.c \
119+
esponewire.c \
119120
modutime.c \
120121
moduos.c \
121122
machine_pin.c \
@@ -126,13 +127,18 @@ SRC_C = \
126127
modnetwork.c \
127128
modsocket.c \
128129
modesp.c \
130+
espneopixel.c \
129131
$(SRC_MOD)
130132

131133
STM_SRC_C = $(addprefix stmhal/,\
132134
pybstdio.c \
133135
input.c \
134136
)
135137

138+
ESP8266_SRC_C = $(addprefix esp8266/,\
139+
modonewire.c \
140+
)
141+
136142
EXTMOD_SRC_C = $(addprefix extmod/,\
137143
)
138144

@@ -169,18 +175,20 @@ LIB_SRC_C += \
169175
endif
170176

171177
DRIVERS_SRC_C = $(addprefix drivers/,\
178+
dht/dht.c \
172179
)
173180

174181
OBJ_MP =
175182
OBJ_MP += $(PY_O)
176183
OBJ_MP += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
177184
OBJ_MP += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
185+
OBJ_MP += $(addprefix $(BUILD)/, $(ESP8266_SRC_C:.c=.o))
178186
OBJ_MP += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o))
179187
OBJ_MP += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
180188
OBJ_MP += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
181189

182190
# List of sources for qstr extraction
183-
SRC_QSTR += $(SRC_C) $(STM_SRC_C) $(EXTMOD_SRC_C) $(DRIVERS_SRC_C)
191+
SRC_QSTR += $(SRC_C) $(STM_SRC_C) $(ESP8266_SRC_C) $(EXTMOD_SRC_C) $(DRIVERS_SRC_C)
184192
# Append any auto-generated sources that are needed by sources listed in SRC_QSTR
185193
SRC_QSTR_AUTO_DEPS +=
186194

@@ -531,16 +539,20 @@ OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_WPA_SUPPLICANT_O))
531539
################################################################################
532540
# Main targets
533541

534-
all: $(BUILD)/bootloader.bin $(BUILD)/partitions.bin $(BUILD)/application.bin
542+
all: $(BUILD)/firmware.bin
535543

536544
.PHONY: idf-version deploy erase
537545

538546
idf-version:
539547
$(ECHO) "ESP IDF supported hash: $(ESPIDF_SUPHASH)"
540548

541-
deploy: $(BUILD)/bootloader.bin $(BUILD)/partitions.bin $(BUILD)/application.bin
549+
$(BUILD)/firmware.bin: $(BUILD)/bootloader.bin $(BUILD)/partitions.bin $(BUILD)/application.bin
550+
$(ECHO) "Create $@"
551+
$(Q)$(PYTHON) makeimg.py $^ $@
552+
553+
deploy: $(BUILD)/firmware.bin
542554
$(ECHO) "Writing $^ to the board"
543-
$(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) write_flash -z --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) --flash_size $(FLASH_SIZE) 0x1000 $(BUILD)/bootloader.bin 0x8000 $(BUILD)/partitions.bin 0x10000 $(BUILD)/application.bin
555+
$(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) write_flash -z --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) --flash_size $(FLASH_SIZE) 0 $^
544556

545557
erase:
546558
$(ECHO) "Erasing flash"

esp32/espneopixel.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Original version from https://github.com/adafruit/Adafruit_NeoPixel
2+
// Modifications by dpgeorge to support auto-CPU-frequency detection
3+
4+
// This is a mash-up of the Due show() code + insights from Michael Miller's
5+
// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus
6+
// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution.
7+
8+
#include "py/mpconfig.h"
9+
#include "py/mphal.h"
10+
#include "modesp.h"
11+
12+
void IRAM_ATTR esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t timing) {
13+
uint8_t *p, *end, pix, mask;
14+
uint32_t t, time0, time1, period, c, startTime, pinMask;
15+
16+
pinMask = 1 << pin;
17+
p = pixels;
18+
end = p + numBytes;
19+
pix = *p++;
20+
mask = 0x80;
21+
startTime = 0;
22+
23+
uint32_t fcpu = ets_get_cpu_frequency() * 1000000;
24+
25+
if (timing == 1) {
26+
// 800 KHz
27+
time0 = (fcpu * 0.35) / 1000000; // 0.35us
28+
time1 = (fcpu * 0.8) / 1000000; // 0.8us
29+
period = (fcpu * 1.25) / 1000000; // 1.25us per bit
30+
} else {
31+
// 400 KHz
32+
time0 = (fcpu * 0.5) / 1000000; // 0.35us
33+
time1 = (fcpu * 1.2) / 1000000; // 0.8us
34+
period = (fcpu * 2.5) / 1000000; // 1.25us per bit
35+
}
36+
37+
uint32_t irq_state = mp_hal_quiet_timing_enter();
38+
for (t = time0;; t = time0) {
39+
if (pix & mask) t = time1; // Bit high duration
40+
while (((c = mp_hal_ticks_cpu()) - startTime) < period); // Wait for bit start
41+
GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, pinMask); // Set high
42+
startTime = c; // Save start time
43+
while (((c = mp_hal_ticks_cpu()) - startTime) < t); // Wait high duration
44+
GPIO_REG_WRITE(GPIO_OUT_W1TC_REG, pinMask); // Set low
45+
if (!(mask >>= 1)) { // Next bit/byte
46+
if(p >= end) break;
47+
pix = *p++;
48+
mask = 0x80;
49+
}
50+
}
51+
while ((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit
52+
mp_hal_quiet_timing_exit(irq_state);
53+
}

esp32/esponewire.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2015-2017 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/mphal.h"
28+
#include "esp8266/esponewire.h"
29+
30+
#define TIMING_RESET1 (0)
31+
#define TIMING_RESET2 (1)
32+
#define TIMING_RESET3 (2)
33+
#define TIMING_READ1 (3)
34+
#define TIMING_READ2 (4)
35+
#define TIMING_READ3 (5)
36+
#define TIMING_WRITE1 (6)
37+
#define TIMING_WRITE2 (7)
38+
#define TIMING_WRITE3 (8)
39+
40+
uint16_t esp_onewire_timings[9] = {480, 40, 420, 5, 5, 40, 10, 50, 10};
41+
42+
#define DELAY_US mp_hal_delay_us_fast
43+
44+
int esp_onewire_reset(mp_hal_pin_obj_t pin) {
45+
mp_hal_pin_write(pin, 0);
46+
DELAY_US(esp_onewire_timings[TIMING_RESET1]);
47+
uint32_t i = disable_irq();
48+
mp_hal_pin_write(pin, 1);
49+
DELAY_US(esp_onewire_timings[TIMING_RESET2]);
50+
int status = !mp_hal_pin_read(pin);
51+
enable_irq(i);
52+
DELAY_US(esp_onewire_timings[TIMING_RESET3]);
53+
return status;
54+
}
55+
56+
int esp_onewire_readbit(mp_hal_pin_obj_t pin) {
57+
mp_hal_pin_write(pin, 1);
58+
uint32_t i = disable_irq();
59+
mp_hal_pin_write(pin, 0);
60+
DELAY_US(esp_onewire_timings[TIMING_READ1]);
61+
mp_hal_pin_write(pin, 1);
62+
DELAY_US(esp_onewire_timings[TIMING_READ2]);
63+
int value = mp_hal_pin_read(pin);
64+
enable_irq(i);
65+
DELAY_US(esp_onewire_timings[TIMING_READ3]);
66+
return value;
67+
}
68+
69+
void esp_onewire_writebit(mp_hal_pin_obj_t pin, int value) {
70+
uint32_t i = disable_irq();
71+
mp_hal_pin_write(pin, 0);
72+
DELAY_US(esp_onewire_timings[TIMING_WRITE1]);
73+
if (value) {
74+
mp_hal_pin_write(pin, 1);
75+
}
76+
DELAY_US(esp_onewire_timings[TIMING_WRITE2]);
77+
mp_hal_pin_write(pin, 1);
78+
DELAY_US(esp_onewire_timings[TIMING_WRITE3]);
79+
enable_irq(i);
80+
}

esp32/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1)
5151
#define MP_TASK_STACK_SIZE (32 * 1024)
5252
#define MP_TASK_STACK_LEN (MP_TASK_STACK_SIZE / sizeof(StackType_t))
53-
#define MP_TASK_HEAP_SIZE (128 * 1024)
53+
#define MP_TASK_HEAP_SIZE (96 * 1024)
5454

5555
//STATIC StaticTask_t mp_task_tcb;
5656
//STATIC StackType_t mp_task_stack[MP_TASK_STACK_LEN] __attribute__((aligned (8)));

esp32/makeimg.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
3+
OFFSET_BOOTLOADER = 0x1000
4+
OFFSET_PARTITIONS = 0x8000
5+
OFFSET_APPLICATION = 0x10000
6+
7+
files_in = [
8+
('bootloader', OFFSET_BOOTLOADER, sys.argv[1]),
9+
('partitions', OFFSET_PARTITIONS, sys.argv[2]),
10+
('application', OFFSET_APPLICATION, sys.argv[3]),
11+
]
12+
file_out = sys.argv[4]
13+
14+
cur_offset = 0
15+
with open(file_out, 'wb') as fout:
16+
for name, offset, file_in in files_in:
17+
assert offset >= cur_offset
18+
fout.write(b'\xff' * (offset - cur_offset))
19+
cur_offset = offset
20+
with open(file_in, 'rb') as fin:
21+
data = fin.read()
22+
fout.write(data)
23+
cur_offset += len(data)
24+
print('%-12s% 8d' % (name, len(data)))
25+
print('%-12s% 8d' % ('total', cur_offset))

esp32/modesp.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
#include "py/runtime.h"
3535
#include "py/mperrno.h"
36+
#include "py/mphal.h"
37+
#include "drivers/dht/dht.h"
38+
#include "modesp.h"
3639

3740
STATIC mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t buf_in) {
3841
mp_int_t offset = mp_obj_get_int(offset_in);
@@ -78,6 +81,15 @@ STATIC mp_obj_t esp_flash_user_start(void) {
7881
}
7982
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_user_start_obj, esp_flash_user_start);
8083

84+
STATIC mp_obj_t esp_neopixel_write_(mp_obj_t pin, mp_obj_t buf, mp_obj_t timing) {
85+
mp_buffer_info_t bufinfo;
86+
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
87+
esp_neopixel_write(mp_hal_get_pin_obj(pin),
88+
(uint8_t*)bufinfo.buf, bufinfo.len, mp_obj_get_int(timing));
89+
return mp_const_none;
90+
}
91+
STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
92+
8193
STATIC const mp_rom_map_elem_t esp_module_globals_table[] = {
8294
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) },
8395

@@ -86,6 +98,9 @@ STATIC const mp_rom_map_elem_t esp_module_globals_table[] = {
8698
{ MP_ROM_QSTR(MP_QSTR_flash_erase), MP_ROM_PTR(&esp_flash_erase_obj) },
8799
{ MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&esp_flash_size_obj) },
88100
{ MP_ROM_QSTR(MP_QSTR_flash_user_start), MP_ROM_PTR(&esp_flash_user_start_obj) },
101+
102+
{ MP_ROM_QSTR(MP_QSTR_neopixel_write), MP_ROM_PTR(&esp_neopixel_write_obj) },
103+
{ MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) },
89104
};
90105

91106
STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table);
@@ -94,3 +109,4 @@ const mp_obj_module_t esp_module = {
94109
.base = { &mp_type_module },
95110
.globals = (mp_obj_dict_t*)&esp_module_globals,
96111
};
112+

esp32/modesp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t timing);

esp32/modmachine.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ STATIC mp_obj_t machine_idle(void) {
7676
}
7777
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
7878

79+
STATIC mp_obj_t machine_disable_irq(void) {
80+
uint32_t state = disable_irq();
81+
return mp_obj_new_int(state);
82+
}
83+
MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);
84+
85+
STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) {
86+
uint32_t state = mp_obj_get_int(state_in);
87+
enable_irq(state);
88+
return mp_const_none;
89+
}
90+
MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq);
91+
7992
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
8093
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
8194

@@ -87,6 +100,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
87100
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
88101
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
89102

103+
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
104+
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
105+
90106
{ MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) },
91107

92108
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy