8000 esp8266, stmhal, zephyr: Rename machine.Pin high/low methods to on/off. by pfalcon · Pull Request #3025 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

esp8266, stmhal, zephyr: Rename machine.Pin high/low methods to on/off. #3025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions drivers/display/ssd1306.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,23 @@ def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):

def write_cmd(self, cmd):
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
self.cs.high()
self.dc.low()
self.cs.low()
self.cs(1)
self.dc(0)
self.cs(0)
self.spi.write(bytearray([cmd]))
self.cs.high()
self.cs(1)

def write_data(self, buf):
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
self.cs.high()
self.dc.high()
self.cs.low()
self.cs(1)
self.dc(1)
self.cs(0)
self.spi.write(buf)
self.cs.high()
self.cs(1)

def poweron(self):
self.res.high()
self.res(1)
time.sleep_ms(1)
self.res.low()
self.res(0)
time.sleep_ms(10)
self.res.high()
self.res(1)
40 changes: 20 additions & 20 deletions drivers/nrf24l01/nrf24l01.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def __init__(self, spi, cs, ce, channel=46, payload_size=16):
ce.init(ce.OUT, value=0)

# reset everything
self.ce.low()
self.cs.high()
self.ce(0)
self.cs(1)
self.payload_size = payload_size
self.pipe0_read_addr = None
utime.sleep_ms(5)
Expand Down Expand Up @@ -109,36 +109,36 @@ def init_spi(self, baudrate):
self.spi.init(master, baudrate=baudrate, polarity=0, phase=0)

def reg_read(self, reg):
self.cs.low()
self.cs(0)
self.spi.readinto(self.buf, reg)
self.spi.readinto(self.buf)
self.cs.high()
self.cs(1)
return self.buf[0]

def reg_write_bytes(self, reg, buf):
self.cs.low()
self.cs(0)
self.spi.readinto(self.buf, 0x20 | reg)
self.spi.write(buf)
self.cs.high()
self.cs(1)
return self.buf[0]

def reg_write(self, reg, value):
self.cs.low()
self.cs(0)
self.spi.readinto(self.buf, 0x20 | reg)
ret = self.buf[0]
self.spi.readinto(self.buf, value)
self.cs.high()
self.cs(1)
return ret

def flush_rx(self):
self.cs.low()
self.cs(0)
self.spi.readinto(self.buf, FLUSH_RX)
self.cs.high()
self.cs(1)

def flush_tx(self):
self.cs.low()
self.cs(0)
self.spi.readinto(self.buf, FLUSH_TX)
self.cs.high()
self.cs(1)

# power is one of POWER_x defines; speed is one of SPEED_x defines
def set_power_speed(self, power, speed):
Expand Down Expand Up @@ -190,11 +190,11 @@ def start_listening(self):

self.flush_rx()
self.flush_tx()
self.ce.high()
self.ce(1)
utime.sleep_us(130)

def stop_listening(self):
self.ce.low()
self.ce(0)
self.flush_tx()
self.flush_rx()

Expand All @@ -204,10 +204,10 @@ def any(self):

def recv(self):
# get the data
self.cs.low()
self.cs(0)
self.spi.readinto(self.buf, R_RX_PAYLOAD)
buf = self.spi.read(self.payload_size)
self.cs.high()
self.cs(1)
# clear RX ready flag
self.reg_write(STATUS, RX_DR)

Expand All @@ -229,17 +229,17 @@ def send_start(self, buf):
self.reg_write(CONFIG, (self.reg_read(CONFIG) | PWR_UP) & ~PRIM_RX)
utime.sleep_us(150)
# send the data
self.cs.low()
self.cs(0)
self.spi.readinto(self.buf, W_TX_PAYLOAD)
self.spi.write(buf)
if len(buf) < self.payload_size:
self.spi.write(b'\x00' * (self.payload_size - len(buf))) # pad out data
self.cs.high()
self.cs(1)

# enable the chip so it can send the data
self.ce.high()
self.ce(1)
utime.sleep_us(15) # needs to be >10us
self.ce.low()
self.ce(0)

# returns None if send still in progress, 1 for success, 2 for fail
def send_done(self):
Expand Down
6 changes: 3 additions & 3 deletions drivers/onewire/ds18x20.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
The following example assumes the ground of your DS18x20 is connected to
Y11, vcc is connected to Y9 and the data pin is connected to Y10.

>>> from pyb import Pin
>>> from machine import Pin
>>> gnd = Pin('Y11', Pin.OUT_PP)
>>> gnd.low()
>>> gnd.off()
>>> vcc = Pin('Y9', Pin.OUT_PP)
>>> vcc.high()
>>> vcc.on()

>>> from ds18x20 import DS18X20
>>> d = DS18X20(Pin('Y10'))
Expand Down
24 changes: 12 additions & 12 deletions drivers/sdcard/sdcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def init_card_v2(self):
raise OSError("timeout waiting for v2 card")

def cmd(self, cmd, arg, crc, final=0, release=True):
self.cs.low()
self.cs(0)

# create and send the command
buf = self.cmdbuf
Expand All @@ -150,12 +150,12 @@ def cmd(self, cmd, arg, crc, final=0, release=True):
for j in range(final):
self.spi.write(b'\xff')
if release:
self.cs.high()
self.cs(1)
self.spi.write(b'\xff')
return response

# timeout
self.cs.high()
self.cs(1)
self.spi.write(b'\xff')
return -1

