From f28f8ba56809fd56e777eabceae21127f95b89ed Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 10 Apr 2017 13:32:19 -0700 Subject: Split up nativeio. This was done to allow greatly granularity when deciding what functionality is built into each board's build. For example, this way pulseio can be omitted to allow for something else such as touchio. --- shared-module/bitbangio/I2C.c | 32 +++++++++---------- shared-module/bitbangio/OneWire.c | 24 +++++++------- shared-module/bitbangio/SPI.c | 56 ++++++++++++++++----------------- shared-module/bitbangio/types.h | 14 ++++----- shared-module/busio/I2C.c | 66 +++++++++++++++++++++++++++++++++++++++ shared-module/busio/I2C.h | 39 +++++++++++++++++++++++ shared-module/busio/OneWire.c | 52 ++++++++++++++++++++++++++++++ shared-module/busio/OneWire.h | 39 +++++++++++++++++++++++ shared-module/nativeio/I2C.c | 66 --------------------------------------- shared-module/nativeio/I2C.h | 42 ------------------------- shared-module/nativeio/OneWire.c | 52 ------------------------------ shared-module/nativeio/OneWire.h | 42 ------------------------- 12 files changed, 259 insertions(+), 265 deletions(-) create mode 100644 shared-module/busio/I2C.c create mode 100644 shared-module/busio/I2C.h create mode 100644 shared-module/busio/OneWire.c create mode 100644 shared-module/busio/OneWire.h delete mode 100644 shared-module/nativeio/I2C.c delete mode 100644 shared-module/nativeio/I2C.h delete mode 100644 shared-module/nativeio/OneWire.c delete mode 100644 shared-module/nativeio/OneWire.h (limited to 'shared-module') diff --git a/shared-module/bitbangio/I2C.c b/shared-module/bitbangio/I2C.c index 422f7778d..4c47629c7 100644 --- a/shared-module/bitbangio/I2C.c +++ b/shared-module/bitbangio/I2C.c @@ -31,7 +31,7 @@ #include "common-hal/microcontroller/types.h" #include "shared-bindings/microcontroller/__init__.h" -#include "shared-bindings/nativeio/DigitalInOut.h" +#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-module/bitbangio/types.h" #define I2C_STRETCH_LIMIT 255 @@ -43,30 +43,30 @@ STATIC void delay(bitbangio_i2c_obj_t *self) { } STATIC void scl_low(bitbangio_i2c_obj_t *self) { - common_hal_nativeio_digitalinout_set_value(&self->scl, false); + common_hal_digitalio_digitalinout_set_value(&self->scl, false); } STATIC void scl_release(bitbangio_i2c_obj_t *self) { - common_hal_nativeio_digitalinout_set_value(&self->scl, true); + common_hal_digitalio_digitalinout_set_value(&self->scl, true); delay(self); // For clock stretching, wait for the SCL pin to be released, with timeout. - for (int count = I2C_STRETCH_LIMIT; !common_hal_nativeio_digitalinout_get_value(&self->scl) && count; --count) { + for (int count = I2C_STRETCH_LIMIT; !common_hal_digitalio_digitalinout_get_value(&self->scl) && count; --count) { common_hal_mcu_delay_us(1); } } STATIC void sda_low(bitbangio_i2c_obj_t *self) { - common_hal_nativeio_digitalinout_set_value(&self->sda, false); + common_hal_digitalio_digitalinout_set_value(&self->sda, false); } STATIC void sda_release(bitbangio_i2c_obj_t *self) { - common_hal_nativeio_digitalinout_set_value(&self->sda, true); + common_hal_digitalio_digitalinout_set_value(&self->sda, true); } STATIC bool sda_read(bitbangio_i2c_obj_t *self) { - common_hal_nativeio_digitalinout_switch_to_input(&self->sda, PULL_UP); - bool value = common_hal_nativeio_digitalinout_get_value(&self->sda); - common_hal_nativeio_digitalinout_switch_to_output(&self->sda, true, DRIVE_MODE_OPEN_DRAIN); + common_hal_digitalio_digitalinout_switch_to_input(&self->sda, PULL_UP); + bool value = common_hal_digitalio_digitalinout_get_value(&self->sda); + common_hal_digitalio_digitalinout_switch_to_output(&self->sda, true, DRIVE_MODE_OPEN_DRAIN); return value; } @@ -147,24 +147,24 @@ void shared_module_bitbangio_i2c_construct(bitbangio_i2c_obj_t *self, if (self->us_delay == 0) { self->us_delay = 1; } - digitalinout_result_t result = common_hal_nativeio_digitalinout_construct(&self->scl, scl); + digitalinout_result_t result = common_hal_digitalio_digitalinout_construct(&self->scl, scl); if (result != DIGITALINOUT_OK) { return; } - result = common_hal_nativeio_digitalinout_construct(&self->sda, sda); + result = common_hal_digitalio_digitalinout_construct(&self->sda, sda); if (result != DIGITALINOUT_OK) { - common_hal_nativeio_digitalinout_deinit(&self->scl); + common_hal_digitalio_digitalinout_deinit(&self->scl); return; } - common_hal_nativeio_digitalinout_switch_to_output(&self->scl, true, DRIVE_MODE_OPEN_DRAIN); - common_hal_nativeio_digitalinout_switch_to_output(&self->sda, true, DRIVE_MODE_OPEN_DRAIN); + common_hal_digitalio_digitalinout_switch_to_output(&self->scl, true, DRIVE_MODE_OPEN_DRAIN); + common_hal_digitalio_digitalinout_switch_to_output(&self->sda, true, DRIVE_MODE_OPEN_DRAIN); stop(self); } void shared_module_bitbangio_i2c_deinit(bitbangio_i2c_obj_t *self) { - common_hal_nativeio_digitalinout_deinit(&self->scl); - common_hal_nativeio_digitalinout_deinit(&self->sda); + common_hal_digitalio_digitalinout_deinit(&self->scl); + common_hal_digitalio_digitalinout_deinit(&self->sda); } bool shared_module_bitbangio_i2c_try_lock(bitbangio_i2c_obj_t *self) { diff --git a/shared-module/bitbangio/OneWire.c b/shared-module/bitbangio/OneWire.c index 5f45b3baf..b78acc8ec 100644 --- a/shared-module/bitbangio/OneWire.c +++ b/shared-module/bitbangio/OneWire.c @@ -27,28 +27,28 @@ #include "common-hal/microcontroller/types.h" #include "shared-bindings/bitbangio/OneWire.h" #include "shared-bindings/microcontroller/__init__.h" -#include "shared-bindings/nativeio/DigitalInOut.h" +#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-module/bitbangio/types.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, const mcu_pin_obj_t* pin) { - self->pin.base.type = &nativeio_digitalinout_type; - common_hal_nativeio_digitalinout_construct(&self->pin, pin); + self->pin.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&self->pin, pin); } void shared_module_bitbangio_onewire_deinit(bitbangio_onewire_obj_t* self) { - common_hal_nativeio_digitalinout_deinit(&self->pin); + common_hal_digitalio_digitalinout_deinit(&self->pin); } bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t* self) { common_hal_mcu_disable_interrupts(); - common_hal_nativeio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN); + common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN); common_hal_mcu_delay_us(480); - common_hal_nativeio_digitalinout_switch_to_input(&self->pin, PULL_NONE); + common_hal_digitalio_digitalinout_switch_to_input(&self->pin, PULL_NONE); common_hal_mcu_delay_us(70); - bool value = common_hal_nativeio_digitalinout_get_value(&self->pin); + bool value = common_hal_digitalio_digitalinout_get_value(&self->pin); common_hal_mcu_delay_us(410); common_hal_mcu_enable_interrupts(); return value; @@ -56,14 +56,14 @@ bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t* self) { bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t* self) { common_hal_mcu_disable_interrupts(); - common_hal_nativeio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN); + common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN); common_hal_mcu_delay_us(6); - common_hal_nativeio_digitalinout_switch_to_input(&self->pin, PULL_NONE); + common_hal_digitalio_digitalinout_switch_to_input(&self->pin, PULL_NONE); // TODO(tannewt): Test with more devices and maybe make the delays // configurable. This should be 9 by the datasheet but all bits read as 1 // then. common_hal_mcu_delay_us(6); - bool value = common_hal_nativeio_digitalinout_get_value(&self->pin); + bool value = common_hal_digitalio_digitalinout_get_value(&self->pin); common_hal_mcu_delay_us(55); common_hal_mcu_enable_interrupts(); return value; @@ -72,9 +72,9 @@ bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t* self) { void shared_module_bitbangio_onewire_write_bit(bitbangio_onewire_obj_t* self, bool bit) { common_hal_mcu_disable_interrupts(); - common_hal_nativeio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN); + common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN); common_hal_mcu_delay_us(bit? 6 : 60); - common_hal_nativeio_digitalinout_switch_to_input(&self->pin, PULL_NONE); + common_hal_digitalio_digitalinout_switch_to_input(&self->pin, PULL_NONE); common_hal_mcu_delay_us(bit? 64 : 10); common_hal_mcu_enable_interrupts(); } diff --git a/shared-module/bitbangio/SPI.c b/shared-module/bitbangio/SPI.c index 5e8d73122..be0deda8f 100644 --- a/shared-module/bitbangio/SPI.c +++ b/shared-module/bitbangio/SPI.c @@ -31,7 +31,7 @@ #include "common-hal/microcontroller/types.h" #include "shared-bindings/microcontroller/__init__.h" -#include "shared-bindings/nativeio/DigitalInOut.h" +#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-module/bitbangio/types.h" #define MAX_BAUDRATE (common_hal_mcu_get_clock_frequency() / 48) @@ -39,26 +39,26 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self, const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi, const mcu_pin_obj_t * miso) { - digitalinout_result_t result = common_hal_nativeio_digitalinout_construct(&self->clock, clock); + digitalinout_result_t result = common_hal_digitalio_digitalinout_construct(&self->clock, clock); if (result != DIGITALINOUT_OK) { nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Clock pin init failed.")); } if (mosi != mp_const_none) { - result = common_hal_nativeio_digitalinout_construct(&self->mosi, mosi); + result = common_hal_digitalio_digitalinout_construct(&self->mosi, mosi); if (result != DIGITALINOUT_OK) { - common_hal_nativeio_digitalinout_deinit(&self->clock); + common_hal_digitalio_digitalinout_deinit(&self->clock); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "MOSI pin init failed.")); } self->has_mosi = true; } if (miso != mp_const_none) { - result = common_hal_nativeio_digitalinout_construct(&self->miso, miso); + result = common_hal_digitalio_digitalinout_construct(&self->miso, miso); if (result != DIGITALINOUT_OK) { - common_hal_nativeio_digitalinout_deinit(&self->clock); + common_hal_digitalio_digitalinout_deinit(&self->clock); if (mosi != mp_const_none) { - common_hal_nativeio_digitalinout_deinit(&self->mosi); + common_hal_digitalio_digitalinout_deinit(&self->mosi); } nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "MISO pin init failed.")); @@ -71,12 +71,12 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self, } void shared_module_bitbangio_spi_deinit(bitbangio_spi_obj_t *self) { - common_hal_nativeio_digitalinout_deinit(&self->clock); + common_hal_digitalio_digitalinout_deinit(&self->clock); if (self->has_mosi) { - common_hal_nativeio_digitalinout_deinit(&self->mosi); + common_hal_digitalio_digitalinout_deinit(&self->mosi); } if (self->has_miso) { - common_hal_nativeio_digitalinout_deinit(&self->miso); + common_hal_digitalio_digitalinout_deinit(&self->miso); } } @@ -129,9 +129,9 @@ bool shared_module_bitbangio_spi_write(bitbangio_spi_obj_t *self, const uint8_t for (size_t i = 0; i < len; ++i) { uint8_t data_out = data[i]; for (int j = 0; j < 8; ++j, data_out <<= 1) { - common_hal_nativeio_digitalinout_set_value(&self->mosi, (data_out >> 7) & 1); - common_hal_nativeio_digitalinout_set_value(&self->clock, 1 - self->polarity); - common_hal_nativeio_digitalinout_set_value(&self->clock, self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->mosi, (data_out >> 7) & 1); + common_hal_digitalio_digitalinout_set_value(&self->clock, 1 - self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, self->polarity); } if (dest != NULL) { dest[i] = data_in; @@ -144,16 +144,16 @@ bool shared_module_bitbangio_spi_write(bitbangio_spi_obj_t *self, const uint8_t for (size_t i = 0; i < len; ++i) { uint8_t data_out = data[i]; for (int j = 0; j < 8; ++j, data_out <<= 1) { - common_hal_nativeio_digitalinout_set_value(&self->mosi, (data_out >> 7) & 1); + common_hal_digitalio_digitalinout_set_value(&self->mosi, (data_out >> 7) & 1); if (self->phase == 0) { common_hal_mcu_delay_us(delay_half); - common_hal_nativeio_digitalinout_set_value(&self->clock, 1 - self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, 1 - self->polarity); common_hal_mcu_delay_us(delay_half); - common_hal_nativeio_digitalinout_set_value(&self->clock, self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, self->polarity); } else { - common_hal_nativeio_digitalinout_set_value(&self->clock, 1 - self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, 1 - self->polarity); common_hal_mcu_delay_us(delay_half); - common_hal_nativeio_digitalinout_set_value(&self->clock, self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, self->polarity); common_hal_mcu_delay_us(delay_half); } } @@ -185,14 +185,14 @@ bool shared_module_bitbangio_spi_read(bitbangio_spi_obj_t *self, uint8_t *data, if (delay_half <= MICROPY_PY_MACHINE_SPI_MIN_DELAY) { // Clock out zeroes while we read. if (self->has_mosi) { - common_hal_nativeio_digitalinout_set_value(&self->mosi, false); + common_hal_digitalio_digitalinout_set_value(&self->mosi, false); } for (size_t i = 0; i < len; ++i) { uint8_t data_in = 0; for (int j = 0; j < 8; ++j, data_out <<= 1) { - common_hal_nativeio_digitalinout_set_value(&self->clock, 1 - self->polarity); - data_in = (data_in << 1) | common_hal_nativeio_digitalinout_get_value(&self->miso); - common_hal_nativeio_digitalinout_set_value(&self->clock, self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, 1 - self->polarity); + data_in = (data_in << 1) | common_hal_digitalio_digitalinout_get_value(&self->miso); + common_hal_digitalio_digitalinout_set_value(&self->clock, self->polarity); } data[i] = data_in; } @@ -200,24 +200,24 @@ bool shared_module_bitbangio_spi_read(bitbangio_spi_obj_t *self, uint8_t *data, } #endif if (self->has_mosi) { - common_hal_nativeio_digitalinout_set_value(&self->mosi, false); + common_hal_digitalio_digitalinout_set_value(&self->mosi, false); } for (size_t i = 0; i < len; ++i) { uint8_t data_in = 0; for (int j = 0; j < 8; ++j) { if (self->phase == 0) { common_hal_mcu_delay_us(delay_half); - common_hal_nativeio_digitalinout_set_value(&self->clock, 1 - self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, 1 - self->polarity); } else { - common_hal_nativeio_digitalinout_set_value(&self->clock, 1 - self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, 1 - self->polarity); common_hal_mcu_delay_us(delay_half); } - data_in = (data_in << 1) | common_hal_nativeio_digitalinout_get_value(&self->miso); + data_in = (data_in << 1) | common_hal_digitalio_digitalinout_get_value(&self->miso); if (self->phase == 0) { common_hal_mcu_delay_us(delay_half); - common_hal_nativeio_digitalinout_set_value(&self->clock, self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, self->polarity); } else { - common_hal_nativeio_digitalinout_set_value(&self->clock, self->polarity); + common_hal_digitalio_digitalinout_set_value(&self->clock, self->polarity); common_hal_mcu_delay_us(delay_half); } } diff --git a/shared-module/bitbangio/types.h b/shared-module/bitbangio/types.h index 8fd4a48c4..46723a958 100644 --- a/shared-module/bitbangio/types.h +++ b/shared-module/bitbangio/types.h @@ -27,28 +27,28 @@ #ifndef __MICROPY_INCLUDED_SHARED_MODULE_BITBANGIO_TYPES_H__ #define __MICROPY_INCLUDED_SHARED_MODULE_BITBANGIO_TYPES_H__ -#include "common-hal/nativeio/DigitalInOut.h" +#include "common-hal/digitalio/DigitalInOut.h" #include "py/obj.h" typedef struct { mp_obj_base_t base; - nativeio_digitalinout_obj_t scl; - nativeio_digitalinout_obj_t sda; + digitalio_digitalinout_obj_t scl; + digitalio_digitalinout_obj_t sda; uint32_t us_delay; volatile bool locked; } bitbangio_i2c_obj_t; typedef struct { mp_obj_base_t base; - nativeio_digitalinout_obj_t pin; + digitalio_digitalinout_obj_t pin; } bitbangio_onewire_obj_t; typedef struct { mp_obj_base_t base; - nativeio_digitalinout_obj_t clock; - nativeio_digitalinout_obj_t mosi; - nativeio_digitalinout_obj_t miso; + digitalio_digitalinout_obj_t clock; + digitalio_digitalinout_obj_t mosi; + digitalio_digitalinout_obj_t miso; uint32_t delay_half; bool has_miso:1; bool has_mosi:1; diff --git a/shared-module/busio/I2C.c b/shared-module/busio/I2C.c new file mode 100644 index 000000000..f8f154e7f --- /dev/null +++ b/shared-module/busio/I2C.c @@ -0,0 +1,66 @@ +/* + * This file is part of the MicroPython 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/busio/I2C.h" +#include "shared-bindings/bitbangio/I2C.h" +#include "py/mperrno.h" +#include "py/nlr.h" + +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 freq) { + shared_module_bitbangio_i2c_construct(&self->bitbang, scl, sda, freq); +} + +void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { + shared_module_bitbangio_i2c_deinit(&self->bitbang); +} + +bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { + return shared_module_bitbangio_i2c_probe(&self->bitbang, addr); +} + +bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { + return shared_module_bitbangio_i2c_try_lock(&self->bitbang); +} + +bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self) { + return shared_module_bitbangio_i2c_has_lock(&self->bitbang); +} + +void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { + shared_module_bitbangio_i2c_unlock(&self->bitbang); +} + +uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, + const uint8_t * data, size_t len, bool transmit_stop_bit) { + return shared_module_bitbangio_i2c_write(&self->bitbang, addr, data, len, + transmit_stop_bit); +} + +uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, + uint8_t * data, size_t len) { + return shared_module_bitbangio_i2c_read(&self->bitbang, addr, data, len); +} diff --git a/shared-module/busio/I2C.h b/shared-module/busio/I2C.h new file mode 100644 index 000000000..9706124c2 --- /dev/null +++ b/shared-module/busio/I2C.h @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython 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_ATMEL_SAMD_SHARED_MODULE_BUSIO_I2C_H__ +#define __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSIO_I2C_H__ + +#include "shared-module/bitbangio/types.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + bitbangio_i2c_obj_t bitbang; +} busio_i2c_obj_t; + +#endif // __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSIO_I2C_H__ diff --git a/shared-module/busio/OneWire.c b/shared-module/busio/OneWire.c new file mode 100644 index 000000000..0e3c2c384 --- /dev/null +++ b/shared-module/busio/OneWire.c @@ -0,0 +1,52 @@ +/* + * 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/types.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); +} + +void common_hal_busio_onewire_deinit(busio_onewire_obj_t* self) { + 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/busio/OneWire.h b/shared-module/busio/OneWire.h new file mode 100644 index 000000000..9404a7206 --- /dev/null +++ b/shared-module/busio/OneWire.h @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython 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_ATMEL_SAMD_SHARED_MODULE_BUSIO_ONEWIRE_H__ +#define __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSIO_ONEWIRE_H__ + +#include "shared-module/bitbangio/types.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + bitbangio_onewire_obj_t bitbang; +} busio_onewire_obj_t; + +#endif // __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSIO_ONEWIRE_H__ diff --git a/shared-module/nativeio/I2C.c b/shared-module/nativeio/I2C.c deleted file mode 100644 index 345a3825a..000000000 --- a/shared-module/nativeio/I2C.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of the MicroPython 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/nativeio/I2C.h" -#include "shared-bindings/bitbangio/I2C.h" -#include "py/mperrno.h" -#include "py/nlr.h" - -void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self, - const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t freq) { - shared_module_bitbangio_i2c_construct(&self->bitbang, scl, sda, freq); -} - -void common_hal_nativeio_i2c_deinit(nativeio_i2c_obj_t *self) { - shared_module_bitbangio_i2c_deinit(&self->bitbang); -} - -bool common_hal_nativeio_i2c_probe(nativeio_i2c_obj_t *self, uint8_t addr) { - return shared_module_bitbangio_i2c_probe(&self->bitbang, addr); -} - -bool common_hal_nativeio_i2c_try_lock(nativeio_i2c_obj_t *self) { - return shared_module_bitbangio_i2c_try_lock(&self->bitbang); -} - -bool common_hal_nativeio_i2c_has_lock(nativeio_i2c_obj_t *self) { - return shared_module_bitbangio_i2c_has_lock(&self->bitbang); -} - -void common_hal_nativeio_i2c_unlock(nativeio_i2c_obj_t *self) { - shared_module_bitbangio_i2c_unlock(&self->bitbang); -} - -uint8_t common_hal_nativeio_i2c_write(nativeio_i2c_obj_t *self, uint16_t addr, - const uint8_t * data, size_t len, bool transmit_stop_bit) { - return shared_module_bitbangio_i2c_write(&self->bitbang, addr, data, len, - transmit_stop_bit); -} - -uint8_t common_hal_nativeio_i2c_read(nativeio_i2c_obj_t *self, uint16_t addr, - uint8_t * data, size_t len) { - return shared_module_bitbangio_i2c_read(&self->bitbang, addr, data, len); -} diff --git a/shared-module/nativeio/I2C.h b/shared-module/nativeio/I2C.h deleted file mode 100644 index b26ba4642..000000000 --- a/shared-module/nativeio/I2C.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the MicroPython 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. - */ - -// This defines the types used to underly the standard nativeio Python objects. -// The shared API is defined in terms of these types. - -#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_NATIVEIO_I2C_H__ -#define __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_NATIVEIO_I2C_H__ - -#include "shared-module/bitbangio/types.h" - -#include "py/obj.h" - -typedef struct { - mp_obj_base_t base; - bitbangio_i2c_obj_t bitbang; -} nativeio_i2c_obj_t; - -#endif // __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_NATIVEIO_I2C_H__ diff --git a/shared-module/nativeio/OneWire.c b/shared-module/nativeio/OneWire.c deleted file mode 100644 index 490f9b109..000000000 --- a/shared-module/nativeio/OneWire.c +++ /dev/null @@ -1,52 +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 nativeio. -#include "common-hal/microcontroller/types.h" -#include "shared-bindings/bitbangio/OneWire.h" -#include "common-hal/nativeio/types.h" - -void common_hal_nativeio_onewire_construct(nativeio_onewire_obj_t* self, - const mcu_pin_obj_t* pin) { - shared_module_bitbangio_onewire_construct(&self->bitbang, pin); -} - -void common_hal_nativeio_onewire_deinit(nativeio_onewire_obj_t* self) { - shared_module_bitbangio_onewire_deinit(&self->bitbang); -} - -bool common_hal_nativeio_onewire_reset(nativeio_onewire_obj_t* self) { - return shared_module_bitbangio_onewire_reset(&self->bitbang); -} - -bool common_hal_nativeio_onewire_read_bit(nativeio_onewire_obj_t* self) { - return shared_module_bitbangio_onewire_read_bit(&self->bitbang); -} - -void common_hal_nativeio_onewire_write_bit(nativeio_onewire_obj_t* self, - bool bit) { - shared_module_bitbangio_onewire_write_bit(&self->bitbang, bit); -} diff --git a/shared-module/nativeio/OneWire.h b/shared-module/nativeio/OneWire.h deleted file mode 100644 index 3704c55a3..000000000 --- a/shared-module/nativeio/OneWire.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the MicroPython 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. - */ - -// This defines the types used to underly the standard nativeio Python objects. -// The shared API is defined in terms of these types. - -#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_NATIVEIO_ONEWIRE_H__ -#define __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_NATIVEIO_ONEWIRE_H__ - -#include "shared-module/bitbangio/types.h" - -#include "py/obj.h" - -typedef struct { - mp_obj_base_t base; - bitbangio_onewire_obj_t bitbang; -} nativeio_onewire_obj_t; - -#endif // __MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_NATIVEIO_ONEWIRE_H__ -- cgit v1.2.3