29
29
#include "py/runtime.h"
30
30
#include "py/objarray.h"
31
31
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"
34
34
#include "common-hal/busio/SPI.h"
35
35
#include "shared-bindings/busio/SPI.h"
36
36
#include "shared-bindings/microcontroller/Pin.h"
37
37
#include "supervisor/flash.h"
38
38
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')"""
70
69
71
70
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 };
73
72
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 } },
76
75
{ MP_QSTR_baudrate , MP_ARG_INT , {.u_int = 8000000 } },
76
+ { MP_QSTR_sdio , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_int = 8000000 } },
77
77
};
78
78
MP_STATIC_ASSERT ( MP_ARRAY_SIZE (allowed_args ) == NUM_ARGS );
79
79
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
83
83
mcu_pin_obj_t * cs = validate_obj_is_free_pin (args [ARG_cs ].u_obj );
84
84
85
85
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 ;
87
87
88
88
common_hal_sdcardio_sdcard_construct (self , spi , cs , args [ARG_baudrate ].u_int );
89
89
90
90
return self ;
91
91
}
92
92
93
93
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
+ //|
100
101
mp_obj_t sdcardio_sdcard_count (mp_obj_t self_in ) {
101
102
sdcardio_sdcard_obj_t * self = (sdcardio_sdcard_obj_t * )self_in ;
102
103
return mp_obj_new_int_from_ull (common_hal_sdcardio_sdcard_get_blockcount (self ));
103
104
}
104
105
MP_DEFINE_CONST_FUN_OBJ_1 (sdcardio_sdcard_count_obj , sdcardio_sdcard_count );
105
106
106
- //| .. method:: deinit
107
- //|
108
- //| Disable permanently.
107
+ //| def deinit():
108
+ //| """Disable permanently.
109
109
//|
110
- //| :return: None
110
+ //| :return: None"""
111
111
//|
112
112
mp_obj_t sdcardio_sdcard_deinit (mp_obj_t self_in ) {
113
113
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) {
117
117
MP_DEFINE_CONST_FUN_OBJ_1 (sdcardio_sdcard_deinit_obj , sdcardio_sdcard_deinit );
118
118
119
119
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):
126
121
//|
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"""
128
128
//|
129
129
130
130
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
141
141
142
142
MP_DEFINE_CONST_FUN_OBJ_3 (sdcardio_sdcard_readblocks_obj , sdcardio_sdcard_readblocks );
143
143
144
- //| .. method:: writeblocks
144
+ //| def writeblocks(start_block: int, buf: bytearray):
145
145
//|
146
- //| Write one or more blocks to the card
146
+ //| """ Write one or more blocks to the card
147
147
//|
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.
150
150
//|
151
- //| :return: None
151
+ //| :return: None"""
152
152
//|
153
153
154
154
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[] = {
172
172
};
173
173
STATIC MP_DEFINE_CONST_DICT (sdcardio_sdcard_locals_dict , sdcardio_sdcard_locals_dict_table );
174
174
175
- const mp_obj_type_t sdcardio_SDCard_type = {
175
+ const mp_obj_type_t sdcardio_SPISDCard_type = {
176
176
{ & mp_type_type },
177
- .name = MP_QSTR_SDCard ,
177
+ .name = MP_QSTR_SPISDCard ,
178
178
.make_new = sdcardio_sdcard_make_new ,
179
179
.locals_dict = (mp_obj_dict_t * )& sdcardio_sdcard_locals_dict ,
180
180
};
0 commit comments