Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
lib/mbedtls_errors/generate_errors.diff
)
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.4.1
hooks:
- id: codespell
args: [-w]
Expand Down
11 changes: 10 additions & 1 deletion extmod/vfs_blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ void mp_vfs_blockdev_init(mp_vfs_blockdev_t *self, mp_obj_t bdev) {
#endif
#if CIRCUITPY_SDIOIO
if (mp_obj_get_type(bdev) == &sdioio_SDCard_type) {
// TODO: Enable native blockdev for SDIO too.
self->flags |= MP_BLOCKDEV_FLAG_NATIVE | MP_BLOCKDEV_FLAG_HAVE_IOCTL;
self->readblocks[0] = mp_const_none;
self->readblocks[1] = bdev;
self->readblocks[2] = (mp_obj_t)sdioio_sdcard_readblocks; // native version
self->writeblocks[0] = mp_const_none;
self->writeblocks[1] = bdev;
self->writeblocks[2] = (mp_obj_t)sdioio_sdcard_writeblocks; // native version
self->u.ioctl[0] = mp_const_none;
self->u.ioctl[1] = bdev;
self->u.ioctl[2] = (mp_obj_t)sdioio_sdcard_ioctl; // native version
}
#endif
if (self->u.ioctl[0] != MP_OBJ_NULL) {
Expand Down
36 changes: 32 additions & 4 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#: ports/raspberrypi/common-hal/usb_host/Port.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/microcontroller/Pin.c shared-module/max3421e/Max3421E.c
#: shared-bindings/i2cioexpander/IOPin.c shared-bindings/microcontroller/Pin.c
#: shared-module/max3421e/Max3421E.c
msgid "%q in use"
msgstr ""

Expand All @@ -132,7 +133,7 @@ msgid "%q indices must be integers, not %s"
msgstr ""

#: ports/analog/common-hal/busio/SPI.c ports/analog/common-hal/busio/UART.c
#: shared-module/bitbangio/SPI.c
#: shared-bindings/digitalio/DigitalInOutProtocol.c
msgid "%q init failed"
msgstr ""

Expand Down Expand Up @@ -235,6 +236,14 @@ msgstr ""
msgid "%q must be power of 2"
msgstr ""

#: shared-bindings/digitalio/DigitalInOutProtocol.c
msgid "%q object missing '%q' attribute"
msgstr ""

#: shared-bindings/digitalio/DigitalInOutProtocol.c
msgid "%q object missing '%q' method"
msgstr ""

#: shared-bindings/wifi/Monitor.c
msgid "%q out of bounds"
msgstr ""
Expand Down Expand Up @@ -766,6 +775,10 @@ msgstr ""
msgid "Cannot create a new Adapter; use _bleio.adapter;"
msgstr ""

#: shared-module/i2cioexpander/IOExpander.c
msgid "Cannot deinitialize board IOExpander"
msgstr ""

#: shared-bindings/displayio/Bitmap.c
#: shared-bindings/memorymonitor/AllocationSize.c
#: shared-bindings/pulseio/PulseIn.c
Expand Down Expand Up @@ -800,6 +813,7 @@ msgid "Cannot remount path when visible via USB."
msgstr ""

#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/i2cioexpander/IOPin.c
msgid "Cannot set value when direction is input."
msgstr ""

Expand Down Expand Up @@ -939,6 +953,7 @@ msgid "Done"
msgstr ""

#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/i2cioexpander/IOPin.c
msgid "Drive mode not used when direction is input."
msgstr ""

Expand Down Expand Up @@ -1277,8 +1292,8 @@ msgstr ""
#: ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c py/argcheck.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/epaperdisplay/EPaperDisplay.c
#: shared-bindings/mipidsi/Display.c shared-bindings/pwmio/PWMOut.c
#: shared-bindings/supervisor/__init__.c
#: shared-bindings/i2cioexpander/IOPin.c shared-bindings/mipidsi/Display.c
#: shared-bindings/pwmio/PWMOut.c shared-bindings/supervisor/__init__.c
#: shared-module/aurora_epaper/aurora_framebuffer.c
#: shared-module/lvfontio/OnDiskFont.c
msgid "Invalid %q"
Expand Down Expand Up @@ -1880,6 +1895,7 @@ msgid "Publishers can only be created from a parent node"
msgstr ""

#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/i2cioexpander/IOPin.c
msgid "Pull not used when direction is output."
msgstr ""

Expand Down Expand Up @@ -2539,6 +2555,10 @@ msgstr ""
msgid "a bytes-like object is required"
msgstr ""

#: shared-bindings/i2cioexpander/IOExpander.c
msgid "address out of range"
msgstr ""

#: shared-bindings/i2ctarget/I2CTarget.c
msgid "addresses is empty"
msgstr ""
Expand Down Expand Up @@ -3814,6 +3834,10 @@ msgstr ""
msgid "not supported for input types"
msgstr ""

#: shared-bindings/i2cioexpander/IOExpander.c
msgid "num_pins must be 8 or 16"
msgstr ""

#: extmod/ulab/code/numpy/create.c
msgid "number of points must be at least 2"
msgstr ""
Expand All @@ -3827,6 +3851,10 @@ msgstr ""
msgid "object '%s' isn't a tuple or list"
msgstr ""

#: shared-bindings/digitalio/DigitalInOutProtocol.c
msgid "object does not support DigitalInOut protocol"
msgstr ""

#: py/obj.c
msgid "object doesn't support item assignment"
msgstr ""
Expand Down
12 changes: 6 additions & 6 deletions ports/analog/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
}

// Write data to the device selected by address
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
mp_errno_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
const uint8_t *data, size_t len) {

int ret;
Expand All @@ -202,14 +202,14 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
};
ret = MXC_I2C_MasterTransaction(&wr_req);
if (ret) {
return MP_EIO;
return -MP_EIO;
}

