Skip to content

Commit 38514a8

Browse files
committed
sdcardio -> _sdcardio, SDCard -> SPISDCard, stubify
1 parent a8d73ba commit 38514a8

File tree

10 files changed

+74
-89
lines changed

10 files changed

+74
-89
lines changed

py/circuitpy_defns.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ ifeq ($(CIRCUITPY_SAMD),1)
211211
SRC_PATTERNS += samd/%
212212
endif
213213
ifeq ($(CIRCUITPY_SDCARDIO),1)
214-
SRC_PATTERNS += sdcardio/%
214+
SRC_PATTERNS += _sdcardio/%
215215
endif
216216
ifeq ($(CIRCUITPY_STAGE),1)
217217
SRC_PATTERNS += _stage/%
@@ -376,8 +376,8 @@ SRC_SHARED_MODULE_ALL = \
376376
fontio/__init__.c \
377377
framebufferio/FramebufferDisplay.c \
378378
framebufferio/__init__.c \
379-
sdcardio/SDCard.c \
380-
sdcardio/__init__.c \
379+
_sdcardio/SPISDCard.c \
380+
_sdcardio/__init__.c \
381381
gamepad/GamePad.c \
382382
gamepad/__init__.c \
383383
gamepadshift/GamePadShift.c \

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ extern const struct _mp_obj_module_t samd_module;
532532

533533
#if CIRCUITPY_SDCARDIO
534534
extern const struct _mp_obj_module_t sdcardio_module;
535-
#define SDCARDIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_sdcardio), (mp_obj_t)&sdcardio_module },
535+
#define SDCARDIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__sdcardio), (mp_obj_t)&sdcardio_module },
536536
#else
537537
#define SDCARDIO_MODULE
538538
#endif

shared-bindings/sdcardio/SDCard.c renamed to shared-bindings/_sdcardio/SPISDCard.c

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -29,51 +29,51 @@
2929
#include "py/runtime.h"
3030
#include "py/objarray.h"
3131

32-
#include "shared-bindings/sdcardio/SDCard.h"
33-
#include "shared-module/sdcardio/SDCard.h"
32+
#include "shared-bindings/_sdcardio/SPISDCard.h"
33+
#include "shared-module/_sdcardio/SPISDCard.h"
3434
#include "common-hal/busio/SPI.h"
3535
#include "shared-bindings/busio/SPI.h"
3636
#include "shared-bindings/microcontroller/Pin.h"
3737
#include "supervisor/flash.h"
3838

39-
//| .. currentmodule:: sdcardio
40-
//|
41-
//| :class:`SDCard` -- SD Card Block Interface
42-
//| ===========================================
43-
//|
44-
//| Controls an SD card over SPI. This built-in module has higher read
45-
//| performance than the library adafruit_sdcard, but it is only compatible with
46-
//| `busio.SPI`, only `bitbangio.SPI`. Usually an SDCard object is used
47-
//| with `storage.VfsFat` to allow file I/O to an SD card.
48-
//|
49-
//| .. class:: SDCard(spi, cs, baudrate)
50-
//|
51-
//| :param busio.SPI spi: The SPI bus
52-
//| :param microcontroller.Pin cs: The chip select connected to the card
53-
//| :param int baudrate: The SPI data rate to use after card setup
54-
//|
55-
//| Example usage:
56-
//|
57-
//| .. code-block:: python
58-
//|
59-
//| import os
60-
//|
61-
//| import board
62-
//| import sdcardio
63-
//| import storage
64-
//|
65-
//| sd = adafruit_sdcard.SDCard(board.SPI(), board.SD_CS)
66-
//| vfs = storage.VfsFat(sdcard)
67-
//| storage.mount(vfs, '/sd')
68-
//| os.listdir('/sd')
69-
//|
39+
//| class SPISDCard:
40+
//| """SD Card Block Interface
41+
//|
42+
//| Controls an SD card over SPI. This built-in module has higher read
43+
//| performance than the library adafruit_sdcard, but it is only compatible with
44+
//| `busio.SPI`, only `bitbangio.SPI`. Usually an SDCard object is used
45+
//| with ``storage.VfsFat`` to allow file I/O to an SD card."""
46+
//|
47+
//| def __init__(bus=None, cs=None, baudrate=8000000):
48+
//| """Construct an SPI SD Card object with the given properties
49+
//|
50+
//| :param busio.SPI spi: The SPI bus
51+
//| :param microcontroller.Pin cs: The chip select connected to the card
52+
//| :param int baudrate: The SPI data rate to use after card setup
53+
//| :param busio.SDIO sdio: The SDIO bus. Mutually exclusive with spi and cs.
54+
//|
55+
//| Example usage:
56+
//|
57+
//| .. code-block:: python
58+
//|
59+
//| import os
60+
//|
61+
//| import board
62+
//| import sdcardio
63+
//| import storage
64+
//|
65+
//| sd = adafruit_sdcard.SPISDCard(board.SPI(), board.SD_CS)
66+
//| vfs = storage.VfsFat(sd)
67+
//| storage.mount(vfs, '/sd')
68+
//| os.listdir('/sd')"""
7069

