8000 Add "pull" parameter to TouchIn ports · tannewt/circuitpython@232b699 · GitHub
[go: up one dir, main page]

10000 Skip to content

Commit 232b699

Browse files
committed
Add "pull" parameter to TouchIn ports
1 parent 6c1b6a4 commit 232b699

File tree

12 files changed

+43
-161
lines changed

12 files changed

+43
-161
lines changed

locale/circuitpython.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ msgstr ""
15551555
msgid "No pulldown on pin; 1Mohm recommended"
15561556
msgstr ""
15571557

1558-
#: ports/raspberrypi/common-hal/touchio/TouchIn.c
1558+
#: shared-module/touchio/TouchIn.c
15591559
msgid "No pullup on pin; 1Mohm recommended"
15601560
msgstr ""
15611561

ports/atmel-samd/common-hal/touchio/TouchIn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "py/binary.h"
1313
#include "py/mphal.h"
1414
#include "shared-bindings/microcontroller/Pin.h"
15+
#include "shared-bindings/digitalio/Pull.h"
1516
#include "shared-bindings/touchio/TouchIn.h"
1617

1718
// Native touchio only exists for SAMD21
@@ -38,7 +39,7 @@ static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
3839
}
3940

4041
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self,
41-
const mcu_pin_obj_t *pin) {
42+
const mcu_pin_obj_t *pin, const digitalio_pull_t pull) {
4243
if (!pin->has_touch) {
4344
raise_ValueError_invalid_pin();
4445
}

ports/espressif/common-hal/touchio/TouchIn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#include "py/runtime.h"
1010
#include "peripherals/touch.h"
1111
#include "shared-bindings/microcontroller/Pin.h"
12+
#include "shared-bindings/digitalio/Pull.h"
1213

1314
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self,
14-
const mcu_pin_obj_t *pin) {
15+
const mcu_pin_obj_t *pin, const digitalio_pull_t pull) {
1516
if (pin->touch_channel == NO_TOUCH_CHANNEL) {
1617
raise_ValueError_invalid_pin();
1718
}

ports/raspberrypi/common-hal/touchio/TouchIn.c

Lines changed: 0 additions & 103 deletions
This file was deleted.

ports/raspberrypi/common-hal/touchio/TouchIn.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

ports/raspberrypi/common-hal/touchio/__init__.c

Lines changed: 0 additions & 5 deletions
This file was deleted.

ports/raspberrypi/mpconfigport.mk

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ CIRCUITPY_ALARM = 0
6464
# Default PICODVI on because it doesn't require much code in RAM to talk to HSTX.
6565
CIRCUITPY_PICODVI ?= 1
6666

67-
# Our generic touchio uses a pull down and RP2350 A2 hardware doesn't work correctly.
68-
# So, turn generic touchio off because it doesn't work.
69-
# And use a "native" touchio that expects 1M pull-up resistor instead of pull-down
70-
CIRCUITPY_TOUCHIO = 1
71-
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1
72-
7367
# delay in ms before calling cyw43_arch_init_with_country
7468
CIRCUITPY_CYW43_INIT_DELAY ?= 0
7569

shared-bindings/touchio/TouchIn.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,29 @@
3131
//| print("touched!")"""
3232
//|
3333

34-
//| def __init__(self, pin: microcontroller.Pin) -> None:
34+
//| def __init__(self, pin: microcontroller.Pin, pull: Optional[digitalio.Pull] = None) -> None:
3535
//| """Use the TouchIn on the given pin.
3636
//|
3737
//| :param ~microcontroller.Pin pin: the pin to read from"""
38+
//| :param Optional[digitalio.Pull] pull: specify external pull resistor type. If None, assume pull-down or chip-specific implementation
3839
//| ...
3940
//|
4041
static mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type,
41-
size_t n_args, size_t n_kw, const mp_obj_t *args) {
42-
// check number of arguments
43-
mp_arg_check_num(n_args, n_kw, 1, 1, false);
42+
size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
4443

45-
// 1st argument is the pin
46-
const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0], MP_QSTR_pin);
44+
enum { ARG_pin, ARG_pull };
45+
static const mp_arg_t allowed_args[] = {
46+
{ MP_QSTR_pin, MP_ARG_OBJ | MP_ARG_REQUIRED },
47+
{ MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none} },
48+
};
49+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
50+
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
51+
52+
const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj, MP_QSTR_pin);
53+
const digitalio_pull_t pull = validate_pull(args[ARG_pull].u_obj, MP_QSTR_pull);
4754

4855
touchio_touchin_obj_t *self = mp_obj_malloc(touchio_touchin_obj_t, &touchio_touchin_type);
49-
common_hal_touchio_touchin_construct(self, pin);
56+
common_hal_touchio_touchin_construct(self, pin, pull);
5057

5158
return (mp_obj_t)self;
5259
}

shared-bindings/touchio/TouchIn.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#pragma once
88

99
#include "common-hal/microcontroller/Pin.h"
10+
#include "shared-bindings/digitalio/Pull.h"
1011

1112
#if CIRCUITPY_TOUCHIO_USE_NATIVE
1213
#include "common-hal/touchio/TouchIn.h"
@@ -16,7 +17,7 @@
1617

1718
extern const mp_obj_type_t touchio_touchin_type;
1819

19-
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self, const mcu_pin_obj_t *pin);
20+
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self, const mcu_pin_obj_t *pin, digitalio_pull_t pull);
2021
void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t *self);
2122
bool common_hal_touchio_touchin_deinited(touchio_touchin_obj_t *self);
2223
bool common_hal_touchio_touchin_get_value(touchio_touchin_obj_t *self);

shared-bindings/touchio/__init__.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
//| For more information about working with the `touchio` module in CircuitPython,
2929
//| see `this Learn guide page <https://learn.adafruit.com/circuitpython-essentials/circuitpython-cap-touch>`_.
3030
//|
31-
//| **Limitations**: `touchio` is available on Raspberry Pi RP2040 builds,
32-
//| but not on RP2350, due to GPIO hardware limitations.
31+
//| **Limitations**: `touchio` on RP2350 must have a pull-up resistor to 3.3V
32+
//| instead of ground and set the `pull=Pull.UP` parameter when constructing
33+
//| a `TouchIn` object, due to GPIO hardware limitations.
3334
//|
3435
//| Example::
3536
//|

0 commit comments

Comments
 (0)
0