mirror of
https://github.com/sipeed/Maixduino.git
synced 2026-03-03 09:04:00 +01:00
add microsecond into Ticker lib #23
This commit is contained in:
@@ -10,8 +10,10 @@ Ticker KEYWORD1
|
||||
|
||||
attach KEYWORD2
|
||||
attach_ms KEYWORD2
|
||||
attach_us KEYWORD2
|
||||
once KEYWORD2
|
||||
once_ms KEYWORD2
|
||||
once_us KEYWORD2
|
||||
detach KEYWORD2
|
||||
|
||||
#######################################
|
||||
|
||||
@@ -25,6 +25,17 @@ Ticker::_attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callb
|
||||
sysctl_enable_irq();
|
||||
}
|
||||
|
||||
void
|
||||
Ticker::_attach_us(uint32_t microseconds, bool repeat, callback_with_arg_t callback, size_t arg)
|
||||
{
|
||||
user_callback = callback;
|
||||
_arg = arg;
|
||||
timer_set_interval(timer_device_number_t(timer_id), TIMER_CHANNEL_0, microseconds * 1000);
|
||||
timer_irq_register(timer_device_number_t(timer_id), TIMER_CHANNEL_0, !repeat, 4, timer_callback, this);
|
||||
timer_set_enable(timer_device_number_t(timer_id), TIMER_CHANNEL_0, 1);
|
||||
sysctl_enable_irq();
|
||||
}
|
||||
|
||||
void
|
||||
Ticker::detach()
|
||||
{
|
||||
|
||||
@@ -32,6 +32,11 @@ public:
|
||||
_attach_ms(milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), 0);
|
||||
}
|
||||
|
||||
void attach_us(uint32_t microseconds, callback_t callback)
|
||||
{
|
||||
_attach_us(microseconds, true, reinterpret_cast<callback_with_arg_t>(callback), 0);
|
||||
}
|
||||
|
||||
template<typename TArg>
|
||||
void attach(float seconds, void (*callback)(TArg), TArg arg)
|
||||
{
|
||||
@@ -48,6 +53,14 @@ public:
|
||||
_attach_ms(milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), arg32);
|
||||
}
|
||||
|
||||
template<typename TArg>
|
||||
void attach_us(uint32_t microseconds, void (*callback)(TArg), TArg arg)
|
||||
{
|
||||
configASSERT(sizeof(TArg) <= sizeof(size_t));
|
||||
size_t arg32 = (size_t)arg;
|
||||
_attach_us(microseconds, true, reinterpret_cast<callback_with_arg_t>(callback), arg32);
|
||||
}
|
||||
|
||||
void once(float seconds, callback_t callback)
|
||||
{
|
||||
_attach_ms(seconds * 1000, false, reinterpret_cast<callback_with_arg_t>(callback), 0);
|
||||
@@ -58,6 +71,11 @@ public:
|
||||
_attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), 0);
|
||||
}
|
||||
|
||||
void once_us(uint32_t microseconds, callback_t callback)
|
||||
{
|
||||
_attach_us(microseconds, false, reinterpret_cast<callback_with_arg_t>(callback), 0);
|
||||
}
|
||||
|
||||
template<typename TArg>
|
||||
void once(float seconds, void (*callback)(TArg), TArg arg)
|
||||
{
|
||||
@@ -74,6 +92,14 @@ public:
|
||||
_attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), arg32);
|
||||
}
|
||||
|
||||
template<typename TArg>
|
||||
void once_us(uint32_t microseconds, void (*callback)(TArg), TArg arg)
|
||||
{
|
||||
configASSERT(sizeof(TArg) <= sizeof(size_t));
|
||||
size_t arg32 = (size_t)(arg);
|
||||
_attach_us(microseconds, false, reinterpret_cast<callback_with_arg_t>(callback), arg32);
|
||||
}
|
||||
|
||||
void detach();
|
||||
bool active();
|
||||
|
||||
@@ -82,6 +108,7 @@ public:
|
||||
|
||||
protected:
|
||||
void _attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, size_t arg);
|
||||
void _attach_us(uint32_t microseconds, bool repeat, callback_with_arg_t callback, size_t arg);
|
||||
|
||||
private:
|
||||
timer_id_t timer_id;
|
||||
|
||||
Reference in New Issue
Block a user