2020-02-03 20:20:29 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
|
|
|
|
* Copyright (c) 2019 Lucian Copeland 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/DigitalInOut.h"
|
|
|
|
#include "py/runtime.h"
|
2022-05-27 15:59:54 -04:00
|
|
|
#include "supervisor/shared/translate/translate.h"
|
2020-02-03 20:20:29 -05:00
|
|
|
|
|
|
|
#include "csr.h"
|
|
|
|
|
|
|
|
void common_hal_digitalio_digitalinout_never_reset(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self) {
|
2020-02-03 20:20:29 -05:00
|
|
|
(void)self;
|
|
|
|
}
|
|
|
|
|
|
|
|
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
|
2020-02-03 20:20:29 -05:00
|
|
|
|
|
|
|
// claim_pin(pin);
|
|
|
|
self->pin = pin;
|
|
|
|
|
|
|
|
return DIGITALINOUT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) {
|
2020-06-26 15:33:50 -04:00
|
|
|
return self->pin == NULL;
|
2020-02-03 20:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) {
|
|
|
|
if (common_hal_digitalio_digitalinout_deinited(self)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reset_pin_number(0, self->pin->number);
|
2020-06-26 15:33:50 -04:00
|
|
|
self->pin = NULL;
|
2020-02-03 20:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_digitalio_digitalinout_switch_to_input(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
|
2020-02-03 20:20:29 -05:00
|
|
|
(void)pull;
|
|
|
|
touch_oe_write(touch_oe_read() & ~(1 << self->pin->number));
|
|
|
|
}
|
|
|
|
|
2020-05-20 12:23:42 -04:00
|
|
|
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self, bool value,
|
|
|
|
digitalio_drive_mode_t drive_mode) {
|
2020-02-03 20:20:29 -05:00
|
|
|
(void)drive_mode;
|
|
|
|
common_hal_digitalio_digitalinout_set_value(self, value);
|
|
|
|
touch_oe_write(touch_oe_read() | (1 << self->pin->number));
|
2020-05-20 12:23:42 -04:00
|
|
|
return DIGITALINOUT_OK;
|
2020-02-03 20:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self) {
|
2020-02-03 20:20:29 -05:00
|
|
|
|
|
|
|
return (touch_oe_read() & (1 << self->pin->number))
|
|
|
|
? DIRECTION_OUTPUT : DIRECTION_INPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_digitalio_digitalinout_set_value(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self, bool value) {
|
|
|
|
if (value) {
|
2020-02-03 20:20:29 -05:00
|
|
|
touch_o_write(touch_o_read() | (1 << self->pin->number));
|
2021-03-15 09:57:36 -04:00
|
|
|
} else {
|
2020-02-03 20:20:29 -05:00
|
|
|
touch_o_write(touch_o_read() & ~(1 << self->pin->number));
|
2021-03-15 09:57:36 -04:00
|
|
|
}
|
2020-02-03 20:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool common_hal_digitalio_digitalinout_get_value(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self) {
|
2020-02-03 20:20:29 -05:00
|
|
|
return !!(touch_i_read() & (1 << self->pin->number));
|
|
|
|
}
|
|
|
|
|
2020-05-20 12:23:42 -04:00
|
|
|
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self,
|
|
|
|
digitalio_drive_mode_t drive_mode) {
|
2020-02-03 20:20:29 -05:00
|
|
|
(void)self;
|
|
|
|
(void)drive_mode;
|
2020-05-20 12:23:42 -04:00
|
|
|
return DIGITALINOUT_OK;
|
2020-02-03 20:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self) {
|
|
|
|
if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_OUTPUT) {
|
2020-02-03 20:20:29 -05:00
|
|
|
return DRIVE_MODE_PUSH_PULL;
|
2021-03-15 09:57:36 -04:00
|
|
|
} else {
|
2020-02-03 20:20:29 -05:00
|
|
|
return DRIVE_MODE_OPEN_DRAIN;
|
2021-03-15 09:57:36 -04:00
|
|
|
}
|
2020-02-03 20:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_digitalio_digitalinout_set_pull(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
|
2020-02-03 20:20:29 -05:00
|
|
|
(void)self;
|
|
|
|
(void)pull;
|
|
|
|
}
|
|
|
|
|
|
|
|
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
|
2021-03-15 09:57:36 -04:00
|
|
|
digitalio_digitalinout_obj_t *self) {
|
2020-02-03 20:20:29 -05:00
|
|
|
return PULL_NONE;
|
|
|
|
}
|