Skip to content

esp32: Two random changes that also fixed the I2C crash for me #3710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ports/esp32s2/common-hal/pulseio/PulseIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ void pulsein_reset(void) {
for (size_t i = 0; i < RMT_CHANNEL_MAX; i++) {
handles[i] = NULL;
}
supervisor_disable_tick();
if (refcount != 0) {
supervisor_disable_tick();
}
refcount = 0;
}

Expand Down Expand Up @@ -122,8 +124,10 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu

// start RMT RX, and enable ticks so the core doesn't turn off.
rmt_rx_start(channel, true);
supervisor_enable_tick();
refcount++;
if (refcount == 1) {
supervisor_enable_tick();
}
}

bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {
Expand Down
10 changes: 5 additions & 5 deletions ports/esp32s2/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ uint32_t port_get_saved_word(void) {
}

uint64_t port_get_raw_ticks(uint8_t* subticks) {
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
// convert usec back to ticks
uint64_t all_subticks = (uint64_t)(tv_now.tv_usec * 2) / 71;
// Convert microseconds to subticks of 1/32768 seconds
// 32768/1000000 = 64/15625 in lowest terms
// this arithmetic overflows after 570 years
int64_t all_subticks = esp_timer_get_time() * 512 / 15625;
if (subticks != NULL) {
*subticks = all_subticks % 32;
}
return (uint64_t)tv_now.tv_sec * 1024L + all_subticks / 32;
return all_subticks / 32;
}

// Enable 1/1024 second tick.
Expand Down