summaryrefslogtreecommitdiff
path: root/atmel-samd/common-hal
diff options
context:
space:
mode:
Diffstat (limited to 'atmel-samd/common-hal')
-rw-r--r--atmel-samd/common-hal/analogio/AnalogIn.c (renamed from atmel-samd/common-hal/nativeio/AnalogIn.c)12
-rw-r--r--atmel-samd/common-hal/analogio/AnalogIn.h49
-rw-r--r--atmel-samd/common-hal/analogio/AnalogOut.c (renamed from atmel-samd/common-hal/nativeio/AnalogOut.c)8
-rw-r--r--atmel-samd/common-hal/analogio/AnalogOut.h (renamed from atmel-samd/common-hal/nativeio/PulseIn.h)19
-rw-r--r--atmel-samd/common-hal/analogio/__init__.c1
-rw-r--r--atmel-samd/common-hal/busio/I2C.c (renamed from atmel-samd/common-hal/nativeio/I2C.c)25
-rw-r--r--atmel-samd/common-hal/busio/I2C.h43
-rw-r--r--atmel-samd/common-hal/busio/OneWire.h (renamed from atmel-samd/common-hal/nativeio/AnalogIn.h)9
-rw-r--r--atmel-samd/common-hal/busio/SPI.c (renamed from atmel-samd/common-hal/nativeio/SPI.c)21
-rw-r--r--atmel-samd/common-hal/busio/SPI.h45
-rw-r--r--atmel-samd/common-hal/busio/UART.c (renamed from atmel-samd/common-hal/nativeio/UART.c)22
-rw-r--r--atmel-samd/common-hal/busio/UART.h50
-rw-r--r--atmel-samd/common-hal/busio/__init__.c1
-rw-r--r--atmel-samd/common-hal/digitalio/DigitalInOut.c (renamed from atmel-samd/common-hal/nativeio/DigitalInOut.c)52
-rw-r--r--atmel-samd/common-hal/digitalio/DigitalInOut.h (renamed from atmel-samd/common-hal/nativeio/DigitalInOut.h)9
-rw-r--r--atmel-samd/common-hal/digitalio/__init__.c1
-rw-r--r--atmel-samd/common-hal/nativeio/TouchInStub.c45
-rw-r--r--atmel-samd/common-hal/nativeio/__init__.c1
-rw-r--r--atmel-samd/common-hal/nativeio/types.h142
-rw-r--r--atmel-samd/common-hal/neopixel_write/__init__.c3
-rw-r--r--atmel-samd/common-hal/pulseio/PWMOut.c (renamed from atmel-samd/common-hal/nativeio/PWMOut.c)24
-rw-r--r--atmel-samd/common-hal/pulseio/PWMOut.h49
-rw-r--r--atmel-samd/common-hal/pulseio/PulseIn.c (renamed from atmel-samd/common-hal/nativeio/PulseIn.c)29
-rw-r--r--atmel-samd/common-hal/pulseio/PulseIn.h49
-rw-r--r--atmel-samd/common-hal/pulseio/PulseOut.c (renamed from atmel-samd/common-hal/nativeio/PulseOut.c)13
-rw-r--r--atmel-samd/common-hal/pulseio/PulseOut.h (renamed from atmel-samd/common-hal/nativeio/PulseOut.h)18
-rw-r--r--atmel-samd/common-hal/pulseio/__init__.c1
-rw-r--r--atmel-samd/common-hal/touchio/TouchIn.c (renamed from atmel-samd/common-hal/nativeio/TouchIn.c)12
-rw-r--r--atmel-samd/common-hal/touchio/TouchIn.h (renamed from atmel-samd/common-hal/nativeio/PWMOut.h)20
-rw-r--r--atmel-samd/common-hal/touchio/__init__.c1
30 files changed, 453 insertions, 321 deletions
diff --git a/atmel-samd/common-hal/nativeio/AnalogIn.c b/atmel-samd/common-hal/analogio/AnalogIn.c
index 2203fc2ca..59ea3b899 100644
--- a/atmel-samd/common-hal/nativeio/AnalogIn.c
+++ b/atmel-samd/common-hal/analogio/AnalogIn.c
@@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
-#include "common-hal/nativeio/AnalogIn.h"
+#include "common-hal/analogio/AnalogIn.h"
#include <string.h>
@@ -33,7 +33,7 @@
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mphal.h"
-#include "shared-bindings/nativeio/AnalogIn.h"
+#include "shared-bindings/analogio/AnalogIn.h"
#include "asf/sam0/drivers/adc/adc.h"
#include "samd21_pins.h"
@@ -42,7 +42,7 @@
volatile uint8_t active_channel_count;
struct adc_module *adc_instance = NULL;
-void common_hal_nativeio_analogin_construct(nativeio_analogin_obj_t* self,
+void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
const mcu_pin_obj_t *pin) {
if (!pin->has_adc) {
// No ADC function on that pin
@@ -72,7 +72,7 @@ void common_hal_nativeio_analogin_construct(nativeio_analogin_obj_t* self,
active_channel_count++;
}
-void common_hal_nativeio_analogin_deinit(nativeio_analogin_obj_t *self) {
+void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
active_channel_count--;
if (active_channel_count == 0) {
adc_reset(adc_instance);
@@ -92,7 +92,7 @@ void analogin_reset() {
active_channel_count = 0;
}
-uint16_t common_hal_nativeio_analogin_get_value(nativeio_analogin_obj_t *self) {
+uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
adc_set_positive_input(adc_instance, self->pin->adc_input);
adc_enable(adc_instance);
@@ -111,6 +111,6 @@ uint16_t common_hal_nativeio_analogin_get_value(nativeio_analogin_obj_t *self) {
return data;
}
-float common_hal_nativeio_analogin_get_reference_voltage(nativeio_analogin_obj_t *self) {
+float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {
return 3.3f;
}
diff --git a/atmel-samd/common-hal/analogio/AnalogIn.h b/atmel-samd/common-hal/analogio/AnalogIn.h
new file mode 100644
index 000000000..78c7b82e8
--- /dev/null
+++ b/atmel-samd/common-hal/analogio/AnalogIn.h
@@ -0,0 +1,49 @@
+/*
+ * 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_ANALOGIO_ANALOGIN_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGIN_H__
+
+#include "common-hal/microcontroller/types.h"
+
+// Don't reorder these includes because they are dependencies of adc_feature.h.
+// They should really be included by adc_feature.h.
+#include <compiler.h>
+#include "asf/sam0/drivers/system/clock/gclk.h"
+#include "asf/sam0/utils/cmsis/samd21/include/component/adc.h"
+#include "asf/sam0/drivers/adc/adc_sam_d_r/adc_feature.h"
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ const mcu_pin_obj_t * pin;
+ struct adc_module * adc_instance;
+} analogio_analogin_obj_t;
+
+void analogin_reset(void);
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGIN_H__
diff --git a/atmel-samd/common-hal/nativeio/AnalogOut.c b/atmel-samd/common-hal/analogio/AnalogOut.c
index f36da1974..a618a6eeb 100644
--- a/atmel-samd/common-hal/nativeio/AnalogOut.c
+++ b/atmel-samd/common-hal/analogio/AnalogOut.c
@@ -30,12 +30,12 @@
#include "py/mperrno.h"
#include "py/runtime.h"
-#include "shared-bindings/nativeio/AnalogOut.h"
+#include "shared-bindings/analogio/AnalogOut.h"
#include "asf/sam0/drivers/dac/dac.h"
#include "samd21_pins.h"
-void common_hal_nativeio_analogout_construct(nativeio_analogout_obj_t* self,
+void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
const mcu_pin_obj_t *pin) {
if (pin->pin != PIN_PA02) {
mp_raise_ValueError("AnalogOut not supported on given pin");
@@ -58,13 +58,13 @@ void common_hal_nativeio_analogout_construct(nativeio_analogout_obj_t* self,
dac_enable(&self->dac_instance);
}
-void common_hal_nativeio_analogout_deinit(nativeio_analogout_obj_t *self) {
+void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
dac_disable(&self->dac_instance);
dac_chan_disable(&self->dac_instance, DAC_CHANNEL_0);
reset_pin(PIN_PA02);
}
-void common_hal_nativeio_analogout_set_value(nativeio_analogout_obj_t *self,
+void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
uint16_t value) {
// Input is 16 bit but we only support 10 bit so we shift the input.
dac_chan_write(&self->dac_instance, DAC_CHANNEL_0, value >> 6);
diff --git a/atmel-samd/common-hal/nativeio/PulseIn.h b/atmel-samd/common-hal/analogio/AnalogOut.h
index 9d6169414..f74592d6a 100644
--- a/atmel-samd/common-hal/nativeio/PulseIn.h
+++ b/atmel-samd/common-hal/analogio/AnalogOut.h
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ * 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
@@ -24,9 +24,18 @@
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PULSEIN_H__
-#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PULSEIN_H__
+#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGOUT_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGOUT_H__
-void pulsein_reset(void);
+#include "common-hal/microcontroller/types.h"
-#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PULSEIN_H__
+#include "asf/sam0/drivers/dac/dac.h"
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ struct dac_module dac_instance;
+} analogio_analogout_obj_t;
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGOUT_H__
diff --git a/atmel-samd/common-hal/analogio/__init__.c b/atmel-samd/common-hal/analogio/__init__.c
new file mode 100644
index 000000000..eea58c77d
--- /dev/null
+++ b/atmel-samd/common-hal/analogio/__init__.c
@@ -0,0 +1 @@
+// No analogio module functions.
diff --git a/atmel-samd/common-hal/nativeio/I2C.c b/atmel-samd/common-hal/busio/I2C.c
index fb5e76505..7b7c6a52c 100644
--- a/atmel-samd/common-hal/nativeio/I2C.c
+++ b/atmel-samd/common-hal/busio/I2C.c
@@ -24,10 +24,7 @@
* THE SOFTWARE.
*/
- // This file contains all of the port specific HAL functions for the machine
- // module.
-
-#include "shared-bindings/nativeio/I2C.h"
+#include "shared-bindings/busio/I2C.h"
#include "py/mperrno.h"
#include "py/nlr.h"
#include "py/runtime.h"
@@ -41,7 +38,7 @@
// Number of times to try to send packet if failed.
#define TIMEOUT 1
-void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
+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) {
struct i2c_master_config config_i2c_master;
i2c_master_get_config_defaults(&config_i2c_master);
@@ -85,7 +82,7 @@ void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
sercom, &config_i2c_master);
if (status != STATUS_OK) {
- common_hal_nativeio_i2c_deinit(self);
+ common_hal_busio_i2c_deinit(self);
if (status == STATUS_ERR_BAUDRATE_UNAVAILABLE) {
mp_raise_ValueError("Unsupported baudrate");
} else {
@@ -96,13 +93,13 @@ void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
i2c_master_enable(&self->i2c_master_instance);
}
-void common_hal_nativeio_i2c_deinit(nativeio_i2c_obj_t *self) {
+void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
i2c_master_reset(&self->i2c_master_instance);
reset_pin(self->sda_pin);
reset_pin(self->scl_pin);
}
-bool common_hal_nativeio_i2c_probe(nativeio_i2c_obj_t *self, uint8_t addr) {
+bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
uint8_t buf;
struct i2c_master_packet packet = {
.address = addr,
@@ -118,26 +115,26 @@ bool common_hal_nativeio_i2c_probe(nativeio_i2c_obj_t *self, uint8_t addr) {
return status == STATUS_OK;
}
-void common_hal_nativeio_i2c_configure(nativeio_i2c_obj_t *self,
+void common_hal_busio_i2c_configure(busio_i2c_obj_t *self,
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
return;
}
-bool common_hal_nativeio_i2c_try_lock(nativeio_i2c_obj_t *self) {
+bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
self->has_lock = i2c_master_lock(&self->i2c_master_instance) == STATUS_OK;
return self->has_lock;
}
-bool common_hal_nativeio_i2c_has_lock(nativeio_i2c_obj_t *self) {
+bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self) {
return self->has_lock;
}
-void common_hal_nativeio_i2c_unlock(nativeio_i2c_obj_t *self) {
+void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
self->has_lock = false;
i2c_master_unlock(&self->i2c_master_instance);
}
-uint8_t common_hal_nativeio_i2c_write(nativeio_i2c_obj_t *self, uint16_t addr,
+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) {
struct i2c_master_packet packet = {
.address = addr,
@@ -171,7 +168,7 @@ uint8_t common_hal_nativeio_i2c_write(nativeio_i2c_obj_t *self, uint16_t addr,
return MP_EIO;
}
-uint8_t common_hal_nativeio_i2c_read(nativeio_i2c_obj_t *self, uint16_t addr,
+uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
uint8_t *data, size_t len) {
struct i2c_master_packet packet = {
.address = addr,
diff --git a/atmel-samd/common-hal/busio/I2C.h b/atmel-samd/common-hal/busio/I2C.h
new file mode 100644
index 000000000..8f09cb343
--- /dev/null
+++ b/atmel-samd/common-hal/busio/I2C.h
@@ -0,0 +1,43 @@
+/*
+ * 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_I2C_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H__
+
+#include "common-hal/microcontroller/types.h"
+
+#include "asf/sam0/drivers/sercom/i2c/i2c_master.h"
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ struct i2c_master_module i2c_master_instance;
+ bool has_lock;
+ uint8_t scl_pin;
+ uint8_t sda_pin;
+} busio_i2c_obj_t;
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H__
diff --git a/atmel-samd/common-hal/nativeio/AnalogIn.h b/atmel-samd/common-hal/busio/OneWire.h
index d975f6cb4..8b61260fc 100644
--- a/atmel-samd/common-hal/nativeio/AnalogIn.h
+++ b/atmel-samd/common-hal/busio/OneWire.h
@@ -24,9 +24,10 @@
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_ANALOGIN_H__
-#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_ANALOGIN_H__
+#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_ONEWIRE_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_ONEWIRE_H__
-void analogin_reset(void);
+// Use bitbangio.
+#include "shared-module/busio/OneWire.h"
-#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_ANALOGIN_H__
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_ONEWIRE_H__
diff --git a/atmel-samd/common-hal/nativeio/SPI.c b/atmel-samd/common-hal/busio/SPI.c
index 3dec31a10..a7175f3d5 100644
--- a/atmel-samd/common-hal/nativeio/SPI.c
+++ b/atmel-samd/common-hal/busio/SPI.c
@@ -24,10 +24,7 @@
* THE SOFTWARE.
*/
- // This file contains all of the port specific HAL functions for the machine
- // module.
-
-#include "shared-bindings/nativeio/SPI.h"
+#include "shared-bindings/busio/SPI.h"
#include "py/nlr.h"
#include "py/runtime.h"
#include "samd21_pins.h"
@@ -38,7 +35,7 @@
// Number of times to try to send packet if failed.
#define TIMEOUT 1
-void common_hal_nativeio_spi_construct(nativeio_spi_obj_t *self,
+void common_hal_busio_spi_construct(busio_spi_obj_t *self,
const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi,
const mcu_pin_obj_t * miso) {
struct spi_config config_spi_master;
@@ -146,14 +143,14 @@ void common_hal_nativeio_spi_construct(nativeio_spi_obj_t *self,
spi_enable(&self->spi_master_instance);
}
-void common_hal_nativeio_spi_deinit(nativeio_spi_obj_t *self) {
+void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
spi_disable(&self->spi_master_instance);
reset_pin(self->clock_pin);
reset_pin(self->MOSI_pin);
reset_pin(self->MISO_pin);
}
-bool common_hal_nativeio_spi_configure(nativeio_spi_obj_t *self,
+bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
// TODO(tannewt): Check baudrate first before changing it.
if (baudrate != self->current_baudrate) {
@@ -194,21 +191,21 @@ bool common_hal_nativeio_spi_configure(nativeio_spi_obj_t *self,
return true;
}
-bool common_hal_nativeio_spi_try_lock(nativeio_spi_obj_t *self) {
+bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
self->has_lock = spi_lock(&self->spi_master_instance) == STATUS_OK;
return self->has_lock;
}
-bool common_hal_nativeio_spi_has_lock(nativeio_spi_obj_t *self) {
+bool common_hal_busio_spi_has_lock(busio_spi_obj_t *self) {
return self->has_lock;
}
-void common_hal_nativeio_spi_unlock(nativeio_spi_obj_t *self) {
+void common_hal_busio_spi_unlock(busio_spi_obj_t *self) {
self->has_lock = false;
spi_unlock(&self->spi_master_instance);
}
-bool common_hal_nativeio_spi_write(nativeio_spi_obj_t *self,
+bool common_hal_busio_spi_write(busio_spi_obj_t *self,
const uint8_t *data, size_t len) {
if (len == 0) {
return true;
@@ -220,7 +217,7 @@ bool common_hal_nativeio_spi_write(nativeio_spi_obj_t *self,
return status == STATUS_OK;
}
-bool common_hal_nativeio_spi_read(nativeio_spi_obj_t *self,
+bool common_hal_busio_spi_read(busio_spi_obj_t *self,
uint8_t *data, size_t len, uint8_t write_value) {
if (len == 0) {
return true;
diff --git a/atmel-samd/common-hal/busio/SPI.h b/atmel-samd/common-hal/busio/SPI.h
new file mode 100644
index 000000000..10dbe5734
--- /dev/null
+++ b/atmel-samd/common-hal/busio/SPI.h
@@ -0,0 +1,45 @@
+/*
+ * 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_SPI_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H__
+
+#include "common-hal/microcontroller/types.h"
+
+#include "asf/sam0/drivers/sercom/spi/spi.h"
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ struct spi_module spi_master_instance;
+ bool has_lock;
+ uint8_t clock_pin;
+ uint8_t MOSI_pin;
+ uint8_t MISO_pin;
+ uint32_t current_baudrate;
+} busio_spi_obj_t;
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H__
diff --git a/atmel-samd/common-hal/nativeio/UART.c b/atmel-samd/common-hal/busio/UART.c
index cc4216348..8d39d5341 100644
--- a/atmel-samd/common-hal/nativeio/UART.c
+++ b/atmel-samd/common-hal/busio/UART.c
@@ -25,7 +25,7 @@
*/
#include "shared-bindings/microcontroller/__init__.h"
-#include "shared-bindings/nativeio/UART.h"
+#include "shared-bindings/busio/UART.h"
#include "mpconfigport.h"
#include "py/gc.h"
@@ -40,7 +40,7 @@
#undef ENABLE
-nativeio_uart_obj_t *_uart_instances[SERCOM_INST_NUM];
+busio_uart_obj_t *_uart_instances[SERCOM_INST_NUM];
static void _sercom_default_handler(
const uint8_t instance)
@@ -48,7 +48,7 @@ static void _sercom_default_handler(
Assert(false);
}
-static void _nativeio_uart_interrupt_handler(uint8_t instance)
+static void _busio_uart_interrupt_handler(uint8_t instance)
{
/* Temporary variables */
uint16_t interrupt_status;
@@ -58,7 +58,7 @@ static void _nativeio_uart_interrupt_handler(uint8_t instance)
struct usart_module *module
= (struct usart_module *)_sercom_instances[instance];
- nativeio_uart_obj_t *self = _uart_instances[instance];
+ busio_uart_obj_t *self = _uart_instances[instance];
/* Pointer to the hardware module instance */
SercomUsart *const usart_hw = &(module->hw->USART);
@@ -122,7 +122,7 @@ static void _nativeio_uart_interrupt_handler(uint8_t instance)
}
}
-void common_hal_nativeio_uart_construct(nativeio_uart_obj_t *self,
+void common_hal_busio_uart_construct(busio_uart_obj_t *self,
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate,
uint8_t bits, uart_parity_t parity, uint8_t stop, uint32_t timeout,
uint8_t receiver_buffer_size) {
@@ -227,7 +227,7 @@ void common_hal_nativeio_uart_construct(nativeio_uart_obj_t *self,
// We use our own interrupt handler because we want a circular buffer
// instead of the jobs that ASF provides.
uint8_t instance_index = _sercom_get_sercom_inst_index(self->uart_instance.hw);
- _sercom_set_handler(instance_index, _nativeio_uart_interrupt_handler);
+ _sercom_set_handler(instance_index, _busio_uart_interrupt_handler);
_sercom_instances[instance_index] = &self->uart_instance;
_uart_instances[instance_index] = self;
@@ -238,7 +238,7 @@ void common_hal_nativeio_uart_construct(nativeio_uart_obj_t *self,
self->uart_instance.hw->USART.INTENSET.bit.RXC = true;
}
-void common_hal_nativeio_uart_deinit(nativeio_uart_obj_t *self) {
+void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
self->uart_instance.hw->USART.INTENCLR.bit.RXC = true;
uint8_t instance_index = _sercom_get_sercom_inst_index(self->uart_instance.hw);
@@ -254,7 +254,7 @@ void common_hal_nativeio_uart_deinit(nativeio_uart_obj_t *self) {
}
// Read characters.
-size_t common_hal_nativeio_uart_read(nativeio_uart_obj_t *self, uint8_t *data, size_t len, int *errcode) {
+size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t len, int *errcode) {
size_t total_read = 0;
uint64_t start_ticks = ticks_ms;
while (total_read < len && ticks_ms - start_ticks < self->timeout_ms) {
@@ -287,7 +287,7 @@ size_t common_hal_nativeio_uart_read(nativeio_uart_obj_t *self, uint8_t *data, s
}
// Write characters.
-size_t common_hal_nativeio_uart_write(nativeio_uart_obj_t *self, const uint8_t *data, size_t len, int *errcode) {
+size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, size_t len, int *errcode) {
/* Check that the transmitter is enabled */
if (!(self->uart_instance.transmitter_enabled)) {
*errcode = MP_EIO;
@@ -362,14 +362,14 @@ size_t common_hal_nativeio_uart_write(nativeio_uart_obj_t *self, const uint8_t *
return tx_pos;
}
-uint32_t common_hal_nativeio_uart_rx_characters_available(nativeio_uart_obj_t *self) {
+uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
if (self->uart_instance.character_size == USART_CHARACTER_SIZE_9BIT) {
return self->buffer_size / 2;
}
return self->buffer_size;
}
-bool common_hal_nativeio_uart_ready_to_tx(nativeio_uart_obj_t *self) {
+bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
if (!(self->uart_instance.transmitter_enabled)) {
return false;
}
diff --git a/atmel-samd/common-hal/busio/UART.h b/atmel-samd/common-hal/busio/UART.h
new file mode 100644
index 000000000..d9a001de4
--- /dev/null
+++ b/atmel-samd/common-hal/busio/UART.h
@@ -0,0 +1,50 @@
+/*
+ * 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_UART_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_UART_H__
+
+#include "common-hal/microcontroller/types.h"
+
+#include "asf/sam0/drivers/sercom/usart/usart.h"
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ struct usart_module uart_instance;
+ uint8_t rx_pin;
+ uint8_t tx_pin;
+ uint32_t timeout_ms;
+ bool rx_error;
+ // Index of the oldest received character.
+ uint32_t buffer_start;
+ // Index of the next available spot to store a character.
+ uint32_t buffer_size;
+ uint32_t buffer_length;
+ uint8_t* buffer;
+} busio_uart_obj_t;
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_UART_H__
diff --git a/atmel-samd/common-hal/busio/__init__.c b/atmel-samd/common-hal/busio/__init__.c
new file mode 100644
index 000000000..41761b674
--- /dev/null
+++ b/atmel-samd/common-hal/busio/__init__.c
@@ -0,0 +1 @@
+// No busio module functions.
diff --git a/atmel-samd/common-hal/nativeio/DigitalInOut.c b/atmel-samd/common-hal/digitalio/DigitalInOut.c
index e09b5af17..391bf8992 100644
--- a/atmel-samd/common-hal/nativeio/DigitalInOut.c
+++ b/atmel-samd/common-hal/digitalio/DigitalInOut.c
@@ -31,13 +31,13 @@
#include "py/runtime.h"
#include "py/mphal.h"
-#include "shared-bindings/nativeio/DigitalInOut.h"
+#include "shared-bindings/digitalio/DigitalInOut.h"
#include "asf/sam0/drivers/port/port.h"
#include "asf/sam0/drivers/system/pinmux/pinmux.h"
-digitalinout_result_t common_hal_nativeio_digitalinout_construct(
- nativeio_digitalinout_obj_t* self, const mcu_pin_obj_t* pin) {
+digitalinout_result_t common_hal_digitalio_digitalinout_construct(
+ digitalio_digitalinout_obj_t* self, const mcu_pin_obj_t* pin) {
self->pin = pin;
struct port_config pin_conf;
@@ -49,7 +49,7 @@ digitalinout_result_t common_hal_nativeio_digitalinout_construct(
return DIGITALINOUT_OK;
}
-void common_hal_nativeio_digitalinout_deinit(nativeio_digitalinout_obj_t* self) {
+void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) {
struct port_config pin_conf;
port_get_config_defaults(&pin_conf);
@@ -57,15 +57,15 @@ void common_hal_nativeio_digitalinout_deinit(nativeio_digitalinout_obj_t* self)
port_pin_set_config(self->pin->pin, &pin_conf);
}
-void common_hal_nativeio_digitalinout_switch_to_input(
- nativeio_digitalinout_obj_t* self, enum digitalinout_pull_t pull) {
+void common_hal_digitalio_digitalinout_switch_to_input(
+ digitalio_digitalinout_obj_t* self, enum digitalinout_pull_t pull) {
self->output = false;
- common_hal_nativeio_digitalinout_set_pull(self, pull);
+ common_hal_digitalio_digitalinout_set_pull(self, pull);
}
-void common_hal_nativeio_digitalinout_switch_to_output(
- nativeio_digitalinout_obj_t* self, bool value,
+void common_hal_digitalio_digitalinout_switch_to_output(
+ digitalio_digitalinout_obj_t* self, bool value,
enum digitalinout_drive_mode_t drive_mode) {
struct port_config pin_conf;
port_get_config_defaults(&pin_conf);
@@ -76,16 +76,16 @@ void common_hal_nativeio_digitalinout_switch_to_output(
self->output = true;
self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN;
- common_hal_nativeio_digitalinout_set_value(self, value);
+ common_hal_digitalio_digitalinout_set_value(self, value);
}
-enum digitalinout_direction_t common_hal_nativeio_digitalinout_get_direction(
- nativeio_digitalinout_obj_t* self) {
+enum digitalinout_direction_t common_hal_digitalio_digitalinout_get_direction(
+ digitalio_digitalinout_obj_t* self) {
return self->output? DIRECTION_OUT : DIRECTION_IN;
}
-void common_hal_nativeio_digitalinout_set_value(
- nativeio_digitalinout_obj_t* self, bool value) {
+void common_hal_digitalio_digitalinout_set_value(
+ digitalio_digitalinout_obj_t* self, bool value) {
uint32_t pin = self->pin->pin;
PortGroup *const port_base = port_get_group_from_gpio_pin(pin);
uint32_t pin_mask = (1UL << (pin % 32));
@@ -104,8 +104,8 @@ void common_hal_nativeio_digitalinout_set_value(
}
}
-bool common_hal_nativeio_digitalinout_get_value(
- nativeio_digitalinout_obj_t* self) {
+bool common_hal_digitalio_digitalinout_get_value(
+ digitalio_digitalinout_obj_t* self) {
uint32_t pin = self->pin->pin;
PortGroup *const port_base = port_get_group_from_gpio_pin(pin);
uint32_t pin_mask = (1UL << (pin % 32));
@@ -120,20 +120,20 @@ bool common_hal_nativeio_digitalinout_get_value(
}
}
-void common_hal_nativeio_digitalinout_set_drive_mode(
- nativeio_digitalinout_obj_t* self,
+void common_hal_digitalio_digitalinout_set_drive_mode(
+ digitalio_digitalinout_obj_t* self,
enum digitalinout_drive_mode_t drive_mode) {
- bool value = common_hal_nativeio_digitalinout_get_value(self);
+ bool value = common_hal_digitalio_digitalinout_get_value(self);
self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN;
// True is implemented differently between modes so reset the value to make
// sure its correct for the new mode.
if (value) {
- common_hal_nativeio_digitalinout_set_value(self, value);
+ common_hal_digitalio_digitalinout_set_value(self, value);
}
}
-enum digitalinout_drive_mode_t common_hal_nativeio_digitalinout_get_drive_mode(
- nativeio_digitalinout_obj_t* self) {
+enum digitalinout_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
+ digitalio_digitalinout_obj_t* self) {
if (self->open_drain) {
return DRIVE_MODE_OPEN_DRAIN;
} else {
@@ -141,8 +141,8 @@ enum digitalinout_drive_mode_t common_hal_nativeio_digitalinout_get_drive_mode(
}
}
-void common_hal_nativeio_digitalinout_set_pull(
- nativeio_digitalinout_obj_t* self, enum digitalinout_pull_t pull) {
+void common_hal_digitalio_digitalinout_set_pull(
+ digitalio_digitalinout_obj_t* self, enum digitalinout_pull_t pull) {
enum port_pin_pull asf_pull = PORT_PIN_PULL_NONE;
switch (pull) {
case PULL_UP:
@@ -163,8 +163,8 @@ void common_hal_nativeio_digitalinout_set_pull(
port_pin_set_config(self->pin->pin, &pin_conf);
}
-enum digitalinout_pull_t common_hal_nativeio_digitalinout_get_pull(
- nativeio_digitalinout_obj_t* self) {
+enum digitalinout_pull_t common_hal_digitalio_digitalinout_get_pull(
+ digitalio_digitalinout_obj_t* self) {
uint32_t pin = self->pin->pin;
PortGroup *const port_base = port_get_group_from_gpio_pin(pin);
uint32_t pin_mask = (1UL << (pin % 32));
diff --git a/atmel-samd/common-hal/nativeio/DigitalInOut.h b/atmel-samd/common-hal/digitalio/DigitalInOut.h
index f517e0d5b..1490765ab 100644
--- a/atmel-samd/common-hal/nativeio/DigitalInOut.h
+++ b/atmel-samd/common-hal/digitalio/DigitalInOut.h
@@ -24,9 +24,10 @@
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_DIGITALINOUT_H__
-#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_DIGITALINOUT_H__
+#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DIGITALIO_DIGITALINOUT_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DIGITALIO_DIGITALINOUT_H__
+#include "common-hal/microcontroller/types.h"
#include "py/obj.h"
typedef struct {
@@ -34,6 +35,6 @@ typedef struct {
const mcu_pin_obj_t * pin;
bool output;
bool open_drain;
-} nativeio_digitalinout_obj_t;
+} digitalio_digitalinout_obj_t;
-#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_DIGITALINOUT_H__
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DIGITALIO_DIGITALINOUT_H__
diff --git a/atmel-samd/common-hal/digitalio/__init__.c b/atmel-samd/common-hal/digitalio/__init__.c
new file mode 100644
index 000000000..20fad4595
--- /dev/null
+++ b/atmel-samd/common-hal/digitalio/__init__.c
@@ -0,0 +1 @@
+// No digitalio module functions.
diff --git a/atmel-samd/common-hal/nativeio/TouchInStub.c b/atmel-samd/common-hal/nativeio/TouchInStub.c
deleted file mode 100644
index cfdc1249f..000000000
--- a/atmel-samd/common-hal/nativeio/TouchInStub.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * This file is part of the Micro Python 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 <string.h>
-
-#include "py/nlr.h"
-#include "py/runtime.h"
-#include "py/binary.h"
-#include "py/mphal.h"
-#include "shared-bindings/nativeio/TouchIn.h"
-
-void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
- const mcu_pin_obj_t *pin) {
- mp_raise_NotImplementedError("No capacitive touch support");
-}
-
-void common_hal_nativeio_touchin_deinit(nativeio_touchin_obj_t* self) {
-}
-
-bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
- return false;
-}
diff --git a/atmel-samd/common-hal/nativeio/__init__.c b/atmel-samd/common-hal/nativeio/__init__.c
deleted file mode 100644
index e0ec8acfb..000000000
--- a/atmel-samd/common-hal/nativeio/__init__.c
+++ /dev/null
@@ -1 +0,0 @@
-// No nativeio module functions.
diff --git a/atmel-samd/common-hal/nativeio/types.h b/atmel-samd/common-hal/nativeio/types.h
deleted file mode 100644
index 9f8c19e9d..000000000
--- a/atmel-samd/common-hal/nativeio/types.h
+++ /dev/null
@@ -1,142 +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.
- */
-
-// 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_COMMON_HAL_NATIVEIO_TYPES_H__
-#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_TYPES_H__
-
-#include "common-hal/microcontroller/types.h"
-
-// Don't reorder these includes because they are dependencies of adc_feature.h.
-// They should really be included by adc_feature.h.
-#include <compiler.h>
-#include "asf/sam0/drivers/system/clock/gclk.h"
-#include "asf/sam0/utils/cmsis/samd21/include/component/adc.h"
-#include "asf/sam0/drivers/adc/adc_sam_d_r/adc_feature.h"
-
-#include "asf/sam0/drivers/dac/dac.h"
-#include "asf/sam0/drivers/sercom/i2c/i2c_master.h"
-#include "asf/sam0/drivers/sercom/spi/spi.h"
-#include "asf/sam0/drivers/sercom/usart/usart.h"
-#include "asf/sam0/drivers/tc/tc.h"
-#include "asf/sam0/drivers/tcc/tcc.h"
-// Only support TouchIn when external SPI flash is used.
-#ifdef SPI_FLASH_SECTOR_SIZE
-#include "QTouch/touch_api_ptc.h"
-#endif
-
-#include "py/obj.h"
-
-// Import bitbang implemented types. Must be after DigitalInOut because they
-// likely depend on it.
-#include "shared-module/nativeio/OneWire.h"
-
-typedef struct {
- mp_obj_base_t base;
- const mcu_pin_obj_t * pin;
- struct adc_module * adc_instance;
-} nativeio_analogin_obj_t;
-
-typedef struct {
- mp_obj_base_t base;
- struct dac_module dac_instance;
-} nativeio_analogout_obj_t;
-
-typedef struct {
- mp_obj_base_t base;
- struct i2c_master_module i2c_master_instance;
- bool has_lock;
- uint8_t scl_pin;
- uint8_t sda_pin;
-} nativeio_i2c_obj_t;
-
-typedef struct {
- mp_obj_base_t base;
- struct spi_module spi_master_instance;
- bool has_lock;
- uint8_t clock_pin;
- uint8_t MOSI_pin;
- uint8_t MISO_pin;
- uint32_t current_baudrate;
-} nativeio_spi_obj_t;
-
-typedef struct {
- mp_obj_base_t base;
- uint8_t channel;
- uint8_t pin;
- uint16_t* buffer;
- uint16_t maxlen;
- bool idle_state;
- volatile uint16_t start;
- volatile uint16_t len;
- volatile bool first_edge;
- uint16_t ticks_per_ms;
-} nativeio_pulsein_obj_t;
-
-typedef struct {
- mp_obj_base_t base;
- __IO PORT_PINCFG_Type *pincfg;
- uint8_t pin;
-} nativeio_pulseout_obj_t;
-
-typedef struct {
- mp_obj_base_t base;
- const mcu_pin_obj_t *pin;
- const pin_timer_t* timer;
- bool variable_frequency;
- union {
- struct tc_module tc_instance;
- struct tcc_module tcc_instance;
- };
-} nativeio_pwmout_obj_t;
-
-typedef struct {
- mp_obj_base_t base;
- // Only support TouchIn when external SPI flash is used.
- #ifdef SPI_FLASH_SECTOR_SIZE
- const mcu_pin_obj_t * pin;
- sensor_id_t sensor_id;
- #endif
-} nativeio_touchin_obj_t;
-
-typedef struct {
- mp_obj_base_t base;
- struct usart_module uart_instance;
- uint8_t rx_pin;
- uint8_t tx_pin;
- uint32_t timeout_ms;
- bool rx_error;
- // Index of the oldest received character.
- uint32_t buffer_start;
- // Index of the next available spot to store a character.
- uint32_t buffer_size;
- uint32_t buffer_length;
- uint8_t* buffer;
-} nativeio_uart_obj_t;
-
-#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_TYPES_H__
diff --git a/atmel-samd/common-hal/neopixel_write/__init__.c b/atmel-samd/common-hal/neopixel_write/__init__.c
index ff0e99cd8..27dc7d6ad 100644
--- a/atmel-samd/common-hal/neopixel_write/__init__.c
+++ b/atmel-samd/common-hal/neopixel_write/__init__.c
@@ -29,8 +29,9 @@
#include "shared-bindings/neopixel_write/__init__.h"
#include "asf/common2/services/delay/delay.h"
+#include "asf/sam0/drivers/port/port.h"
-void common_hal_neopixel_write(const nativeio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) {
+void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) {
// This is adapted directly from the Adafruit NeoPixel library SAMD21G18A code:
// https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.cpp
uint8_t *ptr, *end, p, bitMask;
diff --git a/atmel-samd/common-hal/nativeio/PWMOut.c b/atmel-samd/common-hal/pulseio/PWMOut.c
index 73d83163a..863f2084e 100644
--- a/atmel-samd/common-hal/nativeio/PWMOut.c
+++ b/atmel-samd/common-hal/pulseio/PWMOut.c
@@ -27,8 +27,8 @@
#include <stdint.h>
#include "py/runtime.h"
-#include "common-hal/nativeio/PWMOut.h"
-#include "shared-bindings/nativeio/PWMOut.h"
+#include "common-hal/pulseio/PWMOut.h"
+#include "shared-bindings/pulseio/PWMOut.h"
#include "samd21_pins.h"
@@ -70,7 +70,7 @@ bool channel_ok(const pin_timer_t* t, uint8_t index) {
t->is_tc;
}
-void common_hal_nativeio_pwmout_construct(nativeio_pwmout_obj_t* self,
+void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
const mcu_pin_obj_t* pin,
uint16_t duty,
uint32_t frequency,
@@ -198,10 +198,10 @@ void common_hal_nativeio_pwmout_construct(nativeio_pwmout_obj_t* self,
pin_config.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
system_pinmux_pin_set_config(pin->pin, &pin_config);
- common_hal_nativeio_pwmout_set_duty_cycle(self, duty);
+ common_hal_pulseio_pwmout_set_duty_cycle(self, duty);
}
-extern void common_hal_nativeio_pwmout_deinit(nativeio_pwmout_obj_t* self) {
+extern void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
const pin_timer_t* t = self->timer;
uint8_t index = (((uint32_t) t->tcc) - ((uint32_t) TCC0)) / 0x400;
timer_refcount[index]--;
@@ -225,7 +225,7 @@ extern void common_hal_nativeio_pwmout_deinit(nativeio_pwmout_obj_t* self) {
reset_pin(self->pin->pin);
}
-extern void common_hal_nativeio_pwmout_set_duty_cycle(nativeio_pwmout_obj_t* self, uint16_t duty) {
+extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) {
const pin_timer_t* t = self->timer;
if (t->is_tc) {
uint32_t top = ((uint32_t) t->tc->COUNT16.CC[0].reg + 1);
@@ -238,7 +238,7 @@ extern void common_hal_nativeio_pwmout_set_duty_cycle(nativeio_pwmout_obj_t* sel
}
}
-uint16_t common_hal_nativeio_pwmout_get_duty_cycle(nativeio_pwmout_obj_t* self) {
+uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) {
const pin_timer_t* t = self->timer;
if (t->is_tc) {
uint16_t top = t->tc->COUNT16.CC[0].reg;
@@ -260,7 +260,7 @@ uint16_t common_hal_nativeio_pwmout_get_duty_cycle(nativeio_pwmout_obj_t* self)
}
-void common_hal_nativeio_pwmout_set_frequency(nativeio_pwmout_obj_t* self,
+void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self,
uint32_t frequency) {
if (frequency == 0 || frequency > 6000000) {
mp_raise_ValueError("Invalid PWM frequency");
@@ -281,7 +281,7 @@ void common_hal_nativeio_pwmout_set_frequency(nativeio_pwmout_obj_t* self,
break;
}
}
- uint16_t old_duty = common_hal_nativeio_pwmout_get_duty_cycle(self);
+ uint16_t old_duty = common_hal_pulseio_pwmout_get_duty_cycle(self);
uint8_t old_divisor;
if (t->is_tc) {
old_divisor = t->tc->COUNT16.CTRLA.bit.PRESCALER;
@@ -308,10 +308,10 @@ void common_hal_nativeio_pwmout_set_frequency(nativeio_pwmout_obj_t* self,
tcc_set_top_value(&self->tcc_instance, new_top);
}
- common_hal_nativeio_pwmout_set_duty_cycle(self, old_duty);
+ common_hal_pulseio_pwmout_set_duty_cycle(self, old_duty);
}
-uint32_t common_hal_nativeio_pwmout_get_frequency(nativeio_pwmout_obj_t* self) {
+uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) {
uint32_t system_clock = system_cpu_clock_get_hz();
const pin_timer_t* t = self->timer;
uint32_t top;
@@ -326,6 +326,6 @@ uint32_t common_hal_nativeio_pwmout_get_frequency(nativeio_pwmout_obj_t* self) {
return (system_clock / prescaler[divisor]) / (top + 1);
}
-bool common_hal_nativeio_pwmout_get_variable_frequency(nativeio_pwmout_obj_t* self) {
+bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t* self) {
return self->variable_frequency;
}
diff --git a/atmel-samd/common-hal/pulseio/PWMOut.h b/atmel-samd/common-hal/pulseio/PWMOut.h
new file mode 100644
index 000000000..b8e207f3e
--- /dev/null
+++ b/atmel-samd/common-hal/pulseio/PWMOut.h
@@ -0,0 +1,49 @@
+/*
+ * 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_COMMON_HAL_PULSEIO_PWMOUT_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H__
+
+#include "common-hal/microcontroller/types.h"
+#include "asf/sam0/drivers/tc/tc.h"
+#include "asf/sam0/drivers/tcc/tcc.h"
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ const mcu_pin_obj_t *pin;
+ const pin_timer_t* timer;
+ bool variable_frequency;
+ union {
+ struct tc_module tc_instance;
+ struct tcc_module tcc_instance;
+ };
+} pulseio_pwmout_obj_t;
+
+void pwmout_reset(void);
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H__
diff --git a/atmel-samd/common-hal/nativeio/PulseIn.c b/atmel-samd/common-hal/pulseio/PulseIn.c
index f5df2e8cd..69eff2a0b 100644
--- a/atmel-samd/common-hal/nativeio/PulseIn.c
+++ b/atmel-samd/common-hal/pulseio/PulseIn.c
@@ -24,24 +24,25 @@
* THE SOFTWARE.
*/
-#include "common-hal/nativeio/PulseIn.h"
+#include "common-hal/pulseio/PulseIn.h"
#include <stdint.h>
#include "asf/common2/services/delay/delay.h"
#include "asf/sam0/drivers/extint/extint.h"
#include "asf/sam0/drivers/extint/extint_callback.h"
+#include "asf/sam0/drivers/port/port.h"
#include "mpconfigport.h"
#include "py/gc.h"
#include "py/runtime.h"
#include "samd21_pins.h"
#include "shared-bindings/microcontroller/__init__.h"
-#include "shared-bindings/nativeio/PulseIn.h"
+#include "shared-bindings/pulseio/PulseIn.h"
#include "tick.h"
-static nativeio_pulsein_obj_t *active_pulseins[EIC_NUMBER_OF_INTERRUPTS];
+static pulseio_pulsein_obj_t *active_pulseins[EIC_NUMBER_OF_INTERRUPTS];
static uint64_t last_ms[EIC_NUMBER_OF_INTERRUPTS];
static uint16_t last_us[EIC_NUMBER_OF_INTERRUPTS];
@@ -53,7 +54,7 @@ void pulsein_reset(void) {
}
}
-static void pulsein_set_config(nativeio_pulsein_obj_t* self, bool first_edge) {
+static void pulsein_set_config(pulseio_pulsein_obj_t* self, bool first_edge) {
struct extint_chan_conf config;
extint_chan_get_config_defaults(&config);
config.gpio_pin = self->pin;
@@ -78,7 +79,7 @@ static void pulsein_callback(void) {
// Grab the current time first.
uint16_t current_us = tc_get_count_value(&ms_timer);
uint64_t current_ms = ticks_ms;
- nativeio_pulsein_obj_t* self = active_pulseins[extint_get_current_channel()];
+ pulseio_pulsein_obj_t* self = active_pulseins[extint_get_current_channel()];
current_us = current_us * 1000 / self->ticks_per_ms;
if (self->first_edge) {
self->first_edge = false;
@@ -110,7 +111,7 @@ static void pulsein_callback(void) {
last_us[self->channel] = current_us;
}
-void common_hal_nativeio_pulsein_construct(nativeio_pulsein_obj_t* self,
+void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
const mcu_pin_obj_t* pin, uint16_t maxlen, bool idle_state) {
if (!pin->has_extint) {
mp_raise_RuntimeError("No hardware support on pin");
@@ -144,17 +145,17 @@ void common_hal_nativeio_pulsein_construct(nativeio_pulsein_obj_t* self,
extint_chan_enable_callback(self->channel, EXTINT_CALLBACK_TYPE_DETECT);
}
-void common_hal_nativeio_pulsein_deinit(nativeio_pulsein_obj_t* self) {
+void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
extint_chan_disable_callback(self->channel, EXTINT_CALLBACK_TYPE_DETECT);
active_pulseins[self->channel] = NULL;
reset_pin(self->pin);
}
-void common_hal_nativeio_pulsein_pause(nativeio_pulsein_obj_t* self) {
+void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t* self) {
extint_chan_disable_callback(self->channel, EXTINT_CALLBACK_TYPE_DETECT);
}
-void common_hal_nativeio_pulsein_resume(nativeio_pulsein_obj_t* self,
+void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self,
uint16_t trigger_duration) {
// Send the trigger pulse.
if (trigger_duration > 0) {
@@ -176,14 +177,14 @@ void common_hal_nativeio_pulsein_resume(nativeio_pulsein_obj_t* self,
pulsein_set_config(self, true);
}
-void common_hal_nativeio_pulsein_clear(nativeio_pulsein_obj_t* self) {
+void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) {
common_hal_mcu_disable_interrupts();
self->start = 0;
self->len = 0;
common_hal_mcu_enable_interrupts();
}
-uint16_t common_hal_nativeio_pulsein_popleft(nativeio_pulsein_obj_t* self) {
+uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
if (self->len == 0) {
mp_raise_IndexError("pop from an empty PulseIn");
}
@@ -196,15 +197,15 @@ uint16_t common_hal_nativeio_pulsein_popleft(nativeio_pulsein_obj_t* self) {
return value;
}
-uint16_t common_hal_nativeio_pulsein_get_maxlen(nativeio_pulsein_obj_t* self) {
+uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t* self) {
return self->maxlen;
}
-uint16_t common_hal_nativeio_pulsein_get_len(nativeio_pulsein_obj_t* self) {
+uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) {
return self->len;
}
-uint16_t common_hal_nativeio_pulsein_get_item(nativeio_pulsein_obj_t* self,
+uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self,
int16_t index) {
common_hal_mcu_disable_interrupts();
if (index < 0) {
diff --git a/atmel-samd/common-hal/pulseio/PulseIn.h b/atmel-samd/common-hal/pulseio/PulseIn.h
new file mode 100644
index 000000000..717b7267a
--- /dev/null
+++ b/atmel-samd/common-hal/pulseio/PulseIn.h
@@ -0,0 +1,49 @@
+/*
+ * 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_COMMON_HAL_PULSEIO_PULSEIN_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H__
+
+#include "common-hal/microcontroller/types.h"
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ uint8_t channel;
+ uint8_t pin;
+ uint16_t* buffer;
+ uint16_t maxlen;
+ bool idle_state;
+ volatile uint16_t start;
+ volatile uint16_t len;
+ volatile bool first_edge;
+ uint16_t ticks_per_ms;
+} pulseio_pulsein_obj_t;
+
+void pulsein_reset(void);
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H__
diff --git a/atmel-samd/common-hal/nativeio/PulseOut.c b/atmel-samd/common-hal/pulseio/PulseOut.c
index 76ef849a1..1df4e30db 100644
--- a/atmel-samd/common-hal/nativeio/PulseOut.c
+++ b/atmel-samd/common-hal/pulseio/PulseOut.c
@@ -24,15 +24,16 @@
* THE SOFTWARE.
*/
-#include "common-hal/nativeio/PulseOut.h"
+#include "common-hal/pulseio/PulseOut.h"
#include <stdint.h>
#include "asf/sam0/drivers/tc/tc_interrupt.h"
+#include "asf/sam0/drivers/port/port.h"
#include "mpconfigport.h"
#include "py/runtime.h"
-#include "shared-bindings/nativeio/PulseOut.h"
+#include "shared-bindings/pulseio/PulseOut.h"
#undef ENABLE
@@ -78,8 +79,8 @@ void pulseout_reset() {
active_pincfg = NULL;
}
-void common_hal_nativeio_pulseout_construct(nativeio_pulseout_obj_t* self,
- const nativeio_pwmout_obj_t* carrier) {
+void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
+ const pulseio_pwmout_obj_t* carrier) {
if (refcount == 0) {
// Find a spare timer.
Tc *t = NULL;
@@ -121,7 +122,7 @@ void common_hal_nativeio_pulseout_construct(nativeio_pulseout_obj_t* self,
turn_off(self->pincfg);
}
-void common_hal_nativeio_pulseout_deinit(nativeio_pulseout_obj_t* self) {
+void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) {
PortGroup *const port_base = port_get_group_from_gpio_pin(self->pin);
port_base->DIRCLR.reg = 1 << (self->pin % 32);
@@ -133,7 +134,7 @@ void common_hal_nativeio_pulseout_deinit(nativeio_pulseout_obj_t* self) {
}
}
-void common_hal_nativeio_pulseout_send(nativeio_pulseout_obj_t* self, uint16_t* pulses, uint16_t length) {
+void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pulses, uint16_t length) {
if (active_pincfg != NULL) {
mp_raise_RuntimeError("Another send is already active");
}
diff --git a/atmel-samd/common-hal/nativeio/PulseOut.h b/atmel-samd/common-hal/pulseio/PulseOut.h
index 721670bef..f06dcc44f 100644
--- a/atmel-samd/common-hal/nativeio/PulseOut.h
+++ b/atmel-samd/common-hal/pulseio/PulseOut.h
@@ -24,9 +24,21 @@
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PULSEOUT_H__
-#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PULSEOUT_H__
+#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H__
+
+#include "common-hal/microcontroller/types.h"
+#include "asf/sam0/drivers/tc/tc.h"
+#include "asf/sam0/drivers/tcc/tcc.h"
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ __IO PORT_PINCFG_Type *pincfg;
+ uint8_t pin;
+} pulseio_pulseout_obj_t;
void pulseout_reset(void);
-#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PULSEOUT_H__
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H__
diff --git a/atmel-samd/common-hal/pulseio/__init__.c b/atmel-samd/common-hal/pulseio/__init__.c
new file mode 100644
index 000000000..2bee925bc
--- /dev/null
+++ b/atmel-samd/common-hal/pulseio/__init__.c
@@ -0,0 +1 @@
+// No pulseio module functions.
diff --git a/atmel-samd/common-hal/nativeio/TouchIn.c b/atmel-samd/common-hal/touchio/TouchIn.c
index a98d235ef..a680294e2 100644
--- a/atmel-samd/common-hal/nativeio/TouchIn.c
+++ b/atmel-samd/common-hal/touchio/TouchIn.c
@@ -31,7 +31,7 @@
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mphal.h"
-#include "shared-bindings/nativeio/TouchIn.h"
+#include "shared-bindings/touchio/TouchIn.h"
#include "tick.h"
@@ -182,9 +182,9 @@ touch_config_t touch_config = {
DEF_TOUCH_PTC_ISR_LVL, /* PTC interrupt level. */
};
-nativeio_touchin_obj_t *active_touchin_obj[DEF_SELFCAP_NUM_CHANNELS];
+touchio_touchin_obj_t *active_touchin_obj[DEF_SELFCAP_NUM_CHANNELS];
-void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
+void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self,
const mcu_pin_obj_t *pin) {
if (!pin->has_touch) {
mp_raise_ValueError("Invalid pin");
@@ -245,13 +245,13 @@ void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
}
// Run a measurement to get calibrated.
- common_hal_nativeio_touchin_get_value(self);
+ common_hal_touchio_touchin_get_value(self);
}
// This may get called twice, once on exit or deinit and once from the finaliser
// (__del__). We need the finaliser to reduce the chance of us writing to memory
// we no longer own because we keep track of Python pointers in active_touchin_obj.
-void common_hal_nativeio_touchin_deinit(nativeio_touchin_obj_t* self) {
+void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
touch_selfcap_sensor_disable(self->sensor_id);
// Remove ourselves from the list of active objects. We don't change the
// selfcap settings at all because we don't want to reinit now. Instead,
@@ -273,7 +273,7 @@ void touch_selfcap_measure_complete_callback(void)
touch_acq_status = p_selfcap_measure_data->acq_status;
}
-bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
+bool common_hal_touchio_touchin_get_value(touchio_touchin_obj_t *self) {
if (p_selfcap_measure_data->acq_status & TOUCH_CC_CALIB_ERROR) {
mp_raise_RuntimeError("Touch calibration error");
}
diff --git a/atmel-samd/common-hal/nativeio/PWMOut.h b/atmel-samd/common-hal/touchio/TouchIn.h
index 56994e519..85799529e 100644
--- a/atmel-samd/common-hal/nativeio/PWMOut.h
+++ b/atmel-samd/common-hal/touchio/TouchIn.h
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ * 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
@@ -24,9 +24,19 @@
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PWMOUT_H__
-#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PWMOUT_H__
+#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_TOUCHIO_TOUCHIN_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_TOUCHIO_TOUCHIN_H__
-void pwmout_reset(void);
+#include "common-hal/microcontroller/types.h"
-#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_NATIVEIO_PWMOUT_H__
+#include "QTouch/touch_api_ptc.h"
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ const mcu_pin_obj_t * pin;
+ sensor_id_t sensor_id;
+} touchio_touchin_obj_t;
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_TOUCHIO_TOUCHIN_H__
diff --git a/atmel-samd/common-hal/touchio/__init__.c b/atmel-samd/common-hal/touchio/__init__.c
new file mode 100644
index 000000000..d2290447c
--- /dev/null
+++ b/atmel-samd/common-hal/touchio/__init__.c
@@ -0,0 +1 @@
+// No touchio module functions.