diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2022-06-19 19:47:51 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2022-06-19 19:47:51 +0530 |
commit | 4fd287655a72b9aea14cdac715ad5b90ed082ed2 (patch) | |
tree | 65d393bc0e699dd12d05b29ba568e04cea666207 /circuitpython/shared-bindings/digitalio | |
parent | 0150f70ce9c39e9e6dd878766c0620c85e47bed0 (diff) |
add circuitpython code
Diffstat (limited to 'circuitpython/shared-bindings/digitalio')
-rw-r--r-- | circuitpython/shared-bindings/digitalio/DigitalInOut.c | 363 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/DigitalInOut.h | 70 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/Direction.c | 84 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/Direction.h | 45 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/DriveMode.c | 73 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/DriveMode.h | 46 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/Pull.c | 87 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/Pull.h | 48 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/__init__.c | 100 | ||||
-rw-r--r-- | circuitpython/shared-bindings/digitalio/__init__.h | 34 |
10 files changed, 950 insertions, 0 deletions
diff --git a/circuitpython/shared-bindings/digitalio/DigitalInOut.c b/circuitpython/shared-bindings/digitalio/DigitalInOut.c new file mode 100644 index 0000000..37093ad --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/DigitalInOut.c @@ -0,0 +1,363 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George + * + * 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 <stdint.h> +#include <string.h> + +#include "shared/runtime/context_manager_helpers.h" + +#include "py/nlr.h" +#include "py/objtype.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/mphal.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/digitalio/Direction.h" +#include "shared-bindings/digitalio/DriveMode.h" +#include "shared-bindings/digitalio/Pull.h" +#include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" + +//| class DigitalInOut: +//| """Digital input and output +//| +//| A DigitalInOut is used to digitally control I/O pins. For analog control of +//| a pin, see the :py:class:`analogio.AnalogIn` and +//| :py:class:`analogio.AnalogOut` classes.""" +//| +//| def __init__(self, pin: microcontroller.Pin) -> None: +//| """Create a new DigitalInOut object associated with the pin. Defaults to input +//| with no pull. Use :py:meth:`switch_to_input` and +//| :py:meth:`switch_to_output` to change the direction. +//| +//| :param ~microcontroller.Pin pin: The pin to control""" +//| ... +//| +STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type, + size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); + + digitalio_digitalinout_obj_t *self = m_new_obj(digitalio_digitalinout_obj_t); + self->base.type = &digitalio_digitalinout_type; + + const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); + common_hal_digitalio_digitalinout_construct(self, pin); + + return MP_OBJ_FROM_PTR(self); +} + +//| def deinit(self) -> None: +//| """Turn off the DigitalInOut and release the pin for other use.""" +//| ... +//| +STATIC mp_obj_t digitalio_digitalinout_obj_deinit(mp_obj_t self_in) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_digitalio_digitalinout_deinit(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_deinit_obj, digitalio_digitalinout_obj_deinit); + +//| def __enter__(self) -> DigitalInOut: +//| """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 digitalio_digitalinout_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_digitalio_digitalinout_deinit(MP_OBJ_TO_PTR(args[0])); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(digitalio_digitalinout_obj___exit___obj, 4, 4, digitalio_digitalinout_obj___exit__); + +STATIC void check_for_deinit(digitalio_digitalinout_obj_t *self) { + if (common_hal_digitalio_digitalinout_deinited(self)) { + raise_deinited_error(); + } +} + +//| def switch_to_output(self, value: bool = False, drive_mode: DriveMode = DriveMode.PUSH_PULL) -> None: +//| """Set the drive mode and value and then switch to writing out digital +//| values. +//| +//| :param bool value: default value to set upon switching +//| :param ~digitalio.DriveMode drive_mode: drive mode for the output +//| """ +//| ... +//| +STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_value, ARG_drive_mode }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_value, MP_ARG_BOOL, {.u_bool = false} }, + { MP_QSTR_drive_mode, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&digitalio_drive_mode_push_pull_obj)} }, + }; + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + digitalio_drive_mode_t drive_mode = DRIVE_MODE_PUSH_PULL; + if (args[ARG_drive_mode].u_rom_obj == MP_ROM_PTR(&digitalio_drive_mode_open_drain_obj)) { + drive_mode = DRIVE_MODE_OPEN_DRAIN; + } + // do the transfer + digitalinout_result_t result = common_hal_digitalio_digitalinout_switch_to_output(self, args[ARG_value].u_bool, drive_mode); + if (result == DIGITALINOUT_INPUT_ONLY) { + mp_raise_NotImplementedError(translate("Pin is input only")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_output_obj, 1, digitalio_digitalinout_switch_to_output); + +//| def switch_to_input(self, pull: Optional[Pull] = None) -> None: +//| """Set the pull and then switch to read in digital values. +//| +//| :param Pull pull: pull configuration for the input +//| +//| Example usage:: +//| +//| import digitalio +//| import board +//| +//| switch = digitalio.DigitalInOut(board.SLIDE_SWITCH) +//| switch.switch_to_input(pull=digitalio.Pull.UP) +//| # Or, after switch_to_input +//| switch.pull = digitalio.Pull.UP +//| print(switch.value)""" +//| ... +//| +STATIC mp_obj_t digitalio_digitalinout_switch_to_input(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_pull }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_pull, MP_ARG_OBJ, {.u_rom_obj = mp_const_none} }, + }; + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + common_hal_digitalio_digitalinout_switch_to_input(self, validate_pull(args[ARG_pull].u_rom_obj, MP_QSTR_pull)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_input_obj, 1, digitalio_digitalinout_switch_to_input); + +//| direction: Direction +//| """The direction of the pin. +//| +//| Setting this will use the defaults from the corresponding +//| :py:meth:`switch_to_input` or :py:meth:`switch_to_output` method. If +//| you want to set pull, value or drive mode prior to switching, then use +//| those methods instead.""" +//| +typedef struct { + mp_obj_base_t base; +} digitalio_digitalio_direction_obj_t; +extern const digitalio_digitalio_direction_obj_t digitalio_digitalio_direction_in_obj; +extern const digitalio_digitalio_direction_obj_t digitalio_digitalio_direction_out_obj; + +STATIC mp_obj_t digitalio_digitalinout_obj_get_direction(mp_obj_t self_in) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + digitalio_direction_t direction = common_hal_digitalio_digitalinout_get_direction(self); + if (direction == DIRECTION_INPUT) { + return (mp_obj_t)&digitalio_direction_input_obj; + } + return (mp_obj_t)&digitalio_direction_output_obj; +} +MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_get_direction_obj, digitalio_digitalinout_obj_get_direction); + +STATIC mp_obj_t digitalio_digitalinout_obj_set_direction(mp_obj_t self_in, mp_obj_t value) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + if (value == MP_ROM_PTR(&digitalio_direction_input_obj)) { + common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); + } else if (value == MP_ROM_PTR(&digitalio_direction_output_obj)) { + digitalinout_result_t result = common_hal_digitalio_digitalinout_switch_to_output(self, false, DRIVE_MODE_PUSH_PULL); + if (result == DIGITALINOUT_INPUT_ONLY) { + mp_raise_NotImplementedError(translate("Pin is input only")); + } + } else { + mp_raise_ValueError(translate("Invalid direction.")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(digitalio_digitalinout_set_direction_obj, digitalio_digitalinout_obj_set_direction); + +MP_PROPERTY_GETSET(digitalio_digitalio_direction_obj, + (mp_obj_t)&digitalio_digitalinout_get_direction_obj, + (mp_obj_t)&digitalio_digitalinout_set_direction_obj); + +//| value: bool +//| """The digital logic level of the pin.""" +//| +STATIC mp_obj_t digitalio_digitalinout_obj_get_value(mp_obj_t self_in) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + bool value = common_hal_digitalio_digitalinout_get_value(self); + return mp_obj_new_bool(value); +} +MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_get_value_obj, digitalio_digitalinout_obj_get_value); + +STATIC mp_obj_t digitalio_digitalinout_obj_set_value(mp_obj_t self_in, mp_obj_t value) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { + mp_raise_AttributeError(translate("Cannot set value when direction is input.")); + return mp_const_none; + } + common_hal_digitalio_digitalinout_set_value(self, mp_obj_is_true(value)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(digitalio_digitalinout_set_value_obj, digitalio_digitalinout_obj_set_value); + +MP_PROPERTY_GETSET(digitalio_digitalinout_value_obj, + (mp_obj_t)&digitalio_digitalinout_get_value_obj, + (mp_obj_t)&digitalio_digitalinout_set_value_obj); + +//| drive_mode: DriveMode +//| """The pin drive mode. One of: +//| +//| - `digitalio.DriveMode.PUSH_PULL` +//| - `digitalio.DriveMode.OPEN_DRAIN`""" +//| +STATIC mp_obj_t digitalio_digitalinout_obj_get_drive_mode(mp_obj_t self_in) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { + mp_raise_AttributeError(translate("Drive mode not used when direction is input.")); + return mp_const_none; + } + digitalio_drive_mode_t drive_mode = common_hal_digitalio_digitalinout_get_drive_mode(self); + if (drive_mode == DRIVE_MODE_PUSH_PULL) { + return (mp_obj_t)&digitalio_drive_mode_push_pull_obj; + } + return (mp_obj_t)&digitalio_drive_mode_open_drain_obj; +} +MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_get_drive_mode_obj, digitalio_digitalinout_obj_get_drive_mode); + +STATIC mp_obj_t digitalio_digitalinout_obj_set_drive_mode(mp_obj_t self_in, mp_obj_t drive_mode) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { + mp_raise_AttributeError(translate("Drive mode not used when direction is input.")); + return mp_const_none; + } + digitalio_drive_mode_t c_drive_mode = DRIVE_MODE_PUSH_PULL; + if (drive_mode == MP_ROM_PTR(&digitalio_drive_mode_open_drain_obj)) { + c_drive_mode = DRIVE_MODE_OPEN_DRAIN; + } + common_hal_digitalio_digitalinout_set_drive_mode(self, c_drive_mode); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(digitalio_digitalinout_set_drive_mode_obj, digitalio_digitalinout_obj_set_drive_mode); + +MP_PROPERTY_GETSET(digitalio_digitalio_drive_mode_obj, + (mp_obj_t)&digitalio_digitalinout_get_drive_mode_obj, + (mp_obj_t)&digitalio_digitalinout_set_drive_mode_obj); + +//| pull: Optional[Pull] +//| """The pin pull direction. One of: +//| +//| - `digitalio.Pull.UP` +//| - `digitalio.Pull.DOWN` +//| - `None` +//| +//| :raises AttributeError: if `direction` is :py:data:`~digitalio.Direction.OUTPUT`.""" +//| +STATIC mp_obj_t digitalio_digitalinout_obj_get_pull(mp_obj_t self_in) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_OUTPUT) { + mp_raise_AttributeError(translate("Pull not used when direction is output.")); + return mp_const_none; + } + digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(self); + if (pull == PULL_UP) { + return MP_OBJ_FROM_PTR(&digitalio_pull_up_obj); + } else if (pull == PULL_DOWN) { + return MP_OBJ_FROM_PTR(&digitalio_pull_down_obj); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_get_pull_obj, digitalio_digitalinout_obj_get_pull); + +STATIC mp_obj_t digitalio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t pull_obj) { + digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_OUTPUT) { + mp_raise_AttributeError(translate("Pull not used when direction is output.")); + return mp_const_none; + } + + common_hal_digitalio_digitalinout_set_pull(self, validate_pull(pull_obj, MP_QSTR_pull)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(digitalio_digitalinout_set_pull_obj, digitalio_digitalinout_obj_set_pull); + +MP_PROPERTY_GETSET(digitalio_digitalio_pull_obj, + (mp_obj_t)&digitalio_digitalinout_get_pull_obj, + (mp_obj_t)&digitalio_digitalinout_set_pull_obj); + +STATIC const mp_rom_map_elem_t digitalio_digitalinout_locals_dict_table[] = { + // instance methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&digitalio_digitalinout_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&digitalio_digitalinout_obj___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_switch_to_output), MP_ROM_PTR(&digitalio_digitalinout_switch_to_output_obj) }, + { MP_ROM_QSTR(MP_QSTR_switch_to_input), MP_ROM_PTR(&digitalio_digitalinout_switch_to_input_obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_direction), MP_ROM_PTR(&digitalio_digitalio_direction_obj) }, + { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&digitalio_digitalinout_value_obj) }, + { MP_ROM_QSTR(MP_QSTR_drive_mode), MP_ROM_PTR(&digitalio_digitalio_drive_mode_obj) }, + { MP_ROM_QSTR(MP_QSTR_pull), MP_ROM_PTR(&digitalio_digitalio_pull_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(digitalio_digitalinout_locals_dict, digitalio_digitalinout_locals_dict_table); + +const mp_obj_type_t digitalio_digitalinout_type = { + { &mp_type_type }, + .name = MP_QSTR_DigitalInOut, + .make_new = digitalio_digitalinout_make_new, + .locals_dict = (mp_obj_dict_t *)&digitalio_digitalinout_locals_dict, +}; + +// Helper for validating digitalio.DigitalInOut arguments +digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj) { + if (!mp_obj_is_type(obj, &digitalio_digitalinout_type)) { + mp_raise_TypeError(translate("argument num/types mismatch")); + } + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj); + check_for_deinit(pin); + return pin; +} diff --git a/circuitpython/shared-bindings/digitalio/DigitalInOut.h b/circuitpython/shared-bindings/digitalio/DigitalInOut.h new file mode 100644 index 0000000..b6edbc6 --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/DigitalInOut.h @@ -0,0 +1,70 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George + * + * 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_DIGITALIO_DIGITALINOUT_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DIGITALINOUT_H + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/digitalio/DigitalInOut.h" +#include "shared-bindings/digitalio/Direction.h" +#include "shared-bindings/digitalio/DriveMode.h" +#include "shared-bindings/digitalio/Pull.h" + +extern const mp_obj_type_t digitalio_digitalinout_type; + +typedef enum { + DIGITALINOUT_OK, + DIGITALINOUT_PIN_BUSY, + DIGITALINOUT_INPUT_ONLY +} digitalinout_result_t; + +typedef enum { + DIGITALINOUT_REG_READ, + DIGITALINOUT_REG_WRITE, + DIGITALINOUT_REG_SET, + DIGITALINOUT_REG_RESET, + DIGITALINOUT_REG_TOGGLE, +} digitalinout_reg_op_t; + +digitalinout_result_t common_hal_digitalio_digitalinout_construct(digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin); +void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self); +bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self); +void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull); +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode); +digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(digitalio_digitalinout_obj_t *self); +void common_hal_digitalio_digitalinout_set_value(digitalio_digitalinout_obj_t *self, bool value); +bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self); +digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode); +digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitalio_digitalinout_obj_t *self); +void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull); +digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t *self); +void common_hal_digitalio_digitalinout_never_reset(digitalio_digitalinout_obj_t *self); +digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj); + +volatile uint32_t *common_hal_digitalio_digitalinout_get_reg(digitalio_digitalinout_obj_t *self, digitalinout_reg_op_t op, uint32_t *mask); +bool common_hal_digitalio_has_reg_op(digitalinout_reg_op_t op); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DIGITALINOUT_H diff --git a/circuitpython/shared-bindings/digitalio/Direction.c b/circuitpython/shared-bindings/digitalio/Direction.c new file mode 100644 index 0000000..0ed18f8 --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/Direction.c @@ -0,0 +1,84 @@ +/* + * 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 <stdint.h> +#include <string.h> + +#include "shared/runtime/context_manager_helpers.h" + +#include "py/nlr.h" +#include "py/objtype.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/mphal.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/digitalio/DigitalInOut.h" + +//| class Direction: +//| """Defines the direction of a digital pin""" +//| +//| def __init__(self) -> None: +//| """Enum-like class to define which direction the digital values are +//| going.""" +//| ... +//| +//| INPUT: Direction +//| """Read digital data in""" +//| +//| OUTPUT: Direction +//| """Write digital data out""" +//| +const mp_obj_type_t digitalio_direction_type; + +const digitalio_direction_obj_t digitalio_direction_input_obj = { + { &digitalio_direction_type }, +}; + +const digitalio_direction_obj_t digitalio_direction_output_obj = { + { &digitalio_direction_type }, +}; + +STATIC const mp_rom_map_elem_t digitalio_direction_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_INPUT), MP_ROM_PTR(&digitalio_direction_input_obj) }, + { MP_ROM_QSTR(MP_QSTR_OUTPUT), MP_ROM_PTR(&digitalio_direction_output_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(digitalio_direction_locals_dict, digitalio_direction_locals_dict_table); + +STATIC void digitalio_direction_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + qstr direction = MP_QSTR_INPUT; + if (self_in == MP_ROM_PTR(&digitalio_direction_output_obj)) { + direction = MP_QSTR_OUTPUT; + } + mp_printf(print, "%q.%q.%q", MP_QSTR_digitalio, MP_QSTR_Direction, direction); +} + +const mp_obj_type_t digitalio_direction_type = { + { &mp_type_type }, + .name = MP_QSTR_Direction, + .print = digitalio_direction_print, + .locals_dict = (mp_obj_dict_t *)&digitalio_direction_locals_dict, +}; diff --git a/circuitpython/shared-bindings/digitalio/Direction.h b/circuitpython/shared-bindings/digitalio/Direction.h new file mode 100644 index 0000000..17e1eda --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/Direction.h @@ -0,0 +1,45 @@ +/* + * 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_DIGITALIO_DIRECTION_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DIRECTION_H + +#include "py/obj.h" + +typedef enum { + DIRECTION_INPUT, + DIRECTION_OUTPUT +} digitalio_direction_t; +typedef struct { + mp_obj_base_t base; +} digitalio_direction_obj_t; + +extern const mp_obj_type_t digitalio_direction_type; + +extern const digitalio_direction_obj_t digitalio_direction_input_obj; +extern const digitalio_direction_obj_t digitalio_direction_output_obj; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DIRECTION_H diff --git a/circuitpython/shared-bindings/digitalio/DriveMode.c b/circuitpython/shared-bindings/digitalio/DriveMode.c new file mode 100644 index 0000000..c7c3400 --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/DriveMode.c @@ -0,0 +1,73 @@ +/* + * 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 "shared-bindings/digitalio/DriveMode.h" + +//| class DriveMode: +//| """Defines the drive mode of a digital pin""" +//| +//| def __init__(self) -> None: +//| """Enum-like class to define the drive mode used when outputting +//| digital values.""" +//| ... +//| +//| PUSH_PULL: DriveMode +//| """Output both high and low digital values""" +//| +//| OPEN_DRAIN: DriveMode +//| """Output low digital values but go into high z for digital high. This is +//| useful for i2c and other protocols that share a digital line.""" +//| +const mp_obj_type_t digitalio_drive_mode_type; + +const digitalio_drive_mode_obj_t digitalio_drive_mode_push_pull_obj = { + { &digitalio_drive_mode_type }, +}; + +const digitalio_drive_mode_obj_t digitalio_drive_mode_open_drain_obj = { + { &digitalio_drive_mode_type }, +}; + +STATIC const mp_rom_map_elem_t digitalio_drive_mode_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_PUSH_PULL), MP_ROM_PTR(&digitalio_drive_mode_push_pull_obj) }, + { MP_ROM_QSTR(MP_QSTR_OPEN_DRAIN), MP_ROM_PTR(&digitalio_drive_mode_open_drain_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(digitalio_drive_mode_locals_dict, digitalio_drive_mode_locals_dict_table); + +STATIC void digitalio_drive_mode_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + qstr drive_mode = MP_QSTR_PUSH_PULL; + if (self_in == MP_ROM_PTR(&digitalio_drive_mode_open_drain_obj)) { + drive_mode = MP_QSTR_OPEN_DRAIN; + } + mp_printf(print, "%q.%q.%q", MP_QSTR_digitalio, MP_QSTR_DriveMode, drive_mode); +} + +const mp_obj_type_t digitalio_drive_mode_type = { + { &mp_type_type }, + .name = MP_QSTR_DriveMode, + .print = digitalio_drive_mode_print, + .locals_dict = (mp_obj_dict_t *)&digitalio_drive_mode_locals_dict, +}; diff --git a/circuitpython/shared-bindings/digitalio/DriveMode.h b/circuitpython/shared-bindings/digitalio/DriveMode.h new file mode 100644 index 0000000..01ecaa4 --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/DriveMode.h @@ -0,0 +1,46 @@ +/* + * 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_DIGITALIO_DRIVEMODE_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DRIVEMODE_H + +#include "py/obj.h" + +typedef enum { + DRIVE_MODE_PUSH_PULL, + DRIVE_MODE_OPEN_DRAIN +} digitalio_drive_mode_t; + +typedef struct { + mp_obj_base_t base; +} digitalio_drive_mode_obj_t; + +extern const mp_obj_type_t digitalio_drive_mode_type; + +extern const digitalio_drive_mode_obj_t digitalio_drive_mode_push_pull_obj; +extern const digitalio_drive_mode_obj_t digitalio_drive_mode_open_drain_obj; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DRIVEMODE_H diff --git a/circuitpython/shared-bindings/digitalio/Pull.c b/circuitpython/shared-bindings/digitalio/Pull.c new file mode 100644 index 0000000..4db68dd --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/Pull.c @@ -0,0 +1,87 @@ +/* + * 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 "py/runtime.h" +#include "shared-bindings/digitalio/Pull.h" + +//| class Pull: +//| """Defines the pull of a digital input pin""" +//| +//| def __init__(self) -> None: +//| """Enum-like class to define the pull value, if any, used while reading +//| digital values in.""" +//| ... +//| +//| UP: Pull +//| """When the input line isn't being driven the pull up can pull the state +//| of the line high so it reads as true.""" +//| +//| DOWN: Pull +//| """When the input line isn't being driven the pull down can pull the +//| state of the line low so it reads as false.""" +//| +const mp_obj_type_t digitalio_pull_type; + +const digitalio_pull_obj_t digitalio_pull_up_obj = { + { &digitalio_pull_type }, +}; + +const digitalio_pull_obj_t digitalio_pull_down_obj = { + { &digitalio_pull_type }, +}; + +STATIC const mp_rom_map_elem_t digitalio_pull_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_PTR(&digitalio_pull_up_obj) }, + { MP_ROM_QSTR(MP_QSTR_DOWN), MP_ROM_PTR(&digitalio_pull_down_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(digitalio_pull_locals_dict, digitalio_pull_locals_dict_table); + +STATIC void digitalio_pull_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + qstr pull = MP_QSTR_UP; + if (self_in == MP_ROM_PTR(&digitalio_pull_down_obj)) { + pull = MP_QSTR_DOWN; + } + mp_printf(print, "%q.%q.%q", MP_QSTR_digitalio, MP_QSTR_Pull, pull); +} + +const mp_obj_type_t digitalio_pull_type = { + { &mp_type_type }, + .name = MP_QSTR_Pull, + .print = digitalio_pull_print, + .locals_dict = (mp_obj_dict_t *)&digitalio_pull_locals_dict, +}; + +digitalio_pull_t validate_pull(mp_rom_obj_t obj, qstr arg_name) { + if (obj == MP_ROM_PTR(&digitalio_pull_up_obj)) { + return PULL_UP; + } else if (obj == MP_ROM_PTR(&digitalio_pull_down_obj)) { + return PULL_DOWN; + } + if (obj == MP_ROM_NONE) { + return PULL_NONE; + } + mp_raise_TypeError_varg(translate("%q must be of type %q or None"), arg_name, MP_QSTR_Pull); +} diff --git a/circuitpython/shared-bindings/digitalio/Pull.h b/circuitpython/shared-bindings/digitalio/Pull.h new file mode 100644 index 0000000..f4f6c42 --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/Pull.h @@ -0,0 +1,48 @@ +/* + * 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_DIGITALIO_PULL_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_PULL_H + +#include "py/obj.h" + +typedef enum _digitalio_pull_t { + PULL_NONE, + PULL_UP, + PULL_DOWN +} digitalio_pull_t; + +extern const mp_obj_type_t digitalio_pull_type; + +typedef struct { + mp_obj_base_t base; +} digitalio_pull_obj_t; +extern const digitalio_pull_obj_t digitalio_pull_up_obj; +extern const digitalio_pull_obj_t digitalio_pull_down_obj; + +digitalio_pull_t validate_pull(mp_rom_obj_t obj, qstr arg_name); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_PULL_H diff --git a/circuitpython/shared-bindings/digitalio/__init__.c b/circuitpython/shared-bindings/digitalio/__init__.c new file mode 100644 index 0000000..9a9db69 --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/__init__.c @@ -0,0 +1,100 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * 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 + * 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 <stdint.h> + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/digitalio/__init__.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/digitalio/Direction.h" +#include "shared-bindings/digitalio/DriveMode.h" +#include "shared-bindings/digitalio/Pull.h" + +#include "py/runtime.h" + +//| """Basic digital pin support +//| +//| The `digitalio` module contains classes to provide access to basic digital IO. +//| +//| All classes change hardware state and should be deinitialized when they +//| are no longer needed if the program continues after use. To do so, either +//| call :py:meth:`!deinit` or use a context manager. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| +//| For example:: +//| +//| import digitalio +//| import board +//| +//| pin = digitalio.DigitalInOut(board.LED) +//| print(pin.value) +//| +//| This example will initialize the the device, read +//| :py:data:`~digitalio.DigitalInOut.value` and then +//| :py:meth:`~digitalio.DigitalInOut.deinit` the hardware. +//| +//| Here is blinky:: +//| +//| import time +//| import digitalio +//| import board +//| +//| led = digitalio.DigitalInOut(board.LED) +//| led.direction = digitalio.Direction.OUTPUT +//| while True: +//| led.value = True +//| time.sleep(0.1) +//| led.value = False +//| time.sleep(0.1) +//| +//| For the essentials of `digitalio`, see the `CircuitPython Essentials +//| Learn guide <https://learn.adafruit.com/circuitpython-essentials/circuitpython-digital-in-out>`_ +//| +//| For more information on using `digitalio`, see `this additional Learn guide +//| <https://learn.adafruit.com/circuitpython-digital-inputs-and-outputs>`_ +//| """ + +STATIC const mp_rom_map_elem_t digitalio_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_digitalio) }, + { MP_ROM_QSTR(MP_QSTR_DigitalInOut), MP_ROM_PTR(&digitalio_digitalinout_type) }, + + // Enum-like Classes. + { MP_ROM_QSTR(MP_QSTR_Direction), MP_ROM_PTR(&digitalio_direction_type) }, + { MP_ROM_QSTR(MP_QSTR_DriveMode), MP_ROM_PTR(&digitalio_drive_mode_type) }, + { MP_ROM_QSTR(MP_QSTR_Pull), MP_ROM_PTR(&digitalio_pull_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(digitalio_module_globals, digitalio_module_globals_table); + +const mp_obj_module_t digitalio_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&digitalio_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_digitalio, digitalio_module, CIRCUITPY_DIGITALIO); diff --git a/circuitpython/shared-bindings/digitalio/__init__.h b/circuitpython/shared-bindings/digitalio/__init__.h new file mode 100644 index 0000000..8ab7f78 --- /dev/null +++ b/circuitpython/shared-bindings/digitalio/__init__.h @@ -0,0 +1,34 @@ +/* + * 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_SHARED_BINDINGS_DIGITALIO___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO___INIT___H + +#include "py/obj.h" + +// Nothing now. + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO___INIT___H |