From de796e230478b19bbdd2f1a031da973be10f8c15 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 12 Aug 2021 10:47:14 -0700 Subject: [PATCH] Move OneWire to `onewireio` from `busio` This will allow finer grained inclusion in 8.0.0 Fixes #5135 --- ports/atmel-samd/common-hal/busio/OneWire.h | 33 ---- ports/cxd56/common-hal/busio/OneWire.h | 33 ---- ports/esp32s2/common-hal/busio/OneWire.h | 33 ---- ports/mimxrt10xx/common-hal/busio/OneWire.h | 33 ---- ports/raspberrypi/common-hal/busio/OneWire.h | 33 ---- py/circuitpy_defns.mk | 17 +- py/circuitpy_mpconfig.h | 8 + py/circuitpy_mpconfig.mk | 9 +- shared-bindings/bitbangio/OneWire.c | 172 ------------------ shared-bindings/bitbangio/__init__.c | 4 +- shared-bindings/busio/OneWire.h | 43 ----- shared-bindings/busio/__init__.c | 4 +- .../{busio => onewireio}/OneWire.c | 76 ++++---- .../{bitbangio => onewireio}/OneWire.h | 22 +-- .../onewireio/__init__.c | 32 +++- .../onewireio/__init__.h | 11 +- shared-module/busio/OneWire.c | 59 ------ .../{bitbangio => onewireio}/OneWire.c | 16 +- .../{bitbangio => onewireio}/OneWire.h | 8 +- .../onewireio/__init__.c | 8 +- 20 files changed, 118 insertions(+), 536 deletions(-) delete mode 100644 ports/atmel-samd/common-hal/busio/OneWire.h delete mode 100644 ports/cxd56/common-hal/busio/OneWire.h delete mode 100644 ports/esp32s2/common-hal/busio/OneWire.h delete mode 100644 ports/mimxrt10xx/common-hal/busio/OneWire.h delete mode 100644 ports/raspberrypi/common-hal/busio/OneWire.h delete mode 100644 shared-bindings/bitbangio/OneWire.c delete mode 100644 shared-bindings/busio/OneWire.h rename shared-bindings/{busio => onewireio}/OneWire.c (60%) rename shared-bindings/{bitbangio => onewireio}/OneWire.h (63%) rename shared-module/busio/OneWire.h => shared-bindings/onewireio/__init__.c (61%) rename ports/nrf/common-hal/busio/OneWire.h => shared-bindings/onewireio/__init__.h (84%) delete mode 100644 shared-module/busio/OneWire.c rename shared-module/{bitbangio => onewireio}/OneWire.c (85%) rename shared-module/{bitbangio => onewireio}/OneWire.h (86%) rename ports/stm/common-hal/busio/OneWire.h => shared-module/onewireio/__init__.c (83%) diff --git a/ports/atmel-samd/common-hal/busio/OneWire.h b/ports/atmel-samd/common-hal/busio/OneWire.h deleted file mode 100644 index a09a44c262..0000000000 --- a/ports/atmel-samd/common-hal/busio/OneWire.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Scott Shawcroft - * - * 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_ATMEL_SAMD_COMMON_HAL_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_ONEWIRE_H - -// Use bitbangio. -#include "shared-module/busio/OneWire.h" - -#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/ports/cxd56/common-hal/busio/OneWire.h b/ports/cxd56/common-hal/busio/OneWire.h deleted file mode 100644 index 17c1b22375..0000000000 --- a/ports/cxd56/common-hal/busio/OneWire.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright 2019 Sony Semiconductor Solutions Corporation - * - * 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_CXD56_COMMON_HAL_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_ONEWIRE_H - -// Use bitbangio. -#include "shared-module/busio/OneWire.h" - -#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/ports/esp32s2/common-hal/busio/OneWire.h b/ports/esp32s2/common-hal/busio/OneWire.h deleted file mode 100644 index bb6a014190..0000000000 --- a/ports/esp32s2/common-hal/busio/OneWire.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Scott Shawcroft - * - * 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_ESP32S2_COMMON_HAL_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_BUSIO_ONEWIRE_H - -// Use bitbangio. -#include "shared-module/busio/OneWire.h" - -#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/ports/mimxrt10xx/common-hal/busio/OneWire.h b/ports/mimxrt10xx/common-hal/busio/OneWire.h deleted file mode 100644 index bb4bc016a4..0000000000 --- a/ports/mimxrt10xx/common-hal/busio/OneWire.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Scott Shawcroft - * - * 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_MIMXRT10XX_COMMON_HAL_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_BUSIO_ONEWIRE_H - -// Use bitbangio. -#include "shared-module/busio/OneWire.h" - -#endif // MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/ports/raspberrypi/common-hal/busio/OneWire.h b/ports/raspberrypi/common-hal/busio/OneWire.h deleted file mode 100644 index e27723ab2c..0000000000 --- a/ports/raspberrypi/common-hal/busio/OneWire.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2021 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_RASPBERRYPI_COMMON_HAL_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_BUSIO_ONEWIRE_H - -// Use bitbangio. -#include "shared-module/busio/OneWire.h" - -#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 84c8e22b2b..cd4fab9f09 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -155,7 +155,7 @@ ifeq ($(CIRCUITPY_BUSDEVICE),1) SRC_PATTERNS += adafruit_bus_device/% endif ifeq ($(CIRCUITPY_BUSIO),1) -SRC_PATTERNS += busio/% bitbangio/OneWire.% +SRC_PATTERNS += busio/% endif ifeq ($(CIRCUITPY_CAMERA),1) SRC_PATTERNS += camera/% @@ -218,6 +218,9 @@ endif ifeq ($(CIRCUITPY_NVM),1) SRC_PATTERNS += nvm/% endif +ifeq ($(CIRCUITPY_ONEWIREIO),1) +SRC_PATTERNS += onewireio/% +endif ifeq ($(CIRCUITPY_OS),1) SRC_PATTERNS += os/% endif @@ -493,7 +496,6 @@ SRC_SHARED_MODULE_ALL = \ audiomp3/__init__.c \ audiopwmio/__init__.c \ bitbangio/I2C.c \ - bitbangio/OneWire.c \ bitbangio/SPI.c \ bitbangio/__init__.c \ bitmaptools/__init__.c \ @@ -502,7 +504,6 @@ SRC_SHARED_MODULE_ALL = \ adafruit_bus_device/__init__.c \ adafruit_bus_device/I2CDevice.c \ adafruit_bus_device/SPIDevice.c \ - busio/OneWire.c \ canio/Match.c \ canio/Message.c \ canio/RemoteTransmissionRequest.c \ @@ -522,6 +523,8 @@ SRC_SHARED_MODULE_ALL = \ fontio/__init__.c \ framebufferio/FramebufferDisplay.c \ framebufferio/__init__.c \ + gamepadshift/GamePadShift.c \ + gamepadshift/__init__.c \ getpass/__init__.c \ ipaddress/IPv4Address.c \ ipaddress/__init__.c \ @@ -531,15 +534,13 @@ SRC_SHARED_MODULE_ALL = \ keypad/KeyMatrix.c \ keypad/ShiftRegisterKeys.c \ keypad/Keys.c \ - sdcardio/SDCard.c \ - sdcardio/__init__.c \ - gamepadshift/GamePadShift.c \ - gamepadshift/__init__.c \ memorymonitor/__init__.c \ memorymonitor/AllocationAlarm.c \ memorymonitor/AllocationSize.c \ network/__init__.c \ msgpack/__init__.c \ + onewireio/__init__.c \ + onewireio/OneWire.c \ os/__init__.c \ qrio/__init__.c \ qrio/QRDecoder.c \ @@ -548,6 +549,8 @@ SRC_SHARED_MODULE_ALL = \ rgbmatrix/RGBMatrix.c \ rgbmatrix/__init__.c \ rotaryio/IncrementalEncoder.c \ + sdcardio/SDCard.c \ + sdcardio/__init__.c \ sharpdisplay/SharpMemoryFramebuffer.c \ sharpdisplay/__init__.c \ socket/__init__.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index b8dbcd6de2..aff54f51e5 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -583,6 +583,13 @@ extern const struct _mp_obj_module_t neopixel_write_module; extern const struct _mp_obj_module_t nvm_module; #endif +#if CIRCUITPY_OS +extern const struct _mp_obj_module_t onewireio_module; +#define ONEWIREIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_onewireio), (mp_obj_t)&onewireio_module }, +#else +#define ONEWIREIO_MODULE +#endif + #if CIRCUITPY_OS extern const struct _mp_obj_module_t os_module; #define OS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, @@ -915,6 +922,7 @@ extern const struct _mp_obj_module_t msgpack_module; MICROCONTROLLER_MODULE \ MSGPACK_MODULE \ NEOPIXEL_WRITE_MODULE \ + ONEWIREIO_MODULE \ PEW_MODULE \ PIXELBUF_MODULE \ PS2IO_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index be68904d18..b486497692 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -199,6 +199,9 @@ CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS) CIRCUITPY_I2CPERIPHERAL ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_I2CPERIPHERAL=$(CIRCUITPY_I2CPERIPHERAL) +CIRCUITPY_IMAGECAPTURE ?= 0 +CFLAGS += -DCIRCUITPY_IMAGECAPTURE=$(CIRCUITPY_IMAGECAPTURE) + CIRCUITPY_IPADDRESS ?= $(CIRCUITPY_WIFI) CFLAGS += -DCIRCUITPY_IPADDRESS=$(CIRCUITPY_IPADDRESS) @@ -226,12 +229,12 @@ CFLAGS += -DCIRCUITPY_NEOPIXEL_WRITE=$(CIRCUITPY_NEOPIXEL_WRITE) CIRCUITPY_NVM ?= 1 CFLAGS += -DCIRCUITPY_NVM=$(CIRCUITPY_NVM) +CIRCUITPY_ONEWIREIO ?= $(CIRCUITPY_BUSIO) +CFLAGS += -DCIRCUITPY_ONEWIREIO=$(CIRCUITPY_ONEWIREIO) + CIRCUITPY_OS ?= 1 CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS) -CIRCUITPY_IMAGECAPTURE ?= 0 -CFLAGS += -DCIRCUITPY_IMAGECAPTURE=$(CIRCUITPY_IMAGECAPTURE) - CIRCUITPY_PEW ?= 0 CFLAGS += -DCIRCUITPY_PEW=$(CIRCUITPY_PEW) diff --git a/shared-bindings/bitbangio/OneWire.c b/shared-bindings/bitbangio/OneWire.c deleted file mode 100644 index 15cf833242..0000000000 --- a/shared-bindings/bitbangio/OneWire.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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" -#include "shared-bindings/util.h" - -//| 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""" -//| -//| def __init__(self, pin: microcontroller.Pin) -> None: -//| -//| """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 -//| -//| onewire = bitbangio.OneWire(board.D7) -//| 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, const mp_obj_t *pos_args, mp_map_t *kw_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); - - const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); - - 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); -} - -//| def deinit(self) -> None: -//| """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); - -STATIC void check_for_deinit(bitbangio_onewire_obj_t *self) { - if (shared_module_bitbangio_onewire_deinited(self)) { - raise_deinited_error(); - } -} - -//| def __enter__(self) -> OneWire: -//| """No-op used by Context Managers.""" -//| ... -//| -// Provided by context manager helper. - -//| def __exit__(self) -> None: -//| """Automatically deinitializes the hardware when exiting a context. See -//| :ref:`lifetime-and-contextmanagers` for more info.""" -//| ... -//| -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__); - -//| def reset(self) -> bool: -//| """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); - check_for_deinit(self); - - 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); - -//| def read_bit(self) -> bool: -//| """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); - check_for_deinit(self); - - 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); - -//| def write_bit(self, value: bool) -> None: -//| """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); - check_for_deinit(self); - - 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/__init__.c b/shared-bindings/bitbangio/__init__.c index 81e9d91a37..a8d9f5e615 100644 --- a/shared-bindings/bitbangio/__init__.c +++ b/shared-bindings/bitbangio/__init__.c @@ -34,7 +34,7 @@ #include "shared-bindings/bitbangio/__init__.h" #include "shared-bindings/bitbangio/I2C.h" -#include "shared-bindings/bitbangio/OneWire.h" +#include "shared-bindings/onewireio/OneWire.h" #include "shared-bindings/bitbangio/SPI.h" #include "py/runtime.h" @@ -72,7 +72,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_OneWire), MP_ROM_PTR(&onewireio_onewire_type) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&bitbangio_spi_type) }, }; diff --git a/shared-bindings/busio/OneWire.h b/shared-bindings/busio/OneWire.h deleted file mode 100644 index a270bab5c9..0000000000 --- a/shared-bindings/busio/OneWire.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_ONEWIRE_H - -#include "common-hal/microcontroller/Pin.h" -#include "common-hal/busio/OneWire.h" - -extern const mp_obj_type_t busio_onewire_type; - -extern void common_hal_busio_onewire_construct(busio_onewire_obj_t *self, - const mcu_pin_obj_t *pin); -extern void common_hal_busio_onewire_deinit(busio_onewire_obj_t *self); -extern bool common_hal_busio_onewire_deinited(busio_onewire_obj_t *self); -extern bool common_hal_busio_onewire_reset(busio_onewire_obj_t *self); -extern bool common_hal_busio_onewire_read_bit(busio_onewire_obj_t *self); -extern void common_hal_busio_onewire_write_bit(busio_onewire_obj_t *self, bool bit); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_ONEWIRE_H diff --git a/shared-bindings/busio/__init__.c b/shared-bindings/busio/__init__.c index e7df331c12..2cde3d62b3 100644 --- a/shared-bindings/busio/__init__.c +++ b/shared-bindings/busio/__init__.c @@ -32,9 +32,9 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/busio/__init__.h" #include "shared-bindings/busio/I2C.h" -#include "shared-bindings/busio/OneWire.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/busio/UART.h" +#include "shared-bindings/onewireio/OneWire.h" #include "py/runtime.h" @@ -73,7 +73,7 @@ STATIC const mp_rom_map_elem_t busio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_busio) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&busio_i2c_type) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&busio_spi_type) }, - { MP_ROM_QSTR(MP_QSTR_OneWire), MP_ROM_PTR(&busio_onewire_type) }, + { MP_ROM_QSTR(MP_QSTR_OneWire), MP_ROM_PTR(&onewireio_onewire_type) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&busio_uart_type) }, }; diff --git a/shared-bindings/busio/OneWire.c b/shared-bindings/onewireio/OneWire.c similarity index 60% rename from shared-bindings/busio/OneWire.c rename to shared-bindings/onewireio/OneWire.c index 026e1ee968..dd628884dd 100644 --- a/shared-bindings/busio/OneWire.c +++ b/shared-bindings/onewireio/OneWire.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "py/runtime0.h" #include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/busio/OneWire.h" +#include "shared-bindings/onewireio/OneWire.h" #include "shared-bindings/util.h" //| class OneWire: @@ -51,17 +51,17 @@ //| //| Read a short series of pulses:: //| -//| import busio +//| import onewireio //| import board //| -//| onewire = busio.OneWire(board.D7) +//| onewire = onewireio.OneWire(board.D7) //| onewire.reset() //| onewire.write_bit(True) //| onewire.write_bit(False) //| print(onewire.read_bit())""" //| ... //| -STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t onewireio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_pin }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -70,10 +70,10 @@ STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); - busio_onewire_obj_t *self = m_new_obj(busio_onewire_obj_t); - self->base.type = &busio_onewire_type; + onewireio_onewire_obj_t *self = m_new_obj(onewireio_onewire_obj_t); + self->base.type = &onewireio_onewire_type; - common_hal_busio_onewire_construct(self, pin); + common_hal_onewireio_onewire_construct(self, pin); return MP_OBJ_FROM_PTR(self); } @@ -81,15 +81,15 @@ STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, //| """Deinitialize the OneWire bus and release any hardware resources for reuse.""" //| ... //| -STATIC mp_obj_t busio_onewire_deinit(mp_obj_t self_in) { - busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_busio_onewire_deinit(self); +STATIC mp_obj_t onewireio_onewire_deinit(mp_obj_t self_in) { + onewireio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_onewireio_onewire_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_deinit_obj, busio_onewire_deinit); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewireio_onewire_deinit_obj, onewireio_onewire_deinit); -STATIC void check_for_deinit(busio_onewire_obj_t *self) { - if (common_hal_busio_onewire_deinited(self)) { +STATIC void check_for_deinit(onewireio_onewire_obj_t *self) { + if (common_hal_onewireio_onewire_deinited(self)) { raise_deinited_error(); } } @@ -105,12 +105,12 @@ STATIC void check_for_deinit(busio_onewire_obj_t *self) { //| :ref:`lifetime-and-contextmanagers` for more info.""" //| ... //| -STATIC mp_obj_t busio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t onewireio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; - common_hal_busio_onewire_deinit(args[0]); + common_hal_onewireio_onewire_deinit(args[0]); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_onewire___exit___obj, 4, 4, busio_onewire_obj___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(onewireio_onewire___exit___obj, 4, 4, onewireio_onewire_obj___exit__); //| def reset(self) -> bool: //| """Reset the OneWire bus and read presence @@ -119,13 +119,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_onewire___exit___obj, 4, 4, bus //| :rtype: bool""" //| ... //| -STATIC mp_obj_t busio_onewire_obj_reset(mp_obj_t self_in) { - busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t onewireio_onewire_obj_reset(mp_obj_t self_in) { + onewireio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - return mp_obj_new_bool(common_hal_busio_onewire_reset(self)); + return mp_obj_new_bool(common_hal_onewireio_onewire_reset(self)); } -MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_reset_obj, busio_onewire_obj_reset); +MP_DEFINE_CONST_FUN_OBJ_1(onewireio_onewire_reset_obj, onewireio_onewire_obj_reset); //| def read_bit(self) -> bool: //| """Read in a bit @@ -134,41 +134,41 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_reset_obj, busio_onewire_obj_reset); //| :rtype: bool""" //| ... //| -STATIC mp_obj_t busio_onewire_obj_read_bit(mp_obj_t self_in) { - busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t onewireio_onewire_obj_read_bit(mp_obj_t self_in) { + onewireio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - return mp_obj_new_bool(common_hal_busio_onewire_read_bit(self)); + return mp_obj_new_bool(common_hal_onewireio_onewire_read_bit(self)); } -MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_read_bit_obj, busio_onewire_obj_read_bit); +MP_DEFINE_CONST_FUN_OBJ_1(onewireio_onewire_read_bit_obj, onewireio_onewire_obj_read_bit); //| def write_bit(self, value: bool) -> None: //| """Write out a bit based on value.""" //| ... //| -STATIC mp_obj_t busio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) { - busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t onewireio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) { + onewireio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - common_hal_busio_onewire_write_bit(self, mp_obj_is_true(bool_obj)); + common_hal_onewireio_onewire_write_bit(self, mp_obj_is_true(bool_obj)); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(busio_onewire_write_bit_obj, busio_onewire_obj_write_bit); +MP_DEFINE_CONST_FUN_OBJ_2(onewireio_onewire_write_bit_obj, onewireio_onewire_obj_write_bit); -STATIC const mp_rom_map_elem_t busio_onewire_locals_dict_table[] = { +STATIC const mp_rom_map_elem_t onewireio_onewire_locals_dict_table[] = { // Methods - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&busio_onewire_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&onewireio_onewire_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&busio_onewire___exit___obj) }, - { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&busio_onewire_reset_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_bit), MP_ROM_PTR(&busio_onewire_read_bit_obj) }, - { MP_ROM_QSTR(MP_QSTR_write_bit), MP_ROM_PTR(&busio_onewire_write_bit_obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&onewireio_onewire___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&onewireio_onewire_reset_obj) }, + { MP_ROM_QSTR(MP_QSTR_read_bit), MP_ROM_PTR(&onewireio_onewire_read_bit_obj) }, + { MP_ROM_QSTR(MP_QSTR_write_bit), MP_ROM_PTR(&onewireio_onewire_write_bit_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(busio_onewire_locals_dict, busio_onewire_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(onewireio_onewire_locals_dict, onewireio_onewire_locals_dict_table); -const mp_obj_type_t busio_onewire_type = { +const mp_obj_type_t onewireio_onewire_type = { { &mp_type_type }, .name = MP_QSTR_OneWire, - .make_new = busio_onewire_make_new, - .locals_dict = (mp_obj_dict_t *)&busio_onewire_locals_dict, + .make_new = onewireio_onewire_make_new, + .locals_dict = (mp_obj_dict_t *)&onewireio_onewire_locals_dict, }; diff --git a/shared-bindings/bitbangio/OneWire.h b/shared-bindings/onewireio/OneWire.h similarity index 63% rename from shared-bindings/bitbangio/OneWire.h rename to shared-bindings/onewireio/OneWire.h index 0dbc975122..c6d0fd6ebb 100644 --- a/shared-bindings/bitbangio/OneWire.h +++ b/shared-bindings/onewireio/OneWire.h @@ -24,20 +24,20 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BITBANGIO_ONEWIRE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BITBANGIO_ONEWIRE_H +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ONEWIREIO_ONEWIRE_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_ONEWIREIO_ONEWIRE_H #include "common-hal/microcontroller/Pin.h" -#include "shared-module/bitbangio/OneWire.h" +#include "shared-module/onewireio/OneWire.h" -extern const mp_obj_type_t bitbangio_onewire_type; +extern const mp_obj_type_t onewireio_onewire_type; -extern void shared_module_bitbangio_onewire_construct(bitbangio_onewire_obj_t *self, +extern void common_hal_onewireio_onewire_construct(onewireio_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_deinited(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); +extern void common_hal_onewireio_onewire_deinit(onewireio_onewire_obj_t *self); +extern bool common_hal_onewireio_onewire_deinited(onewireio_onewire_obj_t *self); +extern bool common_hal_onewireio_onewire_reset(onewireio_onewire_obj_t *self); +extern bool common_hal_onewireio_onewire_read_bit(onewireio_onewire_obj_t *self); +extern void common_hal_onewireio_onewire_write_bit(onewireio_onewire_obj_t *self, bool bit); -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BITBANGIO_ONEWIRE_H +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ONEWIREIO_ONEWIRE_H diff --git a/shared-module/busio/OneWire.h b/shared-bindings/onewireio/__init__.c similarity index 61% rename from shared-module/busio/OneWire.h rename to shared-bindings/onewireio/__init__.c index 5d80bab17c..4074891be9 100644 --- a/shared-module/busio/OneWire.h +++ b/shared-bindings/onewireio/__init__.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2016 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 @@ -24,16 +24,28 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSIO_ONEWIRE_H - -#include "shared-module/bitbangio/OneWire.h" +#include #include "py/obj.h" +#include "py/runtime.h" -typedef struct { - mp_obj_base_t base; - bitbangio_onewire_obj_t bitbang; -} busio_onewire_obj_t; +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/onewireio/__init__.h" +#include "shared-bindings/onewireio/OneWire.h" -#endif // MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSIO_ONEWIRE_H +#include "py/runtime.h" + +//| """Low-level bit primitives for """ +//| + +STATIC const mp_rom_map_elem_t onewireio_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_onewireio) }, + { MP_ROM_QSTR(MP_QSTR_OneWire), MP_ROM_PTR(&onewireio_onewire_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(onewireio_module_globals, onewireio_module_globals_table); + +const mp_obj_module_t onewireio_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&onewireio_module_globals, +}; diff --git a/ports/nrf/common-hal/busio/OneWire.h b/shared-bindings/onewireio/__init__.h similarity index 84% rename from ports/nrf/common-hal/busio/OneWire.h rename to shared-bindings/onewireio/__init__.h index 821cc64c1e..25384f6a7b 100644 --- a/ports/nrf/common-hal/busio/OneWire.h +++ b/shared-bindings/onewireio/__init__.h @@ -24,10 +24,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ONEWIREIO___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_ONEWIREIO___INIT___H -// Use bitbangio. -#include "shared-module/busio/OneWire.h" +#include "py/obj.h" -#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H +// Nothing now. + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ONEWIREIO___INIT___H diff --git a/shared-module/busio/OneWire.c b/shared-module/busio/OneWire.c deleted file mode 100644 index 80c55c7b2b..0000000000 --- a/shared-module/busio/OneWire.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - */ - -// Wraps the bitbangio implementation of OneWire for use in busio. -#include "common-hal/microcontroller/Pin.h" -#include "shared-bindings/bitbangio/OneWire.h" -#include "shared-module/busio/OneWire.h" - -void common_hal_busio_onewire_construct(busio_onewire_obj_t *self, - const mcu_pin_obj_t *pin) { - shared_module_bitbangio_onewire_construct(&self->bitbang, pin); -} - -bool common_hal_busio_onewire_deinited(busio_onewire_obj_t *self) { - return shared_module_bitbangio_onewire_deinited(&self->bitbang); -} - -void common_hal_busio_onewire_deinit(busio_onewire_obj_t *self) { - if (common_hal_busio_onewire_deinited(self)) { - return; - } - shared_module_bitbangio_onewire_deinit(&self->bitbang); -} - -bool common_hal_busio_onewire_reset(busio_onewire_obj_t *self) { - return shared_module_bitbangio_onewire_reset(&self->bitbang); -} - -bool common_hal_busio_onewire_read_bit(busio_onewire_obj_t *self) { - return shared_module_bitbangio_onewire_read_bit(&self->bitbang); -} - -void common_hal_busio_onewire_write_bit(busio_onewire_obj_t *self, - bool bit) { - shared_module_bitbangio_onewire_write_bit(&self->bitbang, bit); -} diff --git a/shared-module/bitbangio/OneWire.c b/shared-module/onewireio/OneWire.c similarity index 85% rename from shared-module/bitbangio/OneWire.c rename to shared-module/onewireio/OneWire.c index 8a73817f37..aeb4dcb00d 100644 --- a/shared-module/bitbangio/OneWire.c +++ b/shared-module/onewireio/OneWire.c @@ -25,24 +25,24 @@ */ #include "common-hal/microcontroller/Pin.h" -#include "shared-bindings/bitbangio/OneWire.h" +#include "shared-bindings/onewireio/OneWire.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/digitalio/DigitalInOut.h" // Durations are taken from here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126 -void shared_module_bitbangio_onewire_construct(bitbangio_onewire_obj_t *self, +void common_hal_onewireio_onewire_construct(onewireio_onewire_obj_t *self, const mcu_pin_obj_t *pin) { self->pin.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->pin, pin); } -bool shared_module_bitbangio_onewire_deinited(bitbangio_onewire_obj_t *self) { +bool common_hal_onewireio_onewire_deinited(onewireio_onewire_obj_t *self) { return common_hal_digitalio_digitalinout_deinited(&self->pin); } -void shared_module_bitbangio_onewire_deinit(bitbangio_onewire_obj_t *self) { - if (shared_module_bitbangio_onewire_deinited(self)) { +void common_hal_onewireio_onewire_deinit(onewireio_onewire_obj_t *self) { + if (common_hal_onewireio_onewire_deinited(self)) { return; } common_hal_digitalio_digitalinout_deinit(&self->pin); @@ -51,7 +51,7 @@ void shared_module_bitbangio_onewire_deinit(bitbangio_onewire_obj_t *self) { // 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) { +bool common_hal_onewireio_onewire_reset(onewireio_onewire_obj_t *self) { common_hal_mcu_disable_interrupts(); common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN); common_hal_mcu_delay_us(480); @@ -63,7 +63,7 @@ bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t *self) { return value; } -bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t *self) { +bool common_hal_onewireio_onewire_read_bit(onewireio_onewire_obj_t *self) { common_hal_mcu_disable_interrupts(); common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN); common_hal_mcu_delay_us(6); @@ -78,7 +78,7 @@ bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t *self) { return value; } -void shared_module_bitbangio_onewire_write_bit(bitbangio_onewire_obj_t *self, +void common_hal_onewireio_onewire_write_bit(onewireio_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); diff --git a/shared-module/bitbangio/OneWire.h b/shared-module/onewireio/OneWire.h similarity index 86% rename from shared-module/bitbangio/OneWire.h rename to shared-module/onewireio/OneWire.h index bc4cb2096f..594478f861 100644 --- a/shared-module/bitbangio/OneWire.h +++ b/shared-module/onewireio/OneWire.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BITBANGIO_ONEWIRE_H -#define MICROPY_INCLUDED_SHARED_MODULE_BITBANGIO_ONEWIRE_H +#ifndef MICROPY_INCLUDED_SHARED_MODULE_ONEWIREIO_ONEWIRE_H +#define MICROPY_INCLUDED_SHARED_MODULE_ONEWIREIO_ONEWIRE_H #include "common-hal/digitalio/DigitalInOut.h" @@ -34,6 +34,6 @@ typedef struct { mp_obj_base_t base; digitalio_digitalinout_obj_t pin; -} bitbangio_onewire_obj_t; +} onewireio_onewire_obj_t; -#endif // MICROPY_INCLUDED_SHARED_MODULE_BITBANGIO_ONEWIRE_H +#endif // MICROPY_INCLUDED_SHARED_MODULE_ONEWIREIO_ONEWIRE_H diff --git a/ports/stm/common-hal/busio/OneWire.h b/shared-module/onewireio/__init__.c similarity index 83% rename from ports/stm/common-hal/busio/OneWire.h rename to shared-module/onewireio/__init__.c index 0099593f03..674343c533 100644 --- a/ports/stm/common-hal/busio/OneWire.h +++ b/shared-module/onewireio/__init__.c @@ -24,10 +24,4 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_STM32_COMMON_HAL_BUSIO_ONEWIRE_H - -// Use bitbangio. -#include "shared-module/busio/OneWire.h" - -#endif // MICROPY_INCLUDED_STM32F_COMMON_HAL_BUSIO_ONEWIRE_H +// Nothing now.