kopia lustrzana https://github.com/micropython/micropython
Porównaj commity
5 Commity
af455ef680
...
411d45f64c
Autor | SHA1 | Data |
---|---|---|
Jos Verlinde | 411d45f64c | |
Angus Gratton | d11ca092f7 | |
Jos Verlinde | b52cf9e277 | |
Jos Verlinde | 2db0d9a4ae | |
Jos Verlinde | 7ae7d127b7 |
|
@ -130,15 +130,25 @@ Methods
|
|||
|
||||
Second argument is a memoryview to read the USB control request
|
||||
data for this stage. The memoryview is only valid until the
|
||||
callback function returns.
|
||||
callback function returns. Data in this memoryview will be the same
|
||||
across each of the three stages of a single transfer.
|
||||
|
||||
A successful transfer consists of this callback being called in sequence
|
||||
for the three stages. Generally speaking, if a device wants to do
|
||||
something in response to a control request then it's best to wait until
|
||||
the ACK stage to confirm the host controller completed the transfer as
|
||||
expected.
|
||||
|
||||
The callback should return one of the following values:
|
||||
|
||||
- ``False`` to stall the endpoint and reject the transfer.
|
||||
- ``False`` to stall the endpoint and reject the transfer. It won't
|
||||
proceed to any remaining stages.
|
||||
- ``True`` to continue the transfer to the next stage.
|
||||
- A buffer object to provide data for this stage of the transfer.
|
||||
This should be a writable buffer for an ``OUT`` direction transfer, or a
|
||||
readable buffer with data for an ``IN`` direction transfer.
|
||||
- A buffer object can be returned at the SETUP stage when the transfer
|
||||
will send or receive additional data. Typically this is the case when
|
||||
the ``wLength`` field in the request has a non-zero value. This should
|
||||
be a writable buffer for an ``OUT`` direction transfer, or a readable
|
||||
buffer with data for an ``IN`` direction transfer.
|
||||
|
||||
- ``xfer_cb`` - This callback is called whenever a non-control
|
||||
transfer submitted by calling :func:`USBDevice.submit_xfer` completes.
|
||||
|
|
|
@ -107,7 +107,7 @@ The full list of supported commands are:
|
|||
**Note:** Instead of using the ``connect`` command, there are several
|
||||
:ref:`pre-defined shortcuts <mpremote_shortcuts>` for common device paths. For
|
||||
example the ``a0`` shortcut command is equivalent to
|
||||
``connect /dev/ttyACM0`` (Linux), or ``c0`` for ``COM0`` (Windows).
|
||||
``connect /dev/ttyACM0`` (Linux), or ``c1`` for ``COM1`` (Windows).
|
||||
|
||||
**Note:** The ``auto`` option will only detect USB serial ports, i.e. a serial
|
||||
port that has an associated USB VID/PID (i.e. CDC/ACM or FTDI-style
|
||||
|
@ -429,9 +429,14 @@ Shortcuts can be defined using the macro system. Built-in shortcuts are:
|
|||
|
||||
- ``cat``, ``edit``, ``ls``, ``cp``, ``rm``, ``mkdir``, ``rmdir``, ``touch``: Aliases for ``fs <sub-command>``
|
||||
|
||||
Additional shortcuts can be defined by in user-configuration files, which is
|
||||
located at ``.config/mpremote/config.py``. This file should define a
|
||||
dictionary named ``commands``. The keys of this dictionary are the shortcuts
|
||||
Additional shortcuts can be defined by in the user configuration file ``mpremote/config.py``, located in:
|
||||
# ``$XDG_CONFIG_HOME/mpremote/config.py``
|
||||
# ``$HOME/.config/mpremote/config.py``
|
||||
# ``%APPDATA%/mpremote/config.py``
|
||||
# ``%USERPROFILE%/mpremote/config.py``
|
||||
searched in that order on all platforms.
|
||||
|
||||
This file should define a dictionary named ``commands``. The keys of this dictionary are the shortcuts
|
||||
and the values are either a string or a list-of-strings:
|
||||
|
||||
.. code-block:: python3
|
||||
|
|
|
@ -295,6 +295,7 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
|
|||
mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd));
|
||||
tusb_dir_t dir = request->bmRequestType_bit.direction;
|
||||
mp_buffer_info_t buf_info;
|
||||
bool result;
|
||||
|
||||
if (!usbd) {
|
||||
return false;
|
||||
|
@ -319,7 +320,7 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
|
|||
|
||||
// Check if callback returned any data to submit
|
||||
if (mp_get_buffer(cb_res, &buf_info, dir == TUSB_DIR_IN ? MP_BUFFER_READ : MP_BUFFER_RW)) {
|
||||
bool result = tud_control_xfer(USBD_RHPORT,
|
||||
result = tud_control_xfer(USBD_RHPORT,
|
||||
request,
|
||||
buf_info.buf,
|
||||
buf_info.len);
|
||||
|
@ -328,17 +329,21 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
|
|||
// Keep buffer object alive until the transfer completes
|
||||
usbd->xfer_data[0][dir] = cb_res;
|
||||
}
|
||||
|
||||
return result;
|
||||
} else {
|
||||
// Expect True or False to stall or continue
|
||||
result = mp_obj_is_true(cb_res);
|
||||
|
||||
if (stage == CONTROL_STAGE_ACK) {
|
||||
if (stage == CONTROL_STAGE_SETUP && result) {
|
||||
// If no additional data but callback says to continue transfer then
|
||||
// queue a status response.
|
||||
tud_control_status(rhport, request);
|
||||
} else if (stage == CONTROL_STAGE_ACK) {
|
||||
// Allow data to be GCed once it's no longer in use
|
||||
usbd->xfer_data[0][dir] = mp_const_none;
|
||||
}
|
||||
return mp_obj_is_true(cb_res);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool runtime_dev_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
|
||||
|
|
|
@ -341,10 +341,12 @@ _BUILTIN_COMMAND_EXPANSIONS = {
|
|||
"--version": "version",
|
||||
}
|
||||
|
||||
# Add "a0", "a1", ..., "u0", "u1", ..., "c0", "c1", ... as aliases
|
||||
# Add "a0", "a1", ..., "u0", "u1", ..., "c1", "c2", ... as aliases
|
||||
# for "connect /dev/ttyACMn" (and /dev/ttyUSBn, COMn) etc.
|
||||
for port_num in range(4):
|
||||
for prefix, port in [("a", "/dev/ttyACM"), ("u", "/dev/ttyUSB"), ("c", "COM")]:
|
||||
if port_num == 0 and port == "COM":
|
||||
continue # skip COM0 as it does not exist on Windows
|
||||
_BUILTIN_COMMAND_EXPANSIONS["{}{}".format(prefix, port_num)] = {
|
||||
"command": "connect {}{}".format(port, port_num),
|
||||
"help": 'connect to serial port "{}{}"'.format(port, port_num),
|
||||
|
@ -355,18 +357,22 @@ def load_user_config():
|
|||
# Create empty config object.
|
||||
config = __build_class__(lambda: None, "Config")()
|
||||
config.commands = {}
|
||||
|
||||
# Get config file name.
|
||||
path = os.getenv("XDG_CONFIG_HOME")
|
||||
if path is None:
|
||||
path = os.getenv("HOME")
|
||||
if path is None:
|
||||
return config
|
||||
path = os.path.join(path, ".config")
|
||||
path = os.path.join(path, _PROG)
|
||||
path = None
|
||||
for env_var in ("XDG_CONFIG_HOME", "HOME", "APPDATA", "USERPROFILE"):
|
||||
path = os.getenv(env_var)
|
||||
if not path:
|
||||
continue
|
||||
if env_var == "HOME" and os.path.exists(os.path.join(path, ".config", _PROG, "config.py")):
|
||||
# Unix style
|
||||
path = os.path.join(path, ".config", _PROG)
|
||||
break
|
||||
elif os.path.exists(os.path.join(path, _PROG, "config.py")):
|
||||
# Windows style
|
||||
path = os.path.join(path, _PROG)
|
||||
break
|
||||
if not path:
|
||||
return config
|
||||
config_file = os.path.join(path, "config.py")
|
||||
|
||||
# Check if config file exists.
|
||||
if not os.path.exists(config_file):
|
||||
return config
|
||||
|
||||
|
@ -375,9 +381,11 @@ def load_user_config():
|
|||
config_data = f.read()
|
||||
prev_cwd = os.getcwd()
|
||||
os.chdir(path)
|
||||
# pass in the config path so that the config file can use it
|
||||
config.__dict__["config_path"] = path
|
||||
config.__dict__["__file__"] = config_file
|
||||
exec(config_data, config.__dict__)
|
||||
os.chdir(prev_cwd)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue