diff --git a/core/embed/extmod/modtrezorio/modtrezorio-fatfs.h b/core/embed/extmod/modtrezorio/modtrezorio-fatfs.h index 4d2e8745bc..fbd3fb1e89 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-fatfs.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-fatfs.h @@ -27,9 +27,9 @@ #include "sdcard.h" // clang-format on -DSTATUS disk_initialize(BYTE pdrv) { - return disk_status(pdrv); -} +/// package: trezorio.__init__ + +DSTATUS disk_initialize(BYTE pdrv) { return disk_status(pdrv); } DSTATUS disk_status(BYTE pdrv) { return (sectrue == sdcard_is_present()) ? 0 : (STA_NOINIT | STA_NODISK); diff --git a/core/embed/extmod/modtrezorio/modtrezorio-flash.h b/core/embed/extmod/modtrezorio/modtrezorio-flash.h index 1d15ab1877..3f906b906f 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-flash.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-flash.h @@ -21,6 +21,8 @@ #include "embed/extmod/trezorobj.h" +/// package: trezorio.__init__ + /// class FlashOTP: /// """ /// """ diff --git a/core/embed/extmod/modtrezorio/modtrezorio-hid.h b/core/embed/extmod/modtrezorio/modtrezorio-hid.h index 28761e40e3..9acabb0933 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-hid.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-hid.h @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +/// package: trezorio.__init__ + /// class HID: /// """ /// USB HID interface configuration. diff --git a/core/embed/extmod/modtrezorio/modtrezorio-poll.h b/core/embed/extmod/modtrezorio/modtrezorio-poll.h index 39812c970d..ba250f78ea 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-poll.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-poll.h @@ -26,6 +26,8 @@ #define POLL_READ (0x0000) #define POLL_WRITE (0x0100) +/// package: trezorio.__init__ + /// def poll(ifaces: Iterable[int], list_ref: List, timeout_us: int) -> bool: /// """ /// Wait until one of `ifaces` is ready to read or write (using masks diff --git a/core/embed/extmod/modtrezorio/modtrezorio-sbu.h b/core/embed/extmod/modtrezorio/modtrezorio-sbu.h index e2c1e515a9..623f1b865b 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-sbu.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-sbu.h @@ -19,6 +19,8 @@ #include "sbu.h" +/// package: trezorio.__init__ + /// class SBU: /// """ /// """ diff --git a/core/embed/extmod/modtrezorio/modtrezorio-usb.h b/core/embed/extmod/modtrezorio/modtrezorio-usb.h index 042f1f8361..fff2427e17 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-usb.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-usb.h @@ -24,6 +24,8 @@ enum { USB_OPENED = 1, }; +/// package: trezorio.__init__ + /// class USB: /// """ /// USB device configuration. diff --git a/core/embed/extmod/modtrezorio/modtrezorio-vcp.h b/core/embed/extmod/modtrezorio/modtrezorio-vcp.h index 110999fee5..2253e28578 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-vcp.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-vcp.h @@ -19,6 +19,8 @@ void pendsv_kbd_intr(void); +/// package: trezorio.__init__ + /// class VCP: /// """ /// USB VCP interface configuration. diff --git a/core/embed/extmod/modtrezorio/modtrezorio-webusb.h b/core/embed/extmod/modtrezorio/modtrezorio-webusb.h index c698bc0da2..55f07cc399 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-webusb.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-webusb.h @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +/// package: trezorio.__init__ + /// class WebUSB: /// """ /// USB WebUSB interface configuration. diff --git a/core/embed/extmod/modtrezorio/modtrezorio.c b/core/embed/extmod/modtrezorio/modtrezorio.c index 6e5f01eac2..a0595f8ee0 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio.c +++ b/core/embed/extmod/modtrezorio/modtrezorio.c @@ -47,6 +47,8 @@ #include "modtrezorio-usb.h" // clang-format on +/// package: trezorio.__init__ + /// POLL_READ: int # wait until interface is readable and return read data /// POLL_WRITE: int # wait until interface is writable /// @@ -66,7 +68,7 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_SBU), MP_ROM_PTR(&mod_trezorio_SBU_type)}, - {MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&mod_trezorio_SDCard_type)}, + {MP_ROM_QSTR(MP_QSTR_sdcard), MP_ROM_PTR(&mod_trezorio_sdcard_module)}, {MP_ROM_QSTR(MP_QSTR_USB), MP_ROM_PTR(&mod_trezorio_USB_type)}, {MP_ROM_QSTR(MP_QSTR_HID), MP_ROM_PTR(&mod_trezorio_HID_type)}, diff --git a/core/mocks/generated/trezorio.pyi b/core/mocks/generated/trezorio/__init__.pyi similarity index 85% rename from core/mocks/generated/trezorio.pyi rename to core/mocks/generated/trezorio/__init__.pyi index 27db7ac0b3..70312c0417 100644 --- a/core/mocks/generated/trezorio.pyi +++ b/core/mocks/generated/trezorio/__init__.pyi @@ -220,46 +220,6 @@ class SBU: """ -# extmod/modtrezorio/modtrezorio-sdcard.h -class SDCard: - """ - """ - - def __init__(self) -> None: - """ - """ - - def present(self) -> bool: - """ - Returns True if SD card is detected, False otherwise. - """ - - def power(self, state: bool) -> bool: - """ - Power on or power off the SD card interface. - Returns True if in case of success, False otherwise. - """ - - def capacity(self) -> int: - """ - Returns capacity of the SD card in bytes, or zero if not present. - """ - - def read(self, block_num: int, buf: bytearray) -> None: - """ - Reads blocks starting with block_num from the SD card into buf. - Number of bytes read is length of buf rounded down to multiply of - SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise. - """ - - def write(self, block_num: int, buf: bytes) -> None: - """ - Writes blocks starting with block_num from buf to the SD card. - Number of bytes written is length of buf rounded down to multiply of - SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise. - """ - - # extmod/modtrezorio/modtrezorio-usb.h class USB: """ diff --git a/core/mocks/generated/trezorio/sdcard.pyi b/core/mocks/generated/trezorio/sdcard.pyi new file mode 100644 index 0000000000..b6765a7c5b --- /dev/null +++ b/core/mocks/generated/trezorio/sdcard.pyi @@ -0,0 +1,50 @@ +from typing import * +BLOCK_SIZE: int # size of SD card block + + +# extmod/modtrezorio/modtrezorio-sdcard.h +def is_present() -> bool: + """ + Returns True if SD card is detected, False otherwise. + """ + + +# extmod/modtrezorio/modtrezorio-sdcard.h +def power_on() -> None: + """ + Power on the SD card interface. + Raises OSError if the SD card cannot be powered on, e.g., when there + is no SD card inserted. + """ + + +# extmod/modtrezorio/modtrezorio-sdcard.h +def power_off() -> None: + """ + Power off the SD card interface. + """ + + +# extmod/modtrezorio/modtrezorio-sdcard.h +def capacity() -> int: + """ + Returns capacity of the SD card in bytes, or zero if not present. + """ + + +# extmod/modtrezorio/modtrezorio-sdcard.h +def read(block_num: int, buf: bytearray) -> None: + """ + Reads blocks starting with block_num from the SD card into buf. + Number of bytes read is length of buf rounded down to multiply of + SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise. + """ + + +# extmod/modtrezorio/modtrezorio-sdcard.h +def write(block_num: int, buf: bytes) -> None: + """ + Writes blocks starting with block_num from buf to the SD card. + Number of bytes written is length of buf rounded down to multiply of + SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise. + """