File tree 2 files changed +10
-13
lines changed 2 files changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -283,12 +283,9 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self,
283
283
if (trigger_duration > 0 ) {
284
284
gpio_set_pin_pull_mode (self -> pin , GPIO_PULL_OFF );
285
285
gpio_set_pin_direction (self -> pin , GPIO_DIRECTION_OUT );
286
-
287
- common_hal_mcu_disable_interrupts ();
288
286
gpio_set_pin_level (self -> pin , !self -> idle_state );
289
- common_hal_mcu_delay_us (trigger_duration );
287
+ common_hal_mcu_delay_us (( uint32_t ) trigger_duration );
290
288
gpio_set_pin_level (self -> pin , self -> idle_state );
291
- common_hal_mcu_enable_interrupts ();
292
289
}
293
290
294
291
// Reconfigure the pin and make sure its set to detect the first edge.
Original file line number Diff line number Diff line change @@ -52,21 +52,21 @@ void SysTick_Handler(void) {
52
52
53
53
void tick_init () {
54
54
uint32_t ticks_per_ms = common_hal_mcu_processor_get_frequency () / 1000 ;
55
- SysTick_Config (ticks_per_ms );
55
+ SysTick_Config (ticks_per_ms - 1 );
56
56
NVIC_EnableIRQ (SysTick_IRQn );
57
57
}
58
58
59
59
void tick_delay (uint32_t us ) {
60
60
uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency () / 1000 / 1000 ;
61
- uint32_t us_between_ticks = SysTick -> VAL / ticks_per_us ;
62
- uint64_t start_ms = ticks_ms ;
63
- while (us > 1000 ) {
64
- while ( ticks_ms == start_ms ) {}
65
- us -= us_between_ticks ;
66
- start_ms = ticks_ms ;
67
- us_between_ticks = 1000 ;
61
+ uint32_t us_until_next_tick = SysTick -> VAL / ticks_per_us ;
62
+ uint32_t start_tick ;
63
+ while (us >= us_until_next_tick ) {
64
+ start_tick = SysTick -> VAL ; // wait for SysTick->VAL to RESET
65
+ while ( SysTick -> VAL < start_tick ) {}
66
+ us -= us_until_next_tick ;
67
+ us_until_next_tick = 1000 ;
68
68
}
69
- while (SysTick -> VAL > ((us_between_ticks - us ) * ticks_per_us )) {}
69
+ while (SysTick -> VAL > ((us_until_next_tick - us ) * ticks_per_us )) {}
70
70
}
71
71
72
72
// us counts down!
You can’t perform that action at this time.
0 commit comments