7170
STATIC mp_obj_t sdcardio_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
72-
enum { ARG_spi, ARG_cs, ARG_baudrate, NUM_ARGS };
71+
enum { ARG_spi, ARG_cs, ARG_baudrate, ARG_sdio, NUM_ARGS };
7372
static const mp_arg_t allowed_args[] = {
74-
{ MP_QSTR_spi, MP_ARG_REQUIRED | MP_ARG_OBJ },
75-
{ MP_QSTR_cs, MP_ARG_REQUIRED | MP_ARG_OBJ },
73+
{ MP_QSTR_spi, MP_ARG_OBJ, {.u_obj = mp_const_none } },
74+
{ MP_QSTR_cs, MP_ARG_OBJ, {.u_obj = mp_const_none } },
7675
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 8000000} },
76+
{ MP_QSTR_sdio, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 8000000} },
7777
};
7878
MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS );
7979
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
@@ -83,31 +83,31 @@ STATIC mp_obj_t sdcardio_sdcard_make_new(const mp_obj_type_t *type, size_t n_arg
8383
mcu_pin_obj_t *cs = validate_obj_is_free_pin(args[ARG_cs].u_obj);
8484

8585
sdcardio_sdcard_obj_t *self = m_new_obj(sdcardio_sdcard_obj_t);
86-
self->base.type = &sdcardio_SDCard_type;
86+
self->base.type = &sdcardio_SPISDCard_type;
8787

8888
common_hal_sdcardio_sdcard_construct(self, spi, cs, args[ARG_baudrate].u_int);
8989

9090
return self;
9191
}
9292

9393

94-
//| .. method:: count
95-
//|
96-
//| Returns the total number of sectors
97-
//|
98-
//| :return: The number of 512-byte blocks, as a number
99-
//|
94+
//| def count():
95+
//| """Returns the total number of sectors
96+
//|
97+
//| Due to technical limitations, this is a function and not a property.
98+
//|
99+
//| :return: The number of 512-byte blocks, as a number"""
100+
//|
100101
mp_obj_t sdcardio_sdcard_count(mp_obj_t self_in) {
101102
sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in;
102103
return mp_obj_new_int_from_ull(common_hal_sdcardio_sdcard_get_blockcount(self));
103104
}
104105
MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_count_obj, sdcardio_sdcard_count);
105106

