Did stage, socket, storage

This commit is contained in:
dherrada 2020-05-11 13:40:02 -04:00
parent c7a9d49cba
commit 603df58f97
No known key found for this signature in database
GPG Key ID: CE2ADBAB8775CE81
5 changed files with 196 additions and 192 deletions

View File

@ -30,14 +30,14 @@
#include "Layer.h" #include "Layer.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
//| .. currentmodule:: _stage //| class Layer:
//| """.. currentmodule:: _stage
//| //|
//| :class:`Layer` -- Keep information about a single layer of graphics //| :class:`Layer` -- Keep information about a single layer of graphics
//| =================================================================== //| ==================================================================="""
//| //|
//| .. class:: Layer(width, height, graphic, palette, [grid]) //| def __init__(self, width: int, height: int, graphic: bytearray, palette: bytearray, grid: bytearray):
//| //| """Keep internal information about a layer of graphics (either a
//| Keep internal information about a layer of graphics (either a
//| ``Grid`` or a ``Sprite``) in a format suitable for fast rendering //| ``Grid`` or a ``Sprite``) in a format suitable for fast rendering
//| with the ``render()`` function. //| with the ``render()`` function.
//| //|
@ -48,7 +48,8 @@
//| :param bytearray grid: The contents of the grid map. //| :param bytearray grid: The contents of the grid map.
//| //|
//| This class is intended for internal use in the ``stage`` library and //| This class is intended for internal use in the ``stage`` library and
//| it shouldn't be used on its own. //| it shouldn't be used on its own."""
//| ...
//| //|
STATIC mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args,
const mp_obj_t *args, mp_map_t *kw_args) { const mp_obj_t *args, mp_map_t *kw_args) {
@ -90,9 +91,9 @@ STATIC mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args,
return MP_OBJ_FROM_PTR(self); return MP_OBJ_FROM_PTR(self);
} }
//| .. method:: move(x, y) //| def move(self, x: Any, y: Any) -> Any:
//| //| """Set the offset of the layer to the specified values."""
//| Set the offset of the layer to the specified values. //| ...
//| //|
STATIC mp_obj_t layer_move(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { STATIC mp_obj_t layer_move(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
layer_obj_t *self = MP_OBJ_TO_PTR(self_in); layer_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -102,10 +103,10 @@ STATIC mp_obj_t layer_move(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_3(layer_move_obj, layer_move); STATIC MP_DEFINE_CONST_FUN_OBJ_3(layer_move_obj, layer_move);
//| .. method:: frame(frame, rotation) //| def frame(self, frame: Any, rotation: Any) -> Any:
//| //| """Set the animation frame of the sprite, and optionally rotation its
//| Set the animation frame of the sprite, and optionally rotation its //| graphic."""
//| graphic. //| ...
//| //|
STATIC mp_obj_t layer_frame(mp_obj_t self_in, mp_obj_t frame_in, STATIC mp_obj_t layer_frame(mp_obj_t self_in, mp_obj_t frame_in,
mp_obj_t rotation_in) { mp_obj_t rotation_in) {

View File

@ -30,14 +30,14 @@
#include "Text.h" #include "Text.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
//| .. currentmodule:: _stage //| class Text:
//| """.. currentmodule:: _stage
//| //|
//| :class:`Text` -- Keep information about a single text of text //| :class:`Text` -- Keep information about a single text of text
//| ============================================================== //| =============================================================="""
//| //|
//| .. class:: Text(width, height, font, palette, chars) //| def __init__(self, width: int, height: int, font: bytearray, palette: bytearray, chars: bytearray):
//| //| """Keep internal information about a text of text
//| Keep internal information about a text of text
//| in a format suitable for fast rendering //| in a format suitable for fast rendering
//| with the ``render()`` function. //| with the ``render()`` function.
//| //|
@ -48,7 +48,8 @@
//| :param bytearray chars: The contents of the character grid. //| :param bytearray chars: The contents of the character grid.
//| //|
//| This class is intended for internal use in the ``stage`` library and //| This class is intended for internal use in the ``stage`` library and
//| it shouldn't be used on its own. //| it shouldn't be used on its own."""
//| ...
//| //|
STATIC mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args,
const mp_obj_t *args, mp_map_t *kw_args) { const mp_obj_t *args, mp_map_t *kw_args) {
@ -84,9 +85,9 @@ STATIC mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args,
return MP_OBJ_FROM_PTR(self); return MP_OBJ_FROM_PTR(self);
} }
//| .. method:: move(x, y) //| def move(self, x: Any, y: Any) -> Any:
//| //| """Set the offset of the text to the specified values."""
//| Set the offset of the text to the specified values. //| ...
//| //|
STATIC mp_obj_t text_move(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { STATIC mp_obj_t text_move(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
text_obj_t *self = MP_OBJ_TO_PTR(self_in); text_obj_t *self = MP_OBJ_TO_PTR(self_in);

View File

@ -34,7 +34,7 @@
#include "Layer.h" #include "Layer.h"
#include "Text.h" #include "Text.h"
//| :mod:`_stage` --- C-level helpers for animation of sprites on a stage //| """:mod:`_stage` --- C-level helpers for animation of sprites on a stage
//| ===================================================================== //| =====================================================================
//| //|
//| .. module:: _stage //| .. module:: _stage
@ -49,11 +49,10 @@
//| :maxdepth: 3 //| :maxdepth: 3
//| //|
//| Layer //| Layer
//| Text //| Text"""
//| //|
//| .. function:: render(x0, y0, x1, y1, layers, buffer, display[, scale[, background]]) //| def render(x0: int, y0: int, x1: int, y1: int, layers: list, buffer: bytearray, display: displayio.Display, scale: int, background: int) -> Any:
//| //| """Render and send to the display a fragment of the screen.
//| Render and send to the display a fragment of the screen.
//| //|
//| :param int x0: Left edge of the fragment. //| :param int x0: Left edge of the fragment.
//| :param int y0: Top edge of the fragment. //| :param int y0: Top edge of the fragment.
@ -70,7 +69,8 @@
//| valid. //| valid.
//| //|
//| This function is intended for internal use in the ``stage`` library //| This function is intended for internal use in the ``stage`` library
//| and all the necessary checks are performed there. //| and all the necessary checks are performed there."""
//|
STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) {
uint16_t x0 = mp_obj_get_int(args[0]); uint16_t x0 = mp_obj_get_int(args[0]);
uint16_t y0 = mp_obj_get_int(args[1]); uint16_t y0 = mp_obj_get_int(args[1]);

View File

@ -37,27 +37,28 @@
#include "shared-module/network/__init__.h" #include "shared-module/network/__init__.h"
//| :mod:`socket` --- TCP, UDP and RAW socket support //| """:mod:`socket` --- TCP, UDP and RAW socket support
//| ================================================= //| =================================================
//| //|
//| .. module:: socket //| .. module:: socket
//| :synopsis: TCP, UDP and RAW sockets //| :synopsis: TCP, UDP and RAW sockets
//| :platform: SAMD21, SAMD51 //| :platform: SAMD21, SAMD51
//| //|
//| Create TCP, UDP and RAW sockets for communicating over the Internet. //| Create TCP, UDP and RAW sockets for communicating over the Internet."""
//| //|
STATIC const mp_obj_type_t socket_type; STATIC const mp_obj_type_t socket_type;
//| .. currentmodule:: socket //| class socket:
//| """.. currentmodule:: socket"""
//| //|
//| .. class:: socket(family, type, proto) //| def __init__(self, family: int, type: int, proto: int):
//| //| """Create a new socket
//| Create a new socket
//| //|
//| :param ~int family: AF_INET or AF_INET6 //| :param ~int family: AF_INET or AF_INET6
//| :param ~int type: SOCK_STREAM, SOCK_DGRAM or SOCK_RAW //| :param ~int type: SOCK_STREAM, SOCK_DGRAM or SOCK_RAW
//| :param ~int proto: IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW (ignored) //| :param ~int proto: IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW (ignored)"""
//| ...
//| //|
STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
@ -98,11 +99,11 @@ STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
} }
} }
//| .. method:: bind(address) //| def bind(self, address: tuple) -> Any:
//| """Bind a socket to an address
//| //|
//| Bind a socket to an address //| :param ~tuple address: tuple of (remote_address, remote_port)"""
//| //| ...
//| :param ~tuple address: tuple of (remote_address, remote_port)
//| //|
STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
@ -125,11 +126,11 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
//| .. method:: listen(backlog) //| def listen(self, backlog: int) -> Any:
//| """Set socket to listen for incoming connections
//| //|
//| Set socket to listen for incoming connections //| :param ~int backlog: length of backlog queue for waiting connetions"""
//| //| ...
//| :param ~int backlog: length of backlog queue for waiting connetions
//| //|
STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) { STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
@ -150,11 +151,10 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen); STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen);
//| .. method:: accept() //| def accept(self, ) -> Any:
//| //| """Accept a connection on a listening socket of type SOCK_STREAM,
//| Accept a connection on a listening socket of type SOCK_STREAM,
//| creating a new socket of type SOCK_STREAM. //| creating a new socket of type SOCK_STREAM.
//| Returns a tuple of (new_socket, remote_address) //| Returns a tuple of (new_socket, remote_address)"""
//| //|
STATIC mp_obj_t socket_accept(mp_obj_t self_in) { STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
@ -188,11 +188,11 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
//| .. method:: connect(address) //| def connect(self, address: tuple) -> Any:
//| """Connect a socket to a remote address
//| //|
//| Connect a socket to a remote address //| :param ~tuple address: tuple of (remote_address, remote_port)"""
//| //| ...
//| :param ~tuple address: tuple of (remote_address, remote_port)
//| //|
STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
@ -215,12 +215,12 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
//| .. method:: send(bytes) //| def send(self, bytes: bytes) -> Any:
//| //| """Send some bytes to the connected remote address.
//| Send some bytes to the connected remote address.
//| Suits sockets of type SOCK_STREAM //| Suits sockets of type SOCK_STREAM
//| //|
//| :param ~bytes bytes: some bytes to send //| :param ~bytes bytes: some bytes to send"""
//| ...
//| //|
STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
@ -252,9 +252,8 @@ STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_
} }
//| .. method:: recv_into(buffer[, bufsize]) //| def recv_into(self, buffer: bytearray, bufsize: int) -> Any:
//| //| """Reads some bytes from the connected remote address, writing
//| Reads some bytes from the connected remote address, writing
//| into the provided buffer. If bufsize <= len(buffer) is given, //| into the provided buffer. If bufsize <= len(buffer) is given,
//| a maximum of bufsize bytes will be read into the buffer. If no //| a maximum of bufsize bytes will be read into the buffer. If no
//| valid value is given for bufsize, the default is the length of //| valid value is given for bufsize, the default is the length of
@ -264,7 +263,9 @@ STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_
//| Returns an int of number of bytes read. //| Returns an int of number of bytes read.
//| //|
//| :param bytearray buffer: buffer to receive into //| :param bytearray buffer: buffer to receive into
//| :param int bufsize: optionally, a maximum number of bytes to read. //| :param int bufsize: optionally, a maximum number of bytes to read."""
//| ...
//|
STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]);
@ -287,13 +288,14 @@ STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_into_obj, 2, 3, socket_recv_into); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_into_obj, 2, 3, socket_recv_into);
//| .. method:: recv(bufsize) //| def recv(self, bufsize: int) -> Any:
//| //| """Reads some bytes from the connected remote address.
//| Reads some bytes from the connected remote address.
//| Suits sockets of type SOCK_STREAM //| Suits sockets of type SOCK_STREAM
//| Returns a bytes() of length <= bufsize //| Returns a bytes() of length <= bufsize
//| //|
//| :param ~int bufsize: maximum number of bytes to receive //| :param ~int bufsize: maximum number of bytes to receive"""
//| ...
//|
STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -313,13 +315,13 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv);
//| .. method:: sendto(bytes, address) //| def sendto(self, bytes: bytes, address: tuple) -> Any:
//| //| """Send some bytes to a specific address.
//| Send some bytes to a specific address.
//| Suits sockets of type SOCK_DGRAM //| Suits sockets of type SOCK_DGRAM
//| //|
//| :param ~bytes bytes: some bytes to send //| :param ~bytes bytes: some bytes to send
//| :param ~tuple address: tuple of (remote_address, remote_port) //| :param ~tuple address: tuple of (remote_address, remote_port)"""
//| ...
//| //|
STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) {
@ -347,16 +349,16 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto); STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
//| .. method:: recvfrom(bufsize) //| def recvfrom(self, bufsize: int) -> Any:
//| //| """Reads some bytes from the connected remote address.
//| Reads some bytes from the connected remote address.
//| Suits sockets of type SOCK_STREAM //| Suits sockets of type SOCK_STREAM
//| //|
//| Returns a tuple containing //| Returns a tuple containing
//| * a bytes() of length <= bufsize //| * a bytes() of length <= bufsize
//| * a remote_address, which is a tuple of ip address and port number //| * a remote_address, which is a tuple of ip address and port number
//| //|
//| :param ~int bufsize: maximum number of bytes to receive //| :param ~int bufsize: maximum number of bytes to receive"""
//| ...
//| //|
STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
@ -386,9 +388,9 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom); STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
//| .. method:: setsockopt(level, optname, value) //| def setsockopt(self, level: Any, optname: Any, value: Any) -> Any:
//| //| """Sets socket options"""
//| Sets socket options //| ...
//| //|
STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
@ -420,11 +422,11 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt);
//| .. method:: settimeout(value) //| def settimeout(self, value: int) -> Any:
//| """Set the timeout value for this socket.
//| //|
//| Set the timeout value for this socket. //| :param ~int value: timeout in seconds. 0 means non-blocking. None means block indefinitely."""
//| //| ...
//| :param ~int value: timeout in seconds. 0 means non-blocking. None means block indefinitely.
//| //|
STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
@ -451,11 +453,11 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout);
//| .. method:: setblocking(flag) //| def setblocking(self, flag: bool) -> Any:
//| """Set the blocking behaviour of this socket.
//| //|
//| Set the blocking behaviour of this socket. //| :param ~bool flag: False means non-blocking, True means block indefinitely."""
//| //| ...
//| :param ~bool flag: False means non-blocking, True means block indefinitely.
//| //|
// method socket.setblocking(flag) // method socket.setblocking(flag)
@ -513,13 +515,13 @@ STATIC const mp_obj_type_t socket_type = {
.locals_dict = (mp_obj_dict_t*)&socket_locals_dict, .locals_dict = (mp_obj_dict_t*)&socket_locals_dict,
}; };
//| .. function:: getaddrinfo(host, port) //| def getaddrinfo(host: Any, port: Any) -> Any:
//| //| """Gets the address information for a hostname and port
//| Gets the address information for a hostname and port
//| //|
//| Returns the appropriate family, socket type, socket protocol and //| Returns the appropriate family, socket type, socket protocol and
//| address information to call socket.socket() and socket.connect() with, //| address information to call socket.socket() and socket.connect() with,
//| as a tuple. //| as a tuple."""
//| ...
//| //|
STATIC mp_obj_t socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { STATIC mp_obj_t socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {

View File

@ -35,7 +35,7 @@
#include "shared-bindings/storage/__init__.h" #include "shared-bindings/storage/__init__.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
//| :mod:`storage` --- storage management //| """:mod:`storage` --- storage management
//| ======================================================== //| ========================================================
//| //|
//| .. module:: storage //| .. module:: storage
@ -45,16 +45,16 @@
//| The `storage` provides storage management functionality such as mounting and //| The `storage` provides storage management functionality such as mounting and
//| unmounting which is typically handled by the operating system hosting Python. //| unmounting which is typically handled by the operating system hosting Python.
//| CircuitPython does not have an OS, so this module provides this functionality //| CircuitPython does not have an OS, so this module provides this functionality
//| directly. //| directly."""
//| //|
//| .. function:: mount(filesystem, mount_path, *, readonly=False) //| def mount(filesystem: Any, mount_path: Any, *, readonly: bool = False) -> Any:
//| //| """Mounts the given filesystem object at the given path.
//| Mounts the given filesystem object at the given path.
//| //|
//| This is the CircuitPython analog to the UNIX ``mount`` command. //| This is the CircuitPython analog to the UNIX ``mount`` command.
//| //|
//| :param bool readonly: True when the filesystem should be readonly to CircuitPython. //| :param bool readonly: True when the filesystem should be readonly to CircuitPython."""
//| ...
//| //|
mp_obj_t storage_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_obj_t storage_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_readonly }; enum { ARG_readonly };
@ -85,12 +85,12 @@ mp_obj_t storage_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
} }
MP_DEFINE_CONST_FUN_OBJ_KW(storage_mount_obj, 2, storage_mount); MP_DEFINE_CONST_FUN_OBJ_KW(storage_mount_obj, 2, storage_mount);
//| .. function:: umount(mount) //| def umount(mount: Any) -> Any:
//| //| """Unmounts the given filesystem object or if *mount* is a path, then unmount
//| Unmounts the given filesystem object or if *mount* is a path, then unmount
//| the filesystem mounted at that location. //| the filesystem mounted at that location.
//| //|
//| This is the CircuitPython analog to the UNIX ``umount`` command. //| This is the CircuitPython analog to the UNIX ``umount`` command."""
//| ...
//| //|
mp_obj_t storage_umount(mp_obj_t mnt_in) { mp_obj_t storage_umount(mp_obj_t mnt_in) {
if (MP_OBJ_IS_STR(mnt_in)) { if (MP_OBJ_IS_STR(mnt_in)) {
@ -103,15 +103,15 @@ mp_obj_t storage_umount(mp_obj_t mnt_in) {
} }
MP_DEFINE_CONST_FUN_OBJ_1(storage_umount_obj, storage_umount); MP_DEFINE_CONST_FUN_OBJ_1(storage_umount_obj, storage_umount);
//| .. function:: remount(mount_path, readonly=False, *, disable_concurrent_write_protection=False) //| def remount(mount_path: Any, readonly: bool = False, *, disable_concurrent_write_protection: bool = False) -> Any:
//| //| """Remounts the given path with new parameters.
//| Remounts the given path with new parameters.
//| //|
//| :param bool readonly: True when the filesystem should be readonly to CircuitPython. //| :param bool readonly: True when the filesystem should be readonly to CircuitPython.
//| :param bool disable_concurrent_write_protection: When True, the check that makes sure the //| :param bool disable_concurrent_write_protection: When True, the check that makes sure the
//| underlying filesystem data is written by one computer is disabled. Disabling the protection //| underlying filesystem data is written by one computer is disabled. Disabling the protection
//| allows CircuitPython and a host to write to the same filesystem with the risk that the //| allows CircuitPython and a host to write to the same filesystem with the risk that the
//| filesystem will be corrupted. //| filesystem will be corrupted."""
//| ...
//| //|
mp_obj_t storage_remount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_obj_t storage_remount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_readonly, ARG_disable_concurrent_write_protection }; enum { ARG_readonly, ARG_disable_concurrent_write_protection };
@ -133,18 +133,17 @@ mp_obj_t storage_remount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
} }
MP_DEFINE_CONST_FUN_OBJ_KW(storage_remount_obj, 1, storage_remount); MP_DEFINE_CONST_FUN_OBJ_KW(storage_remount_obj, 1, storage_remount);
//| .. function:: getmount(mount_path) //| def getmount(mount_path: Any) -> Any:
//| //| """Retrieves the mount object associated with the mount path"""
//| Retrieves the mount object associated with the mount path //| ...
//| //|
mp_obj_t storage_getmount(const mp_obj_t mnt_in) { mp_obj_t storage_getmount(const mp_obj_t mnt_in) {
return common_hal_storage_getmount(mp_obj_str_get_str(mnt_in)); return common_hal_storage_getmount(mp_obj_str_get_str(mnt_in));
} }
MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount); MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
//| .. function:: erase_filesystem() //| def erase_filesystem() -> Any:
//| //| """Erase and re-create the ``CIRCUITPY`` filesystem.
//| Erase and re-create the ``CIRCUITPY`` filesystem.
//| //|
//| On boards that present USB-visible ``CIRCUITPY`` drive (e.g., SAMD21 and SAMD51), //| On boards that present USB-visible ``CIRCUITPY`` drive (e.g., SAMD21 and SAMD51),
//| then call `microcontroller.reset()` to restart CircuitPython and have the //| then call `microcontroller.reset()` to restart CircuitPython and have the
@ -154,7 +153,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
//| has become corrupted. //| has become corrupted.
//| //|
//| .. warning:: All the data on ``CIRCUITPY`` will be lost, and //| .. warning:: All the data on ``CIRCUITPY`` will be lost, and
//| CircuitPython will restart on certain boards. //| CircuitPython will restart on certain boards."""
//| ...
//|
mp_obj_t storage_erase_filesystem(void) { mp_obj_t storage_erase_filesystem(void) {
common_hal_storage_erase_filesystem(); common_hal_storage_erase_filesystem();
@ -171,54 +172,53 @@ STATIC const mp_rom_map_elem_t storage_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) }, { MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) },
{ MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) }, { MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) },
//| .. class:: VfsFat(block_device) //| class VfsFat:
//| def __init__(self, block_device: Any): ...
//| """Create a new VfsFat filesystem around the given block device.
//| //|
//| Create a new VfsFat filesystem around the given block device. //| :param block_device: Block device the the filesystem lives on"""
//| //|
//| :param block_device: Block device the the filesystem lives on //| label: Any = ...
//| //| """The filesystem label, up to 11 case-insensitive bytes. Note that
//| .. attribute:: label
//|
//| The filesystem label, up to 11 case-insensitive bytes. Note that
//| this property can only be set when the device is writable by the //| this property can only be set when the device is writable by the
//| microcontroller. //| microcontroller."""
//| //|
//| .. method:: mkfs() //| def mkfs(self, ) -> Any:
//| """Format the block device, deleting any data that may have been there"""
//| ...
//| //|
//| Format the block device, deleting any data that may have been there //| def open(self, path: Any, mode: Any) -> Any:
//| """Like builtin ``open()``"""
//| ...
//| //|
//| .. method:: open(path, mode) //| def ilistdir(self, path: Any) -> Any:
//| """Return an iterator whose values describe files and folders within
//| ``path``"""
//| ...
//| //|
//| Like builtin ``open()`` //| def mkdir(self, path: Any) -> Any:
//| """Like `os.mkdir`"""
//| ...
//| //|
//| .. method:: ilistdir([path]) //| def rmdir(self, path: Any) -> Any:
//| """Like `os.rmdir`"""
//| ...
//| //|
//| Return an iterator whose values describe files and folders within //| def stat(self, path: Any) -> Any:
//| ``path`` //| """Like `os.stat`"""
//| ...
//| //|
//| .. method:: mkdir(path) //| def statvfs(self, path: Any) -> Any:
//| """Like `os.statvfs`"""
//| ...
//| //|
//| Like `os.mkdir` //| def mount(self, readonly: Any, mkfs: Any) -> Any:
//| """Don't call this directly, call `storage.mount`."""
//| ...
//| //|
//| .. method:: rmdir(path) //| def umount(self, ) -> Any:
//| //| """Don't call this directly, call `storage.umount`."""
//| Like `os.rmdir` //| ...
//|
//| .. method:: stat(path)
//|
//| Like `os.stat`
//|
//| .. method:: statvfs(path)
//|
//| Like `os.statvfs`
//|
//| .. method:: mount(readonly, mkfs)
//|
//| Don't call this directly, call `storage.mount`.
//|
//| .. method:: umount()
//|
//| Don't call this directly, call `storage.umount`.
//| //|
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) }, { MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
}; };