summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-06-29 16:01:46 -0400
committerDan Halbert <halbert@halwitz.org>2018-06-29 16:01:46 -0400
commit2a0b8576439b0cfefff909135dba424a2a179275 (patch)
tree65af38bd381fbf571692540cf5814812d7de77ca /shared-module
parentb4fd77bb7c041d2855dba826f380ce66944c23d4 (diff)
implement mp_hal_delay_us() to not need interrupts, and use it
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/bitbangio/OneWire.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/shared-module/bitbangio/OneWire.c b/shared-module/bitbangio/OneWire.c
index b226b9d78..f5f479087 100644
--- a/shared-module/bitbangio/OneWire.c
+++ b/shared-module/bitbangio/OneWire.c
@@ -24,8 +24,6 @@
* THE SOFTWARE.
*/
-#include "mphalport.h"
-
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/bitbangio/OneWire.h"
#include "shared-bindings/microcontroller/__init__.h"
@@ -51,17 +49,17 @@ void shared_module_bitbangio_onewire_deinit(bitbangio_onewire_obj_t* self) {
common_hal_digitalio_digitalinout_deinit(&self->pin);
}
-// We can't use common_hal_mcu_delay_us() here because it needs interrupts to be accurate
-// due to SysTick rollover checking, done by an interrupt.
+// We use common_hal_mcu_delay_us(). It should not be dependent on interrupts
+// to do accurate timekeeping, since we disable interrupts during the delays below.
bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t* self) {
common_hal_mcu_disable_interrupts();
common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN);
- mp_hal_delay_us_loop(480);
+ common_hal_mcu_delay_us(480);
common_hal_digitalio_digitalinout_switch_to_input(&self->pin, PULL_NONE);
- mp_hal_delay_us_loop(70);
+ common_hal_mcu_delay_us(70);
bool value = common_hal_digitalio_digitalinout_get_value(&self->pin);
- mp_hal_delay_us_loop(410);
+ common_hal_mcu_delay_us(410);
common_hal_mcu_enable_interrupts();
return value;
}
@@ -69,14 +67,14 @@ bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t* self) {
bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t* self) {
common_hal_mcu_disable_interrupts();
common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN);
- mp_hal_delay_us_loop(6);
+ common_hal_mcu_delay_us(6);
common_hal_digitalio_digitalinout_switch_to_input(&self->pin, PULL_NONE);
// TODO(tannewt): Test with more devices and maybe make the delays
// configurable. This should be 9 by the datasheet but all bits read as 1
// then.
- mp_hal_delay_us_loop(6);
+ common_hal_mcu_delay_us(6);
bool value = common_hal_digitalio_digitalinout_get_value(&self->pin);
- mp_hal_delay_us_loop(55);
+ common_hal_mcu_delay_us(55);
common_hal_mcu_enable_interrupts();
return value;
}
@@ -85,8 +83,8 @@ void shared_module_bitbangio_onewire_write_bit(bitbangio_onewire_obj_t* self,
bool bit) {
common_hal_mcu_disable_interrupts();
common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN);
- mp_hal_delay_us_loop(bit? 6 : 60);
+ common_hal_mcu_delay_us(bit? 6 : 60);
common_hal_digitalio_digitalinout_switch_to_input(&self->pin, PULL_NONE);
- mp_hal_delay_us_loop(bit? 64 : 10);
+ common_hal_mcu_delay_us(bit? 64 : 10);
common_hal_mcu_enable_interrupts();
}