Expand All @@ -164,15 +164,15 @@ def cmd_nodata(self, cmd):
self.spi.read(1, 0xff) # ignore stuff byte
for _ in range(_CMD_TIMEOUT):
if self.spi.read(1, 0xff)[0] == 0xff:
self.cs.high()
self.cs(1)
self.spi.write(b'\xff')
return 0 # OK
self.cs.high()
self.cs(1)
self.spi.write(b'\xff')
return 1 # timeout

def readinto(self, buf):
self.cs.low()
self.cs(0)

# read until start byte (0xff)
while self.spi.read(1, 0xff)[0] != 0xfe:
Expand All @@ -186,11 +186,11 @@ def readinto(self, buf):
self.spi.write(b'\xff')
self.spi.write(b'\xff')

self.cs.high()
self.cs(1)
self.spi.write(b'\xff')

def write(self, token, buf):
self.cs.low()
self.cs(0)

# send: start of block, data, checksum
self.spi.read(1, token)
Expand All @@ -200,26 +200,26 @@ def write(self, token, buf):

# check the response
if (self.spi.read(1, 0xff)[0] & 0x1f) != 0x05:
self.cs.high()
self.cs(1)
self.spi.write(b'\xff')
return

# wait for write to finish
while self.spi.read(1, 0xff)[0] == 0:
pass

self.cs.high()
self.cs(1)
self.spi.write(b'\xff')

def write_token(self, token):
self.cs.low()
self.cs(0)
self.spi.read(1, token)
self.spi.write(b'\xff')
# wait for write to finish
while self.spi.read(1, 0xff)[0] == 0x00:
pass

self.cs.high()
self.cs(1)
self.spi.write(b'\xff')

def count(self):
Expand Down
14 changes: 6 additions & 8 deletions esp8266/machine_pin.c
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,19 @@ STATIC mp_obj_t pyb_pin_value(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_pin_value_obj, 1, 2, pyb_pin_value);

// pin.low()
STATIC mp_obj_t pyb_pin_low(mp_obj_t self_in) {
STATIC mp_obj_t pyb_pin_off(mp_obj_t self_in) {
pyb_pin_obj_t *self = self_in;
pin_set(self->phys_port, 0);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_low_obj, pyb_pin_low);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_off_obj, pyb_pin_off);

// pin.high()
STATIC mp_obj_t pyb_pin_high(mp_obj_t self_in) {
STATIC mp_obj_t pyb_pin_on(mp_obj_t self_in) {
pyb_pin_obj_t *self = self_in;
pin_set(self->phys_port, 1);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_high_obj, pyb_pin_high);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_on_obj, pyb_pin_on);

// pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False)
STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
Expand Down Expand Up @@ -410,8 +408,8 @@ STATIC const mp_map_elem_t pyb_pin_locals_dict_table[] = {
// instance methods
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_pin_init_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pyb_pin_value_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_low), (mp_obj_t)&pyb_pin_low_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_high), (mp_obj_t)&pyb_pin_high_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&pyb_pin_off_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&pyb_pin_on_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_pin_irq_obj },

// class constants
Expand Down
19 changes: 9 additions & 10 deletions stmhal/pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,23 +400,19 @@ STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);

/// \method low()
/// Set the pin to a low logic level.
STATIC mp_obj_t pin_low(mp_obj_t self_in) {
STATIC mp_obj_t pin_off(mp_obj_t self_in) {
pin_obj_t *self = self_in;
mp_hal_pin_low(self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off);

/// \method high()
/// Set the pin to a high logic level.
STATIC mp_obj_t pin_high(mp_obj_t self_in) {
STATIC mp_obj_t pin_on(mp_obj_t self_in) {
pin_obj_t *self = self_in;
mp_hal_pin_high(self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on);

/// \method name()
/// Get the pin name.
Expand Down Expand Up @@ -500,8 +496,11 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
// instance methods
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) },
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) },
{ MP_ROM_QSTR(MP_QSTR_low), MP_ROM_PTR(&pin_low_obj) },
{ MP_ROM_QSTR(MP_QSTR_high), MP_ROM_PTR(&pin_high_obj) },
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&pin_off_obj) },
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&pin_on_obj) },
// Legacy names as used by pyb.Pin
{ MP_ROM_QSTR(MP_QSTR_low), MP_ROM_PTR(&pin_off_obj) },
{ MP_ROM_QSTR(MP_QSTR_high), MP_ROM_PTR(&pin_on_obj) },
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_name_obj) },
{ MP_ROM_QSTR(MP_QSTR_names), MP_ROM_PTR(&pin_names_obj) },
{ MP_ROM_QSTR(MP_QSTR_af_list), MP_ROM_PTR(&pin_af_list_obj) },
Expand Down
14 changes: 6 additions & 8 deletions zephyr/machine_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,19 @@ STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value);

// pin.low()
STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) {
STATIC mp_obj_t machine_pin_off(mp_obj_t self_in) {
machine_pin_obj_t *self = self_in;
(void)gpio_pin_write(self->port, self->pin, 0);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off);

// pin.high()
STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) {
STATIC mp_obj_t machine_pin_on(mp_obj_t self_in) {
machine_pin_obj_t *self = self_in;
(void)gpio_pin_write(self->port, self->pin, 1);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on);

STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
(void)errcode;
Expand All @@ -176,8 +174,8 @@ STATIC const mp_map_elem_t machine_pin_locals_dict_table[] = {
// instance methods
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&machine_pin_init_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&machine_pin_value_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_low), (mp_obj_t)&machine_pin_low_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_high), (mp_obj_t)&machine_pin_high_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&machine_pin_off_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&machine_pin_on_obj },

// class constants
{ MP_OBJ_NEW_QSTR(MP_QSTR_IN), MP_OBJ_NEW_SMALL_INT(GPIO_DIR_IN) },
Expand Down
0