This documentation is part of the MicroPython project, http://micropython.org/
These MP_* macros have been scanned from the source code in the MicroPython repository. The descriptions for each macro have been generated based on the surrounding code context using the OpenAI o3-mini model.
You are invited to correct any inaccuracy or misinterpretatie you find by editing this page directly.
MP_BC
This configuration set defines the structure and behavior of bytecode operations in a MicroPython environment, including the encoding of various instructions, the handling of data types, and the management of control flow. It encompasses the creation and manipulation of fundamental data structures, function calls, and variable management, ensuring efficient execution of Python code at the bytecode level.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_BC_BASE_BYTE_E |
Base value for bytecode instructions with specific encoding. | (0x60) // --BREEEYYI------ |
MP_BC_BASE_BYTE_O |
Base offset for bytecode operations with specific bit patterns. | (0x50) // LLLLSSDTTTTTEEFF |
MP_BC_BASE_JUMP_E |
Base value for jump-related bytecode operations. | (0x40) // J-JJJJJEEEEF---- |
MP_BC_BASE_QSTR_O |
Base value for bytecode operations involving qstr (string) constants. | (0x10) // LLLLLLSSSDDII--- |
MP_BC_BASE_RESERVED |
Represents a reserved opcode value for bytecode. | (0x00) // ---------------- |
MP_BC_BASE_VINT_E |
Base value for variable-length integer bytecode operations. | (0x20) // MMLLLLSSDDBBBBBB |
MP_BC_BASE_VINT_O |
Base value for variable integer bytecode operations. | (0x30) // UUMMCCCC-------- |
MP_BC_BINARY_OP_MULTI |
Represents a multi-byte binary operation opcode. | (0xd7) // OOOOOOOOO |
MP_BC_BINARY_OP_MULTI_NUM |
Defines the number of binary operation bytecode instructions. | (MP_BINARY_OP_NUM_BYTECODE) |
MP_BC_BUILD_LIST |
Represents the bytecode operation for building a list. | (MP_BC_BASE_VINT_E + 0x0b) // uint |
MP_BC_BUILD_MAP |
Represents the bytecode operation for building a map (dictionary) object. | (MP_BC_BASE_VINT_E + 0x0c) // uint |
MP_BC_BUILD_SET |
Represents the bytecode operation for building a set. | (MP_BC_BASE_VINT_E + 0x0d) // uint |
MP_BC_BUILD_SLICE |
Represents the bytecode for building a slice object. | (MP_BC_BASE_VINT_E + 0x0e) // uint |
MP_BC_BUILD_TUPLE |
Represents the bytecode operation for building a tuple. | (MP_BC_BASE_VINT_E + 0x0a) // uint |
MP_BC_CALL_FUNCTION |
Represents the bytecode operation for calling a function with positional and keyword arguments. | (MP_BC_BASE_VINT_O + 0x04) // uint |
MP_BC_CALL_FUNCTION_VAR_KW |
Represents a bytecode instruction for calling a function with variable positional and keyword arguments. | (MP_BC_BASE_VINT_O + 0x05) // uint |
MP_BC_CALL_METHOD |
Represents the bytecode operation for calling a method with positional and keyword arguments. | (MP_BC_BASE_VINT_O + 0x06) // uint |
MP_BC_CALL_METHOD_VAR_KW |
Represents a bytecode instruction for calling a method with variable positional and keyword arguments. | (MP_BC_BASE_VINT_O + 0x07) // uint |
MP_BC_DELETE_DEREF |
Represents a bytecode operation for deleting a dereferenced variable. | (MP_BC_BASE_VINT_E + 0x09) // uint |
MP_BC_DELETE_FAST |
Represents a bytecode operation for fast deletion of local variables. | (MP_BC_BASE_VINT_E + 0x08) // uint |
MP_BC_DELETE_GLOBAL |
Bytecode for deleting a global variable identified by a qstr. | (MP_BC_BASE_QSTR_O + 0x0a) // qstr |
MP_BC_DELETE_NAME |
Represents the bytecode operation for deleting a variable by name. | (MP_BC_BASE_QSTR_O + 0x09) // qstr |
MP_BC_DUP_TOP |
Replicates the top item on the stack. | (MP_BC_BASE_BYTE_O + 0x07) |
MP_BC_DUP_TOP_TWO |
Replicates the top two items on the stack. | (MP_BC_BASE_BYTE_O + 0x08) |
MP_BC_END_FINALLY |
Handles the end of a finally block, managing the top of stack based on its value. | (MP_BC_BASE_BYTE_O + 0x0d) |
MP_BC_FORMAT_BYTE |
Represents the format type for a byte in bytecode. | (0) |
MP_BC_FORMAT_OFFSET |
Indicates an opcode format that uses an offset for addressing. | (3) |
MP_BC_FORMAT_QSTR |
Indicates that the bytecode format is a QSTR (string constant). Examples: opcode formats for loading string constants or handling string-related operations. | (1) |
MP_BC_FORMAT_VAR_UINT |
Indicates a variable-length unsigned integer format for bytecode. | (2) |
MP_BC_FOR_ITER |
Unsigned relative bytecode offset for the 'for' iteration operation. | (MP_BC_BASE_JUMP_E + 0x0b) // unsigned relative bytecode offset |
MP_BC_GET_ITER |
Bytecode for retrieving an iterator from the top of the stack. | (MP_BC_BASE_BYTE_O + 0x0e) |
MP_BC_GET_ITER_STACK |
Bytecode for obtaining an iterator using the stack. | (MP_BC_BASE_BYTE_O + 0x0f) |
MP_BC_IMPORT_FROM |
Opcode for importing a specific attribute from a module. | (MP_BC_BASE_QSTR_O + 0x0c) // qstr |
MP_BC_IMPORT_NAME |
Represents the bytecode operation for importing a module by name. | (MP_BC_BASE_QSTR_O + 0x0b) // qstr |
MP_BC_IMPORT_STAR |
Represents the bytecode operation for importing all names from a module. | (MP_BC_BASE_BYTE_E + 0x09) |
MP_BC_JUMP |
Represents a signed relative bytecode offset for jump instructions. | (MP_BC_BASE_JUMP_E + 0x02) // signed relative bytecode offset |
MP_BC_JUMP_IF_FALSE_OR_POP |
Executes a jump if the top stack value is false, otherwise pops the value. | (MP_BC_BASE_JUMP_E + 0x06) // unsigned relative bytecode offset |
MP_BC_JUMP_IF_TRUE_OR_POP |
Executes a jump if the top stack value is true, otherwise pops the value. | (MP_BC_BASE_JUMP_E + 0x05) // unsigned relative bytecode offset |
MP_BC_LOAD_ATTR |
Loads an attribute from an object using its qualified string identifier. | (MP_BC_BASE_QSTR_O + 0x03) // qstr |
MP_BC_LOAD_BUILD_CLASS |
Bytecode for loading the 'build_class' function. | (MP_BC_BASE_BYTE_O + 0x04) |
MP_BC_LOAD_CONST_FALSE |
Represents the bytecode instruction to load the constant value False. | (MP_BC_BASE_BYTE_O + 0x00) |
MP_BC_LOAD_CONST_NONE |
Represents the bytecode operation to load the constant None onto the stack. | (MP_BC_BASE_BYTE_O + 0x01) |
MP_BC_LOAD_CONST_OBJ |
Loads a constant object pointer onto the stack. | (MP_BC_BASE_VINT_E + 0x03) // ptr |
MP_BC_LOAD_CONST_SMALL_INT |
Represents a signed variable integer constant in bytecode. | (MP_BC_BASE_VINT_E + 0x02) // signed var-int |
MP_BC_LOAD_CONST_SMALL_INT_MULTI |
Represents a bytecode operation for loading multiple small integer constants. | (0x70) // LLLLLLLLLLLLLLLL |
MP_BC_LOAD_CONST_SMALL_INT_MULTI_EXCESS |
Defines the excess offset for loading small integer constants in multi-bytecode. | (16) |
MP_BC_LOAD_CONST_SMALL_INT_MULTI_NUM |
Defines the maximum number of small integer constants that can be loaded in a single bytecode operation. | (64) |
MP_BC_LOAD_CONST_STRING |
Loads a constant string (qstr) onto the stack. | (MP_BC_BASE_QSTR_O + 0x00) // qstr |
MP_BC_LOAD_CONST_TRUE |
Represents the bytecode for loading the constant true value. | (MP_BC_BASE_BYTE_O + 0x02) |
MP_BC_LOAD_DEREF |
Represents a bytecode operation for loading a variable from a closure or local scope. | (MP_BC_BASE_VINT_E + 0x05) // uint |
MP_BC_LOAD_FAST_MULTI |
Bytecode for loading multiple fast local variables. | (0xb0) // LLLLLLLLLLLLLLLL |
MP_BC_LOAD_FAST_MULTI_NUM |
Indicates the number of fast variable loading bytecodes. | (16) |
MP_BC_LOAD_FAST_N |
Represents a bytecode operation for loading a fast local variable by index. | (MP_BC_BASE_VINT_E + 0x04) // uint |
MP_BC_LOAD_GLOBAL |
Loads a global variable using its qstr identifier. | (MP_BC_BASE_QSTR_O + 0x02) // qstr |
MP_BC_LOAD_METHOD |
Loads a method from an object using a qualified string identifier. | (MP_BC_BASE_QSTR_O + 0x04) // qstr |
MP_BC_LOAD_NAME |
Represents a bytecode operation for loading a variable by name using a qstr. | (MP_BC_BASE_QSTR_O + 0x01) // qstr |
MP_BC_LOAD_NULL |
Represents the bytecode operation to load a null object. | (MP_BC_BASE_BYTE_O + 0x03) |
MP_BC_LOAD_SUBSCR |
Bytecode for loading a subscription (indexing) operation. | (MP_BC_BASE_BYTE_O + 0x05) |
MP_BC_LOAD_SUPER_METHOD |
Loads a method from a superclass using a qualified string. | (MP_BC_BASE_QSTR_O + 0x05) // qstr |
MP_BC_MAKE_CLOSURE |
Represents the bytecode operation for creating a closure with an extra byte. | (MP_BC_BASE_VINT_E + 0x00) // uint; extra byte |
MP_BC_MAKE_CLOSURE_DEFARGS |
Represents a bytecode operation for creating a closure with additional arguments. | (MP_BC_BASE_VINT_E + 0x01) // uint; extra byte |
MP_BC_MAKE_FUNCTION |
Represents the bytecode operation for creating a function. | (MP_BC_BASE_VINT_O + 0x02) // uint |
MP_BC_MAKE_FUNCTION_DEFARGS |
Represents a bytecode operation for creating a function with default arguments. | (MP_BC_BASE_VINT_O + 0x03) // uint |
MP_BC_MASK_EXTRA_BYTE |
Mask for determining the presence of an extra byte in bytecode. | (0x9e) |
MP_BC_MASK_FORMAT |
Mask for identifying bytecode format in instruction parsing. | (0xf0) |
MP_BC_POP_EXCEPT_JUMP |
Handles jumping to a specified label after popping an exception block. | (MP_BC_BASE_JUMP_E + 0x0a) // unsigned relative bytecode offset |
MP_BC_POP_JUMP_IF_FALSE |
Represents a bytecode instruction for jumping if the top stack value is false. | (MP_BC_BASE_JUMP_E + 0x04) // signed relative bytecode offset |
MP_BC_POP_JUMP_IF_TRUE |
Represents a bytecode instruction for conditional jumping based on a true value. | (MP_BC_BASE_JUMP_E + 0x03) // signed relative bytecode offset |
MP_BC_POP_TOP |
Removes the top item from the stack. | (MP_BC_BASE_BYTE_O + 0x09) |
MP_BC_RAISE_FROM |
Represents a bytecode operation for raising exceptions with a specified cause. | (MP_BC_BASE_BYTE_E + 0x06) |
MP_BC_RAISE_LAST |
Represents the bytecode operation for raising the last exception. | (MP_BC_BASE_BYTE_E + 0x04) |
MP_BC_RAISE_OBJ |
Represents bytecode for raising an exception object. | (MP_BC_BASE_BYTE_E + 0x05) |
MP_BC_RETURN_VALUE |
Represents the bytecode operation for returning a value from a function. | (MP_BC_BASE_BYTE_E + 0x03) |
MP_BC_ROT_THREE |
Bytecode operation for rotating the top three stack elements. | (MP_BC_BASE_BYTE_O + 0x0b) |
MP_BC_ROT_TWO |
Rotates the top two items on the stack. | (MP_BC_BASE_BYTE_O + 0x0a) |
MP_BC_SETUP_EXCEPT |
Unsigned relative bytecode offset for setting up exception handling. | (MP_BC_BASE_JUMP_E + 0x08) // unsigned relative bytecode offset |
MP_BC_SETUP_FINALLY |
Unsigned relative bytecode offset for setting up a finally block in exception handling. | (MP_BC_BASE_JUMP_E + 0x09) // unsigned relative bytecode offset |
MP_BC_SETUP_WITH |
Unsigned relative bytecode offset for the SETUP_WITH opcode. | (MP_BC_BASE_JUMP_E + 0x07) // unsigned relative bytecode offset |
MP_BC_STORE_ATTR |
Represents the bytecode operation for storing an attribute in an object using a qstr. | (MP_BC_BASE_QSTR_O + 0x08) // qstr |
MP_BC_STORE_COMP |
Represents the bytecode operation for storing a comprehension result. | (MP_BC_BASE_VINT_E + 0x0f) // uint |
MP_BC_STORE_DEREF |
Represents a bytecode operation for storing a value in a dereferenced local variable. | (MP_BC_BASE_VINT_E + 0x07) // uint |
MP_BC_STORE_FAST_MULTI |
Bytecode for storing multiple fast local variables. | (0xc0) // SSSSSSSSSSSSSSSS |
MP_BC_STORE_FAST_MULTI_NUM |
Limits the number of fast store operations to 16. | (16) |
MP_BC_STORE_FAST_N |
Represents a bytecode operation for storing a value in a fast local variable. | (MP_BC_BASE_VINT_E + 0x06) // uint |
MP_BC_STORE_GLOBAL |
Encodes a bytecode instruction for storing a global variable using a qstr. | (MP_BC_BASE_QSTR_O + 0x07) // qstr |
MP_BC_STORE_MAP |
Bytecode for storing a value in a map (dictionary) object. | (MP_BC_BASE_BYTE_E + 0x02) |
MP_BC_STORE_NAME |
Bytecode operation for storing a value in a variable identified by a qstr. | (MP_BC_BASE_QSTR_O + 0x06) // qstr |
MP_BC_STORE_SUBSCR |
Bytecode for storing a value in a subscripted location. | (MP_BC_BASE_BYTE_O + 0x06) |
MP_BC_UNARY_OP_MULTI |
Represents a bytecode for multiple unary operations. | (0xd0) // OOOOOOO |
MP_BC_UNARY_OP_MULTI_NUM |
Defines the number of unary operation bytecode instructions. | (MP_UNARY_OP_NUM_BYTECODE) |
MP_BC_UNPACK_EX |
Handles unpacking of multiple values from a sequence with specified counts. | (MP_BC_BASE_VINT_O + 0x01) // uint |
MP_BC_UNPACK_SEQUENCE |
Opcode for unpacking a sequence in bytecode. | (MP_BC_BASE_VINT_O + 0x00) // uint |
MP_BC_UNWIND_JUMP |
Represents a signed relative bytecode offset for unwinding jumps in exception handling. | (MP_BC_BASE_JUMP_E + 0x00) // signed relative bytecode offset; then a byte |
MP_BC_WITH_CLEANUP |
Represents bytecode for the 'with' statement that includes cleanup handling. | (MP_BC_BASE_BYTE_O + 0x0c) |
MP_BC_YIELD_FROM |
Represents the bytecode operation for yielding from a generator. | (MP_BC_BASE_BYTE_E + 0x08) |
MP_BC_YIELD_VALUE |
Represents the bytecode for yielding a value from a generator. | (MP_BC_BASE_BYTE_E + 0x07) |
MP_BLOCKDEV
This configuration set manages the behavior and capabilities of block devices, including their initialization, synchronization, and interaction with filesystems. It provides flags and ioctl commands that facilitate operations such as reading, writing, and erasing blocks, as well as managing the lifecycle of block device objects.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_BLOCKDEV_FLAG_FREE_OBJ |
Indicates that the fs_user_mount_t object should be freed upon unmounting. | (0x0002) // fs_user_mount_t obj should be freed on umount |
MP_BLOCKDEV_FLAG_HAVE_IOCTL |
Indicates support for the new block protocol with ioctl functionality. | (0x0004) // new protocol with ioctl |
MP_BLOCKDEV_FLAG_NATIVE |
Indicates that readblocks[2]/writeblocks[2] contain native functions. | (0x0001) // readblocks[2]/writeblocks[2] contain native func |
MP_BLOCKDEV_FLAG_NO_FILESYSTEM |
Indicates that the block device lacks a filesystem. | (0x0008) // the block device has no filesystem on it |
MP_BLOCKDEV_IOCTL_BLOCK_COUNT |
Retrieves the total number of blocks in a block device. | (4) |
MP_BLOCKDEV_IOCTL_BLOCK_ERASE |
Erases a specified block in a block device. | (6) |
MP_BLOCKDEV_IOCTL_BLOCK_SIZE |
Retrieves the size of a block in bytes for block devices. | (5) |
MP_BLOCKDEV_IOCTL_DEINIT |
Indicates the command to deinitialize a block device. | (2) |
MP_BLOCKDEV_IOCTL_INIT |
Indicates initialization of a block device in the block protocol. | (1) |
MP_BLOCKDEV_IOCTL_SYNC |
Indicates a request to synchronize the block device. | (3) |
MP_BLUETOOTH
This configuration set manages various aspects of Bluetooth functionality, including address modes, characteristic properties, and GATT operations. It defines parameters for authentication, encryption, and permissions, ensuring secure and efficient communication between Bluetooth devices.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_BLUETOOTH_ADDRESS_MODE_NRPA |
Represents the Non-Resolvable Private Address mode for Bluetooth. | (3) |
MP_BLUETOOTH_ADDRESS_MODE_PUBLIC |
Indicates the use of a public Bluetooth address. | (0) |
MP_BLUETOOTH_ADDRESS_MODE_RANDOM |
Indicates the use of a random Bluetooth address mode. | (1) |
MP_BLUETOOTH_ADDRESS_MODE_RPA |
Represents the Resolvable Private Address mode for Bluetooth. | (2) |
MP_BLUETOOTH_CCCD_LEN |
Defines the length of the Client Characteristic Configuration Descriptor (CCCD) as 2 bytes. | (2) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_AUTHENTICATED_SIGNED_WRITE |
Indicates that a characteristic supports authenticated signed writes. | (0x0040) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_AUX_WRITE |
Extended flag for Bluetooth characteristic indicating auxiliary write capability. | (0x0100) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_BROADCAST |
Indicates that the characteristic can be broadcasted. | (0x0001) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_INDICATE |
Indicates that a Bluetooth characteristic supports indications for data transfer. | (0x0020) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_NOTIFY |
Indicates that a Bluetooth characteristic supports notifications. | (0x0010) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ |
Indicates that a Bluetooth characteristic can be read. | (0x0002) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ_AUTHENTICATED |
Indicates that a Bluetooth characteristic requires authenticated access for reading. | (0x0400) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ_AUTHORIZED |
Indicates that a Bluetooth characteristic read requires authorization. | (0x0800) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ_ENCRYPTED |
Indicates that a Bluetooth characteristic requires encrypted access for reading. | (0x0200) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE |
Indicates that a Bluetooth characteristic supports write operations. | (0x0008) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_AUTHENTICATED |
Indicates that a Bluetooth characteristic requires authenticated write access. | (0x2000) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_AUTHORIZED |
Indicates that a Bluetooth characteristic write operation is authorized. | (0x4000) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_ENCRYPTED |
Indicates that a Bluetooth characteristic requires encrypted write access. | (0x1000) |
MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_NO_RESPONSE |
Indicates a Bluetooth characteristic that allows writing without requiring a response. | (0x0004) |
MP_BLUETOOTH_CONNECT_DEFAULT_SCAN_DURATION_MS |
Default duration for Bluetooth scanning in milliseconds. | 2000 |
MP_BLUETOOTH_DEFAULT_ATTR_LEN |
Defines the default attribute length for Bluetooth GATT services, set to 20 bytes. | (20) |
MP_BLUETOOTH_GAP_ADV_MAX_LEN |
Maximum length of Bluetooth advertisement packets. | (32) |
MP_BLUETOOTH_GATTS_ERROR_INSUFFICIENT_AUTHENTICATION |
Indicates insufficient authentication for a GATT server operation. | (0x05) |
MP_BLUETOOTH_GATTS_ERROR_INSUFFICIENT_AUTHORIZATION |
Indicates insufficient authorization for a GATT operation, represented by the value 0x08. | (0x08) |
MP_BLUETOOTH_GATTS_ERROR_INSUFFICIENT_ENCRYPTION |
Indicates insufficient encryption for a GATT server operation. | (0x0f) |
MP_BLUETOOTH_GATTS_ERROR_READ_NOT_PERMITTED |
Indicates that a read request is not permitted. | (0x02) |
MP_BLUETOOTH_GATTS_ERROR_WRITE_NOT_PERMITTED |
Indicates that a write operation is not permitted. | (0x03) |
MP_BLUETOOTH_GATTS_NO_ERROR |
Indicates a successful read request with no errors. | (0x00) |
MP_BLUETOOTH_GATTS_OP_INDICATE |
Represents the operation for sending an indication in Bluetooth GATT. | (2) |
MP_BLUETOOTH_GATTS_OP_NOTIFY |
Represents the notify operation for Bluetooth GATT server notifications. | (1) |
MP_BLUETOOTH_IO_CAPABILITY_DISPLAY_ONLY |
Represents the Bluetooth I/O capability for devices that can only display information. | (0) |
MP_BLUETOOTH_IO_CAPABILITY_DISPLAY_YESNO |
Indicates the device can display a prompt and receive a yes/no response during Bluetooth pairing. | (1) |
MP_BLUETOOTH_IO_CAPABILITY_KEYBOARD_DISPLAY |
Indicates a device can display a passkey and accept input from a keyboard. | (4) |
MP_BLUETOOTH_IO_CAPABILITY_KEYBOARD_ONLY |
Indicates that the device has keyboard-only input capability. | (2) |
MP_BLUETOOTH_IO_CAPABILITY_NO_INPUT_OUTPUT |
Indicates no input or output capabilities for Bluetooth pairing. | (3) |
MP_BLUETOOTH_IRQ_CENTRAL_CONNECT |
Indicates a central device connection event for the IRQ handler. | (1) |
MP_BLUETOOTH_IRQ_CENTRAL_DISCONNECT |
Indicates a disconnection event from a central Bluetooth device. | (2) |
MP_BLUETOOTH_IRQ_CONNECTION_UPDATE |
Indicates a connection update event in Bluetooth communication. | (27) |
MP_BLUETOOTH_IRQ_ENCRYPTION_UPDATE |
Triggers an interrupt for Bluetooth encryption updates. | (28) |
MP_BLUETOOTH_IRQ_GATTC_CHARACTERISTIC_DONE |
Indicates the completion of a GATT characteristic discovery process. | (12) |
MP_BLUETOOTH_IRQ_GATTC_CHARACTERISTIC_RESULT |
Indicates a result for a GATT client characteristic operation. | (11) |
MP_BLUETOOTH_IRQ_GATTC_DESCRIPTOR_DONE |
Indicates the completion of a GATT descriptor discovery operation. | (14) |
MP_BLUETOOTH_IRQ_GATTC_DESCRIPTOR_RESULT |
Indicates a result from a GATT Client operation related to a descriptor. | (13) |
MP_BLUETOOTH_IRQ_GATTC_INDICATE |
Indicates a GATT indication event for Bluetooth communication. | (19) |
MP_BLUETOOTH_IRQ_GATTC_NOTIFY |
Indicates a GATT client notification event. | (18) |
MP_BLUETOOTH_IRQ_GATTC_READ_DONE |
Indicates the completion of a GATT client read operation. | (16) |
MP_BLUETOOTH_IRQ_GATTC_READ_RESULT |
Indicates a result from a GATT client read operation. | (15) |
MP_BLUETOOTH_IRQ_GATTC_SERVICE_DONE |
Indicates the completion of a GATT service discovery operation. | (10) |
MP_BLUETOOTH_IRQ_GATTC_SERVICE_RESULT |
Indicates a result from a GATT client service discovery event. | (9) |
MP_BLUETOOTH_IRQ_GATTC_WRITE_DONE |
Indicates the completion status of a GATT client write operation. | (17) |
MP_BLUETOOTH_IRQ_GATTS_INDICATE_DONE |
Indicates the completion of a GATT server indication event. | (20) |
MP_BLUETOOTH_IRQ_GATTS_READ_REQUEST |
Indicates a read request event for a GATT server. | (4) |
MP_BLUETOOTH_IRQ_GATTS_WRITE |
Indicates a write event on a GATT server, providing connection and value handles. | (3) |
MP_BLUETOOTH_IRQ_GET_SECRET |
Triggers an interrupt to retrieve a secret key in Bluetooth operations. | (29) |
MP_BLUETOOTH_IRQ_L2CAP_ACCEPT |
IRQ for handling L2CAP connection accept events. | (22) |
MP_BLUETOOTH_IRQ_L2CAP_CONNECT |
IRQ for handling L2CAP connection events. | (23) |
MP_BLUETOOTH_IRQ_L2CAP_DISCONNECT |
Indicates a disconnection event in the L2CAP layer of Bluetooth. | (24) |
MP_BLUETOOTH_IRQ_L2CAP_RECV |
Triggers an interrupt for receiving L2CAP data. | (25) |
MP_BLUETOOTH_IRQ_L2CAP_SEND_READY |
Indicates that the L2CAP layer is ready to send data. | (26) |
MP_BLUETOOTH_IRQ_MTU_EXCHANGED |
Indicates that the MTU (Maximum Transmission Unit) has been exchanged during a Bluetooth connection. | (21) |
MP_BLUETOOTH_IRQ_PASSKEY_ACTION |
IRQ for handling Bluetooth passkey actions during pairing. | (31) |
MP_BLUETOOTH_IRQ_PERIPHERAL_CONNECT |
Indicates a successful connection from a peripheral device. | (7) |
MP_BLUETOOTH_IRQ_PERIPHERAL_DISCONNECT |
Indicates a peripheral device has disconnected from the Bluetooth connection. | (8) |
MP_BLUETOOTH_IRQ_SCAN_DONE |
Indicates the completion of a Bluetooth scan without parameters. | (6) |
MP_BLUETOOTH_IRQ_SCAN_RESULT |
Indicates a Bluetooth scan result event with associated parameters. | (5) |
MP_BLUETOOTH_IRQ_SET_SECRET |
IRQ identifier for setting a Bluetooth secret. | (30) |
MP_BLUETOOTH_NIMBLE_MAX_SERVICES |
Limits the maximum number of Bluetooth services to 8. | (8) |
MP_BLUETOOTH_PASSKEY_ACTION_DISPLAY |
Indicates that the passkey should be displayed to the user. | (3) |
MP_BLUETOOTH_PASSKEY_ACTION_INPUT |
Indicates that a passkey input action is required during Bluetooth pairing. | (2) |
MP_BLUETOOTH_PASSKEY_ACTION_NONE |
Represents no action for Bluetooth passkey input. | (0) |
MP_BLUETOOTH_PASSKEY_ACTION_NUMERIC_COMPARISON |
Represents the action for numeric comparison during Bluetooth passkey entry. | (4) |
MP_BLUETOOTH_UUID_TYPE_128 |
Represents a 128-bit Bluetooth UUID type. | (16) |
MP_BLUETOOTH_UUID_TYPE_16 |
Indicates a 16-bit Bluetooth UUID type, with the value also representing its length. | (2) |
MP_BLUETOOTH_UUID_TYPE_32 |
Represents a 32-bit Bluetooth UUID type. | (4) |
MP_BLUETOOTH_WRITE_MODE_NO_RESPONSE |
Indicates a write operation without expecting a response in Bluetooth GATT client operations. | (0) |
MP_BLUETOOTH_WRITE_MODE_WITH_RESPONSE |
Indicates that a Bluetooth write operation expects a response. | (1) |
MP_BLUETOOTH_ZEPHYR_MAX_SERVICES |
Limits the maximum number of Bluetooth services in the Zephyr port to 8. | (8) |
MP_EMIT
This collection of macros configures the bytecode emission process for various operations in a programming language environment. It encompasses actions related to attribute manipulation, data structure construction, variable handling, import statements, and control flow, enabling efficient execution of high-level constructs in the generated bytecode.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_EMIT_ATTR_DELETE |
Indicates the operation to delete an attribute in bytecode emission. | (2) |
MP_EMIT_ATTR_LOAD |
Indicates loading an attribute in the emission process. | (0) |
MP_EMIT_ATTR_STORE |
Indicates the operation for storing an attribute. | (1) |
MP_EMIT_BREAK_FROM_FOR |
Indicates a break from a for loop during bytecode emission. | (0x8000) |
MP_EMIT_BUILD_LIST |
Indicates the construction of a list during bytecode emission. | (1) |
MP_EMIT_BUILD_MAP |
Indicates the construction of a map (dictionary) during bytecode emission. | (2) |
MP_EMIT_BUILD_SET |
Indicates the construction of a set during bytecode emission. | (3) |
MP_EMIT_BUILD_SLICE |
Indicates the kind for building a slice during bytecode emission. | (4) |
MP_EMIT_BUILD_TUPLE |
Indicates the kind for building a tuple during bytecode emission. | (0) |
MP_EMIT_IDOP_GLOBAL_GLOBAL |
Indicates the kind for global variable operations in the emitter. | (1) |
MP_EMIT_IDOP_GLOBAL_NAME |
Indicates the kind for emitting global name operations. | (0) |
MP_EMIT_IDOP_LOCAL_DEREF |
Indicates a local variable dereference operation in bytecode emission. | (1) |
MP_EMIT_IDOP_LOCAL_FAST |
Indicates a fast local variable operation in the emitter. | (0) |
MP_EMIT_IMPORT_FROM |
Indicates the kind of import operation for importing specific attributes from a module. | (1) |
MP_EMIT_IMPORT_NAME |
Indicates the kind of import operation for emitting an import statement. | (0) |
MP_EMIT_IMPORT_STAR |
Indicates the import kind for importing all names from a module. | (2) |
MP_EMIT_SETUP_BLOCK_EXCEPT |
Indicates the setup for an exception handling block during bytecode emission. | (1) |
MP_EMIT_SETUP_BLOCK_FINALLY |
Indicates the setup for a finally block in exception handling. | (2) |
MP_EMIT_SETUP_BLOCK_WITH |
Indicates the kind for setting up a 'with' block during bytecode emission. | (0) |
MP_EMIT_STAR_FLAG_DOUBLE |
Indicates the presence of double-star arguments in function calls. | (0x02) |
MP_EMIT_STAR_FLAG_SINGLE |
Indicates the presence of a single star argument in function calls. | (0x01) |
MP_EMIT_SUBSCR_DELETE |
Indicates the operation for deleting a subscription in bytecode emission. | (2) |
MP_EMIT_SUBSCR_LOAD |
Indicates loading a subscription from an object. | (0) |
MP_EMIT_SUBSCR_STORE |
Indicates the operation for storing a value in a subscription. | (1) |
MP_EMIT_YIELD_FROM |
Indicates the kind of yield operation for generator functions. | (1) |
MP_EMIT_YIELD_VALUE |
Indicates the kind for emitting a yield value during code generation. | (0) |
MP_HAL
This configuration set manages the behavior and characteristics of GPIO pins, including their drive strength, modes, pull-up/down settings, and interrupt triggers. It allows for precise control over pin functionalities such as analog input, digital output, and signal timing, enabling efficient hardware interaction in embedded applications.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_HAL_BITSTREAM_NS_OVERHEAD |
Defines the overhead in nanoseconds for bitstream timing calculations. | (5) |
MP_HAL_PIN_DRIVE_0 |
Represents low power drive strength for GPIO pins. | (GPIO_LOW_POWER) |
MP_HAL_PIN_DRIVE_1 |
Represents a mid-level power drive configuration for GPIO pins. | (GPIO_MID_POWER) |
MP_HAL_PIN_DRIVE_12MA |
Defines the drive strength of a pin to 12mA. | (PADCTRL_OUTPUT_DRIVE_STRENGTH_12MA) |
MP_HAL_PIN_DRIVE_2 |
Represents a pin drive strength level of mid-fast power. | (GPIO_MID_FAST_POWER) |
MP_HAL_PIN_DRIVE_2MA |
Defines the output drive strength of a pin to 2mA. | (PADCTRL_OUTPUT_DRIVE_STRENGTH_2MA) |
MP_HAL_PIN_DRIVE_3 |
Represents a high power drive mode for GPIO pins. | (GPIO_HIGH_POWER) |
MP_HAL_PIN_DRIVE_4MA |
Sets the pin drive strength to 4mA. | (PADCTRL_OUTPUT_DRIVE_STRENGTH_4MA) |
MP_HAL_PIN_DRIVE_8MA |
Defines the drive strength of a pin to 8mA. | (PADCTRL_OUTPUT_DRIVE_STRENGTH_8MA) |
MP_HAL_PIN_FMT |
Format specifier for pin names, typically used in print functions. | "%q" |
MP_HAL_PIN_MODE_ADC |
Configures a pin for analog-to-digital conversion mode. | (GPIO_MODE_ANALOG) |
MP_HAL_PIN_MODE_ALT |
Configures a pin for alternate function mode. | (GPIO_MODE_AF_PP) |
MP_HAL_PIN_MODE_ALT_OPEN_DRAIN |
Configures a pin for alternate function in open-drain mode. | (GPIO_MODE_AF_OD) |
MP_HAL_PIN_MODE_ANALOG |
Defines the analog pin mode for GPIO configuration. | (GPIO_MODE_ANALOG) |
MP_HAL_PIN_MODE_INPUT |
Represents the input mode for GPIO pins. | (GPIO_MODE_INPUT) |
MP_HAL_PIN_MODE_OPEN_DRAIN |
Configures a pin for open-drain output mode. | (GPIO_MODE_OUTPUT_OD) |
MP_HAL_PIN_MODE_OUTPUT |
Defines the output mode for GPIO pins. | (GPIO_MODE_OUTPUT_PP) |
MP_HAL_PIN_PULL_DOWN |
Indicates a pull-down resistor configuration for a pin. | PIN_PULL_DOWN_100K |
MP_HAL_PIN_PULL_NONE |
Indicates that no pull-up or pull-down resistor is enabled for a pin. | PIN_PULL_DISABLED |
MP_HAL_PIN_PULL_UP |
Enables a pull-up resistor on a pin. | PIN_PULL_UP_100K |
MP_HAL_PIN_SPEED_HIGH |
Sets the pin speed to high, enabling fast signal transitions. | (PADCTRL_SLEW_RATE_FAST) |
MP_HAL_PIN_SPEED_LOW |
Sets the GPIO pin speed to low frequency. | (GPIO_SPEED_FREQ_LOW) |
MP_HAL_PIN_SPEED_MEDIUM |
Represents a medium speed setting for GPIO pins. | (GPIO_SPEED_FREQ_MEDIUM) |
MP_HAL_PIN_SPEED_VERY_HIGH |
Defines the very high speed setting for GPIO pins. | (GPIO_SPEED_FREQ_VERY_HIGH) |
MP_HAL_PIN_TRIGGER_FALL |
Indicates a falling edge interrupt trigger for GPIO pins. | kGPIO_IntFallingEdge |
MP_HAL_PIN_TRIGGER_FALLING |
Defines the falling edge trigger for GPIO interrupts. | (GPIO_IRQ_FALLING) |
MP_HAL_PIN_TRIGGER_HIGHLEVEL |
Indicates a high-level trigger for GPIO interrupts. | (GPIO_IRQ_HIGHLEVEL) |
MP_HAL_PIN_TRIGGER_LOWLEVEL |
Indicates a low-level trigger for GPIO interrupts. | (GPIO_IRQ_LOWLEVEL) |
MP_HAL_PIN_TRIGGER_NONE |
Indicates no interrupt mode for GPIO pins. | kGPIO_NoIntmode |
MP_HAL_PIN_TRIGGER_RISE |
Indicates a rising edge trigger for GPIO interrupts. | kGPIO_IntRisingEdge |
MP_HAL_PIN_TRIGGER_RISE_FALL |
Triggers an interrupt on both rising and falling edges of a GPIO pin. | kGPIO_IntRisingOrFallingEdge |
MP_HAL_PIN_TRIGGER_RISING |
Indicates a rising edge trigger for GPIO interrupts. | (GPIO_IRQ_RISING) |
MP_HAL_UNIQUE_ID_ADDRESS |
Memory address for accessing the unique identifier of the hardware. | (0x1ffff7ac) /* To be fixed */ |
MP_MPU
This configuration set manages memory protection unit (MPU) settings, defining various memory attributes and regions to control access permissions and caching behaviors. It ensures that different types of memory, such as SRAM, flash, and peripheral regions, are appropriately configured for optimal performance and security.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_MPU_ATTR_NORMAL_NON_CACHEABLE |
Defines a memory region attribute for normal memory that is non-cacheable. | (4) |
MP_MPU_ATTR_NORMAL_WB_RA_WA |
Defines memory attributes for normal memory with write-back caching and read-allocate/write-allocate policies. | (2) |
MP_MPU_ATTR_NORMAL_WT_RA |
Memory attribute for normal memory with write-through and read-allocate caching. | (3) |
MP_MPU_ATTR_NORMAL_WT_RA_TRANSIENT |
Defines a memory attribute for normal memory with write-through caching and read-allocate, transient behavior. | (0) |
MP_MPU_REGION_HOST_PERIPHERALS |
Identifies the memory region for host peripherals with specific access permissions. | (2) |
MP_MPU_REGION_MRAM |
Identifies the Memory Region Attribute for MRAM in the MPU configuration. | (3) |
MP_MPU_REGION_OPENAMP |
Identifies the OpenAMP memory region for MPU configuration. | (7) |
MP_MPU_REGION_OSPI0_XIP |
Identifies the OSPI0 XIP flash memory region with specific access permissions. | (5) |
MP_MPU_REGION_OSPI1_XIP |
Identifies the OSPI1 XIP flash memory region with specific access permissions. | (6) |
MP_MPU_REGION_OSPI_REGISTERS |
Identifies the memory region for OSPI registers with specific access permissions. | (4) |
MP_MPU_REGION_SRAM0 |
Identifies the first SRAM region in the MPU configuration. | (0) |
MP_MPU_REGION_SRAM1 |
Identifies the second SRAM region in the memory protection unit configuration. | (1) |
MP_OBJ
This collection of macros is focused on defining and managing object types and their properties within the MicroPython environment. They facilitate type checking, memory management, and function argument handling, ensuring efficient and accurate manipulation of various object types.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_OBJ_ARRAY_FREE_SIZE_BITS |
Bit size allocated for the 'free' member in the mp_obj_array_t structure. | (8 * sizeof(size_t) - 8) |
MP_OBJ_ARRAY_TYPECODE_FLAG_RW |
Indicates a writable memoryview when set in the typecode. | (0x80) |
MP_OBJ_FUN_ARGS_MAX |
Maximum number of arguments allowed for function calls. | (0xffff) // to set maximum value in n_args_max below |
MP_OBJ_IS_FUN |
Checks if an object is a function. | mp_obj_is_fun |
MP_OBJ_IS_INT |
Checks if an object is an integer. | mp_obj_is_int |
MP_OBJ_IS_OBJ |
Checks if an object is of type 'object'. | mp_obj_is_obj |
MP_OBJ_IS_QSTR |
Checks if an object is a QSTR (interned string) type. | mp_obj_is_qstr |
MP_OBJ_IS_SMALL_INT |
Maps the legacy API for checking small integer objects. | mp_obj_is_small_int |
MP_OBJ_IS_STR |
Checks if an object is a string. | mp_obj_is_str |
MP_OBJ_IS_STR_OR_BYTES |
Checks if an object is either a string or bytes. | mp_obj_is_str_or_bytes |
MP_OBJ_IS_TYPE |
Checks if an object is of a specific type. | mp_obj_is_type |
MP_OBJ_ITER_BUF_NSLOTS |
Calculates the number of slots required for mp_obj_iter_buf_t on the Python value stack. | ((sizeof(mp_obj_iter_buf_t) + sizeof(mp_obj_t) - 1) / sizeof(mp_obj_t)) |
MP_OBJ_JSPROXY_REF_GLOBAL_THIS |
Reference identifier for the JavaScript globalThis object. | (0) |
MP_OBJ_JSPROXY_REF_UNDEFINED |
Represents an undefined JavaScript proxy reference. | (1) |
MP_OBJ_NULL |
Represents a null object pointer in the MicroPython object system. | (MP_OBJ_FROM_PTR((void *)0)) |
MP_OBJ_SENTINEL |
Represents a special object used as a sentinel value in various data structures and operations. | (MP_OBJ_FROM_PTR((void *)8)) |
MP_OBJ_STOP_ITERATION |
Indicates the end of an iteration process. | (MP_OBJ_FROM_PTR((void *)4)) |
MP_OBJ_WORD_MSBIT_HIGH |
mp_int_t value with the most significant bit set, calculated based on object word size. | (((mp_uint_t)1) << (MP_BYTES_PER_OBJ_WORD * MP_BITS_PER_BYTE - 1)) |
MP_SCOPE
This configuration group manages various flags related to function scopes in MicroPython, enabling specific behaviors for functions, including support for default arguments, variable arguments, and generator functions. It also handles aspects related to the native emitter and viper code, such as the presence of constants, global references, and read-only data, ensuring efficient execution and memory management.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_SCOPE_FLAG_ALL_SIG |
Mask for all significant scope flags (4 bits) in function signatures. | (0x0f) |
MP_SCOPE_FLAG_DEFKWARGS |
Indicates the presence of default keyword arguments in a function's scope. | (0x08) |
MP_SCOPE_FLAG_GENERATOR |
Indicates that the current scope is a generator, affecting function behavior and bytecode generation. | (0x01) |
MP_SCOPE_FLAG_HASCONSTS |
Indicates that a function or closure has constant values when the native emitter is enabled. | (0x20) // used only if native emitter enabled |
MP_SCOPE_FLAG_REFGLOBALS |
Indicates that a function/closure takes a reference to the current global variables when the native emitter is enabled. | (0x10) // used only if native emitter enabled |
MP_SCOPE_FLAG_VARARGS |
Indicates that a function accepts variable positional arguments. | (0x04) |
MP_SCOPE_FLAG_VARKEYWORDS |
Indicates the presence of variable keyword arguments in a function's scope. | (0x02) |
MP_SCOPE_FLAG_VIPERBSS |
Indicates the presence of BSS (Block Started by Symbol) section when loading viper from .mpy files. | (0x40) // used only when loading viper from .mpy |
MP_SCOPE_FLAG_VIPERRELOC |
Indicates relocation of viper code when loading from .mpy files. | (0x10) // used only when loading viper from .mpy |
MP_SCOPE_FLAG_VIPERRET_POS |
Indicates the position of viper return type bits in scope flags for compiler to native emitter communication. | (6) // 3 bits used for viper return type, to pass from compiler to native emitter |
MP_SCOPE_FLAG_VIPERRODATA |
Indicates the presence of read-only data when loading viper code from a .mpy file. | (0x20) // used only when loading viper from .mpy |
MP_STREAM
This collection of macros is designed to manage and configure stream operations, including reading, writing, and error handling. They provide essential functionalities for stream control, such as flushing buffers, polling for status, and setting options, ensuring efficient data handling in various stream contexts.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_STREAM_CLOSE |
Indicates a request to close a stream. | (4) |
MP_STREAM_ERROR |
Indicates an error in stream operations, represented by the value ((mp_uint_t)-1). Examples include read/write failures in I2S and deflate operations. | ((mp_uint_t)-1) |
MP_STREAM_FLUSH |
Flushes the stream, ensuring all buffered data is written out. | (1) |
MP_STREAM_GET_BUFFER_SIZE |
Retrieves the preferred buffer size for file streams. | (11) // Get preferred buffer size for file |
MP_STREAM_GET_DATA_OPTS |
Retrieves options related to data or message handling. | (8) // Get data/message options |
MP_STREAM_GET_FILENO |
Retrieves the file descriptor of the underlying file. | (10) // Get fileno of underlying file |
MP_STREAM_GET_OPTS |
Retrieves options for a stream. | (6) // Get stream options |
MP_STREAM_OP_IOCTL |
Indicates the ioctl operation for stream objects. | (4) |
MP_STREAM_OP_READ |
Flag for read operations in stream protocols, can be combined with other operation flags. | (1) |
MP_STREAM_OP_WRITE |
Indicates the stream operation for writing data. | (2) |
MP_STREAM_POLL |
Indicates a request to poll a stream for readability or writability. | (3) |
MP_STREAM_POLL_ERR |
Indicates an error condition in stream polling. | (0x0008) |
MP_STREAM_POLL_HUP |
Indicates that a socket has been hung up (disconnected). Examples include detecting closed connections in socket programming. | (0x0010) |
MP_STREAM_POLL_NVAL |
Indicates an invalid file descriptor or socket state during polling. | (0x0020) |
MP_STREAM_POLL_RD |
Indicates readiness for reading in stream polling, compatible with Linux poll values. | (0x0001) |
MP_STREAM_POLL_RDWR |
Combines read and write polling flags for stream operations. | (MP_STREAM_POLL_RD | MP_STREAM_POLL_WR) |
MP_STREAM_POLL_WR |
Indicates that a stream is writable. | (0x0004) |
MP_STREAM_RW_ONCE |
Indicates that a stream operation should be performed only once. | 1 |
MP_STREAM_RW_READ |
Flag indicating read operation for stream functions. | 0 |
MP_STREAM_RW_WRITE |
Flag indicating a write operation in stream functions. | 2 |
MP_STREAM_SEEK |
Request code for seeking within a stream. | (2) |
MP_STREAM_SET_DATA_OPTS |
Sets data/message options for a stream. | (9) // Set data/message options |
MP_STREAM_SET_OPTS |
Sets options for a stream. | (7) // Set stream options |
MP_STREAM_TIMEOUT |
Get or set the timeout for a single stream operation. | (5) // Get/set timeout (single op) |
MP_TYPE
This collection of macros configures various behaviors and characteristics of types in MicroPython, such as method binding, equality checks, iteration mechanisms, and special accessors. They enable fine-tuning of type functionalities, allowing for custom implementations and optimizations in type handling.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_TYPE_FLAG_BINDS_SELF |
Indicates that a method binds 'self' as the first argument. | (0x0020) |
MP_TYPE_FLAG_BUILTIN_FUN |
Indicates that the type is a built-in function type. | (0x0040) |
MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE |
Enables equality checks between different types. | (0x0008) |
MP_TYPE_FLAG_EQ_HAS_NEQ_TEST |
Indicates that a type implements the ne operator for inequality checks. | (0x0010) |
MP_TYPE_FLAG_EQ_NOT_REFLEXIVE |
Indicates that equality comparison (eq) is not reflexive, meaning A==A may return False. | (0x0004) |
MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS |
Indicates that attribute lookups for a class should check for special accessor methods. | (0x0002) |
MP_TYPE_FLAG_INSTANCE_TYPE |
Indicates that a type is an instance type defined in Python. | (0x0200) |
MP_TYPE_FLAG_IS_SUBCLASSED |
Indicates that subclasses of the class have been created, preventing certain mutations. | (0x0001) |
MP_TYPE_FLAG_ITER_IS_CUSTOM |
Indicates that the 'iter' slot points to a custom iterator structure with both 'getiter' and 'iternext' functions. | (0x0100) |
MP_TYPE_FLAG_ITER_IS_GETITER |
Indicates that the default behavior for the iter slot is to use the getiter function. | (0x0000) |
MP_TYPE_FLAG_ITER_IS_ITERNEXT |
Indicates that the 'iter' slot corresponds to the 'iternext' function, with 'getiter' automatically implemented as 'return self'. Examples include mp_type_poll, mp_type_array_it, and mp_type_dict_view_it. | (0x0080) |
MP_TYPE_FLAG_ITER_IS_STREAM |
Indicates that a type supports streaming iteration with a default getiter implementation. | (MP_TYPE_FLAG_ITER_IS_ITERNEXT | MP_TYPE_FLAG_ITER_IS_CUSTOM) |
MP_TYPE_FLAG_NONE |
Indicates no special type behavior flags are set. | (0x0000) |
MP_TYPE_FLAG_SUBSCR_ALLOWS_STACK_SLICE |
Enables the 'subscr' slot to accept stack-allocated slices without retaining references. | (0x0400) |
MP_MISC
This collection of macros provides essential configurations and constants for various aspects of the MicroPython environment, including mathematical constants, error codes, buffer operations, and runtime initialization. They facilitate low-level operations, optimize performance through inlining, and ensure compatibility across different compilers and platforms.
| Macro | Description | Sample value(s) |
|---|---|---|
MP_3_PI_4 |
Represents the constant value of 3π/4 as a floating-point number. | MICROPY_FLOAT_CONST(2.35619449019234492885) |
MP_ALWAYSINLINE |
Forces functions to be always inlined by the compiler. | attribute((always_inline)) |
MP_ASAN |
Enables AddressSanitizer feature if supported by the compiler. | __has_feature(address_sanitizer) |
MP_ASM_PASS_COMPUTE |
Indicates the assembly pass for computation in the assembly framework. | (1) |
MP_ASM_PASS_EMIT |
Indicates the assembly pass for emitting code. | (2) |
MP_BINARY_OP_NUM_BYTECODE |
Defines the count of bytecode operations for binary operations. | (MP_BINARY_OP_POWER + 1) |
MP_BINARY_OP_NUM_RUNTIME |
Determines the number of runtime binary operations based on the presence of reverse special methods. | (MP_BINARY_OP_REVERSE_POWER + 1) |
MP_BITS_PER_BYTE |
Represents the number of bits in a byte, set to 8. | (8) |
MP_BUFFER_RAISE_IF_UNSUPPORTED |
Triggers a TypeError if the buffer protocol is unsupported. | (4) |
MP_BUFFER_READ |
Indicates that a buffer is to be read from. | (1) |
MP_BUFFER_RW |
Combines read and write buffer access flags for buffer operations. | (MP_BUFFER_READ | MP_BUFFER_WRITE) |
MP_BUFFER_WRITE |
Indicates that a buffer is intended for writing data. | (2) |
MP_BYTES_PER_OBJ_WORD |
Defines the number of bytes in an object word, equivalent to the size of mp_uint_t. | (sizeof(mp_uint_t)) |
MP_CLOCKS_PER_SEC |
Represents the number of clock ticks per second, adjusted for compatibility with different compilers. | MP_REMOVE_BRACKETSC(CLOCKS_PER_SEC) |
MP_CODE_STATE_EXC_SP_IDX_SENTINEL |
Sentinel value indicating an invalid exception stack pointer index. | ((uint16_t)-1) |
MP_DYNRUNTIME_INIT_ENTRY |
Initializes the dynamic runtime environment for a module, setting up global variables and context. | \ |
MP_DYNRUNTIME_INIT_EXIT |
Restores the global dictionary and returns None at the end of dynamic runtime initialization. | \ |
MP_E2BIG |
Indicates that the argument list is too long. | (7) // Argument list too long |
MP_EACCES |
Represents a permission denied error with a value of 13. | (13) // Permission denied |
MP_EADDRINUSE |
Error code indicating that an address is already in use. | (98) // Address already in use |
MP_EAFNOSUPPORT |
Error code indicating the address family is not supported by the protocol. | (97) // Address family not supported by protocol |
MP_EAGAIN |
Indicates that an operation should be retried. | (11) // Try again |
MP_EALREADY |
Indicates that an operation is already in progress. | (114) // Operation already in progress |
MP_EBADF |
Indicates a bad file number error. | (9) // Bad file number |
MP_EBUSY |
Indicates that a device or resource is busy. | (16) // Device or resource busy |
MP_ECANCELED |
Error code indicating that an operation was canceled. | (125) // Operation canceled |
MP_ECHILD |
Indicates that there are no child processes. | (10) // No child processes |
MP_ECONNABORTED |
Indicates a software-caused connection abort with a value of 103. | (103) // Software caused connection abort |
MP_ECONNREFUSED |
Error code indicating that a connection attempt was refused. | (111) // Connection refused |
MP_ECONNRESET |
Indicates a connection reset by the peer. | (104) // Connection reset by peer |
MP_EDOM |
Math argument out of domain of function. | (33) // Math argument out of domain of func |
MP_EEXIST |
Indicates that a file or directory already exists. | (17) // File exists |
MP_EFAULT |
Indicates a bad address error with a value of 14. | (14) // Bad address |
MP_EFBIG |
Indicates that a file is too large. | (27) // File too large |
MP_EHOSTUNREACH |
Indicates that there is no route to the host. | (113) // No route to host |
MP_EINPROGRESS |
Indicates that an operation is currently in progress. | (115) // Operation now in progress |
MP_EINTR |
Represents an interrupted system call error with a value of 4. | (4) // Interrupted system call |
MP_EINVAL |
Error code indicating an invalid argument. | (22) // Invalid argument |
MP_EIO |
Represents an I/O error with a value of 5. | (5) // I/O error |
MP_EISCONN |
Error code indicating that a transport endpoint is already connected. | (106) // Transport endpoint is already connected |
MP_EISDIR |
Error code indicating that the operation is attempted on a directory. | (21) // Is a directory |
MP_EMFILE |
Error code indicating too many open files. | (24) // Too many open files |
MP_EMLINK |
Error code indicating too many links to a file. | (31) // Too many links |
MP_ENCODE_UINT_MAX_BYTES |
Calculates the maximum number of bytes needed to encode an unsigned integer using a variable-length encoding scheme. | ((MP_BYTES_PER_OBJ_WORD * 8 + 6) / 7) |
MP_ENDIANNESS_BIG |
Indicates big-endian byte order, defined as the negation of MP_ENDIANNESS_LITTLE. | (!MP_ENDIANNESS_LITTLE) |
MP_ENDIANNESS_LITTLE |
Indicates little-endian byte order, primarily for compatibility with Windows. | (1) |
MP_ENDPOINT_IS_SERVER |
Indicates that the endpoint is a server in the TLS/DTLS protocol. | (1 << 0) |
MP_ENFILE |
Indicates a file table overflow error. | (23) // File table overflow |
MP_ENOBUFS |
Indicates that no buffer space is available. | (105) // No buffer space available |
MP_ENODEV |
Error code indicating that no such device exists. | (19) // No such device |
MP_ENOENT |
Error code indicating no such file or directory. | (2) // No such file or directory |
MP_ENOEXEC |
Error code indicating an exec format error. | (8) // Exec format error |
MP_ENOMEM |
Indicates an out of memory error. | (12) // Out of memory |
MP_ENOSPC |
Error code indicating no space left on device. | (28) // No space left on device |
MP_ENOTBLK |
Error code indicating a block device is required. | (15) // Block device required |
MP_ENOTCONN |
Indicates that a transport endpoint is not connected. | (107) // Transport endpoint is not connected |
MP_ENOTDIR |
Error code indicating that a specified path is not a directory. | (20) // Not a directory |
MP_ENOTTY |
Error code indicating that the operation is not supported on the specified device. | (25) // Not a typewriter |
MP_ENXIO |
Error code indicating no such device or address. | (6) // No such device or address |
MP_EOPNOTSUPP |
Indicates that an operation is not supported on the transport endpoint. | (95) // Operation not supported on transport endpoint |
MP_EPERM |
Indicates that an operation is not permitted. | (1) // Operation not permitted |
MP_EPIPE |
Error code for a broken pipe. | (32) // Broken pipe |
MP_ERANGE |
Math result not representable. | (34) // Math result not representable |
MP_EROFS |
Indicates a read-only file system error. | (30) // Read-only file system |
MP_ESPIPE |
Error code for illegal seek operation. | (29) // Illegal seek |
MP_ESRCH |
Error code indicating no such process. | (3) // No such process |
MP_ETIMEDOUT |
Error code indicating a connection timed out. | (110) // Connection timed out |
MP_ETXTBSY |
Error code indicating that a text file is busy. | (26) // Text file busy |
MP_EWOULDBLOCK |
Indicates that an operation would block, often used in non-blocking I/O scenarios. | MP_EAGAIN // Operation would block |
MP_EXDEV |
Error code for cross-device link. | (18) // Cross-device link |
MP_FALLTHROUGH |
Annotates intentional fall-through behavior in switch-case statements. | attribute((fallthrough)); |
MP_FFUINT_FMT |
Format specifier for unsigned long integers in floating-point formatting. | "%lu" |
MP_FLOAT_EXP_BIAS |
Calculates the exponent bias for floating-point representation. | ((1 << (MP_FLOAT_EXP_BITS - 1)) - 1) |
MP_FLOAT_EXP_BITS |
Defines the number of bits used for the exponent in floating-point representation. | (11) |
MP_FLOAT_EXP_OFFSET |
Represents the exponent offset for floating-point numbers in double precision format. | (1023) |
MP_FLOAT_EXP_SHIFT_I32 |
Calculates the shift amount for the exponent in a floating-point representation based on fractional bits. | (MP_FLOAT_FRAC_BITS % 32) |
MP_FLOAT_FRAC_BITS |
Defines the number of bits used for the fractional part of floating-point numbers, set to 52 for double precision. | (52) |
MP_FLOAT_REPR_PREC |
Sets the precision value for optimal float representation behavior. | (99) // magic prec value for optimal repr behaviour |
MP_FLOAT_SIGN_SHIFT_I32 |
Calculates the bit position for the sign bit in a 32-bit integer representation of a floating-point number. | ((MP_FLOAT_FRAC_BITS + MP_FLOAT_EXP_BITS) % 32) |
MP_FROZEN_PATH_PREFIX |
Indicates the virtual sys.path entry for frozen modules, prefixed with '.frozen/'. | ".frozen/" |
MP_FROZEN_STR_NAMES |
Contains a list of frozen module names for inclusion in the build. | \ |
MP_GCC_HAS_BUILTIN_OVERFLOW |
Indicates support for GCC's integer overflow builtins starting from version 5. | (GNUC >= 5) |
MP_HW_SPI_MAX_XFER_BITS |
Calculates the maximum transfer size in bits for SPI transactions based on the maximum transfer size in bytes. | (MP_HW_SPI_MAX_XFER_BYTES * 8) // Has to be an even multiple of 8 |
MP_HW_SPI_MAX_XFER_BYTES |
Maximum number of bytes that can be transferred in a single SPI transaction, set to 4092. | (4092) |
MP_IGMP_IP_ADDR_TYPE |
Defines the IP address type used for IGMP operations, varying based on LWIP version. | ip4_addr_t |
MP_INT_MAX |
Defines the maximum value for integer types based on the pointer size. | INTPTR_MAX |
MP_INT_MIN |
Represents the minimum value for signed integer types. | INTPTR_MIN |
MP_INT_TYPE |
Determines the integer type used for mp_int_t based on the object representation. | (MP_INT_TYPE_INTPTR) |
MP_INT_TYPE_INT64 |
Indicates the use of 64-bit integers for the mp_int_t type. | (1) |
MP_INT_TYPE_INTPTR |
Defines the integer type as a pointer-sized integer for mp_int_t and mp_uint_t. | (0) |
MP_INT_TYPE_OTHER |
Indicates a custom integer type for exceptions requiring specific typedefs and defines. | (2) |
MP_LEXER_EOF |
Represents the end-of-file character in the lexer as a null character ('\0'). Examples include checking for end of input in lexer functions. | ('\0') |
MP_LEXER_INVALID_BYTE |
Represents an invalid byte in the lexer, used to differentiate from valid end-of-stream markers. | ('\1') |
MP_MACHINE_I2C_FLAG_READ |
Indicates a read operation in I2C communication; if not set, a write operation occurs. | (0x01) // if not set then it's a write |
MP_MACHINE_I2C_FLAG_STOP |
Indicates that a STOP condition should be sent after an I2C transaction. | (0x02) |
MP_MACHINE_I2C_FLAG_WRITE1 |
Indicates that the first buffer in an I2C transfer is a write operation. | (0x04) |
MP_MAP_SLOT_IS_FILLED |
Checks if a specific slot in a map is filled with an element. | mp_map_slot_is_filled |
MP_MAX_UNCOMPRESSED_TEXT_LEN |
Determines the maximum length for uncompressed error text strings. | (73) |
MP_NATIVE_TYPE_BOOL |
Represents the native boolean type in function signatures. | (0x01) |
MP_NATIVE_TYPE_INT |
Represents the native integer type in function signatures. | (0x02) |
MP_NATIVE_TYPE_OBJ |
Represents the object type in native (viper) function signatures. | (0x00) |
MP_NATIVE_TYPE_PTR |
Represents a pointer type in native function signatures. | (0x04) |
MP_NATIVE_TYPE_PTR16 |
Represents a 16-bit pointer type. | (0x06) |
MP_NATIVE_TYPE_PTR32 |
Represents a 32-bit pointer type in native code. | (0x07) |
MP_NATIVE_TYPE_PTR8 |
Represents a pointer type with 8-bit addressing. | (0x05) |
MP_NATIVE_TYPE_QSTR |
Indicates the QSTR type for dynamic native modules. | (0x08) |
MP_NATIVE_TYPE_UINT |
Represents the unsigned integer type in native function signatures. | (0x03) |
MP_NEED_LOG2 |
Indicates the requirement for a non-macro implementation of the log2 function. | (1) |
MP_NOINLINE |
Prevents function inlining to manage stack usage and maintain function call integrity. | attribute((noinline)) |
MP_NORETURN |
Indicates that a function does not return to the caller. | attribute((noreturn)) |
MP_PARSE_NODE_ID |
Represents a parse node type for identifiers. | (0x02) |
MP_PARSE_NODE_NULL |
Represents a null parse node value. | (0) |
MP_PARSE_NODE_SMALL_INT |
Represents a small integer node in the parse tree. | (0x1) |
MP_PARSE_NODE_STRING |
Represents a parse node for string literals. | (0x06) |
MP_PARSE_NODE_TOKEN |
Represents a token node in the parse tree. | (0x0a) |
MP_PI |
Represents the mathematical constant π with high precision. | MICROPY_FLOAT_CONST(3.14159265358979323846) |
MP_PIN_INPUT |
Represents the input mode for a pin. | (3) |
MP_PIN_OUTPUT |
Represents a pin configured for output mode. | (4) |
MP_PIN_READ |
Indicates a request to read the value from a pin. | (1) |
MP_PIN_WRITE |
Indicates a request to write a value to a pin. | (2) |
MP_PI_4 |
Represents the value of π/4 as a constant float. | MICROPY_FLOAT_CONST(0.78539816339744830962) |
MP_PROTOCOL_DTLS_CLIENT |
Indicates the use of DTLS protocol for client connections. | MP_TRANSPORT_IS_DTLS |
MP_PROTOCOL_DTLS_SERVER |
Indicates a DTLS server endpoint with transport layer security. | (MP_ENDPOINT_IS_SERVER | MP_TRANSPORT_IS_DTLS) |
MP_PROTOCOL_TLS_CLIENT |
Indicates the TLS client protocol. | 0 |
MP_PROTOCOL_TLS_SERVER |
Indicates the use of TLS protocol for server endpoints. | MP_ENDPOINT_IS_SERVER |
MP_PROTO_FUN_INDICATOR_RAW_CODE_0 |
Indicates a pointer to a raw code structure for distinguishing between bytecode and raw code. | (0) |
MP_PROTO_FUN_INDICATOR_RAW_CODE_1 |
Indicates a raw code function pointer in the proto_fun_indicator array. | (0) |
MP_PYSTACK_DEBUG |
Enables memory allocation debugging to verify consistency between allocated and freed memory. | (0) |
MP_PYTHON_PRINTER |
Points to the function used for printing output, typically the standard output stream. | &mp_sys_stdout_print |
MP_READER_EOF |
Indicates the end of the input stream for the readbyte function. | ((mp_uint_t)(-1)) |
MP_READER_IS_ROM |
Indicates that the data is in ROM and remains valid until a soft reset. | ((size_t)-1) |
MP_ROM_FALSE |
Represents the constant false value as a read-only pointer. | MP_ROM_PTR(&mp_const_false_obj) |
MP_ROM_NONE |
Represents a constant pointer to the None object. | MP_ROM_PTR(&mp_const_none_obj) |
MP_ROM_TRUE |
Represents a constant pointer to the true object. | MP_ROM_PTR(&mp_const_true_obj) |
MP_SANITIZER_BUILD |
Enables sanitizer features based on the presence of UBSAN or ASAN. | (MP_UBSAN || MP_ASAN) |
MP_SCHED_IDLE |
Indicates that the scheduler is in an idle state. | (1) |
MP_SCHED_LOCKED |
Indicates that the scheduler is in a locked state, preventing task switching. | (-1) |
MP_SCHED_PENDING |
Indicates that the scheduler has pending tasks to execute. | (0) // 0 so it's a quick check in the VM |
MP_SEEK_CUR |
Indicates seeking from the current position in a stream. | (1) |
MP_SEEK_END |
Indicates seeking to the end of a stream. | (2) |
MP_SEEK_SET |
Indicates the start of a stream for seeking operations. | (0) |
MP_SET_SLOT_IS_FILLED |
Determines if a slot in a map is filled. | mp_set_slot_is_filled |
MP_SMALL_INT_BITS |
Number of bits in a small integer, including the sign bit. | (MP_IMAX_BITS(MP_SMALL_INT_MAX) + 1) |
MP_SMALL_INT_MAX |
Maximum value for small integers, calculated as the bitwise negation of the minimum small integer. | ((mp_int_t)(~(MP_SMALL_INT_MIN))) |
MP_SMALL_INT_MIN |
Defines the minimum value for small integers based on the highest bit representation. | ((mp_int_t)(((mp_int_t)MP_OBJ_WORD_MSBIT_HIGH) >> 1)) |
MP_SMALL_INT_POSITIVE_MASK |
Mask for truncating mp_int_t to positive values. | ~(MP_OBJ_WORD_MSBIT_HIGH | (MP_OBJ_WORD_MSBIT_HIGH >> 1) | (MP_OBJ_WORD_MSBIT_HIGH >> 2)) |
MP_SPIFLASH_ERASE_BLOCK_SIZE |
Defines the erase block size for SPI flash, set to 4096 bytes. | (4096) // must be a power of 2 |
MP_SSIZE_MAX |
Defines the maximum size for signed integers, typically set to the largest value for ssize_t. | (0x7fffffffffffffff) |
MP_STATE_PORT |
Accesses port-specific state variables, typically for managing resources like I2C targets or network interfaces. | MP_STATE_VM |
MP_STATIC_ASSERT_STR_ARRAY_COMPATIBLE |
Ensures compatibility of mp_obj_str_t and mp_obj_array_t by checking offset alignment of their struct members. | \ |
MP_S_IFDIR |
Represents a directory in the file system with a value of 0x4000. | (0x4000) |
MP_S_IFREG |
Represents a regular file type in the filesystem. | (0x8000) |
MP_TASK_COREID |
Determines the core ID for task creation based on FreeRTOS configuration. | (0) |
MP_TASK_PRIORITY |
Defines the priority level for the MicroPython task in FreeRTOS. | (ESP_TASK_PRIO_MIN + 1) |
MP_THREAD_DEFAULT_STACK_SIZE |
Calculates the default stack size for threads by adding minimum stack size and stack check margin. | (MP_THREAD_MIN_STACK_SIZE + MICROPY_STACK_CHECK_MARGIN) |
MP_THREAD_GC_SIGNAL |
Signal used for triggering garbage collection in multi-threaded environments. | (SIGRTMIN + 5) |
MP_THREAD_MAXIMUM_USER_THREADS |
Limits the maximum number of user threads that can be created. | (4) |
MP_THREAD_MIN_STACK_SIZE |
Defines the minimum stack size for threads, set to 4 KB. | (4 * 1024) |
MP_THREAD_PRIORITY |
Sets the thread priority to match the main thread's priority. | (k_thread_priority_get(k_current_get())) // same priority as the main thread |
MP_THREAD_TERMINATE_SIGNAL |
Signal used for terminating threads on Android platforms. | (SIGRTMIN + 6) |
MP_TRANSPORT_IS_DTLS |
Indicates the use of Datagram Transport Layer Security (DTLS) protocol. | (1 << 1) |
MP_UART_ALLOWED_FLAGS |
Bitwise OR of IRQ flags permitted for user configuration. | (UART_UARTMIS_RTMIS_BITS | UART_UARTMIS_TXMIS_BITS | UART_UARTMIS_BEMIS_BITS) |
MP_UART_IRQ_RX |
Indicates a receive interrupt for UART. | (1) |
MP_UART_IRQ_RXIDLE |
Indicates the UART RX idle interrupt event. | (2) |
MP_UART_IRQ_TXIDLE |
Indicates the UART transmit idle interrupt. | (4) |
MP_UART_RESERVED_FLAGS |
IRQ flags that are not to be modified by the user. | ((uint16_t)0x0020) |
MP_UBSAN |
Enables support for the Undefined Behavior Sanitizer if detected by the compiler. | __has_feature(undefined_behavior_sanitizer) |
MP_UINT_MAX |
Represents the maximum value for unsigned integers based on the pointer type. | INTPTR_UMAX |
MP_UNARY_OP_NUM_BYTECODE |
Defines the count of unary operation bytecode instructions. | (MP_UNARY_OP_NOT + 1) |
MP_UNARY_OP_NUM_RUNTIME |
Count of unary operations available at runtime. | (MP_UNARY_OP_SIZEOF + 1) |
MP_UNREACHABLE |
Indicates unreachable code, allowing the compiler to optimize accordingly. | __builtin_unreachable(); |
MP_USBD_BUILTIN_DESC_CFG_LEN |
Calculates the length of the built-in USB configuration descriptor. | (TUD_CONFIG_DESC_LEN + \ |
MP_USBD_MAX_PEND_EXCS |
Limits the number of pending exceptions during a TinyUSB task execution. | 2 |
MP_VFS_NONE |
Indicates that a path was not found in the virtual file system. | ((mp_vfs_mount_t *)1) |
MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS |
Returns the number of segments in the ROM filesystem. | (1) // rom_ioctl(1) |
MP_VFS_ROM_IOCTL_GET_SEGMENT |
Retrieves a segment of the ROM filesystem. | (2) // rom_ioctl(2, ) |
MP_VFS_ROM_IOCTL_WRITE |
Initiates a write operation to ROM with specified parameters. | (4) // rom_ioctl(4, , , ) |
MP_VFS_ROM_IOCTL_WRITE_COMPLETE |
Indicates completion of a write operation in the VFS ROM IOCTL interface. | (5) // rom_ioctl(5, ) |
MP_VFS_ROM_IOCTL_WRITE_PREPARE |
Prepares for writing to a ROM filesystem by specifying the destination and length. | (3) // rom_ioctl(3, , ) |
MP_VFS_ROOT |
Represents the root directory in the virtual file system. | ((mp_vfs_mount_t *)0) |
MP_WEAK |
Marks a function as weak, allowing it to be overridden by other definitions. | attribute((weak)) |