Skip to content

Commit 984b8d8

Browse files
committed
ports/cheriot-rtos/machine_pin: Added toggle method; handle enable bit.
Signed-off-by: Jacob Trevor <[email protected]>
1 parent 3a33584 commit 984b8d8

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

ports/cheriot-rtos/machine_pin.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ static void machine_pin_obj_init_helper(machine_pin_obj_t *self, size_t n_args,
9494
(self->mode == MACHINE_PIN_MODE_OPEN_DRAIN && !init);
9595

9696
uint32_t block = self->port->output;
97-
block = set_pin_enable(block, self->pin, enabled);
97+
98+
if (self->port != MMIO_CAPABILITY(gpio_block_t, gpio)) {
99+
block = set_pin_enable(block, self->pin, enabled);
100+
}
101+
98102
block = set_pin_value(block, self->pin, init);
99103
self->port->output = block;
100104
}
@@ -120,6 +124,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
120124
pin->base.type = &machine_pin_type;
121125
pin->port = wanted_port;
122126
pin->pin = wanted_pin;
127+
pin->mode = MACHINE_PIN_MODE_OUT;
123128

124129
if (n_args > 1 || n_kw > 0) {
125130
mp_map_t kw_args;
@@ -157,7 +162,7 @@ static mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i
157162
}
158163
case MP_PIN_WRITE: {
159164
uint32_t block = set_pin_value(self->port->output, self->pin, (bool)arg);
160-
if (self->mode == MACHINE_PIN_MODE_OPEN_DRAIN) {
165+
if ((self->port != MMIO_CAPABILITY(gpio_block_t, gpio)) & (self->mode == MACHINE_PIN_MODE_OPEN_DRAIN)) {
161166
block = set_pin_enable(block, self->pin, !(bool)arg);
162167
}
163168
self->port->output = block;
@@ -237,6 +242,21 @@ static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in,
237242
}
238243

239244

245+
static mp_obj_t machine_pin_toggle(mp_obj_t self_in) {
246+
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
247+
// if (self->mode == MACHINE_PIN_MODE_IN) {
248+
// }
249+
if (self->mode == MACHINE_PIN_MODE_OUT) {
250+
self->port->output = set_pin_value(self->port->output, self->pin, !GET_BUFFER(self));
251+
} else if (self->mode == MACHINE_PIN_MODE_OPEN_DRAIN) {
252+
bool value = GET_BUFFER(self);
253+
uint32_t block = set_pin_value(self->port->output, self->pin, !value);
254+
self->port->output = set_pin_enable(block, self->pin, value);
255+
}
256+
return mp_const_none;
257+
}
258+
static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle);
259+
240260
static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
241261
// instance methods
242262
{MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj)},
@@ -245,6 +265,7 @@ static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
245265
{MP_ROM_QSTR(MP_QSTR_high), MP_ROM_PTR(&machine_pin_on_obj)},
246266
{MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&machine_pin_off_obj)},
247267
{MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&machine_pin_on_obj)},
268+
{MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&machine_pin_toggle_obj)},
248269

249270
// class constants
250271
{MP_ROM_QSTR(MP_QSTR_IN), MP_ROM_INT(MACHINE_PIN_MODE_IN)},

ports/cheriot-rtos/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum { SPI_MSB_FIRST, SPI_LSB_FIRST };
1111

1212
// Use the minimal starting configuration (disables all optional features).
1313
#define MICROPY_CONFIG_ROM_LEVEL \
14-
(MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES) // MINIMUM)
14+
(MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES) // MINIMUM)
1515

1616
// You can disable the built-in MicroPython compiler by setting the following
1717
// config option to 0. If you do this then you won't get a REPL prompt, but you

0 commit comments

Comments
 (0)