ESPHome
2026.5.0b1
Loading...
Searching...
No Matches
esphome
core
time_conversion.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstdint>
4
5
namespace
esphome
{
6
30
template
<
typename
ReturnT = u
int
32_t>
31
__attribute__
((always_inline))
inline
constexpr
ReturnT micros_to_millis(uint64_t us) {
32
constexpr
uint32_t
d = 125U;
33
constexpr
uint32_t
q =
static_cast<
uint32_t
>
((1ULL << 32) / d);
// 34359738
34
constexpr
uint32_t
r =
static_cast<
uint32_t
>
((1ULL << 32) % d);
// 46
35
// 1000 = 8 * 125; divide-by-8 is a free shift
36
uint64_t
x
= us >> 3;
37
uint32_t
lo =
static_cast<
uint32_t
>
(
x
);
38
uint32_t
hi =
static_cast<
uint32_t
>
(
x
>> 32);
39
// Combine remainder term: hi * (2^32 % 125) + lo
40
uint32_t
adj = hi * r + lo;
41
// If adj overflowed, the true value is 2^32 + adj; apply the identity again
42
// static_cast<ReturnT>(hi) widens to 64-bit when ReturnT=uint64_t, preserving upper bits of hi*q
43
return
static_cast<
ReturnT
>
(hi) * q + (adj < lo ? (adj + r) / d + q : adj / d);
44
}
45
46
}
// namespace esphome
__attribute__
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition
main_task.h:32
esphome
Definition
a01nyub.cpp:7
uint32_t
static void uint32_t
Definition
crash_handler.cpp:141
x
uint16_t x
Definition
tt21100.cpp:5
Generated by
1.12.0