Skip to content

Commit f28f8ba

Browse files
committed
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.
1 parent 4810722 commit f28f8ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+2690
-1909
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ project admins. Please join the [Gitter chat](https://gitter.im/adafruit/circuit
3232
* Port for Atmel SAMD21 (Commonly known as M0 in product names.)
3333
* No `machine` API on Atmel SAMD21 port.
3434
* Only supports Atmel SAMD21 and ESP8266 ports.
35-
* Unified hardware API: [`nativeio`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/nativeio/__init__.html), [`microcontroller`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/microcontroller/__init__.html), [`board`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/board/__init__.html), [`bitbangio`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/bitbangio/__init__.html) (Only available on atmel-samd21 and ESP8266 currently.)
35+
* Unified hardware APIs: [`analogio`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/analogio/__init__.html), [`busio`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/busio/__init__.html), [`digitalio`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/digitalio/__init__.html), [`pulseio`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/pulseio/__init__.html), [`touchio`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/touchio/__init__.html), [`microcontroller`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/microcontroller/__init__.html), [`board`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/board/__init__.html), [`bitbangio`](https://circuitpython.readthedocs.io/en/latest/shared-bindings/bitbangio/__init__.html) (Only available on atmel-samd21 and ESP8266 currently.)
3636
* Tracks MicroPython's releases (not master).
3737
* No module aliasing. (`uos` and `utime` are not available as `os` and `time` respectively.)
3838
* Modules with a CPython counterpart, such as `time`, are strict [subsets](https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html) of their [CPython version](https://docs.python.org/3.4/library/time.html?highlight=time#module-time). Therefore, code from CircuitPython is runnable on CPython but not necessarily the reverse.

atmel-samd/Makefile

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -221,41 +221,42 @@ SRC_BINDINGS = \
221221
board/__init__.c \
222222
microcontroller/__init__.c \
223223
microcontroller/Pin.c \
224-
nativeio/__init__.c \
225-
nativeio/AnalogIn.c \
226-
nativeio/AnalogOut.c \
227-
nativeio/DigitalInOut.c \
228-
nativeio/I2C.c \
229-
nativeio/PulseIn.c \
230-
nativeio/PulseOut.c \
231-
nativeio/PWMOut.c \
232-
nativeio/SPI.c \
233-
nativeio/UART.c \
224+
analogio/__init__.c \
225+
analogio/AnalogIn.c \
226+
analogio/AnalogOut.c \
227+
digitalio/__init__.c \
228+
digitalio/DigitalInOut.c \
229+
pulseio/__init__.c \
230+
pulseio/PulseIn.c \
231+
pulseio/PulseOut.c \
232+
pulseio/PWMOut.c \
233+
busio/__init__.c \
234+
busio/I2C.c \
235+
busio/SPI.c \
236+
busio/UART.c \
234237
neopixel_write/__init__.c \
235238
time/__init__.c \
236239
usb_hid/__init__.c \
237240
usb_hid/Device.c
238241

239-
SRC_BINDINGS_EXPANDED = $(addprefix shared-bindings/, $(SRC_BINDINGS)) \
240-
$(addprefix common-hal/, $(SRC_BINDINGS))
241-
242242
# Handle touch support on its own since it only fits in the image when external
243243
# flash is used to store the file system.
244-
SRC_BINDINGS_EXPANDED += shared-bindings/nativeio/TouchIn.c
245-
246-
ifeq ($(FLASH_IMPL),internal_flash.c)
247-
SRC_BINDINGS_EXPANDED += common-hal/nativeio/TouchInStub.c
248-
else
249-
SRC_BINDINGS_EXPANDED += common-hal/nativeio/TouchIn.c
244+
# TODO(tannewt): Remove this after we switch to freetouch and rely on the linker
245+
# to drop classes we don't need.
246+
ifneq ($(FLASH_IMPL),internal_flash.c)
247+
SRC_BINDINGS += touchio/__init__.c touchio/TouchIn.c
250248
endif
251249

250+
SRC_BINDINGS_EXPANDED = $(addprefix shared-bindings/, $(SRC_BINDINGS)) \
251+
$(addprefix common-hal/, $(SRC_BINDINGS))
252+
252253
SRC_SHARED_MODULE = \
253254
help.c \
254255
bitbangio/__init__.c \
255256
bitbangio/I2C.c \
256257
bitbangio/OneWire.c \
257258
bitbangio/SPI.c \
258-
nativeio/OneWire.c \
259+
busio/OneWire.c \
259260
uheap/__init__.c \
260261

261262
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \

atmel-samd/common-hal/nativeio/AnalogIn.c renamed to atmel-samd/common-hal/analogio/AnalogIn.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "common-hal/nativeio/AnalogIn.h"
27+
#include "common-hal/analogio/AnalogIn.h"
2828

2929
#include <string.h>
3030

@@ -33,7 +33,7 @@
3333
#include "py/runtime.h"
3434
#include "py/binary.h"
3535
#include "py/mphal.h"
36-
#include "shared-bindings/nativeio/AnalogIn.h"
36+
#include "shared-bindings/analogio/AnalogIn.h"
3737

3838
#include "asf/sam0/drivers/adc/adc.h"
3939
#include "samd21_pins.h"
@@ -42,7 +42,7 @@
4242
volatile uint8_t active_channel_count;
4343
struct adc_module *adc_instance = NULL;
4444

45-
void common_hal_nativeio_analogin_construct(nativeio_analogin_obj_t* self,
45+
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
4646
const mcu_pin_obj_t *pin) {
4747
if (!pin->has_adc) {
4848
// No ADC function on that pin
@@ -72,7 +72,7 @@ void common_hal_nativeio_analogin_construct(nativeio_analogin_obj_t* self,
7272
active_channel_count++;
7373
}
7474

75-
void common_hal_nativeio_analogin_deinit(nativeio_analogin_obj_t *self) {
75+
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
7676
active_channel_count--;
7777
if (active_channel_count == 0) {
7878
adc_reset(adc_instance);
@@ -92,7 +92,7 @@ void analogin_reset() {
9292
active_channel_count = 0;
9393
}
9494

95-
uint16_t common_hal_nativeio_analogin_get_value(nativeio_analogin_obj_t *self) {
95+
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
9696
adc_set_positive_input(adc_instance, self->pin->adc_input);
9797

9898
adc_enable(adc_instance);
@@ -111,6 +111,6 @@ uint16_t common_hal_nativeio_analogin_get_value(nativeio_analogin_obj_t *self) {
111111
return data;
112112
}
113113

114-
float common_hal_nativeio_analogin_get_reference_voltage(nativeio_analogin_obj_t *self) {
114+
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {
115115
return 3.3f;
116116
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGIN_H__
28+
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGIN_H__
29+
30+
#include "common-hal/microcontroller/types.h"
31+
32+
// Don't reorder these includes because they are dependencies of adc_feature.h.
33+
// They should really be included by adc_feature.h.
34+
#include <compiler.h>
35+
#include "asf/sam0/drivers/system/clock/gclk.h"
36+
#include "asf/sam0/utils/cmsis/samd21/include/component/adc.h"
37+
#include "asf/sam0/drivers/adc/adc_sam_d_r/adc_feature.h"
38+
39+
#include "py/obj.h"
40+
41+
typedef struct {
42+
mp_obj_base_t base;
43+
const mcu_pin_obj_t * pin;
44+
struct adc_module * adc_instance;
45+
} analogio_analogin_obj_t;
46+
47+
void analogin_reset(void);
48+
49+
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGIN_H__

atmel-samd/common-hal/nativeio/AnalogOut.c renamed to atmel-samd/common-hal/analogio/AnalogOut.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
#include "py/mperrno.h"
3131
#include "py/runtime.h"
3232

33-
#include "shared-bindings/nativeio/AnalogOut.h"
33+
#include "shared-bindings/analogio/AnalogOut.h"
3434

3535
#include "asf/sam0/drivers/dac/dac.h"
3636
#include "samd21_pins.h"
3737

38-
void common_hal_nativeio_analogout_construct(nativeio_analogout_obj_t* self,
38+
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
3939
const mcu_pin_obj_t *pin) {
4040
if (pin->pin != PIN_PA02) {
4141
mp_raise_ValueError("AnalogOut not supported on given pin");
@@ -58,13 +58,13 @@ void common_hal_nativeio_analogout_construct(nativeio_analogout_obj_t* self,
5858
dac_enable(&self->dac_instance);
5959
}
6060

61-
void common_hal_nativeio_analogout_deinit(nativeio_analogout_obj_t *self) {
61+
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
6262
dac_disable(&self->dac_instance);
6363
dac_chan_disable(&self->dac_instance, DAC_CHANNEL_0);
6464
reset_pin(PIN_PA02);
6565
}
6666

67-
void common_hal_nativeio_analogout_set_value(nativeio_analogout_obj_t *self,
67+
void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
6868
uint16_t value) {
6969
// Input is 16 bit but we only support 10 bit so we shift the input.
7070
dac_chan_write(&self->dac_instance, DAC_CHANNEL_0, value >> 6);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGOUT_H__
28+
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGOUT_H__
29+
30+
#include "common-hal/microcontroller/types.h"
31+
32+
#include "asf/sam0/drivers/dac/dac.h"
33+
34+
#include "py/obj.h"
35+
36+
typedef struct {
37+
mp_obj_base_t base;
38+
struct dac_module dac_instance;
39+
} analogio_analogout_obj_t;
40+
41+
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGOUT_H__
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// No analogio module functions.

atmel-samd/common-hal/nativeio/I2C.c renamed to atmel-samd/common-hal/busio/I2C.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
// This file contains all of the port specific HAL functions for the machine
28-
// module.
29-
30-
#include "shared-bindings/nativeio/I2C.h"
27+
#include "shared-bindings/busio/I2C.h"
3128
#include "py/mperrno.h"
3229
#include "py/nlr.h"
3330
#include "py/runtime.h"
@@ -41,7 +38,7 @@
4138
// Number of times to try to send packet if failed.
4239
#define TIMEOUT 1
4340

44-
void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
41+
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
4542
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency) {
4643
struct i2c_master_config config_i2c_master;
4744
i2c_master_get_config_defaults(&config_i2c_master);
@@ -85,7 +82,7 @@ void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
8582
sercom, &config_i2c_master);
8683

8784
if (status != STATUS_OK) {
88-
common_hal_nativeio_i2c_deinit(self);
85+
common_hal_busio_i2c_deinit(self);
8986
if (status == STATUS_ERR_BAUDRATE_UNAVAILABLE) {
9087
mp_raise_ValueError("Unsupported baudrate");
9188
} else {
@@ -96,13 +93,13 @@ void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
9693
i2c_master_enable(&self->i2c_master_instance);
9794
}
9895

99-
void common_hal_nativeio_i2c_deinit(nativeio_i2c_obj_t *self) {
96+
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
10097
i2c_master_reset(&self->i2c_master_instance);
10198
reset_pin(self->sda_pin);
10299
reset_pin(self->scl_pin);
103100
}
104101

105-
bool common_hal_nativeio_i2c_probe(nativeio_i2c_obj_t *self, uint8_t addr) {
102+
bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
106103
uint8_t buf;
107104
struct i2c_master_packet packet = {
108105
.address = addr,
@@ -118,26 +115,26 @@ bool common_hal_nativeio_i2c_probe(nativeio_i2c_obj_t *self, uint8_t addr) {
118115
return status == STATUS_OK;
119116
}
120117

121-
void common_hal_nativeio_i2c_configure(nativeio_i2c_obj_t *self,
118+
void common_hal_busio_i2c_configure(busio_i2c_obj_t *self,
122119
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
123120
return;
124121
}
125122

126-
bool common_hal_nativeio_i2c_try_lock(nativeio_i2c_obj_t *self) {
123+
bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
127124
self->has_lock = i2c_master_lock(&self->i2c_master_instance) == STATUS_OK;
128125
return self->has_lock;
129126
}
130127

131-
bool common_hal_nativeio_i2c_has_lock(nativeio_i2c_obj_t *self) {
128+
bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self) {
132129
return self->has_lock;
133130
}
134131

135-
void common_hal_nativeio_i2c_unlock(nativeio_i2c_obj_t *self) {
132+
void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
136133
self->has_lock = false;
137134
i2c_master_unlock(&self->i2c_master_instance);
138135
}
139136

140-
uint8_t common_hal_nativeio_i2c_write(nativeio_i2c_obj_t *self, uint16_t addr,
137+
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
141138
const uint8_t *data, size_t len, bool transmit_stop_bit) {
142139
struct i2c_master_packet packet = {
143140
.address = addr,
@@ -171,7 +168,7 @@ uint8_t common_hal_nativeio_i2c_write(nativeio_i2c_obj_t *self, uint16_t addr,
171168
return MP_EIO;
172169
}
173170

174-
uint8_t common_hal_nativeio_i2c_read(nativeio_i2c_obj_t *self, uint16_t addr,
171+
uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
175172
uint8_t *data, size_t len) {
176173
struct i2c_master_packet packet = {
177174
.address = addr,

atmel-samd/common-hal/busio/I2C.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H__
28+
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H__
29+
30+
#include "common-hal/microcontroller/types.h"
31+
32+
#include "asf/sam0/drivers/sercom/i2c/i2c_master.h"
33+
#include "py/obj.h"
34+
35+
typedef struct {
36+
mp_obj_base_t base;
37+
struct i2c_master_module i2c_master_instance;
38+
bool has_lock;
39+
uint8_t scl_pin;
40+
uint8_t sda_pin;
41+
} busio_i2c_obj_t;
42+
43+
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H__

0 commit comments

Comments
 (0)