Skip to content

Commit 79feb95

Browse files
bgamaridpgeorge
authored andcommitted
esp32: Provide machine.Signal class.
1 parent 7895a03 commit 79feb95

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

esp32/machine_pin.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "py/runtime.h"
3535
#include "py/mphal.h"
3636
#include "modmachine.h"
37+
#include "extmod/virtpin.h"
3738

3839
typedef struct _machine_pin_obj_t {
3940
mp_obj_base_t base;
@@ -162,7 +163,7 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
162163
}
163164

164165
// constructor(id, ...)
165-
STATIC mp_obj_t machine_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
166+
mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
166167
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
167168

168169
// get the wanted pin object
@@ -257,14 +258,35 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
257258
{ MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_PIN_INTR_NEGEDGE) },
258259
};
259260

261+
STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
262+
(void)errcode;
263+
machine_pin_obj_t *self = self_in;
264+
265+
switch (request) {
266+
case MP_PIN_READ: {
267+
return gpio_get_level(self->id);
268+
}
269+
case MP_PIN_WRITE: {
270+
gpio_set_level(self->id, arg);
271+
return 0;
272+
}
273+
}
274+
return -1;
275+
}
276+
260277
STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table);
261278

279+
STATIC const mp_pin_p_t pin_pin_p = {
280+
.ioctl = pin_ioctl,
281+
};
282+
262283
const mp_obj_type_t machine_pin_type = {
263284
{ &mp_type_type },
264285
.name = MP_QSTR_Pin,
265286
.print = machine_pin_print,
266-
.make_new = machine_pin_make_new,
287+
.make_new = mp_pin_make_new,
267288
.call = machine_pin_call,
289+
.protocol = &pin_pin_p,
268290
.locals_dict = (mp_obj_t)&machine_pin_locals_dict,
269291
};
270292

esp32/modmachine.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "py/obj.h"
3939
#include "py/runtime.h"
4040
#include "extmod/machine_mem.h"
41+
#include "extmod/machine_signal.h"
4142
#include "extmod/machine_pulse.h"
4243
#include "extmod/machine_i2c.h"
4344
#include "extmod/machine_spi.h"
@@ -115,6 +116,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
115116

116117
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) },
117118
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
119+
{ MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) },
118120
{ MP_ROM_QSTR(MP_QSTR_TouchPad), MP_ROM_PTR(&machine_touchpad_type) },
119121
{ MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&machine_adc_type) },
120122
{ MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&machine_dac_type) },

esp32/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
#define MICROPY_PY_URANDOM (1)
128128
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
129129
#define MICROPY_PY_MACHINE (1)
130+
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
130131
#define MICROPY_PY_MACHINE_PULSE (1)
131132
#define MICROPY_PY_MACHINE_I2C (1)
132133
#define MICROPY_PY_MACHINE_SPI (1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy