-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update time
to use SysTick
#274
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also some merge conflicts to fix.
atmel-samd/tick.c
Outdated
// _gclk_enable_channel(TC5_GCLK_ID, GCLK_SOURCE_DFLL48M); | ||
|
||
// timer_init(&ms_timer, TC5, _tc_get_timer()); | ||
SysTick->LOAD = ((CONF_CPU_FREQUENCY / 1000 - 1) << SysTick_LOAD_RELOAD_Pos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a TODO to replace this eventually, or have this call a HAL routine that returns the frequency? Could call common_hal_mcu_processor_get_frequency()
.
atmel-samd/tick.c
Outdated
uint64_t start_ms = ticks_ms; | ||
while (us > 1000) { | ||
while (ticks_ms == start_ms) {} | ||
us -= fractional; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my Googling, SysTick
units are dependent on clock frequency, right? The SysTick timer is decremented on each clock cycle. So for instance at 48MHz, one tick is 1sec/48e6. So are you mixing microsoeconds (us
) with SysTicks units?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! You are right.
Thanks for the review! I'll get to this in a few days after Maker Faire craziness. |
0a177fb
to
9dd16ac
Compare
@dhalbert could you take another look at this today? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good; just the one comment about using CMSIS.
atmel-samd/tick.c
Outdated
|
||
// timer_init(&ms_timer, TC5, _tc_get_timer()); | ||
uint32_t ticks_per_ms = common_hal_mcu_processor_get_frequency() / 1000; | ||
SysTick->LOAD = ((ticks_per_ms - 1) << SysTick_LOAD_RELOAD_Pos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do SysTick_Config(ticks_per_ms)
to replace lines 49-53.
I remembered what Dean told me about CMSIS and thought there might be a function to do this.
9dd16ac
to
93481ae
Compare
Ok, this is ready for review. I confirmed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
The HID descriptor reported by circuitpython erroneously limited the maximum keycode to 101, which prevented circuitpython from sending a number of otherwise valid keycodes. Closes #274
This doesn't actually use ASF4 at all but enables it again. This depends on #258