From ff208d767741104f7d2644a58269d7064d4c1b6a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Sat, 25 Mar 2017 12:04:49 +0000 Subject: Add low-level OneWire support class. This class focuses on the timing sensitive parts of the protocol. Everything else will be done by Python code. This also establishes that its OK to back a nativeio class with a bitbang implementation when no hardware acceleration exists. When it does, then bitbangio should be used to explicitly bitbang a protocol. --- shared-bindings/bitbangio/OneWire.c | 166 ++++++++++++++++++++++++++++++++++ shared-bindings/bitbangio/OneWire.h | 42 +++++++++ shared-bindings/bitbangio/__init__.c | 5 +- shared-bindings/nativeio/OneWire.c | 169 +++++++++++++++++++++++++++++++++++ shared-bindings/nativeio/OneWire.h | 42 +++++++++ shared-bindings/nativeio/__init__.c | 20 +++-- 6 files changed, 435 insertions(+), 9 deletions(-) create mode 100644 shared-bindings/bitbangio/OneWire.c create mode 100644 shared-bindings/bitbangio/OneWire.h create mode 100644 shared-bindings/nativeio/OneWire.c create mode 100644 shared-bindings/nativeio/OneWire.h (limited to 'shared-bindings') diff --git a/shared-bindings/bitbangio/OneWire.c b/shared-bindings/bitbangio/OneWire.c new file mode 100644 index 000000000..14645444d --- /dev/null +++ b/shared-bindings/bitbangio/OneWire.c @@ -0,0 +1,166 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/runtime0.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/bitbangio/OneWire.h" + +//| .. currentmodule:: bitbangio +//| +//| :class:`OneWire` -- Lowest-level of the Maxim OneWire protocol +//| =============================================================== +//| +//| :class:`~bitbangio.OneWire` implements the timing-sensitive foundation of +//| the Maxim (formerly Dallas Semi) OneWire protocol. +//| +//| Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126 +//| +//| .. class:: OneWire(pin) +//| +//| Create a OneWire object associated with the given pin. The object +//| implements the lowest level timing-sensitive bits of the protocol. +//| +//| :param ~microcontroller.Pin pin: Pin to read pulses from. +//| +//| Read a short series of pulses:: +//| +//| import bitbangio +//| import board +//| +//| with bitbangio.OneWire(board.D7) as onewire: +//| onewire.reset() +//| onewire.write_bit(True) +//| onewire.write_bit(False) +//| print(onewire.read_bit()) +//| +STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { + mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); + enum { ARG_pin }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + assert_pin(args[ARG_pin].u_obj, false); + const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj); + assert_pin_free(pin); + + bitbangio_onewire_obj_t *self = m_new_obj(bitbangio_onewire_obj_t); + self->base.type = &bitbangio_onewire_type; + + shared_module_bitbangio_onewire_construct(self, pin); + return MP_OBJ_FROM_PTR(self); +} + +//| .. method:: deinit() +//| +//| Deinitialize the OneWire bus and release any hardware resources for reuse. +//| +STATIC mp_obj_t bitbangio_onewire_deinit(mp_obj_t self_in) { + bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + shared_module_bitbangio_onewire_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_deinit_obj, bitbangio_onewire_deinit); + +//| .. method:: __enter__() +//| +//| No-op used by Context Managers. +//| +// Provided by context manager helper. + +//| .. method:: __exit__() +//| +//| Automatically deinitializes the hardware when exiting a context. +//| +STATIC mp_obj_t bitbangio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + shared_module_bitbangio_onewire_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_onewire___exit___obj, 4, 4, bitbangio_onewire_obj___exit__); + +//| .. method:: reset() +//| +//| Reset the OneWire bus +//| +STATIC mp_obj_t bitbangio_onewire_obj_reset(mp_obj_t self_in) { + bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_bool(shared_module_bitbangio_onewire_reset(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_reset_obj, bitbangio_onewire_obj_reset); + +//| .. method:: read_bit() +//| +//| Read in a bit +//| +//| :returns: bit state read +//| :rtype: bool +//| +STATIC mp_obj_t bitbangio_onewire_obj_read_bit(mp_obj_t self_in) { + bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_bool(shared_module_bitbangio_onewire_read_bit(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_read_bit_obj, bitbangio_onewire_obj_read_bit); + +//| .. method:: write_bit(value) +//| +//| Write out a bit based on value. +//| +STATIC mp_obj_t bitbangio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) { + bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + + shared_module_bitbangio_onewire_write_bit(self, mp_obj_is_true(bool_obj)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_onewire_write_bit_obj, bitbangio_onewire_obj_write_bit); + +STATIC const mp_rom_map_elem_t bitbangio_onewire_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&bitbangio_onewire_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&bitbangio_onewire___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&bitbangio_onewire_reset_obj) }, + { MP_ROM_QSTR(MP_QSTR_read_bit), MP_ROM_PTR(&bitbangio_onewire_read_bit_obj) }, + { MP_ROM_QSTR(MP_QSTR_write_bit), MP_ROM_PTR(&bitbangio_onewire_write_bit_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(bitbangio_onewire_locals_dict, bitbangio_onewire_locals_dict_table); + +const mp_obj_type_t bitbangio_onewire_type = { + { &mp_type_type }, + .name = MP_QSTR_OneWire, + .make_new = bitbangio_onewire_make_new, + .locals_dict = (mp_obj_dict_t*)&bitbangio_onewire_locals_dict, +}; diff --git a/shared-bindings/bitbangio/OneWire.h b/shared-bindings/bitbangio/OneWire.h new file mode 100644 index 000000000..dcc0386d4 --- /dev/null +++ b/shared-bindings/bitbangio/OneWire.h @@ -0,0 +1,42 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_ONEWIRE_H__ +#define __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_ONEWIRE_H__ + +#include "common-hal/microcontroller/types.h" +#include "shared-module/bitbangio/types.h" + +extern const mp_obj_type_t bitbangio_onewire_type; + +extern void shared_module_bitbangio_onewire_construct(bitbangio_onewire_obj_t* self, + const mcu_pin_obj_t* pin); +extern void shared_module_bitbangio_onewire_deinit(bitbangio_onewire_obj_t* self); +extern bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t* self); +extern bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t* self); +extern void shared_module_bitbangio_onewire_write_bit(bitbangio_onewire_obj_t* self, bool bit); + +#endif // __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_ONEWIRE_H__ diff --git a/shared-bindings/bitbangio/__init__.c b/shared-bindings/bitbangio/__init__.c index 6d864fd18..5fe469758 100644 --- a/shared-bindings/bitbangio/__init__.c +++ b/shared-bindings/bitbangio/__init__.c @@ -34,6 +34,7 @@ #include "shared-bindings/bitbangio/__init__.h" #include "shared-bindings/bitbangio/I2C.h" +#include "shared-bindings/bitbangio/OneWire.h" #include "shared-bindings/bitbangio/SPI.h" #include "shared-module/bitbangio/types.h" @@ -49,7 +50,7 @@ //| The `bitbangio` module contains classes to provide digital protocol support //| regardless of whether the underlying hardware exists to use the protocol. //| -//| First try to use `nativeio` module instead which utilizes peripheral +//| First try to use `nativeio` module instead which may utilize peripheral //| hardware to implement the protocols. Native implementations will be faster //| than bitbanged versions and have more capabilities. //| @@ -59,6 +60,7 @@ //| :maxdepth: 3 //| //| I2C +//| OneWire //| SPI //| //| All libraries change hardware state and should be deinitialized when they @@ -81,6 +83,7 @@ STATIC const mp_rom_map_elem_t bitbangio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bitbangio) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&bitbangio_i2c_type) }, + { MP_ROM_QSTR(MP_QSTR_OneWire), MP_ROM_PTR(&bitbangio_onewire_type) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&bitbangio_spi_type) }, }; diff --git a/shared-bindings/nativeio/OneWire.c b/shared-bindings/nativeio/OneWire.c new file mode 100644 index 000000000..f9fbbe63c --- /dev/null +++ b/shared-bindings/nativeio/OneWire.c @@ -0,0 +1,169 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/runtime0.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/nativeio/OneWire.h" + +//| .. currentmodule:: nativeio +//| +//| :class:`OneWire` -- Lowest-level of the Maxim OneWire protocol +//| ================================================================= +//| +//| :class:`~nativeio.OneWire` implements the timing-sensitive foundation of the Maxim +//| (formerly Dallas Semi) OneWire protocol. +//| +//| Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126 +//| +//| .. class:: OneWire(pin) +//| +//| Create a OneWire object associated with the given pin. The object +//| implements the lowest level timing-sensitive bits of the protocol. +//| +//| :param ~microcontroller.Pin pin: Pin connected to the OneWire bus +//| +//| Read a short series of pulses:: +//| +//| import nativeio +//| import board +//| +//| with nativeio.OneWire(board.D7) as onewire: +//| onewire.reset() +//| onewire.write_bit(True) +//| onewire.write_bit(False) +//| print(onewire.read_bit()) +//| +STATIC mp_obj_t nativeio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { + mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); + enum { ARG_pin }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + assert_pin(args[ARG_pin].u_obj, false); + const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj); + assert_pin_free(pin); + + nativeio_onewire_obj_t *self = m_new_obj(nativeio_onewire_obj_t); + self->base.type = &nativeio_onewire_type; + + common_hal_nativeio_onewire_construct(self, pin); + return MP_OBJ_FROM_PTR(self); +} + +//| .. method:: deinit() +//| +//| Deinitialize the OneWire bus and release any hardware resources for reuse. +//| +STATIC mp_obj_t nativeio_onewire_deinit(mp_obj_t self_in) { + nativeio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_nativeio_onewire_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(nativeio_onewire_deinit_obj, nativeio_onewire_deinit); + +//| .. method:: __enter__() +//| +//| No-op used by Context Managers. +//| +// Provided by context manager helper. + +//| .. method:: __exit__() +//| +//| Automatically deinitializes the hardware when exiting a context. +//| +STATIC mp_obj_t nativeio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_nativeio_onewire_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nativeio_onewire___exit___obj, 4, 4, nativeio_onewire_obj___exit__); + +//| .. method:: reset() +//| +//| Reset the OneWire bus and read presence +//| +//| :returns: False when at least one device is present +//| :rtype: bool +//| +STATIC mp_obj_t nativeio_onewire_obj_reset(mp_obj_t self_in) { + nativeio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_bool(common_hal_nativeio_onewire_reset(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(nativeio_onewire_reset_obj, nativeio_onewire_obj_reset); + +//| .. method:: read_bit() +//| +//| Read in a bit +//| +//| :returns: bit state read +//| :rtype: bool +//| +STATIC mp_obj_t nativeio_onewire_obj_read_bit(mp_obj_t self_in) { + nativeio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_bool(common_hal_nativeio_onewire_read_bit(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(nativeio_onewire_read_bit_obj, nativeio_onewire_obj_read_bit); + +//| .. method:: write_bit(value) +//| +//| Write out a bit based on value. +//| +STATIC mp_obj_t nativeio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) { + nativeio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + + common_hal_nativeio_onewire_write_bit(self, mp_obj_is_true(bool_obj)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(nativeio_onewire_write_bit_obj, nativeio_onewire_obj_write_bit); + +STATIC const mp_rom_map_elem_t nativeio_onewire_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&nativeio_onewire_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&nativeio_onewire___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&nativeio_onewire_reset_obj) }, + { MP_ROM_QSTR(MP_QSTR_read_bit), MP_ROM_PTR(&nativeio_onewire_read_bit_obj) }, + { MP_ROM_QSTR(MP_QSTR_write_bit), MP_ROM_PTR(&nativeio_onewire_write_bit_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(nativeio_onewire_locals_dict, nativeio_onewire_locals_dict_table); + +const mp_obj_type_t nativeio_onewire_type = { + { &mp_type_type }, + .name = MP_QSTR_OneWire, + .make_new = nativeio_onewire_make_new, + .locals_dict = (mp_obj_dict_t*)&nativeio_onewire_locals_dict, +}; diff --git a/shared-bindings/nativeio/OneWire.h b/shared-bindings/nativeio/OneWire.h new file mode 100644 index 000000000..9d5c2c932 --- /dev/null +++ b/shared-bindings/nativeio/OneWire.h @@ -0,0 +1,42 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_ONEWIRE_H__ +#define __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_ONEWIRE_H__ + +#include "common-hal/microcontroller/types.h" +#include "common-hal/nativeio/types.h" + +extern const mp_obj_type_t nativeio_onewire_type; + +extern void common_hal_nativeio_onewire_construct(nativeio_onewire_obj_t* self, + const mcu_pin_obj_t* pin); +extern void common_hal_nativeio_onewire_deinit(nativeio_onewire_obj_t* self); +extern bool common_hal_nativeio_onewire_reset(nativeio_onewire_obj_t* self); +extern bool common_hal_nativeio_onewire_read_bit(nativeio_onewire_obj_t* self); +extern void common_hal_nativeio_onewire_write_bit(nativeio_onewire_obj_t* self, bool bit); + +#endif // __MICROPY_INCLUDED_SHARED_BINDINGS_NATIVEIO_ONEWIRE_H__ diff --git a/shared-bindings/nativeio/__init__.c b/shared-bindings/nativeio/__init__.c index 7395ce311..3287a46cd 100644 --- a/shared-bindings/nativeio/__init__.c +++ b/shared-bindings/nativeio/__init__.c @@ -39,6 +39,7 @@ #include "shared-bindings/nativeio/AnalogOut.h" #include "shared-bindings/nativeio/DigitalInOut.h" #include "shared-bindings/nativeio/I2C.h" +#include "shared-bindings/nativeio/OneWire.h" #include "shared-bindings/nativeio/PulseIn.h" #include "shared-bindings/nativeio/PulseOut.h" #include "shared-bindings/nativeio/PWMOut.h" @@ -57,15 +58,16 @@ //| :synopsis: Hardware accelerated behavior //| :platform: SAMD21 //| -//| The `nativeio` module contains classes to provide access to IO accelerated -//| by hardware on the onboard microcontroller. The classes are meant to align -//| with commonly hardware accelerated IO and not necessarily match up with -//| microcontroller structure (because it varies). +//| The `nativeio` module contains classes to provide access to IO typically +//| accelerated by hardware on the onboard microcontroller. The classes are +//| meant to align with commonly hardware accelerated IO and not necessarily +//| match up with microcontroller structure (because it varies). //| -//| If the microcontroller doesn't not support the behavior in a hardware -//| accelerated fashion it throws a NotImplementedError on construction. Use -//| `bitbangio` module instead which only depends on -//| :py:class:`~nativeio.DigitalInOut` and is shared across hardware ports. +//| When the microcontroller does not support the behavior in a hardware +//| accelerated fashion it may internally use a bitbang routine. However, if +//| hardware support is available on a subset of pins but not those provided, +//| then a RuntimeError will be raised. Use the `bitbangio` module to explicitly +//| bitbang a protocol on any general purpose pins. //| //| Libraries //| @@ -76,6 +78,7 @@ //| AnalogOut //| DigitalInOut //| I2C +//| OneWire //| PulseIn //| PulseOut //| PWMOut @@ -120,6 +123,7 @@ STATIC const mp_rom_map_elem_t nativeio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_AnalogOut), MP_ROM_PTR(&nativeio_analogout_type) }, { MP_ROM_QSTR(MP_QSTR_DigitalInOut), MP_ROM_PTR(&nativeio_digitalinout_type) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&nativeio_i2c_type) }, + { MP_ROM_QSTR(MP_QSTR_OneWire), MP_ROM_PTR(&nativeio_onewire_type) }, { MP_ROM_QSTR(MP_QSTR_PulseIn), MP_ROM_PTR(&nativeio_pulsein_type) }, { MP_ROM_QSTR(MP_QSTR_PulseOut), MP_ROM_PTR(&nativeio_pulseout_type) }, { MP_ROM_QSTR(MP_QSTR_PWMOut), MP_ROM_PTR(&nativeio_pwmout_type) }, -- cgit v1.2.3