|
| 1 | +// This file is part of the CircuitPython project: https://circuitpython.org |
| 2 | +// |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries |
| 4 | +// SPDX-FileCopyrightText: Copyright (c) 2018 Artur Pacholec |
| 5 | +// SPDX-FileCopyrightText: Copyright (c) 2017 hathach |
| 6 | +// SPDX-FileCopyrightText: Copyright (c) 2016 Sandeep Mistry All right reserved. |
| 7 | +// |
| 8 | +// SPDX-License-Identifier: MIT |
| 9 | + |
| 10 | +#include "shared-bindings/busio/I2C.h" |
| 11 | +#include "shared-bindings/microcontroller/__init__.h" |
| 12 | +#include "shared-bindings/microcontroller/Pin.h" |
| 13 | +#include "supervisor/shared/tick.h" |
| 14 | +#include "py/mperrno.h" |
| 15 | +#include "py/runtime.h" |
| 16 | + |
| 17 | + |
| 18 | +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { |
| 19 | + never_reset_pin_number(self->scl_pin_number); |
| 20 | + never_reset_pin_number(self->sda_pin_number); |
| 21 | +} |
| 22 | + |
| 23 | +void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { |
| 24 | + |
| 25 | +} |
| 26 | + |
| 27 | +bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { |
| 28 | + return self->sda_pin_number == NO_PIN; |
| 29 | +} |
| 30 | + |
| 31 | +void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { |
| 32 | + if (common_hal_busio_i2c_deinited(self)) { |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + // nrfx_twim_uninit(&self->twim_peripheral->twim); |
| 37 | + |
| 38 | + // reset_pin_number(self->sda_pin_number); |
| 39 | + // reset_pin_number(self->scl_pin_number); |
| 40 | + |
| 41 | + // self->twim_peripheral->in_use = false; |
| 42 | + // common_hal_busio_i2c_mark_deinit(self); |
| 43 | +} |
| 44 | + |
| 45 | +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { |
| 46 | + self->sda_pin_number = NO_PIN; |
| 47 | +} |
| 48 | + |
| 49 | +// nrfx_twim_tx doesn't support 0-length data so we fall back to the hal API |
| 50 | +bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { |
| 51 | + bool found = true; |
| 52 | + |
| 53 | + return found; |
| 54 | +} |
| 55 | + |
| 56 | +bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { |
| 57 | + if (common_hal_busio_i2c_deinited(self)) { |
| 58 | + return false; |
| 59 | + } |
| 60 | + bool grabbed_lock = false; |
| 61 | + return grabbed_lock; |
| 62 | +} |
| 63 | + |
| 64 | +bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self) { |
| 65 | + return self->has_lock; |
| 66 | +} |
| 67 | + |
| 68 | +void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { |
| 69 | + self->has_lock = false; |
| 70 | +} |
| 71 | + |
| 72 | +uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, const uint8_t *data, size_t len) { |
| 73 | + return 0; |
| 74 | +} |
| 75 | + |
| 76 | +uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, uint8_t *data, size_t len) { |
| 77 | + if (len == 0) { |
| 78 | + return 0; |
| 79 | + } |
| 80 | + |
| 81 | +} |
| 82 | + |
| 83 | +uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr, |
| 84 | + uint8_t *out_data, size_t out_len, uint8_t *in_data, size_t in_len) { |
| 85 | + uint8_t result = _common_hal_busio_i2c_write(self, addr, out_data, out_len, false); |
| 86 | + if (result != 0) { |
| 87 | + return result; |
| 88 | + } |
| 89 | + |
| 90 | + return common_hal_busio_i2c_read(self, addr, in_data, in_len); |
| 91 | +} |
0 commit comments