106-
//| .. method:: deinit
107-
//|
108-
//| Disable permanently.
107+
//| def deinit():
108+
//| """Disable permanently.
109109
//|
110-
//| :return: None
110+
//| :return: None"""
111111
//|
112112
mp_obj_t sdcardio_sdcard_deinit(mp_obj_t self_in) {
113113
sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in;
@@ -117,14 +117,14 @@ mp_obj_t sdcardio_sdcard_deinit(mp_obj_t self_in) {
117117
MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_deinit_obj, sdcardio_sdcard_deinit);
118118

119119

120-
//| .. method:: readblocks
121-
//|
122-
//| Read one or more blocks from the card
123-
//|
124-
//| :param int start_block: The block to start reading from
125-
//| :param bytearray buf: The buffer to write into. Length must be multiple of 512.
120+
//| def readblocks(start_block: int, buf: bytearray):
126121
//|
127-
//| :return: None
122+
//| """Read one or more blocks from the card
123+
//|
124+
//| :param int start_block: The block to start reading from
125+
//| :param bytearray buf: The buffer to write into. Length must be multiple of 512.
126+
//|
127+
//| :return: None"""
128128
//|
129129

130130
mp_obj_t sdcardio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) {
@@ -141,14 +141,14 @@ mp_obj_t sdcardio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, m
141141

142142
MP_DEFINE_CONST_FUN_OBJ_3(sdcardio_sdcard_readblocks_obj, sdcardio_sdcard_readblocks);
143143

144-
//| .. method:: writeblocks
144+
//| def writeblocks(start_block: int, buf: bytearray):
145145
//|
146-
//| Write one or more blocks to the card
146+
//| """Write one or more blocks to the card
147147
//|
148-
//| :param int start_block: The block to start writing from
149-
//| :param bytearray buf: The buffer to read from. Length must be multiple of 512.
148+
//| :param int start_block: The block to start writing from
149+
//| :param bytearray buf: The buffer to read from. Length must be multiple of 512.
150150
//|
151-
//| :return: None
151+
//| :return: None"""
152152
//|
153153

154154
mp_obj_t sdcardio_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) {
@@ -172,9 +172,9 @@ STATIC const mp_rom_map_elem_t sdcardio_sdcard_locals_dict_table[] = {
172172
};
173173
STATIC MP_DEFINE_CONST_DICT(sdcardio_sdcard_locals_dict, sdcardio_sdcard_locals_dict_table);
174174

175-
const mp_obj_type_t sdcardio_SDCard_type = {
175+
const mp_obj_type_t sdcardio_SPISDCard_type = {
176176
{ &mp_type_type },
177-
.name = MP_QSTR_SDCard,
177+
.name = MP_QSTR_SPISDCard,
178178
.make_new = sdcardio_sdcard_make_new,
179179
.locals_dict = (mp_obj_dict_t*)&sdcardio_sdcard_locals_dict,
180180
};

shared-bindings/sdcardio/SDCard.h renamed to shared-bindings/_sdcardio/SPISDCard.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
* THE SOFTWARE.
2626
*/
2727

28-
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SDCARDIO_SDCARD_H
29-
#define MICROPY_INCLUDED_SHARED_BINDINGS_SDCARDIO_SDCARD_H
28+
#pragma once
3029

31-
extern const mp_obj_type_t sdcardio_SDCard_type;
32-
33-
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_FRAMEBUFFERDISPLAY_H
30+
extern const mp_obj_type_t sdcardio_SPISDCard_type;

shared-bindings/sdcardio/__init__.c renamed to shared-bindings/_sdcardio/__init__.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,13 @@
3030
#include "py/obj.h"
3131
#include "py/runtime.h"
3232

33-
#include "shared-bindings/sdcardio/SDCard.h"
34-
35-
//| :mod:`sdcardio` --- Low-level routines for SD card I/O
36-
//| =====================================================================
37-
//|
38-
//| .. module:: sdcardio
39-
//| :synopsis: Low-level routines for SD card I/O
40-
//|
41-
//| .. toctree::
42-
//| :maxdepth: 3
43-
//|
44-
//| SDCard
33+
#include "shared-bindings/_sdcardio/SPISDCard.h"
34+
35+
//| """Low-level routines for SD card I/O"""
4536

4637
STATIC const mp_rom_map_elem_t sdcardio_module_globals_table[] = {
47-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sdcardio) },
48-
{ MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&sdcardio_SDCard_type) },
38+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__sdcardio) },
39+
{ MP_ROM_QSTR(MP_QSTR_SPISDCard), MP_ROM_PTR(&sdcardio_SPISDCard_type) },
4940
};
5041

5142
STATIC MP_DEFINE_CONST_DICT(sdcardio_module_globals, sdcardio_module_globals_table);

shared-module/sdcardio/SDCard.c renamed to shared-module/_sdcardio/SPISDCard.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "shared-bindings/digitalio/DigitalInOut.h"
3131
#include "shared-bindings/time/__init__.h"
3232
#include "shared-bindings/util.h"
33-
#include "shared-module/sdcardio/SDCard.h"
33+
#include "shared-module/_sdcardio/SPISDCard.h"
3434

3535
#include "py/mperrno.h"
3636

shared-module/sdcardio/SDCard.h renamed to shared-module/_sdcardio/SPISDCard.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_SHARED_MODULE_SDCARDIO_SDCARD_H
28-
#define MICROPY_INCLUDED_SHARED_MODULE_SDCARDIO_SDCARD_H
27+
#pragma once
2928

3029
#include "py/obj.h"
3130
#include "py/objproperty.h"
@@ -50,5 +49,3 @@ void common_hal_sdcardio_sdcard_check_for_deinit(sdcardio_sdcard_obj_t *self);
5049
int common_hal_sdcardio_sdcard_get_blockcount(sdcardio_sdcard_obj_t *self);
5150
int common_hal_sdcardio_sdcard_readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf);
5251
int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf);
53-
54-
#endif

0 commit comments

Comments
 (0)