return 0;
}

// Read into buffer from the device selected by address
uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self,
mp_errno_t common_hal_busio_i2c_read(busio_i2c_obj_t *self,
uint16_t addr,
uint8_t *data, size_t len) {

Expand All @@ -226,14 +226,14 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self,
ret = MXC_I2C_MasterTransaction(&rd_req);
if (ret) {
// Return I/O error
return MP_EIO;
return -MP_EIO;
}

return 0;
}

// Write the bytes from out_data to the device selected by address
uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
mp_errno_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
uint8_t *out_data, size_t out_len,
uint8_t *in_data, size_t in_len) {

Expand All @@ -249,7 +249,7 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
};
ret = MXC_I2C_MasterTransaction(&wr_rd_req);
if (ret) {
return MP_EIO;
return -MP_EIO;
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/asf4_conf/samd21/hpl_sercom_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
// <0x2=>8x arithmetic
// <0x3=>8x fractional
// <0x3=>3x
// <i> How many over-sampling bits used when samling data state
// <i> How many over-sampling bits used when sampling data state
// <id> usart_arch_sampr
#ifndef CONF_SERCOM_2_USART_SAMPR
#define CONF_SERCOM_2_USART_SAMPR 0x0
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/asf4_conf/samd51/hpl_sercom_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
// <0x2=>8x arithmetic
// <0x3=>8x fractional
// <0x3=>3x
// <i> How many over-sampling bits used when samling data state
// <i> How many over-sampling bits used when sampling data state
// <id> usart_arch_sampr
#ifndef CONF_SERCOM_2_USART_SAMPR
#define CONF_SERCOM_2_USART_SAMPR 0x0
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/asf4_conf/same51/hpl_sercom_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
// <0x2=>8x arithmetic
// <0x3=>8x fractional
// <0x3=>3x
// <i> How many over-sampling bits used when samling data state
// <i> How many over-sampling bits used when sampling data state
// <id> usart_arch_sampr
#ifndef CONF_SERCOM_2_USART_SAMPR
#define CONF_SERCOM_2_USART_SAMPR 0x0
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/asf4_conf/same54/hpl_sercom_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
// <0x2=>8x arithmetic
// <0x3=>8x fractional
// <0x3=>3x
// <i> How many over-sampling bits used when samling data state
// <i> How many over-sampling bits used when sampling data state
// <id> usart_arch_sampr
#ifndef CONF_SERCOM_2_USART_SAMPR
#define CONF_SERCOM_2_USART_SAMPR 0x0
Expand Down
18 changes: 9 additions & 9 deletions ports/atmel-samd/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
self->has_lock = false;
}

static uint8_t _common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
static mp_errno_t _common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
const uint8_t *data, size_t len, bool transmit_stop_bit) {

uint16_t attempts = ATTEMPTS;
Expand All @@ -197,17 +197,17 @@ static uint8_t _common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
if (status == I2C_OK) {
return 0;
} else if (status == I2C_ERR_BAD_ADDRESS) {
return MP_ENODEV;
return -MP_ENODEV;
}
return MP_EIO;
return -MP_EIO;
}

uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
mp_errno_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
const uint8_t *data, size_t len) {
return _common_hal_busio_i2c_write(self, addr, data, len, true);
}

uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
mp_errno_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
uint8_t *data, size_t len) {

uint16_t attempts = ATTEMPTS;
Expand All @@ -228,14 +228,14 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
if (status == ERR_NONE) {
return 0;
} else if (status == I2C_ERR_BAD_ADDRESS) {
return MP_ENODEV;
return -MP_ENODEV;
}
return MP_EIO;
return -MP_EIO;
}

uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
mp_errno_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
uint8_t *out_data, size_t out_len, uint8_t *in_data, size_t in_len) {
uint8_t result = _common_hal_busio_i2c_write(self, addr, out_data, out_len, false);
mp_errno_t result = _common_hal_busio_i2c_write(self, addr, out_data, out_len, false);
if (result != 0) {
return result;
}
Expand Down
69 changes: 56 additions & 13 deletions ports/atmel-samd/common-hal/sdioio/SDCard.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "py/runtime.h"

#include "common-hal/microcontroller/Pin.h"
#include "extmod/vfs.h"
#include "shared-bindings/sdioio/SDCard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/__init__.h"
Expand Down Expand Up @@ -170,43 +171,85 @@ static void debug_print_state(sdioio_sdcard_obj_t *self, const char *what, sd_mm
#endif
}

int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
check_for_deinit(self);
check_whole_block(bufinfo);
mp_errno_t sdioio_sdcard_writeblocks(mp_obj_t self_in, uint8_t *buf,
uint32_t start_block, uint32_t num_blocks) {
sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in);
wait_write_complete(self);
self->state_programming = true;
sd_mmc_err_t r = sd_mmc_init_write_blocks(0, start_block, bufinfo->len / 512);
sd_mmc_err_t r = sd_mmc_init_write_blocks(0, start_block, num_blocks);
if (r != SD_MMC_OK) {
debug_print_state(self, "sd_mmc_init_write_blocks", r);
return -EIO;
return -MP_EIO;
}
r = sd_mmc_start_write_blocks(bufinfo->buf, bufinfo->len / 512);
r = sd_mmc_start_write_blocks(buf, num_blocks);
if (r != SD_MMC_OK) {
debug_print_state(self, "sd_mmc_start_write_blocks", r);
return -EIO;
return -MP_EIO;
}
// debug_print_state(self, "after writeblocks OK");
return 0;
}

int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
mp_errno_t common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
check_for_deinit(self);
check_whole_block(bufinfo);

uint32_t num_blocks = bufinfo->len / 512;
return sdioio_sdcard_writeblocks(MP_OBJ_FROM_PTR(self), bufinfo->buf,
start_block, num_blocks);
}

mp_errno_t sdioio_sdcard_readblocks(mp_obj_t self_in, uint8_t *buf,
uint32_t start_block, uint32_t num_blocks) {
sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in);
wait_write_complete(self);
sd_mmc_err_t r = sd_mmc_init_read_blocks(0, start_block, bufinfo->len / 512);
sd_mmc_err_t r = sd_mmc_init_read_blocks(0, start_block, num_blocks);
if (r != SD_MMC_OK) {
debug_print_state(self, "sd_mmc_init_read_blocks", r);
return -EIO;
return -MP_EIO;
}
r = sd_mmc_start_read_blocks(bufinfo->buf, bufinfo->len / 512);
r = sd_mmc_start_read_blocks(buf, num_blocks);
if (r != SD_MMC_OK) {
debug_print_state(self, "sd_mmc_start_read_blocks", r);
return -EIO;
return -MP_EIO;
}
sd_mmc_wait_end_of_write_blocks(0);
return 0;
}

mp_errno_t common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
check_for_deinit(self);
check_whole_block(bufinfo);

uint32_t num_blocks = bufinfo->len / 512;
return sdioio_sdcard_readblocks(MP_OBJ_FROM_PTR(self), bufinfo->buf,
start_block, num_blocks);
}

// Native function for VFS blockdev layer
bool sdioio_sdcard_ioctl(mp_obj_t self_in, size_t cmd, size_t arg,
mp_int_t *out_value) {
sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in);
*out_value = 0;

switch (cmd) {
case MP_BLOCKDEV_IOCTL_DEINIT:
case MP_BLOCKDEV_IOCTL_SYNC:
// SDIO operations are synchronous, no action needed
return true;

case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
*out_value = common_hal_sdioio_sdcard_get_count(self);
return true;

case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
*out_value = 512; // SD cards use 512-byte sectors
return true;

default:
return false; // Unsupported command
}
}

bool common_hal_sdioio_sdcard_configure(sdioio_sdcard_obj_t *self, uint32_t frequency, uint8_t bits) {
check_for_deinit(self);
return true;
Expand Down
Loading
Loading