Merge branch 'dumb-git-stuff' into stm32-meowbit

This commit is contained in:
Hierophect 2019-12-12 16:34:11 -05:00
commit ab3762d8f5
104 changed files with 1637 additions and 482 deletions

View File

@ -129,6 +129,7 @@ jobs:
- "pewpew10"
- "pewpew_m4"
- "pirkey_m0"
- "pyb_nano_v2"
- "pybadge"
- "pybadge_airlift"
- "pyboard_v11"
@ -150,6 +151,7 @@ jobs:
- "sparkfun_samd21_dev"
- "sparkfun_samd21_mini"
- "spresense"
- "stm32f411ce_blackpill"
- "stm32f411ve_discovery"
- "stm32f412zg_discovery"
- "stringcar_m0_express"

3
.gitmodules vendored
View File

@ -102,3 +102,6 @@
[submodule "ports/cxd56/spresense-exported-sdk"]
path = ports/cxd56/spresense-exported-sdk
url = https://github.com/sonydevworld/spresense-exported-sdk.git
[submodule "lib/mp3"]
path = lib/mp3
url = https://github.com/adafruit/Adafruit_MP3

View File

@ -318,7 +318,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_init_obj, 1, machine_i2c_obj_init);
STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
mp_obj_base_t *self = MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
mp_obj_t list = mp_obj_new_list(0, NULL);
// 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
for (int addr = 0x08; addr < 0x78; ++addr) {
@ -333,7 +333,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_scan_obj, machine_i2c_scan);
STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
if (i2c_p->start == NULL) {
mp_raise_msg(&mp_type_OSError, translate("I2C operation not supported"));
}
@ -347,7 +347,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_start_obj, machine_i2c_start);
STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
if (i2c_p->stop == NULL) {
mp_raise_msg(&mp_type_OSError, translate("I2C operation not supported"));
}
@ -361,7 +361,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_stop_obj, machine_i2c_stop);
STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
if (i2c_p->read == NULL) {
mp_raise_msg(&mp_type_OSError, translate("I2C operation not supported"));
}
@ -385,7 +385,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readinto_obj, 2, 3, machine_i2c_
STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
if (i2c_p->write == NULL) {
mp_raise_msg(&mp_type_OSError, translate("I2C operation not supported"));
}
@ -407,7 +407,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(machine_i2c_write_obj, machine_i2c_write);
STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
mp_int_t addr = mp_obj_get_int(args[1]);
vstr_t vstr;
vstr_init_len(&vstr, mp_obj_get_int(args[2]));
@ -422,7 +422,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_obj, 3, 4, machine_i2c_
STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
mp_int_t addr = mp_obj_get_int(args[1]);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
@ -437,7 +437,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_into_obj, 3, 4, machine
STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
mp_int_t addr = mp_obj_get_int(args[1]);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
@ -453,7 +453,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writeto_obj, 3, 4, machin
STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, uint8_t *buf, size_t len) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
uint8_t memaddr_buf[4];
size_t memaddr_len = 0;
for (int16_t i = addrsize - 8; i >= 0; i -= 8) {
@ -473,7 +473,7 @@ STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t a
STATIC int write_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, const uint8_t *buf, size_t len) {
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)mp_proto_get(self, QSTR_protocol_i2c);
// need some memory to create the buffer to send; try to use stack if possible
uint8_t buf2_stack[MAX_MEMADDR_SIZE + BUF_STACK_SIZE];
@ -621,6 +621,7 @@ int mp_machine_soft_i2c_write(mp_obj_base_t *self_in, const uint8_t *src, size_t
}
STATIC const mp_machine_i2c_p_t mp_machine_soft_i2c_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_i2c)
.start = (int(*)(mp_obj_base_t*))mp_hal_i2c_start,
.stop = (int(*)(mp_obj_base_t*))mp_hal_i2c_stop,
.read = mp_machine_soft_i2c_read,

View File

@ -27,10 +27,12 @@
#define MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H
#include "py/obj.h"
#include "py/proto.h"
// I2C protocol
// the first 4 methods can be NULL, meaning operation is not supported
typedef struct _mp_machine_i2c_p_t {
MP_PROTOCOL_HEAD
int (*start)(mp_obj_base_t *obj);
int (*stop)(mp_obj_base_t *obj);
int (*read)(mp_obj_base_t *obj, uint8_t *dest, size_t len, bool nack);

View File

@ -74,6 +74,7 @@ mp_uint_t pinbase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *err
}
STATIC const mp_pin_p_t pinbase_pin_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_pin)
.ioctl = pinbase_ioctl,
};

View File

@ -47,12 +47,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, const
bool invert = false;
#if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW)
mp_pin_p_t *pin_p = NULL;
if (MP_OBJ_IS_OBJ(pin)) {
mp_obj_base_t *pin_base = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
pin_p = (mp_pin_p_t*)pin_base->type->protocol;
}
mp_pin_p_t *pin_p = (mp_pin_t*)mp_proto_get(QSTR_pin_protocol, pin);
if (pin_p == NULL) {
// If first argument isn't a Pin-like object, we filter out "invert"
@ -170,6 +165,7 @@ STATIC const mp_rom_map_elem_t signal_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(signal_locals_dict, signal_locals_dict_table);
STATIC const mp_pin_p_t signal_pin_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_pin)
.ioctl = signal_ioctl,
};

View File

@ -67,7 +67,7 @@ mp_obj_t mp_machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, const
STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
mp_obj_base_t *s = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)s->type->protocol;
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)mp_proto_get(QSTR_protocol_spi, s);
spi_p->init(s, n_args - 1, args + 1, kw_args);
return mp_const_none;
}
@ -75,7 +75,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_spi_init_obj, 1, machine_spi_init);
STATIC mp_obj_t machine_spi_deinit(mp_obj_t self) {
mp_obj_base_t *s = (mp_obj_base_t*)MP_OBJ_TO_PTR(self);
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)s->type->protocol;
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)mp_proto_get(QSTR_protocol_spi, s);
if (spi_p->deinit != NULL) {
spi_p->deinit(s);
}
@ -85,7 +85,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_spi_deinit_obj, machine_spi_deinit);
STATIC void mp_machine_spi_transfer(mp_obj_t self, size_t len, const void *src, void *dest) {
mp_obj_base_t *s = (mp_obj_base_t*)MP_OBJ_TO_PTR(self);
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)s->type->protocol;
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t*)mp_proto_get(QSTR_protocol_spi, s);
spi_p->transfer(s, len, src, dest);
}
@ -268,6 +268,7 @@ STATIC void mp_machine_soft_spi_transfer(mp_obj_base_t *self_in, size_t len, con
}
const mp_machine_spi_p_t mp_machine_soft_spi_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_spi)
.init = mp_machine_soft_spi_init,
.deinit = NULL,
.transfer = mp_machine_soft_spi_transfer,

View File

@ -27,11 +27,13 @@
#define MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H
#include "py/obj.h"
#include "py/proto.h"
#include "py/mphal.h"
#include "drivers/bus/spi.h"
// SPI protocol
typedef struct _mp_machine_spi_p_t {
MP_PROTOCOL_HEAD
void (*init)(mp_obj_base_t *obj, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
void (*deinit)(mp_obj_base_t *obj); // can be NULL
void (*transfer)(mp_obj_base_t *obj, size_t len, const uint8_t *src, uint8_t *dest);

View File

@ -28,6 +28,7 @@
#include <string.h>
#include "py/runtime.h"
#include "py/proto.h"
#if MICROPY_PY_FRAMEBUF
@ -46,6 +47,7 @@ typedef uint32_t (*getpixel_t)(const mp_obj_framebuf_t*, int, int);
typedef void (*fill_rect_t)(const mp_obj_framebuf_t *, int, int, int, int, uint32_t);
typedef struct _mp_framebuf_p_t {
MP_PROTOCOL_HEAD
setpixel_t setpixel;
getpixel_t getpixel;
fill_rect_t fill_rect;
@ -227,13 +229,13 @@ STATIC void gs8_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int
}
STATIC mp_framebuf_p_t formats[] = {
[FRAMEBUF_MVLSB] = {mvlsb_setpixel, mvlsb_getpixel, mvlsb_fill_rect},
[FRAMEBUF_RGB565] = {rgb565_setpixel, rgb565_getpixel, rgb565_fill_rect},
[FRAMEBUF_GS2_HMSB] = {gs2_hmsb_setpixel, gs2_hmsb_getpixel, gs2_hmsb_fill_rect},
[FRAMEBUF_GS4_HMSB] = {gs4_hmsb_setpixel, gs4_hmsb_getpixel, gs4_hmsb_fill_rect},
[FRAMEBUF_GS8] = {gs8_setpixel, gs8_getpixel, gs8_fill_rect},
[FRAMEBUF_MHLSB] = {mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect},
[FRAMEBUF_MHMSB] = {mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect},
[FRAMEBUF_MVLSB] = {MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuf) mvlsb_setpixel, mvlsb_getpixel, mvlsb_fill_rect},
[FRAMEBUF_RGB565] = {MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuf) rgb565_setpixel, rgb565_getpixel, rgb565_fill_rect},
[FRAMEBUF_GS2_HMSB] = {MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuf) gs2_hmsb_setpixel, gs2_hmsb_getpixel, gs2_hmsb_fill_rect},
[FRAMEBUF_GS4_HMSB] = {MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuf) gs4_hmsb_setpixel, gs4_hmsb_getpixel, gs4_hmsb_fill_rect},
[FRAMEBUF_GS8] = {MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuf) gs8_setpixel, gs8_getpixel, gs8_fill_rect},
[FRAMEBUF_MHLSB] = {MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuf) mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect},
[FRAMEBUF_MHMSB] = {MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuf) mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect},
};
static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {

View File

@ -1261,6 +1261,7 @@ STATIC const mp_rom_map_elem_t lwip_socket_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(lwip_socket_locals_dict, lwip_socket_locals_dict_table);
STATIC const mp_stream_p_t lwip_socket_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = lwip_socket_read,
.write = lwip_socket_write,
.ioctl = lwip_socket_ioctl,

View File

@ -221,6 +221,7 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
STATIC const mp_stream_p_t ussl_socket_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = socket_read,
.write = socket_write,
.ioctl = socket_ioctl,

View File

@ -305,6 +305,7 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
STATIC const mp_stream_p_t ussl_socket_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = socket_read,
.write = socket_write,
.ioctl = socket_ioctl,

View File

@ -134,6 +134,7 @@ STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table);
STATIC const mp_stream_p_t decompio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = decompio_read,
};

View File

@ -331,6 +331,7 @@ STATIC const mp_rom_map_elem_t webrepl_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(webrepl_locals_dict, webrepl_locals_dict_table);
STATIC const mp_stream_p_t webrepl_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = webrepl_read,
.write = webrepl_write,
.ioctl = webrepl_ioctl,

View File

@ -286,6 +286,7 @@ STATIC const mp_rom_map_elem_t websocket_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(websocket_locals_dict, websocket_locals_dict_table);
STATIC const mp_stream_p_t websocket_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = websocket_read,
.write = websocket_write,
.ioctl = websocket_ioctl,

View File

@ -126,7 +126,7 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
}
// If the mounted object has the VFS protocol, call its import_stat helper
const mp_vfs_proto_t *proto = mp_obj_get_type(vfs->obj)->protocol;
const mp_vfs_proto_t *proto = (mp_vfs_proto_t*)mp_proto_get(MP_QSTR_protocol_vfs, vfs->obj);
if (proto != NULL) {
return proto->import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
}

View File

@ -28,6 +28,7 @@
#include "py/lexer.h"
#include "py/obj.h"
#include "py/proto.h"
// return values of mp_vfs_lookup_path
// ROOT is 0 so that the default current directory is the root directory
@ -47,6 +48,7 @@
// At the moment the VFS protocol just has import_stat, but could be extended to other methods
typedef struct _mp_vfs_proto_t {
MP_PROTOCOL_HEAD
mp_import_stat_t (*import_stat)(void *self, const char *path);
} mp_vfs_proto_t;

View File

@ -488,6 +488,7 @@ STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table);
STATIC const mp_vfs_proto_t fat_vfs_proto = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_vfs)
.import_stat = fat_vfs_import_stat,
};

View File

@ -254,6 +254,7 @@ STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
#if MICROPY_PY_IO_FILEIO
STATIC const mp_stream_p_t fileio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = file_obj_read,
.write = file_obj_write,
.ioctl = file_obj_ioctl,
@ -272,6 +273,7 @@ const mp_obj_type_t mp_type_vfs_fat_fileio = {
#endif
STATIC const mp_stream_p_t textio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = file_obj_read,
.write = file_obj_write,
.ioctl = file_obj_ioctl,

View File

@ -350,6 +350,7 @@ STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table);
STATIC const mp_vfs_proto_t vfs_posix_proto = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_vfs)
.import_stat = mp_vfs_posix_import_stat,
};

View File

@ -220,6 +220,7 @@ STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
#if MICROPY_PY_IO_FILEIO
STATIC const mp_stream_p_t fileio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = vfs_posix_file_read,
.write = vfs_posix_file_write,
.ioctl = vfs_posix_file_ioctl,
@ -238,6 +239,7 @@ const mp_obj_type_t mp_type_vfs_posix_fileio = {
#endif
STATIC const mp_stream_p_t textio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = vfs_posix_file_read,
.write = vfs_posix_file_write,
.ioctl = vfs_posix_file_ioctl,

View File

@ -25,15 +25,16 @@
*/
#include "extmod/virtpin.h"
#include "py/proto.h"
int mp_virtual_pin_read(mp_obj_t pin) {
mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(pin);
mp_pin_p_t *pin_p = (mp_pin_p_t*)s->type->protocol;
const mp_pin_p_t *pin_p = mp_proto_get(MP_QSTR_protocol_pin, s);
return pin_p->ioctl(pin, MP_PIN_READ, 0, NULL);
}
void mp_virtual_pin_write(mp_obj_t pin, int value) {
mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(pin);
mp_pin_p_t *pin_p = (mp_pin_p_t*)s->type->protocol;
const mp_pin_p_t *pin_p = mp_proto_get(MP_QSTR_protocol_pin, s);
pin_p->ioctl(pin, MP_PIN_WRITE, value, NULL);
}

View File

@ -27,6 +27,7 @@
#define MICROPY_INCLUDED_EXTMOD_VIRTPIN_H
#include "py/obj.h"
#include "py/proto.h"
#define MP_PIN_READ (1)
#define MP_PIN_WRITE (2)
@ -35,6 +36,7 @@
// Pin protocol
typedef struct _mp_pin_p_t {
MP_PROTOCOL_HEAD
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode);
} mp_pin_p_t;

1
lib/mp3 Submodule

@ -0,0 +1 @@
Subproject commit 2a3cc7873b5c642d4bb60043dc14d2555e3377a5

View File

@ -3382,7 +3382,11 @@ FRESULT f_read (
if (!sect) ABORT(fs, FR_INT_ERR);
sect += csect;
cc = btr / SS(fs); /* When remaining bytes >= sector size, */
if (cc) { /* Read maximum contiguous sectors directly */
if (cc
#if _FS_DISK_READ_ALIGNED
&& (((int)rbuff & 3) == 0)
#endif
) {/* Read maximum contiguous sectors directly */
if (csect + cc > fs->csize) { /* Clip at cluster boundary */
cc = fs->csize - csect;
}

View File

@ -343,6 +343,12 @@
/ SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
/ included somewhere in the scope of ff.h. */
// Set to nonzero if buffers passed to disk_read have a word alignment
// restriction
#ifndef _FS_DISK_READ_ALIGNED
#define _FS_DISK_READ_ALIGNED 0
#endif
/* #include <windows.h> // O/S definitions */

@ -1 +1 @@
Subproject commit e413c9efa303d70de019a91aa415384fe80ca78f
Subproject commit 7a05b177a43b368fea1d60ca344fe4ae9902a432

View File

@ -123,6 +123,7 @@ STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table);
STATIC const mp_stream_p_t stdio_obj_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = stdio_read,
.write = stdio_write,
.ioctl = stdio_ioctl,
@ -158,6 +159,7 @@ STATIC mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t
}
STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = stdio_buffer_read,
.write = stdio_buffer_write,
.is_text = false,

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -120,6 +120,10 @@ msgstr ""
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr "'%s' integer 0x%x tidak cukup didalam mask 0x%x"
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -492,11 +496,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr "Tidak dapat menginisialisasi UART"
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
msgid "Couldn't allocate first buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr ""
@ -609,6 +623,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, fuzzy, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1775,7 +1793,7 @@ msgstr "argumen keyword ekstra telah diberikan"
msgid "extra positional arguments given"
msgstr "argumen posisi ekstra telah diberikan"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -119,6 +119,10 @@ msgstr ""
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr ""
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -482,11 +486,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
msgid "Couldn't allocate first buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr ""
@ -598,6 +612,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1745,7 +1763,7 @@ msgstr ""
msgid "extra positional arguments given"
msgstr ""
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: Pascal Deneaux\n"
"Language-Team: Sebastian Plamauer, Pascal Deneaux\n"
@ -121,6 +121,10 @@ msgstr "'%s' integer %d ist nicht im Bereich %d..%d"
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr "'%s' Integer 0x%x passt nicht in Maske 0x%x"
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -486,11 +490,21 @@ msgstr "Beschädigter raw code"
msgid "Could not initialize UART"
msgstr "Konnte UART nicht initialisieren"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr "Konnte first buffer nicht zuteilen"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr "Konnte second buffer nicht zuteilen"
@ -602,6 +616,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr "Verbindung nicht erfolgreich: timeout"
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1794,7 +1812,7 @@ msgstr "Es wurden zusätzliche Keyword-Argumente angegeben"
msgid "extra positional arguments given"
msgstr "Es wurden zusätzliche Argumente ohne Keyword angegeben"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr "Die Datei muss eine im Byte-Modus geöffnete Datei sein"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -119,6 +119,10 @@ msgstr ""
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr ""
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -482,11 +486,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
msgid "Couldn't allocate first buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr ""
@ -598,6 +612,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1745,7 +1763,7 @@ msgstr ""
msgid "extra positional arguments given"
msgstr ""
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: @sommersoft, @MrCertainly\n"
@ -121,6 +121,10 @@ msgstr ""
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr ""
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -486,11 +490,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
msgid "Couldn't allocate first buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr ""
@ -602,6 +616,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1749,7 +1767,7 @@ msgstr ""
msgid "extra positional arguments given"
msgstr ""
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2018-08-24 22:56-0500\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -121,6 +121,10 @@ msgstr "'%s' entero %d no esta dentro del rango %d..%d"
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr "'%s' entero 0x%x no cabe en la máscara 0x%x"
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -490,11 +494,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr "No se puede inicializar la UART"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr "No se pudo asignar el primer buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr "No se pudo asignar el segundo buffer"
@ -606,6 +620,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1798,7 +1816,7 @@ msgstr "argumento(s) por palabra clave adicionales fueron dados"
msgid "extra positional arguments given"
msgstr "argumento posicional adicional dado"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr "el archivo deberia ser una archivo abierto en modo byte"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2018-12-20 22:15-0800\n"
"Last-Translator: Timothy <me@timothygarcia.ca>\n"
"Language-Team: fil\n"
@ -122,6 +122,10 @@ msgstr "'%s' integer %d ay wala sa sakop ng %d..%d"
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr "'%s' integer 0x%x ay wala sa mask na sakop ng 0x%x"
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -491,11 +495,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr "Hindi ma-initialize ang UART"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr "Hindi ma-iallocate ang first buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr "Hindi ma-iallocate ang second buffer"
@ -612,6 +626,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, fuzzy, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1806,7 +1824,7 @@ msgstr "dagdag na keyword argument na ibinigay"
msgid "extra positional arguments given"
msgstr "dagdag na positional argument na ibinigay"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr "file ay dapat buksan sa byte mode"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2019-04-14 20:05+0100\n"
"Last-Translator: Pierrick Couturier <arofarn@arofarn.info>\n"
"Language-Team: fr\n"
@ -123,6 +123,10 @@ msgstr "'%s' l'entier %d n'est pas dans la gamme %d..%d"
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr "'%s' l'entier 0x%x ne correspond pas au masque 0x%x"
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -497,11 +501,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr "L'UART n'a pu être initialisé"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr "Impossible d'allouer le 1er tampon"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr "Impossible d'allouer le 2e tampon"
@ -616,6 +630,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, fuzzy, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1838,7 +1856,7 @@ msgstr "argument(s) nommé(s) supplémentaire(s) donné(s)"
msgid "extra positional arguments given"
msgstr "argument(s) positionnel(s) supplémentaire(s) donné(s)"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr "le fichier doit être un fichier ouvert en mode 'byte'"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2018-10-02 16:27+0200\n"
"Last-Translator: Enrico Paganin <enrico.paganin@mail.com>\n"
"Language-Team: \n"
@ -121,6 +121,10 @@ msgstr "intero '%s' non è nell'intervallo %d..%d"
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr "intero '%s' non è nell'intervallo %d..%d"
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -492,11 +496,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr "Impossibile inizializzare l'UART"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr "Impossibile allocare il primo buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr "Impossibile allocare il secondo buffer"
@ -612,6 +626,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, fuzzy, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1799,7 +1817,7 @@ msgstr "argomento nominato aggiuntivo fornito"
msgid "extra positional arguments given"
msgstr "argomenti posizonali extra dati"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2019-05-06 14:22-0700\n"
"Last-Translator: \n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -121,6 +121,10 @@ msgstr ""
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr ""
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -486,11 +490,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
msgid "Couldn't allocate first buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr ""
@ -602,6 +616,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1750,7 +1768,7 @@ msgstr ""
msgid "extra positional arguments given"
msgstr ""
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2019-03-19 18:37-0700\n"
"Last-Translator: Radomir Dopieralski <circuitpython@sheep.art.pl>\n"
"Language-Team: pl\n"
@ -120,6 +120,10 @@ msgstr "'%s' liczba %d poza zakresem %d..%d"
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr "'%s' liczba 0x%x nie pasuje do maski 0x%x"
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -485,11 +489,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr "Ustawienie UART nie powiodło się"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr "Nie udała się alokacja pierwszego bufora"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr "Nie udała się alokacja drugiego bufora"
@ -601,6 +615,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1770,7 +1788,7 @@ msgstr "nadmiarowe argumenty nazwane"
msgid "extra positional arguments given"
msgstr "nadmiarowe argumenty pozycyjne"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr "file musi być otwarte w trybie bajtowym"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2018-10-02 21:14-0000\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -121,6 +121,10 @@ msgstr ""
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr ""
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -488,11 +492,21 @@ msgstr ""
msgid "Could not initialize UART"
msgstr "Não foi possível inicializar o UART"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr "Não pôde alocar primeiro buffer"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr "Não pôde alocar segundo buffer"
@ -607,6 +621,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr ""
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, fuzzy, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1767,7 +1785,7 @@ msgstr "argumentos extras de palavras-chave passados"
msgid "extra positional arguments given"
msgstr "argumentos extra posicionais passados"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: circuitpython-cn\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-27 14:54-0500\n"
"POT-Creation-Date: 2019-12-10 13:55-0600\n"
"PO-Revision-Date: 2019-04-13 10:10-0700\n"
"Last-Translator: hexthat\n"
"Language-Team: Chinese Hanyu Pinyin\n"
@ -121,6 +121,10 @@ msgstr "'%s' zhěngshù %d bùzài fànwéi nèi %d.%d"
msgid "'%s' integer 0x%x does not fit in mask 0x%x"
msgstr "'%s' zhěngshù 0x%x bù shìyòng yú yǎn mǎ 0x%x"
#: py/proto.c
msgid "'%s' object does not support '%q'"
msgstr ""
#: py/obj.c
#, c-format
msgid "'%s' object does not support item assignment"
@ -486,11 +490,21 @@ msgstr "Sǔnhuài de yuánshǐ dàimǎ"
msgid "Could not initialize UART"
msgstr "Wúfǎ chūshǐhuà UART"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate decoder"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate first buffer"
msgstr "Wúfǎ fēnpèi dì yī gè huǎnchōng qū"
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate input buffer"
msgstr ""
#: shared-module/audiocore/WaveFile.c shared-module/audiomixer/Mixer.c
#: shared-module/audiomp3/MP3File.c
msgid "Couldn't allocate second buffer"
msgstr "Wúfǎ fēnpèi dì èr gè huǎnchōng qū"
@ -602,6 +616,10 @@ msgstr ""
msgid "Failed to connect: timeout"
msgstr "Liánjiē shībài: Chāoshí"
#: shared-module/audiomp3/MP3File.c
msgid "Failed to parse MP3 file"
msgstr ""
#: ports/nrf/sd_mutex.c
#, c-format
msgid "Failed to release mutex, err 0x%04x"
@ -1781,7 +1799,7 @@ msgstr "éwài de guānjiàn cí cānshù"
msgid "extra positional arguments given"
msgstr "gěi chūle éwài de wèizhì cānshù"
#: shared-bindings/audiocore/WaveFile.c
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3File.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
msgstr "wénjiàn bìxū shì zài zì jié móshì xià dǎkāi de wénjiàn"

View File

@ -16,3 +16,4 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_NETWORK = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_AUDIOMP3 = 0

View File

@ -34,24 +34,62 @@
#ifdef SAMD51
#include "hri/hri_cmcc_d51.h"
#include "hri/hri_nvmctrl_d51.h"
// This magical macro makes sure the delay isn't optimized out and is the
// minimal three instructions.
#define delay_cycles(cycles) \
{ \
uint32_t t; \
asm volatile ( \
"movs %[t], %[c]\n\t" \
"loop%=:\n\t" \
"subs %[t], #1\n\t" \
"bne.n loop%=" : [t] "=r"(t) : [c] "I" (cycles)); \
}
#endif
// Ensure this code is compiled with -Os. Any other optimization level may change the timing of it
// and break neopixels.
#pragma GCC push_options
#pragma GCC optimize ("Os")
__attribute__((naked,noinline,aligned(16)))
static void neopixel_send_buffer_core(volatile uint32_t *clraddr, uint32_t pinMask,
const uint8_t *ptr, int numBytes);
static void neopixel_send_buffer_core(volatile uint32_t *clraddr, uint32_t pinMask,
const uint8_t *ptr, int numBytes) {
asm volatile(" push {r4, r5, r6, lr};"
" add r3, r2, r3;"
"loopLoad:"
" ldrb r5, [r2, #0];" // r5 := *ptr
" add r2, #1;" // ptr++
" movs r4, #128;" // r4-mask, 0x80
"loopBit:"
" str r1, [r0, #4];" // set
#ifdef SAMD21
" movs r6, #3; d2: sub r6, #1; bne d2;" // delay 3
#endif
#ifdef SAMD51
" movs r6, #3; d2: subs r6, #1; bne d2;" // delay 3
#endif
" tst r4, r5;" // mask&r5
" bne skipclr;"
" str r1, [r0, #0];" // clr
"skipclr:"
#ifdef SAMD21
" movs r6, #6; d0: sub r6, #1; bne d0;" // delay 6
#endif
#ifdef SAMD51
" movs r6, #6; d0: subs r6, #1; bne d0;" // delay 6
#endif
" str r1, [r0, #0];" // clr (possibly again, doesn't matter)
#ifdef SAMD21
" asr r4, r4, #1;" // mask >>= 1
#endif
#ifdef SAMD51
" asrs r4, r4, #1;" // mask >>= 1
#endif
" beq nextbyte;"
" uxtb r4, r4;"
#ifdef SAMD21
" movs r6, #2; d1: sub r6, #1; bne d1;" // delay 2
#endif
#ifdef SAMD51
" movs r6, #2; d1: subs r6, #1; bne d1;" // delay 2
#endif
" b loopBit;"
"nextbyte:"
" cmp r2, r3;"
" bcs neopixel_stop;"
" b loopLoad;"
"neopixel_stop:"
" pop {r4, r5, r6, pc};"
"");
}
uint64_t next_start_tick_ms = 0;
uint32_t next_start_tick_us = 1000;
@ -59,7 +97,7 @@ uint32_t next_start_tick_us = 1000;
void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) {
// This is adapted directly from the Adafruit NeoPixel library SAMD21G18A code:
// https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.cpp
uint8_t *ptr, *end, p, bitMask;
// and the asm version from https://github.com/microsoft/uf2-samdx1/blob/master/inc/neopixel.h
uint32_t pinMask;
PortGroup* port;
@ -71,21 +109,18 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
mp_hal_disable_all_interrupts();
#ifdef SAMD21
// Make sure the NVM cache is consistently timed.
NVMCTRL->CTRLB.bit.READMODE = NVMCTRL_CTRLB_READMODE_DETERMINISTIC_Val;
#endif
#ifdef SAMD51
// When this routine is positioned at certain addresses, the timing logic
// below can be too fast by about 2.5x. This is some kind of (un)fortunate code
// positiong with respect to a cache line.
// positioning with respect to a cache line.
// Theoretically we should turn on off the CMCC caches and the
// NVM caches to ensure consistent timing. Testing shows the the NVMCTRL
// cache disabling seems to make the difference. But turn both off to make sure.
// It's difficult to test because additions to the code before the timing loop
// below change instruction placement. Testing was done by adding cache changes
// below the loop (so only the first time through is wrong).
// below change instruction placement. (though this should be less true now that
// the main code is in the cache-aligned function neopixel_send_buffer_core)
// Testing was done by adding cache changes below the loop (so only the
// first time through is wrong).
//
// Turn off instruction, data, and NVM caches to force consistent timing.
// Invalidate existing cache entries.
@ -98,73 +133,8 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
uint32_t pin = digitalinout->pin->number;
port = &PORT->Group[GPIO_PORT(pin)]; // Convert GPIO # to port register
pinMask = (1UL << (pin % 32)); // From port_pin_set_output_level ASF code.
ptr = pixels;
end = ptr + numBytes;
p = *ptr++;
bitMask = 0x80;
volatile uint32_t *set = &(port->OUTSET.reg),
*clr = &(port->OUTCLR.reg);
for(;;) {
*set = pinMask;
// This is the time where the line is always high regardless of the bit.
// For the SK6812 its 0.3us +- 0.15us
#ifdef SAMD21
asm("nop; nop;");
#endif
#ifdef SAMD51
delay_cycles(2);
#endif
if((p & bitMask) != 0) {
// This is the high delay unique to a one bit.
// For the SK6812 its 0.3us
#ifdef SAMD21
asm("nop; nop; nop; nop; nop; nop; nop;");
#endif
#ifdef SAMD51
delay_cycles(3);
#endif
*clr = pinMask;
} else {
*clr = pinMask;
// This is the low delay unique to a zero bit.
// For the SK6812 its 0.3us
#ifdef SAMD21
asm("nop; nop;");
#endif
#ifdef SAMD51
delay_cycles(2);
#endif
}
if((bitMask >>= 1) != 0) {
// This is the delay between bits in a byte and is the 1 code low
// level time from the datasheet.
// For the SK6812 its 0.6us +- 0.15us
#ifdef SAMD21
asm("nop; nop; nop; nop; nop;");
#endif
#ifdef SAMD51
delay_cycles(4);
#endif
} else {
if(ptr >= end) break;
p = *ptr++;
bitMask = 0x80;
// This is the delay between bytes. It's similar to the other branch
// in the if statement except its tuned to account for the time the
// above operations take.
// For the SK6812 its 0.6us +- 0.15us
#ifdef SAMD51
delay_cycles(3);
#endif
}
}
#ifdef SAMD21
// Speed up! (But inconsistent timing.)
NVMCTRL->CTRLB.bit.READMODE = NVMCTRL_CTRLB_READMODE_NO_MISS_PENALTY_Val;
#endif
volatile uint32_t *clr = &(port->OUTCLR.reg);
neopixel_send_buffer_core(clr, pinMask, pixels, numBytes);
#ifdef SAMD51
// Turn instruction, data, and NVM caches back on.
@ -189,4 +159,3 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
}
#pragma GCC pop_options

View File

@ -21,6 +21,10 @@ ifndef CIRCUITPY_AUDIOMIXER
CIRCUITPY_AUDIOMIXER = 0
endif
ifndef CIRCUITPY_AUDIOMP3
CIRCUITPY_AUDIOMP3 = 0
endif
ifndef CIRCUITPY_FREQUENCYIO
CIRCUITPY_FREQUENCYIO = 0
endif

View File

@ -106,6 +106,7 @@ CFLAGS += -Wno-undef
CFLAGS += -Wno-cast-align
NRF_DEFINES += -DCONFIG_GPIO_AS_PINRESET
NRF_DEFINES += -D_FS_DISK_READ_ALIGNED=1
CFLAGS += $(NRF_DEFINES)
CFLAGS += \

View File

@ -25,6 +25,11 @@
*/
#include "boards/board.h"
#include "mpconfigboard.h"
#include "py/obj.h"
#include "peripherals/nrf/pins.h"
#include "nrf_gpio.h"
void board_init(void) {
}
@ -34,5 +39,12 @@ bool board_requests_safe_mode(void) {
}
void reset_board(void) {
// Turn off board.POWER_SWITCH (power-saving switch) on each soft reload, to prevent confusion.
nrf_gpio_cfg(POWER_SWITCH_PIN->number,
NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_NOPULL,
NRF_GPIO_PIN_S0S1,
NRF_GPIO_PIN_NOSENSE);
nrf_gpio_pin_write(POWER_SWITCH_PIN->number, false);
}

View File

@ -54,6 +54,9 @@
#define SPI_FLASH_CS_PIN &pin_P0_15
#endif
// Disables onboard peripherals and neopixels to save power.
#define POWER_SWITCH_PIN (&pin_P0_06)
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
#define CIRCUITPY_INTERNAL_NVM_SIZE (4096)

View File

@ -48,8 +48,12 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_SLIDE_SWITCH), MP_ROM_PTR(&pin_P1_06) },
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_P1_06) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P1_14) },
// If high, turns off NeoPixels, LIS3DH, sound sensor, light sensor, temp sensor.
{ MP_ROM_QSTR(MP_QSTR_POWER_SWITCH), MP_ROM_PTR(&pin_P0_06) },
{ MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_P0_06) },
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P1_14) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P1_14) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_P0_13) },
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_P0_13) },

View File

@ -97,27 +97,28 @@ STATIC void fill_buffers(audiopwmio_pwmaudioout_obj_t *self, int buf) {
common_hal_audiopwmio_pwmaudioout_stop(self);
return;
}
uint32_t num_samples = buffer_length / self->bytes_per_sample / self->spacing;
uint32_t num_samples = buffer_length / self->bytes_per_sample / self->sample_channel_count;
uint16_t *end_dev_buffer = dev_buffer + 2 * num_samples;
if (self->bytes_per_sample == 1) {
uint8_t offset = self->signed_to_unsigned ? 0x80 : 0;
uint16_t scale = self->scale;
for (uint32_t i=0; i<buffer_length/self->spacing; i++) {
while (dev_buffer < end_dev_buffer) {
uint8_t rawval = (*buffer++ + offset);
uint16_t val = (uint16_t)(((uint32_t)rawval * (uint32_t)scale) >> 8);
*dev_buffer++ = val;
if (self->spacing == 1)
if (self->sample_channel_count == 1)
*dev_buffer++ = val;
}
} else {
uint16_t offset = self->signed_to_unsigned ? 0x8000 : 0;
uint16_t scale = self->scale;
uint16_t *buffer16 = (uint16_t*)buffer;
for (uint32_t i=0; i<buffer_length/2/self->spacing; i++) {
while (dev_buffer < end_dev_buffer) {
uint16_t rawval = (*buffer16++ + offset);
uint16_t val = (uint16_t)((rawval * (uint32_t)scale) >> 16);
*dev_buffer++ = val;
if (self->spacing == 1)
if (self->sample_channel_count == 1)
*dev_buffer++ = val;
}
}
@ -231,9 +232,12 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t* self,
self->bytes_per_sample = audiosample_bits_per_sample(sample) / 8;
uint32_t max_buffer_length;
uint8_t spacing;
audiosample_get_buffer_structure(sample, /* single channel */ false,
&self->single_buffer, &self->signed_to_unsigned, &max_buffer_length,
&self->spacing);
&spacing);
self->sample_channel_count = audiosample_channel_count(sample);
if (max_buffer_length > UINT16_MAX) {
mp_raise_ValueError_varg(translate("Buffer length %d too big. It must be less than %d"), max_buffer_length, UINT16_MAX);
}

View File

@ -41,7 +41,7 @@ typedef struct {
uint8_t left_channel_number;
uint8_t right_channel_number;
uint8_t spacing;
uint8_t sample_channel_count;
uint8_t bytes_per_sample;
bool playing;

View File

@ -26,27 +26,22 @@
//Micropython setup
#define MICROPY_HW_BOARD_NAME "Feather STM32F405 Express"
#define MICROPY_HW_MCU_NAME "STM32F405RG"
#define MICROPY_HW_BOARD_NAME "PYB LR Nano V2"
#define MICROPY_HW_MCU_NAME "STM32F411CE"
#define FLASH_SIZE (0x100000)
#define FLASH_SIZE (0x80000)
#define FLASH_PAGE_SIZE (0x4000)
#define AUTORESET_DELAY_MS 500
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
#define BOARD_OSC_DIV 8
// On-board flash
#define SPI_FLASH_MOSI_PIN &pin_PB05
#define SPI_FLASH_MISO_PIN &pin_PB04
#define SPI_FLASH_SCK_PIN &pin_PB03
#define SPI_FLASH_CS_PIN &pin_PA15
#define SPI_FLASH_MOSI_PIN (&pin_PB15)
#define SPI_FLASH_MISO_PIN (&pin_PB14)
#define SPI_FLASH_SCK_PIN (&pin_PB13)
#define SPI_FLASH_CS_PIN (&pin_PB12)
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
#define DEFAULT_SPI_BUS_SCK (&pin_PB13)
#define DEFAULT_SPI_BUS_MOSI (&pin_PB15)
#define DEFAULT_SPI_BUS_MISO (&pin_PB14)
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000)
#define DEFAULT_UART_BUS_RX (&pin_PB11)
#define DEFAULT_UART_BUS_TX (&pin_PB10)
#define AUTORESET_DELAY_MS 500

View File

@ -1,19 +1,19 @@
USB_VID = 0x239A
USB_PID = 0x805A
USB_PRODUCT = "Feather STM32F405 Express"
USB_MANUFACTURER = "Adafruit Industries LLC"
USB_PID = 0x8068
USB_PRODUCT = "PYB LR Nano V2"
USB_MANUFACTURER = "MicroPython Chinese Community"
USB_DEVICES = "CDC,MSC"
SPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = GD25Q16C
EXTERNAL_FLASH_DEVICES = W25Q64JV_IQ
LONGINT_IMPL = MPZ
MCU_SERIES = m4
MCU_VARIANT = stm32f4
MCU_SUB_VARIANT = stm32f405xx
MCU_PACKAGE = 64
CMSIS_MCU = STM32F405xx
LD_FILE = boards/STM32F405.ld
MCU_SUB_VARIANT = stm32f411xe
MCU_PACKAGE = 48
CMSIS_MCU = STM32F411xE
LD_FILE = boards/STM32F411VETx_FLASH.ld
TEXT0_ADDR = 0x08000000
TEXT1_ADDR = 0x08010000
TEXT1_ADDR = 0x08020000

View File

@ -1,33 +1,59 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PC04) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PC05) },
{ MP_ROM_QSTR(MP_QSTR_Y10), MP_ROM_PTR(&pin_PA10) },
{ MP_ROM_QSTR(MP_QSTR_Y9), MP_ROM_PTR(&pin_PA13) },
{ MP_ROM_QSTR(MP_QSTR_Y8), MP_ROM_PTR(&pin_PA14) },
{ MP_ROM_QSTR(MP_QSTR_Y7), MP_ROM_PTR(&pin_PA15) },
{ MP_ROM_QSTR(MP_QSTR_Y6), MP_ROM_PTR(&pin_PB03) },
{ MP_ROM_QSTR(MP_QSTR_Y5), MP_ROM_PTR(&pin_PB04) },
{ MP_ROM_QSTR(MP_QSTR_Y4), MP_ROM_PTR(&pin_PB05) },
{ MP_ROM_QSTR(MP_QSTR_Y3), MP_ROM_PTR(&pin_PB06) },
{ MP_ROM_QSTR(MP_QSTR_Y2), MP_ROM_PTR(&pin_PB07) },
{ MP_ROM_QSTR(MP_QSTR_Y1), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_Y0), MP_ROM_PTR(&pin_PB09) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PC07) },
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PC06) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PB09) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PC03) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PC02) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PC01) },
{ MP_ROM_QSTR(MP_QSTR_X15), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_X14), MP_ROM_PTR(&pin_PB15) },
{ MP_ROM_QSTR(MP_QSTR_X13), MP_ROM_PTR(&pin_PB14) },
{ MP_ROM_QSTR(MP_QSTR_X12), MP_ROM_PTR(&pin_PB13) },
{ MP_ROM_QSTR(MP_QSTR_X11), MP_ROM_PTR(&pin_PB12) },
{ MP_ROM_QSTR(MP_QSTR_X10), MP_ROM_PTR(&pin_PB10) },
{ MP_ROM_QSTR(MP_QSTR_X9), MP_ROM_PTR(&pin_PB01) },
{ MP_ROM_QSTR(MP_QSTR_X8), MP_ROM_PTR(&pin_PB00) },
{ MP_ROM_QSTR(MP_QSTR_X7), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_X6), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR_X5), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR_X4), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR_X3), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_X2), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_X1), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_X0), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB07) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB06) },
{ MP_ROM_QSTR(MP_QSTR_SDA1), MP_ROM_PTR(&pin_PB09) },
{ MP_ROM_QSTR(MP_QSTR_SCL1), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_SDA2), MP_ROM_PTR(&pin_PB03) },
{ MP_ROM_QSTR(MP_QSTR_SCL2), MP_ROM_PTR(&pin_PB10) },
{ MP_ROM_QSTR(MP_QSTR_SDA3), MP_ROM_PTR(&pin_PB04) },
{ MP_ROM_QSTR(MP_QSTR_SCL3), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB13) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PB14) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB15) },
{ MP_ROM_QSTR(MP_QSTR_SCK1), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR_MISO1), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR_MOSI1), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_SCK2), MP_ROM_PTR(&pin_PB13) },
{ MP_ROM_QSTR(MP_QSTR_MISO2), MP_ROM_PTR(&pin_PB14) },
{ MP_ROM_QSTR(MP_QSTR_MOSI2), MP_ROM_PTR(&pin_PB15) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB10) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB11) },
{ MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_PB07) },
{ MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_PB06) },
{ MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_LED_YELLOW), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_SW), MP_ROM_PTR(&pin_PC13) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -93,7 +93,7 @@
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)12000000) /*!< Value of the External oscillator in Hz */
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)

View File

@ -26,27 +26,23 @@
//Micropython setup
#define MICROPY_HW_BOARD_NAME "Feather STM32F405 Express"
#define MICROPY_HW_MCU_NAME "STM32F405RG"
#define MICROPY_HW_BOARD_NAME "stm32f411ce-blackpill"
#define MICROPY_HW_MCU_NAME "STM32F411CE"
#define FLASH_SIZE (0x100000)
#define FLASH_SIZE (0x80000)
#define FLASH_PAGE_SIZE (0x4000)
#define AUTORESET_DELAY_MS 500
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
#define BOARD_OSC_DIV 25
#define BOARD_NO_VBUS
// On-board flash
#define SPI_FLASH_MOSI_PIN &pin_PB05
#define SPI_FLASH_MISO_PIN &pin_PB04
#define SPI_FLASH_SCK_PIN &pin_PB03
#define SPI_FLASH_CS_PIN &pin_PA15
// #define SPI_FLASH_MOSI_PIN (&pin_PA07)
// #define SPI_FLASH_MISO_PIN (&pin_PA06)
// #define SPI_FLASH_SCK_PIN (&pin_PA05)
// #define SPI_FLASH_CS_PIN (&pin_PA04)
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
#define DEFAULT_SPI_BUS_SCK (&pin_PB13)
#define DEFAULT_SPI_BUS_MOSI (&pin_PB15)
#define DEFAULT_SPI_BUS_MISO (&pin_PB14)
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000)
#define DEFAULT_UART_BUS_RX (&pin_PB11)
#define DEFAULT_UART_BUS_TX (&pin_PB10)
#define AUTORESET_DELAY_MS 500

View File

@ -0,0 +1,41 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
//Micropython setup
#define MICROPY_HW_BOARD_NAME "stm32f411ce-blackpill"
#define MICROPY_HW_MCU_NAME "STM32F411CE"
#define FLASH_SIZE (0x80000)
#define FLASH_PAGE_SIZE (0x4000)
#define BOARD_OSC_DIV 25
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000)
#define AUTORESET_DELAY_MS 500

View File

@ -1,19 +1,22 @@
USB_VID = 0x239A
USB_PID = 0x805A
USB_PRODUCT = "Feather STM32F405 Express"
USB_MANUFACTURER = "Adafruit Industries LLC"
USB_PID = 0x806A
USB_PRODUCT = "stm32f411ce blackpill"
USB_MANUFACTURER = "Unknown"
USB_DEVICES = "CDC,MSC"
SPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = GD25Q16C
LONGINT_IMPL = MPZ
# SPI_FLASH_FILESYSTEM = 1
# EXTERNAL_FLASH_DEVICE_COUNT = 1
# EXTERNAL_FLASH_DEVICES = xxxxxx #See supervisor/shared/external_flash/devices.h for options
# LONGINT_IMPL = MPZ
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
MCU_SERIES = m4
MCU_VARIANT = stm32f4
MCU_SUB_VARIANT = stm32f405xx
MCU_PACKAGE = 64
CMSIS_MCU = STM32F405xx
LD_FILE = boards/STM32F405.ld
MCU_SUB_VARIANT = stm32f411xe
MCU_PACKAGE = 48
CMSIS_MCU = STM32F411xE
LD_FILE = boards/STM32F411VETx_FLASH.ld
TEXT0_ADDR = 0x08000000
TEXT1_ADDR = 0x08010000
TEXT1_ADDR = 0x08020000

View File

@ -1,33 +1,39 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PC04) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PC05) },
{ MP_ROM_QSTR(MP_QSTR_B12), MP_ROM_PTR(&pin_PB12) },
{ MP_ROM_QSTR(MP_QSTR_B13), MP_ROM_PTR(&pin_PB13) },
{ MP_ROM_QSTR(MP_QSTR_B14), MP_ROM_PTR(&pin_PB14) },
{ MP_ROM_QSTR(MP_QSTR_B15), MP_ROM_PTR(&pin_PB15) },
{ MP_ROM_QSTR(MP_QSTR_A8), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_A9), MP_ROM_PTR(&pin_PA09) }, //USB (shouldn't be used)
{ MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_PA10) }, //USB (shouldn't be used)
{ MP_ROM_QSTR(MP_QSTR_A11), MP_ROM_PTR(&pin_PA11) }, //USB (shouldn't be used)
{ MP_ROM_QSTR(MP_QSTR_A12), MP_ROM_PTR(&pin_PA12) }, //USB (shouldn't be used)
{ MP_ROM_QSTR(MP_QSTR_A15), MP_ROM_PTR(&pin_PA15) },
{ MP_ROM_QSTR(MP_QSTR_B3), MP_ROM_PTR(&pin_PB03) },
{ MP_ROM_QSTR(MP_QSTR_B4), MP_ROM_PTR(&pin_PB04) },
{ MP_ROM_QSTR(MP_QSTR_B5), MP_ROM_PTR(&pin_PB05) },
{ MP_ROM_QSTR(MP_QSTR_B6), MP_ROM_PTR(&pin_PB06) },
{ MP_ROM_QSTR(MP_QSTR_B7), MP_ROM_PTR(&pin_PB07) },
{ MP_ROM_QSTR(MP_QSTR_B8), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_B9), MP_ROM_PTR(&pin_PB09) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PC07) },
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PC06) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PB09) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PC03) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PC02) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PC01) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB07) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB06) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB13) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PB14) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB15) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB10) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB11) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
{ MP_ROM_QSTR(MP_QSTR_B10), MP_ROM_PTR(&pin_PB10) },
{ MP_ROM_QSTR(MP_QSTR_B2), MP_ROM_PTR(&pin_PB02) },
{ MP_ROM_QSTR(MP_QSTR_B1), MP_ROM_PTR(&pin_PB01) },
{ MP_ROM_QSTR(MP_QSTR_B0), MP_ROM_PTR(&pin_PB00) },
{ MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_C15), MP_ROM_PTR(&pin_PC15) },
{ MP_ROM_QSTR(MP_QSTR_C14), MP_ROM_PTR(&pin_PC14) },
{ MP_ROM_QSTR(MP_QSTR_C13), MP_ROM_PTR(&pin_PC13) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PC13) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -67,7 +67,7 @@
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
/* #define HAL_WWDG_MODULE_ENABLED */
#define HAL_PCD_MODULE_ENABLED
/* #define HAL_PCD_MODULE_ENABLED */
/* #define HAL_HCD_MODULE_ENABLED */
/* #define HAL_DSI_MODULE_ENABLED */
/* #define HAL_QSPI_MODULE_ENABLED */
@ -93,7 +93,7 @@
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)12000000) /*!< Value of the External oscillator in Hz */
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)

View File

@ -32,6 +32,8 @@
#define FLASH_SIZE (0x80000) //512K
#define FLASH_PAGE_SIZE (0x4000) //16K
#define BOARD_OSC_DIV 8
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000)

View File

@ -46,8 +46,12 @@ bool neopixel_in_use;
#elif MCU_PACKAGE == 64
#define GPIO_PORT_COUNT 3
GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC};
#elif MCU_PACKAGE == 48
#define GPIO_PORT_COUNT 3
GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC};
#endif
STATIC uint16_t claimed_pins[GPIO_PORT_COUNT];
STATIC uint16_t never_reset_pins[GPIO_PORT_COUNT];

View File

@ -169,8 +169,8 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_PE15), MP_ROM_PTR(&pin_PE15) },
#endif
{ MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) },
#if (0)
// { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) },
#if MCU_PACKAGE == 144
{ MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) },
#endif
{ MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) },
{ MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) },

View File

@ -25,6 +25,7 @@
* THE SOFTWARE.
*/
#include "stm32f4xx_hal.h"
#include "py/mpconfig.h"
void stm32f4_peripherals_clocks_init(void) {
//System clock init
@ -44,7 +45,7 @@ void stm32f4_peripherals_clocks_init(void) {
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLM = BOARD_OSC_DIV;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;

View File

@ -24,94 +24,12 @@
* THE SOFTWARE.
*/
/* GPIO PIN REFERENCE
#define DATA_Ready_Pin GPIO_PIN_2
#define DATA_Ready_GPIO_Port GPIOE
#define CS_I2C_SPI_Pin GPIO_PIN_3
#define CS_I2C_SPI_GPIO_Port GPIOE
#define INT1_Pin GPIO_PIN_4
#define INT1_GPIO_Port GPIOE
#define INT2_Pin GPIO_PIN_5
#define INT2_GPIO_Port GPIOE
#define PC14_OSC32_IN_Pin GPIO_PIN_14
#define PC14_OSC32_IN_GPIO_Port GPIOC
#define PC15_OSC32_OUT_Pin GPIO_PIN_15
#define PC15_OSC32_OUT_GPIO_Port GPIOC
#define PH0_OSC_IN_Pin GPIO_PIN_0
#define PH0_OSC_IN_GPIO_Port GPIOH
#define PH1_OSC_OUT_Pin GPIO_PIN_1
#define PH1_OSC_OUT_GPIO_Port GPIOH
#define OTG_FS_PowerSwitchOn_Pin GPIO_PIN_0
#define OTG_FS_PowerSwitchOn_GPIO_Port GPIOC
#define PDM_OUT_Pin GPIO_PIN_3
#define PDM_OUT_GPIO_Port GPIOC
#define I2S3_WS_Pin GPIO_PIN_4
#define I2S3_WS_GPIO_Port GPIOA
#define SPI1_SCK_Pin GPIO_PIN_5
#define SPI1_SCK_GPIO_Port GPIOA
#define SPI1_MISO_Pin GPIO_PIN_6
#define SPI1_MISO_GPIO_Port GPIOA
#define SPI1_MOSI_Pin GPIO_PIN_7
#define SPI1_MOSI_GPIO_Port GPIOA
#define CLK_IN_Pin GPIO_PIN_10
#define CLK_IN_GPIO_Port GPIOB
#define LD4_Pin GPIO_PIN_12
#define LD4_GPIO_Port GPIOD
#define LD3_Pin GPIO_PIN_13
#define LD3_GPIO_Port GPIOD
#define LD5_Pin GPIO_PIN_14
#define LD5_GPIO_Port GPIOD
#define LD6_Pin GPIO_PIN_15
#define LD6_GPIO_Port GPIOD
#define I2S3_MCK_Pin GPIO_PIN_7
#define I2S3_MCK_GPIO_Port GPIOC
#define VBUS_FS_Pin GPIO_PIN_9
#define VBUS_FS_GPIO_Port GPIOA
#define OTG_FS_ID_Pin GPIO_PIN_10
#define OTG_FS_ID_GPIO_Port GPIOA
#define OTG_FS_DM_Pin GPIO_PIN_11
#define OTG_FS_DM_GPIO_Port GPIOA
#define OTG_FS_DP_Pin GPIO_PIN_12
#define OTG_FS_DP_GPIO_Port GPIOA
#define SWDIO_Pin GPIO_PIN_13
#define SWDIO_GPIO_Port GPIOA
#define SWCLK_Pin GPIO_PIN_14
#define SWCLK_GPIO_Port GPIOA
#define I2S3_SCK_Pin GPIO_PIN_10
#define I2S3_SCK_GPIO_Port GPIOC
#define I2S3_SD_Pin GPIO_PIN_12
#define I2S3_SD_GPIO_Port GPIOC
#define Audio_RST_Pin GPIO_PIN_4
#define Audio_RST_GPIO_Port GPIOD
#define OTG_FS_OverCurrent_Pin GPIO_PIN_5
#define OTG_FS_OverCurrent_GPIO_Port GPIOD
#define SWO_Pin GPIO_PIN_3
#define SWO_GPIO_Port GPIOB
#define Audio_SCL_Pin GPIO_PIN_6
#define Audio_SCL_GPIO_Port GPIOB
#define Audio_SDA_Pin GPIO_PIN_9
#define Audio_SDA_GPIO_Port GPIOB
#define MEMS_INT2_Pin GPIO_PIN_1
#define MEMS_INT2_GPIO_Port GPIOE
*/
#define LD4_Pin GPIO_PIN_12
#define LD4_GPIO_Port GPIOD
#define LD3_Pin GPIO_PIN_13
#define LD3_GPIO_Port GPIOD
#define LD5_Pin GPIO_PIN_14
#define LD5_GPIO_Port GPIOD
#define LD6_Pin GPIO_PIN_15
#define LD6_GPIO_Port GPIOD
#include "stm32f4xx_hal.h"
#include "stm32f4/gpio.h"
#include "common-hal/microcontroller/Pin.h"
void stm32f4_peripherals_gpio_init(void) {
//Enable all GPIO for now
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
//* GPIO Ports Clock Enable */
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
@ -119,31 +37,11 @@ void stm32f4_peripherals_gpio_init(void) {
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin */
GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
//Status LED chain
stm32f4_peripherals_status_led(0,1);
stm32f4_peripherals_status_led(1,0);
stm32f4_peripherals_status_led(2,0);
stm32f4_peripherals_status_led(3,0);
//Never reset pins
never_reset_pin_number(2,13); //PC13 anti tamp
never_reset_pin_number(2,14); //PC14 OSC32_IN
never_reset_pin_number(2,15); //PC15 OSC32_OUT
never_reset_pin_number(0,13); //PA13 SWDIO
never_reset_pin_number(0,14); //PA14 SWCLK
never_reset_pin_number(0,15); //PA15 JTDI
never_reset_pin_number(1,3); //PB3 JTDO
never_reset_pin_number(1,4); //PB4 JTRST
// Port H is not included in GPIO port array
// never_reset_pin_number(5,0); //PH0 JTDO
@ -152,18 +50,6 @@ void stm32f4_peripherals_gpio_init(void) {
//LEDs are inverted on F411 DISCO
void stm32f4_peripherals_status_led(uint8_t led, uint8_t state) {
switch(led)
{
case 0: HAL_GPIO_WritePin(GPIOD, LD4_Pin, (state ^ 1));
break;
case 1: HAL_GPIO_WritePin(GPIOD, LD3_Pin, (state ^ 1));
break;
case 2: HAL_GPIO_WritePin(GPIOD, LD5_Pin, (state ^ 1));
break;
case 3: HAL_GPIO_WritePin(GPIOD, LD6_Pin, (state ^ 1));
break;
default: break;
}
}

View File

@ -32,6 +32,8 @@
#include "lib/mp-readline/readline.h"
#include "stm32f4xx_hal.h"
#include "py/mpconfig.h"
#include "common-hal/microcontroller/Pin.h"
void init_usb_hardware(void) {
@ -80,6 +82,20 @@ void init_usb_hardware(void) {
never_reset_pin_number(0, 8);
#endif
#ifdef BOARD_NO_VBUS
disable_usb_vbus();
#endif
/* Peripheral clock enable */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
}
STATIC void disable_usb_vbus(void) {
#ifdef USB_OTG_GCCFG_VBDEN
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
#else
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
#endif
}

View File

@ -96,6 +96,7 @@ STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
STATIC const mp_stream_p_t fileio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = stest_read,
.write = stest_write,
.ioctl = stest_ioctl,
@ -123,6 +124,7 @@ STATIC const mp_rom_map_elem_t rawfile_locals_dict_table2[] = {
STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict2, rawfile_locals_dict_table2);
STATIC const mp_stream_p_t textio_stream_p2 = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = stest_read2,
.write = NULL,
.is_text = true,

View File

@ -230,6 +230,7 @@ STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
#if MICROPY_PY_IO_FILEIO
STATIC const mp_stream_p_t fileio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = fdfile_read,
.write = fdfile_write,
.ioctl = fdfile_ioctl,
@ -248,6 +249,7 @@ const mp_obj_type_t mp_type_fileio = {
#endif
STATIC const mp_stream_p_t textio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = fdfile_read,
.write = fdfile_write,
.ioctl = fdfile_ioctl,

View File

@ -374,6 +374,7 @@ STATIC const mp_rom_map_elem_t usocket_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(usocket_locals_dict, usocket_locals_dict_table);
STATIC const mp_stream_p_t usocket_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = socket_read,
.write = socket_write,
.ioctl = socket_ioctl,

View File

@ -117,6 +117,9 @@ endif
ifeq ($(CIRCUITPY_AUDIOMIXER),1)
SRC_PATTERNS += audiomixer/%
endif
ifeq ($(CIRCUITPY_AUDIOMP3),1)
SRC_PATTERNS += audiomp3/%
endif
ifeq ($(CIRCUITPY_BITBANGIO),1)
SRC_PATTERNS += bitbangio/%
endif
@ -319,6 +322,8 @@ SRC_SHARED_MODULE_ALL = \
audiomixer/__init__.c \
audiomixer/Mixer.c \
audiomixer/MixerVoice.c \
audiomp3/__init__.c \
audiomp3/MP3File.c \
bitbangio/I2C.c \
bitbangio/OneWire.c \
bitbangio/SPI.c \
@ -371,6 +376,26 @@ SRC_SHARED_MODULE_ALL += \
touchio/TouchIn.c \
touchio/__init__.c
endif
ifeq ($(CIRCUITPY_AUDIOMP3),1)
SRC_MOD += $(addprefix lib/mp3/src/, \
bitstream.c \
buffers.c \
dct32.c \
dequant.c \
dqchan.c \
huffman.c \
hufftabs.c \
imdct.c \
mp3dec.c \
mp3tabs.c \
polyphase.c \
scalfact.c \
stproc.c \
subband.c \
trigtabs.c \
)
$(BUILD)/lib/mp3/src/buffers.o: CFLAGS += -include "py/misc.h" -D'MPDEC_ALLOCATOR(x)=m_malloc(x,0)' -D'MPDEC_FREE(x)=m_free(x)'
endif
# All possible sources are listed here, and are filtered by SRC_PATTERNS.
SRC_SHARED_MODULE_INTERNAL = \

View File

@ -252,6 +252,13 @@ extern const struct _mp_obj_module_t audiomixer_module;
#define AUDIOMIXER_MODULE
#endif
#if CIRCUITPY_AUDIOMP3
#define AUDIOMP3_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_audiomp3), (mp_obj_t)&audiomp3_module },
extern const struct _mp_obj_module_t audiomp3_module;
#else
#define AUDIOMP3_MODULE
#endif
#if CIRCUITPY_AUDIOPWMIO
#define AUDIOPWMIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_audiopwmio), (mp_obj_t)&audiopwmio_module },
extern const struct _mp_obj_module_t audiopwmio_module;
@ -582,6 +589,7 @@ extern const struct _mp_obj_module_t ustack_module;
AUDIOCORE_MODULE \
AUDIOIO_MODULE \
AUDIOMIXER_MODULE \
AUDIOMP3_MODULE \
AUDIOPWMIO_MODULE \
BITBANGIO_MODULE \
BLEIO_MODULE \

View File

@ -104,6 +104,15 @@ CIRCUITPY_AUDIOMIXER = $(CIRCUITPY_AUDIOIO)
endif
CFLAGS += -DCIRCUITPY_AUDIOMIXER=$(CIRCUITPY_AUDIOMIXER)
ifndef CIRCUITPY_AUDIOMP3
ifeq ($(CIRCUITPY_FULL_BUILD),1)
CIRCUITPY_AUDIOMP3 = $(CIRCUITPY_AUDIOCORE)
else
CIRCUITPY_AUDIOMP3 = 0
endif
endif
CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3)
ifndef CIRCUITPY_BITBANGIO
CIRCUITPY_BITBANGIO = $(CIRCUITPY_FULL_BUILD)
endif

View File

@ -667,6 +667,9 @@ void gc_free(void *ptr) {
if (ptr == NULL) {
GC_EXIT();
} else {
if (MP_STATE_MEM(gc_pool_start) == 0) {
reset_into_safe_mode(GC_ALLOC_OUTSIDE_VM);
}
// get the GC block number corresponding to this pointer
assert(VERIFY_PTR(ptr));
size_t block = BLOCK_FROM_PTR(ptr);

View File

@ -90,6 +90,7 @@ STATIC mp_uint_t iobase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, in
}
STATIC const mp_stream_p_t iobase_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = iobase_read,
.write = iobase_write,
.ioctl = iobase_ioctl,
@ -185,6 +186,7 @@ STATIC const mp_rom_map_elem_t bufwriter_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(bufwriter_locals_dict, bufwriter_locals_dict_table);
STATIC const mp_stream_p_t bufwriter_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.write = bufwriter_write,
};

View File

@ -240,6 +240,7 @@ STATIC const mp_rom_map_elem_t stringio_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(stringio_locals_dict, stringio_locals_dict_table);
STATIC const mp_stream_p_t stringio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = stringio_read,
.write = stringio_write,
.ioctl = stringio_ioctl,
@ -247,6 +248,7 @@ STATIC const mp_stream_p_t stringio_stream_p = {
};
STATIC const mp_stream_p_t bytesio_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = stringio_read,
.write = stringio_write,
.ioctl = stringio_ioctl,

50
py/proto.c Normal file
View File

@ -0,0 +1,50 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/obj.h"
#include "py/proto.h"
#include "py/runtime.h"
#ifndef MICROPY_UNSAFE_PROTO
const void *mp_proto_get(uint16_t name, mp_const_obj_t obj) {
mp_obj_type_t *type = mp_obj_get_type(obj);
if (!type->protocol) return NULL;
uint16_t proto_name = *(const uint16_t*) type->protocol;
if (proto_name == name) {
return type->protocol;
}
return NULL;
}
#endif
const void *mp_proto_get_or_throw(uint16_t name, mp_const_obj_t obj) {
const void *proto = mp_proto_get(name, obj);
if (proto) {
return proto;
}
mp_raise_TypeError_varg(translate("'%s' object does not support '%q'"),
mp_obj_get_type_str(obj), name);
}

43
py/proto.h Normal file
View File

@ -0,0 +1,43 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_PY_PROTO_H
#define MICROPY_INCLUDED_PY_PROTO_H
#ifdef MICROPY_UNSAFE_PROTO
#define MP_PROTOCOL_HEAD /* NOTHING */
#define MP_PROTO_IMPLEMENT(name) /* NOTHING */
static inline void *mp_proto_get(uint16_t name, mp_const_obj_type_t obj) { return mp_obj_get_type(obj)->protocol; }
#else
#define MP_PROTOCOL_HEAD \
uint16_t name; // The name of this protocol, a qstr
#define MP_PROTO_IMPLEMENT(n) .name = n,
const void *mp_proto_get(uint16_t name, mp_const_obj_t obj);
const void *mp_proto_get_or_throw(uint16_t name, mp_const_obj_t obj);
#endif
#endif

View File

@ -214,6 +214,7 @@ PY_CORE_O_BASENAME = $(addprefix py/,\
objtype.o \
objzip.o \
opmethods.o \
proto.o \
reload.o \
sequence.o \
stream.o \

View File

@ -86,8 +86,7 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode
}
const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) {
mp_obj_type_t *type = mp_obj_get_type(self_in);
const mp_stream_p_t *stream_p = type->protocol;
const mp_stream_p_t *stream_p = mp_proto_get(MP_QSTR_protocol_stream, self_in);
if (stream_p == NULL
|| ((flags & MP_STREAM_OP_READ) && stream_p->read == NULL)
|| ((flags & MP_STREAM_OP_WRITE) && stream_p->write == NULL)
@ -522,7 +521,7 @@ int mp_stream_errno;
ssize_t mp_stream_posix_write(mp_obj_t stream, const void *buf, size_t len) {
mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
const mp_stream_p_t *stream_p = o->type->protocol;
const mp_stream_p_t *stream_p = mp_get_stream(o);
mp_uint_t out_sz = stream_p->write(stream, buf, len, &mp_stream_errno);
if (out_sz == MP_STREAM_ERROR) {
return -1;
@ -533,7 +532,7 @@ ssize_t mp_stream_posix_write(mp_obj_t stream, const void *buf, size_t len) {
ssize_t mp_stream_posix_read(mp_obj_t stream, void *buf, size_t len) {
mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
const mp_stream_p_t *stream_p = o->type->protocol;
const mp_stream_p_t *stream_p = mp_get_stream(o);
mp_uint_t out_sz = stream_p->read(stream, buf, len, &mp_stream_errno);
if (out_sz == MP_STREAM_ERROR) {
return -1;
@ -544,7 +543,7 @@ ssize_t mp_stream_posix_read(mp_obj_t stream, void *buf, size_t len) {
off_t mp_stream_posix_lseek(mp_obj_t stream, off_t offset, int whence) {
const mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
const mp_stream_p_t *stream_p = o->type->protocol;
const mp_stream_p_t *stream_p = mp_get_stream(o);
struct mp_stream_seek_t seek_s;
seek_s.offset = offset;
seek_s.whence = whence;
@ -557,7 +556,7 @@ off_t mp_stream_posix_lseek(mp_obj_t stream, off_t offset, int whence) {
int mp_stream_posix_fsync(mp_obj_t stream) {
mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
const mp_stream_p_t *stream_p = o->type->protocol;
const mp_stream_p_t *stream_p = mp_get_stream(o);
mp_uint_t res = stream_p->ioctl(stream, MP_STREAM_FLUSH, 0, &mp_stream_errno);
if (res == MP_STREAM_ERROR) {
return -1;

View File

@ -27,6 +27,7 @@
#define MICROPY_INCLUDED_PY_STREAM_H
#include "py/obj.h"
#include "py/proto.h"
#include "py/mperrno.h"
#define MP_STREAM_ERROR ((mp_uint_t)-1)
@ -64,6 +65,7 @@ struct mp_stream_seek_t {
// Stream protocol
typedef struct _mp_stream_p_t {
MP_PROTOCOL_HEAD
// On error, functions should return MP_STREAM_ERROR and fill in *errcode (values
// are implementation-dependent, but will be exposed to user, e.g. via exception).
mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
@ -93,7 +95,7 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj);
// Object is assumed to have a non-NULL stream protocol with valid r/w/ioctl methods
static inline const mp_stream_p_t *mp_get_stream(mp_const_obj_t self) {
return (const mp_stream_p_t*)((const mp_obj_base_t*)MP_OBJ_TO_PTR(self))->type->protocol;
return mp_proto_get(MP_QSTR_protocol_stream, self);
}
const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags);

View File

@ -230,6 +230,7 @@ STATIC const mp_rom_map_elem_t bleio_characteristic_buffer_locals_dict_table[] =
STATIC MP_DEFINE_CONST_DICT(bleio_characteristic_buffer_locals_dict, bleio_characteristic_buffer_locals_dict_table);
STATIC const mp_stream_p_t characteristic_buffer_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = bleio_characteristic_buffer_read,
.write = bleio_characteristic_buffer_write,
.ioctl = bleio_characteristic_buffer_ioctl,

View File

@ -180,9 +180,20 @@ STATIC const mp_rom_map_elem_t audioio_rawsample_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(audioio_rawsample_locals_dict, audioio_rawsample_locals_dict_table);
STATIC const audiosample_p_t audioio_rawsample_proto = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample)
.sample_rate = (audiosample_sample_rate_fun)common_hal_audioio_rawsample_get_sample_rate,
.bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audioio_rawsample_get_bits_per_sample,
.channel_count = (audiosample_channel_count_fun)common_hal_audioio_rawsample_get_channel_count,
.reset_buffer = (audiosample_reset_buffer_fun)audioio_rawsample_reset_buffer,
.get_buffer = (audiosample_get_buffer_fun)audioio_rawsample_get_buffer,
.get_buffer_structure = (audiosample_get_buffer_structure_fun)audioio_rawsample_get_buffer_structure,
};
const mp_obj_type_t audioio_rawsample_type = {
{ &mp_type_type },
.name = MP_QSTR_RawSample,
.make_new = audioio_rawsample_make_new,
.locals_dict = (mp_obj_dict_t*)&audioio_rawsample_locals_dict,
.protocol = &audioio_rawsample_proto,
};

View File

@ -39,6 +39,8 @@ void common_hal_audioio_rawsample_construct(audioio_rawsample_obj_t* self,
void common_hal_audioio_rawsample_deinit(audioio_rawsample_obj_t* self);
bool common_hal_audioio_rawsample_deinited(audioio_rawsample_obj_t* self);
uint32_t common_hal_audioio_rawsample_get_sample_rate(audioio_rawsample_obj_t* self);
uint8_t common_hal_audioio_rawsample_get_bits_per_sample(audioio_rawsample_obj_t* self);
uint8_t common_hal_audioio_rawsample_get_channel_count(audioio_rawsample_obj_t* self);
void common_hal_audioio_rawsample_set_sample_rate(audioio_rawsample_obj_t* self, uint32_t sample_rate);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H

View File

@ -206,9 +206,21 @@ STATIC const mp_rom_map_elem_t audioio_wavefile_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(audioio_wavefile_locals_dict, audioio_wavefile_locals_dict_table);
STATIC const audiosample_p_t audioio_wavefile_proto = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample)
.sample_rate = (audiosample_sample_rate_fun)common_hal_audioio_wavefile_get_sample_rate,
.bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audioio_wavefile_get_bits_per_sample,
.channel_count = (audiosample_channel_count_fun)common_hal_audioio_wavefile_get_channel_count,
.reset_buffer = (audiosample_reset_buffer_fun)audioio_wavefile_reset_buffer,
.get_buffer = (audiosample_get_buffer_fun)audioio_wavefile_get_buffer,
.get_buffer_structure = (audiosample_get_buffer_structure_fun)audioio_wavefile_get_buffer_structure,
};
const mp_obj_type_t audioio_wavefile_type = {
{ &mp_type_type },
.name = MP_QSTR_WaveFile,
.make_new = audioio_wavefile_make_new,
.locals_dict = (mp_obj_dict_t*)&audioio_wavefile_locals_dict,
.protocol = &audioio_wavefile_proto,
};

View File

@ -291,9 +291,20 @@ STATIC const mp_rom_map_elem_t audiomixer_mixer_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(audiomixer_mixer_locals_dict, audiomixer_mixer_locals_dict_table);
STATIC const audiosample_p_t audiomixer_mixer_proto = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample)
.sample_rate = (audiosample_sample_rate_fun)common_hal_audiomixer_mixer_get_sample_rate,
.bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audiomixer_mixer_get_bits_per_sample,
.channel_count = (audiosample_channel_count_fun)common_hal_audiomixer_mixer_get_channel_count,
.reset_buffer = (audiosample_reset_buffer_fun)audiomixer_mixer_reset_buffer,
.get_buffer = (audiosample_get_buffer_fun)audiomixer_mixer_get_buffer,
.get_buffer_structure = (audiosample_get_buffer_structure_fun)audiomixer_mixer_get_buffer_structure,
};
const mp_obj_type_t audiomixer_mixer_type = {
{ &mp_type_type },
.name = MP_QSTR_Mixer,
.make_new = audiomixer_mixer_make_new,
.locals_dict = (mp_obj_dict_t*)&audiomixer_mixer_locals_dict,
.protocol = &audiomixer_mixer_proto,
};

View File

@ -47,5 +47,7 @@ bool common_hal_audiomixer_mixer_deinited(audiomixer_mixer_obj_t* self);
bool common_hal_audiomixer_mixer_get_playing(audiomixer_mixer_obj_t* self);
uint32_t common_hal_audiomixer_mixer_get_sample_rate(audiomixer_mixer_obj_t* self);
uint8_t common_hal_audiomixer_mixer_get_channel_count(audiomixer_mixer_obj_t* self);
uint8_t common_hal_audiomixer_mixer_get_bits_per_sample(audiomixer_mixer_obj_t* self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMIXER_MIXER_H

View File

@ -0,0 +1,226 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdint.h>
#include "lib/utils/context_manager_helpers.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "shared-bindings/audiomp3/MP3File.h"
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
//| .. currentmodule:: audiomp3
//|
//| :class:`MP3` -- Load a mp3 file for audio playback
//| ========================================================
//|
//| A .mp3 file prepped for audio playback. Only mono and stereo files are supported. Samples must
//| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating
//| an internal buffer.
//|
//| .. class:: MP3(file[, buffer])
//|
//| Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
//|
//| :param typing.BinaryIO file: Already opened mp3 file
//| :param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two buffers are allocated internally. The specific buffer size required depends on the mp3 file.
//|
//|
//| Playing a mp3 file from flash::
//|
//| import board
//| import audiomp3
//| import audioio
//| import digitalio
//|
//| # Required for CircuitPlayground Express
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
//| speaker_enable.switch_to_output(value=True)
//|
//| data = open("cplay-16bit-16khz-64kbps.mp3", "rb")
//| mp3 = audiomp3.MP3File(data)
//| a = audioio.AudioOut(board.A0)
//|
//| print("playing")
//| a.play(mp3)
//| while a.playing:
//| pass
//| print("stopped")
//|
STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
mp_arg_check_num(n_args, kw_args, 1, 2, false);
audiomp3_mp3file_obj_t *self = m_new_obj(audiomp3_mp3file_obj_t);
self->base.type = &audiomp3_mp3file_type;
if (!MP_OBJ_IS_TYPE(args[0], &mp_type_fileio)) {
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
}
uint8_t *buffer = NULL;
size_t buffer_size = 0;
if (n_args >= 2) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE);
buffer = bufinfo.buf;
buffer_size = bufinfo.len;
}
common_hal_audiomp3_mp3file_construct(self, MP_OBJ_TO_PTR(args[0]),
buffer, buffer_size);
return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit()
//|
//| Deinitialises the MP3 and releases all memory resources for reuse.
//|
STATIC mp_obj_t audiomp3_mp3file_deinit(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiomp3_mp3file_deinit(self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiomp3_mp3file_deinit_obj, audiomp3_mp3file_deinit);
STATIC void check_for_deinit(audiomp3_mp3file_obj_t *self) {
if (common_hal_audiomp3_mp3file_deinited(self)) {
raise_deinited_error();
}
}
//| .. method:: __enter__()
//|
//| No-op used by Context Managers.
//|
// Provided by context manager helper.
//| .. method:: __exit__()
//|
//| Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info.
//|
STATIC mp_obj_t audiomp3_mp3file_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiomp3_mp3file_deinit(args[0]);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomp3_mp3file___exit___obj, 4, 4, audiomp3_mp3file_obj___exit__);
//| .. attribute:: sample_rate
//|
//| 32 bit value that dictates how quickly samples are loaded into the DAC
//| in Hertz (cycles per second). When the sample is looped, this can change
//| the pitch output without changing the underlying sample.
//|
STATIC mp_obj_t audiomp3_mp3file_obj_get_sample_rate(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
return MP_OBJ_NEW_SMALL_INT(common_hal_audiomp3_mp3file_get_sample_rate(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(audiomp3_mp3file_get_sample_rate_obj, audiomp3_mp3file_obj_get_sample_rate);
STATIC mp_obj_t audiomp3_mp3file_obj_set_sample_rate(mp_obj_t self_in, mp_obj_t sample_rate) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
common_hal_audiomp3_mp3file_set_sample_rate(self, mp_obj_get_int(sample_rate));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(audiomp3_mp3file_set_sample_rate_obj, audiomp3_mp3file_obj_set_sample_rate);
const mp_obj_property_t audiomp3_mp3file_sample_rate_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&audiomp3_mp3file_get_sample_rate_obj,
(mp_obj_t)&audiomp3_mp3file_set_sample_rate_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: bits_per_sample
//|
//| Bits per sample. (read only)
//|
STATIC mp_obj_t audiomp3_mp3file_obj_get_bits_per_sample(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
return MP_OBJ_NEW_SMALL_INT(common_hal_audiomp3_mp3file_get_bits_per_sample(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(audiomp3_mp3file_get_bits_per_sample_obj, audiomp3_mp3file_obj_get_bits_per_sample);
const mp_obj_property_t audiomp3_mp3file_bits_per_sample_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&audiomp3_mp3file_get_bits_per_sample_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: channel_count
//|
//| Number of audio channels. (read only)
//|
STATIC mp_obj_t audiomp3_mp3file_obj_get_channel_count(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
return MP_OBJ_NEW_SMALL_INT(common_hal_audiomp3_mp3file_get_channel_count(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(audiomp3_mp3file_get_channel_count_obj, audiomp3_mp3file_obj_get_channel_count);
const mp_obj_property_t audiomp3_mp3file_channel_count_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&audiomp3_mp3file_get_channel_count_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
STATIC const mp_rom_map_elem_t audiomp3_mp3file_locals_dict_table[] = {
// Methods
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiomp3_mp3file_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiomp3_mp3file___exit___obj) },
// Properties
{ MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audiomp3_mp3file_sample_rate_obj) },
{ MP_ROM_QSTR(MP_QSTR_bits_per_sample), MP_ROM_PTR(&audiomp3_mp3file_bits_per_sample_obj) },
{ MP_ROM_QSTR(MP_QSTR_channel_count), MP_ROM_PTR(&audiomp3_mp3file_channel_count_obj) },
};
STATIC MP_DEFINE_CONST_DICT(audiomp3_mp3file_locals_dict, audiomp3_mp3file_locals_dict_table);
STATIC const audiosample_p_t audiomp3_mp3file_proto = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample)
.sample_rate = (audiosample_sample_rate_fun)common_hal_audiomp3_mp3file_get_sample_rate,
.bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audiomp3_mp3file_get_bits_per_sample,
.channel_count = (audiosample_channel_count_fun)common_hal_audiomp3_mp3file_get_channel_count,
.reset_buffer = (audiosample_reset_buffer_fun)audiomp3_mp3file_reset_buffer,
.get_buffer = (audiosample_get_buffer_fun)audiomp3_mp3file_get_buffer,
.get_buffer_structure = (audiosample_get_buffer_structure_fun)audiomp3_mp3file_get_buffer_structure,
};
const mp_obj_type_t audiomp3_mp3file_type = {
{ &mp_type_type },
.name = MP_QSTR_MP3File,
.make_new = audiomp3_mp3file_make_new,
.locals_dict = (mp_obj_dict_t*)&audiomp3_mp3file_locals_dict,
.protocol = &audiomp3_mp3file_proto,
};

View File

@ -0,0 +1,48 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MP3FILE_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MP3FILE_H
#include "py/obj.h"
#include "extmod/vfs_fat.h"
#include "shared-module/audiomp3/MP3File.h"
extern const mp_obj_type_t audiomp3_mp3file_type;
void common_hal_audiomp3_mp3file_construct(audiomp3_mp3file_obj_t* self,
pyb_file_obj_t* file, uint8_t *buffer, size_t buffer_size);
void common_hal_audiomp3_mp3file_deinit(audiomp3_mp3file_obj_t* self);
bool common_hal_audiomp3_mp3file_deinited(audiomp3_mp3file_obj_t* self);
uint32_t common_hal_audiomp3_mp3file_get_sample_rate(audiomp3_mp3file_obj_t* self);
void common_hal_audiomp3_mp3file_set_sample_rate(audiomp3_mp3file_obj_t* self, uint32_t sample_rate);
uint8_t common_hal_audiomp3_mp3file_get_bits_per_sample(audiomp3_mp3file_obj_t* self);
uint8_t common_hal_audiomp3_mp3file_get_channel_count(audiomp3_mp3file_obj_t* self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MP3FILE_H

View File

@ -0,0 +1,60 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdint.h>
#include "py/obj.h"
#include "py/runtime.h"
#include "shared-bindings/audiomp3/MP3File.h"
//| :mod:`audiomp3` --- Support for MP3-compressed audio files
//| ==========================================================
//|
//| .. module:: audiomp3
//| :synopsis: Support for mp3 files
//|
//| The `audiomp3` module contains an mp3 decoder
//|
//| Libraries
//|
//| .. toctree::
//| :maxdepth: 3
//|
//| MP3File
//|
STATIC const mp_rom_map_elem_t audiomp3_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audiomp3) },
{ MP_ROM_QSTR(MP_QSTR_MP3File), MP_ROM_PTR(&audiomp3_mp3file_type) },
};
STATIC MP_DEFINE_CONST_DICT(audiomp3_module_globals, audiomp3_module_globals_table);
const mp_obj_module_t audiomp3_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&audiomp3_module_globals,
};

View File

@ -0,0 +1,34 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMP3___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMP3___INIT___H
#include "py/obj.h"
// Nothing now.
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMP3___INIT___H

View File

@ -398,6 +398,7 @@ STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(busio_uart_locals_dict, busio_uart_locals_dict_table);
STATIC const mp_stream_p_t uart_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = busio_uart_read,
.write = busio_uart_write,
.ioctl = busio_uart_ioctl,

View File

@ -500,6 +500,7 @@ mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *
}
STATIC const mp_stream_p_t socket_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.ioctl = socket_ioctl,
.is_text = false,
};

View File

@ -112,6 +112,7 @@ STATIC const mp_rom_map_elem_t terminalio_terminal_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(terminalio_terminal_locals_dict, terminalio_terminal_locals_dict_table);
STATIC const mp_stream_p_t terminalio_terminal_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = NULL,
.write = terminalio_terminal_write,
.ioctl = terminalio_terminal_ioctl,

View File

@ -107,6 +107,7 @@ STATIC const mp_rom_map_elem_t usb_midi_portin_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(usb_midi_portin_locals_dict, usb_midi_portin_locals_dict_table);
STATIC const mp_stream_p_t usb_midi_portin_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = usb_midi_portin_read,
.write = NULL,
.ioctl = usb_midi_portin_ioctl,

View File

@ -89,6 +89,7 @@ STATIC const mp_rom_map_elem_t usb_midi_portout_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(usb_midi_portout_locals_dict, usb_midi_portout_locals_dict_table);
STATIC const mp_stream_p_t usb_midi_portout_stream_p = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
.read = NULL,
.write = usb_midi_portout_write,
.ioctl = usb_midi_portout_ioctl,

View File

@ -60,6 +60,12 @@ void common_hal_audioio_rawsample_set_sample_rate(audioio_rawsample_obj_t* self,
uint32_t sample_rate) {
self->sample_rate = sample_rate;
}
uint8_t common_hal_audioio_rawsample_get_bits_per_sample(audioio_rawsample_obj_t* self) {
return self->bits_per_sample;
}
uint8_t common_hal_audioio_rawsample_get_channel_count(audioio_rawsample_obj_t* self) {
return self->channel_count;
}
void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t* self,
bool single_channel,

View File

@ -36,103 +36,37 @@
#include "shared-module/audiomixer/Mixer.h"
uint32_t audiosample_sample_rate(mp_obj_t sample_obj) {
if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) {
audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj);
return sample->sample_rate;
} else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) {
audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
return file->sample_rate;
#if CIRCUITPY_AUDIOMIXER
} else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) {
audiomixer_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj);
return mixer->sample_rate;
#endif
}
return 16000;
const audiosample_p_t *proto = mp_proto_get_or_throw(MP_QSTR_protocol_audiosample, sample_obj);
return proto->sample_rate(MP_OBJ_TO_PTR(sample_obj));
}
uint8_t audiosample_bits_per_sample(mp_obj_t sample_obj) {
if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) {
audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj);
return sample->bits_per_sample;
} else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) {
audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
return file->bits_per_sample;
#if CIRCUITPY_AUDIOMIXER
} else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) {
audiomixer_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj);
return mixer->bits_per_sample;
#endif
}
return 8;
const audiosample_p_t *proto = mp_proto_get_or_throw(MP_QSTR_protocol_audiosample, sample_obj);
return proto->bits_per_sample(MP_OBJ_TO_PTR(sample_obj));
}
uint8_t audiosample_channel_count(mp_obj_t sample_obj) {
if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) {
audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj);
return sample->channel_count;
} else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) {
audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
return file->channel_count;
#if CIRCUITPY_AUDIOMIXER
} else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) {
audiomixer_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj);
return mixer->channel_count;
#endif
}
return 1;
const audiosample_p_t *proto = mp_proto_get_or_throw(MP_QSTR_protocol_audiosample, sample_obj);
return proto->channel_count(MP_OBJ_TO_PTR(sample_obj));
}
void audiosample_reset_buffer(mp_obj_t sample_obj, bool single_channel, uint8_t audio_channel) {
if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) {
audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj);
audioio_rawsample_reset_buffer(sample, single_channel, audio_channel);
} else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) {
audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
audioio_wavefile_reset_buffer(file, single_channel, audio_channel);
#if CIRCUITPY_AUDIOMIXER
} else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) {
audiomixer_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
audiomixer_mixer_reset_buffer(file, single_channel, audio_channel);
#endif
}
const audiosample_p_t *proto = mp_proto_get_or_throw(MP_QSTR_protocol_audiosample, sample_obj);
proto->reset_buffer(MP_OBJ_TO_PTR(sample_obj));
}
audioio_get_buffer_result_t audiosample_get_buffer(mp_obj_t sample_obj,
bool single_channel,
uint8_t channel,
uint8_t** buffer, uint32_t* buffer_length) {
if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) {
audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj);
return audioio_rawsample_get_buffer(sample, single_channel, channel, buffer, buffer_length);
} else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) {
audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
return audioio_wavefile_get_buffer(file, single_channel, channel, buffer, buffer_length);
#if CIRCUITPY_AUDIOMIXER
} else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) {
audiomixer_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
return audiomixer_mixer_get_buffer(file, single_channel, channel, buffer, buffer_length);
#endif
}
return GET_BUFFER_DONE;
const audiosample_p_t *proto = mp_proto_get_or_throw(MP_QSTR_protocol_audiosample, sample_obj);
return proto->get_buffer(MP_OBJ_TO_PTR(sample_obj), single_channel, channel, buffer, buffer_length);
}
void audiosample_get_buffer_structure(mp_obj_t sample_obj, bool single_channel,
bool* single_buffer, bool* samples_signed,
uint32_t* max_buffer_length, uint8_t* spacing) {
if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) {
audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj);
audioio_rawsample_get_buffer_structure(sample, single_channel, single_buffer,
const audiosample_p_t *proto = mp_proto_get_or_throw(MP_QSTR_protocol_audiosample, sample_obj);
proto->get_buffer_structure(MP_OBJ_TO_PTR(sample_obj), single_channel, single_buffer,
samples_signed, max_buffer_length, spacing);
} else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) {
audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
audioio_wavefile_get_buffer_structure(file, single_channel, single_buffer, samples_signed,
max_buffer_length, spacing);
#if CIRCUITPY_AUDIOMIXER
} else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) {
audiomixer_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj);
audiomixer_mixer_get_buffer_structure(file, single_channel, single_buffer, samples_signed,
max_buffer_length, spacing);
#endif
}
}

View File

@ -31,6 +31,7 @@
#include <stdint.h>
#include "py/obj.h"
#include "py/proto.h"
typedef enum {
GET_BUFFER_DONE, // No more data to read
@ -38,6 +39,28 @@ typedef enum {
GET_BUFFER_ERROR, // Error while reading data.
} audioio_get_buffer_result_t;
typedef uint32_t (*audiosample_sample_rate_fun)(mp_obj_t);
typedef uint8_t (*audiosample_bits_per_sample_fun)(mp_obj_t);
typedef uint8_t (*audiosample_channel_count_fun)(mp_obj_t);
typedef void (*audiosample_reset_buffer_fun)(mp_obj_t);
typedef audioio_get_buffer_result_t (*audiosample_get_buffer_fun)(mp_obj_t,
bool single_channel, uint8_t channel, uint8_t** buffer,
uint32_t* buffer_length);
typedef void (*audiosample_get_buffer_structure_fun)(mp_obj_t,
bool single_channel, bool* single_buffer,
bool* samples_signed, uint32_t *max_buffer_length,
uint8_t* spacing);
typedef struct _audiosample_p_t {
MP_PROTOCOL_HEAD // MP_QSTR_protocol_audiosample
audiosample_sample_rate_fun sample_rate;
audiosample_bits_per_sample_fun bits_per_sample;
audiosample_channel_count_fun channel_count;
audiosample_reset_buffer_fun reset_buffer;
audiosample_get_buffer_fun get_buffer;
audiosample_get_buffer_structure_fun get_buffer_structure;
} audiosample_p_t;
uint32_t audiosample_sample_rate(mp_obj_t sample_obj);
uint8_t audiosample_bits_per_sample(mp_obj_t sample_obj);
uint8_t audiosample_channel_count(mp_obj_t sample_obj);

View File

@ -76,6 +76,14 @@ uint32_t common_hal_audiomixer_mixer_get_sample_rate(audiomixer_mixer_obj_t* sel
return self->sample_rate;
}
uint8_t common_hal_audiomixer_mixer_get_channel_count(audiomixer_mixer_obj_t* self) {
return self->channel_count;
}
uint8_t common_hal_audiomixer_mixer_get_bits_per_sample(audiomixer_mixer_obj_t* self) {
return self->bits_per_sample;
}
bool common_hal_audiomixer_mixer_get_playing(audiomixer_mixer_obj_t* self) {
for (uint8_t v = 0; v < self->voice_count; v++) {
if (common_hal_audiomixer_mixervoice_get_playing(MP_OBJ_TO_PTR(self->voice[v]))) {

View File

@ -0,0 +1,270 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "shared-bindings/audiomp3/MP3File.h"
#include <stdint.h>
#include <string.h>
#include "py/mperrno.h"
#include "py/runtime.h"
#include "shared-module/audiomp3/MP3File.h"
#include "supervisor/shared/translate.h"
#include "lib/mp3/src/mp3common.h"
/** Fill the input buffer if it is less than half full.
*
* Returns true if the input buffer contains any useful data,
* false otherwise. (The input buffer will be padded to the end with
* 0 bytes, which do not interfere with MP3 decoding)
*
* Raises OSError if f_read fails.
*
* Sets self->eof if any read of the file returns 0 bytes
*/
STATIC bool mp3file_update_inbuf(audiomp3_mp3file_obj_t* self) {
// If buffer is over half full, do nothing
if (self->inbuf_offset < self->inbuf_length/2) return true;
// If we didn't previously reach the end of file, we can try reading now
if (!self->eof) {
// Move the unconsumed portion of the buffer to the start
uint8_t *end_of_buffer = self->inbuf + self->inbuf_length;
uint8_t *new_end_of_data = self->inbuf + self->inbuf_length - self->inbuf_offset;
memmove(self->inbuf, self->inbuf + self->inbuf_offset,
self->inbuf_length - self->inbuf_offset);
self->inbuf_offset = 0;
UINT to_read = end_of_buffer - new_end_of_data;
UINT bytes_read = 0;
memset(new_end_of_data, 0, to_read);
if (f_read(&self->file->fp, new_end_of_data, to_read, &bytes_read) != FR_OK) {
self->eof = true;
mp_raise_OSError(MP_EIO);
}
if (bytes_read == 0) {
self->eof = true;
}
if (to_read != bytes_read) {
new_end_of_data += bytes_read;
memset(new_end_of_data, 0, end_of_buffer - new_end_of_data);
}
}
// Return true iff there are at least some useful bytes in the buffer
return self->inbuf_offset < self->inbuf_length;
}
#define READ_PTR(self) (self->inbuf + self->inbuf_offset)
#define BYTES_LEFT(self) (self->inbuf_length - self->inbuf_offset)
#define CONSUME(self, n) (self->inbuf_offset += n)
/* If a sync word can be found, advance to it and return true. Otherwise,
* return false.
*/
STATIC bool mp3file_find_sync_word(audiomp3_mp3file_obj_t* self) {
do {
mp3file_update_inbuf(self);
int offset = MP3FindSyncWord(READ_PTR(self), BYTES_LEFT(self));
if (offset >= 0) {
CONSUME(self, offset);
mp3file_update_inbuf(self);
return true;
}
CONSUME(self, MAX(0, BYTES_LEFT(self) - 16));
} while (!self->eof);
return false;
}
STATIC bool mp3file_get_next_frame_info(audiomp3_mp3file_obj_t* self, MP3FrameInfo* fi) {
int err = MP3GetNextFrameInfo(self->decoder, fi, READ_PTR(self));
return err == ERR_MP3_NONE;
}
void common_hal_audiomp3_mp3file_construct(audiomp3_mp3file_obj_t* self,
pyb_file_obj_t* file,
uint8_t *buffer,
size_t buffer_size) {
// XXX Adafruit_MP3 uses a 2kB input buffer and two 4kB output buffers.
// for a whopping total of 10kB buffers (+mp3 decoder state and frame buffer)
// At 44kHz, that's 23ms of output audio data.
//
// We will choose a slightly different allocation strategy for the output:
// Make sure the buffers are sized exactly to match (a multiple of) the
// frame size; this is typically 2304 * 2 bytes, so a little bit bigger
// than the two 4kB output buffers, except that the alignment allows to
// never allocate that extra frame buffer.
self->file = file;
self->inbuf_length = 2048;
self->inbuf_offset = self->inbuf_length;
self->inbuf = m_malloc(self->inbuf_length, false);
if (self->inbuf == NULL) {
common_hal_audiomp3_mp3file_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
translate("Couldn't allocate input buffer"));
}
self->decoder = MP3InitDecoder();
if (self->decoder == NULL) {
common_hal_audiomp3_mp3file_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
translate("Couldn't allocate decoder"));
}
mp3file_find_sync_word(self);
MP3FrameInfo fi;
if(!mp3file_get_next_frame_info(self, &fi)) {
mp_raise_msg(&mp_type_RuntimeError,
translate("Failed to parse MP3 file"));
}
self->sample_rate = fi.samprate;
self->channel_count = fi.nChans;
self->frame_buffer_size = fi.outputSamps*sizeof(int16_t);
if (buffer_size >= 2 * self->frame_buffer_size) {
self->len = buffer_size / 2 / self->frame_buffer_size * self->frame_buffer_size;
self->buffers[0] = buffer;
self->buffers[1] = buffer + self->len;
} else {
self->len = 2 * self->frame_buffer_size;
self->buffers[0] = m_malloc(self->len, false);
if (self->buffers[0] == NULL) {
common_hal_audiomp3_mp3file_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
translate("Couldn't allocate first buffer"));
}
self->buffers[1] = m_malloc(self->len, false);
if (self->buffers[1] == NULL) {
common_hal_audiomp3_mp3file_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
translate("Couldn't allocate second buffer"));
}
}
}
void common_hal_audiomp3_mp3file_deinit(audiomp3_mp3file_obj_t* self) {
MP3FreeDecoder(self->decoder);
self->decoder = NULL;
self->inbuf = NULL;
self->buffers[0] = NULL;
self->buffers[1] = NULL;
self->file = NULL;
}
bool common_hal_audiomp3_mp3file_deinited(audiomp3_mp3file_obj_t* self) {
return self->buffers[0] == NULL;
}
uint32_t common_hal_audiomp3_mp3file_get_sample_rate(audiomp3_mp3file_obj_t* self) {
return self->sample_rate;
}
void common_hal_audiomp3_mp3file_set_sample_rate(audiomp3_mp3file_obj_t* self,
uint32_t sample_rate) {
self->sample_rate = sample_rate;
}
uint8_t common_hal_audiomp3_mp3file_get_bits_per_sample(audiomp3_mp3file_obj_t* self) {
return 16;
}
uint8_t common_hal_audiomp3_mp3file_get_channel_count(audiomp3_mp3file_obj_t* self) {
return self->channel_count;
}
bool audiomp3_mp3file_samples_signed(audiomp3_mp3file_obj_t* self) {
return true;
}
void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t* self,
bool single_channel,
uint8_t channel) {
if (single_channel && channel == 1) {
return;
}
// We don't reset the buffer index in case we're looping and we have an odd number of buffer
// loads
f_lseek(&self->file->fp, 0);
self->inbuf_offset = self->inbuf_length;
self->eof = 0;
mp3file_update_inbuf(self);
mp3file_find_sync_word(self);
}
audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t* self,
bool single_channel,
uint8_t channel,
uint8_t** bufptr,
uint32_t* buffer_length) {
if (!single_channel) {
channel = 0;
}
uint16_t channel_read_count = self->channel_read_count[channel]++;
bool need_more_data = self->read_count++ == channel_read_count;
*bufptr = self->buffers[self->buffer_index] + channel;
*buffer_length = self->frame_buffer_size;
if (need_more_data) {
self->buffer_index = !self->buffer_index;
int16_t *buffer = (int16_t *)(void *)self->buffers[self->buffer_index];
if (!mp3file_find_sync_word(self)) {
return self->eof ? GET_BUFFER_DONE : GET_BUFFER_ERROR;
}
int bytes_left = BYTES_LEFT(self);
uint8_t *inbuf = READ_PTR(self);
int err = MP3Decode(self->decoder, &inbuf, &bytes_left, buffer, 0);
CONSUME(self, BYTES_LEFT(self) - bytes_left);
if (err) {
return GET_BUFFER_DONE;
}
}
return GET_BUFFER_MORE_DATA;
}
void audiomp3_mp3file_get_buffer_structure(audiomp3_mp3file_obj_t* self, bool single_channel,
bool* single_buffer, bool* samples_signed,
uint32_t* max_buffer_length, uint8_t* spacing) {
*single_buffer = false;
*samples_signed = true;
*max_buffer_length = self->frame_buffer_size;
if (single_channel) {
*spacing = self->channel_count;
} else {
*spacing = 1;
}
}

View File

@ -0,0 +1,70 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MP3FILE_H
#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MP3FILE_H
#include "extmod/vfs_fat.h"
#include "py/obj.h"
#include "shared-module/audiocore/__init__.h"
typedef struct {
mp_obj_base_t base;
struct _MP3DecInfo *decoder;
uint8_t* inbuf;
uint32_t inbuf_length;
uint32_t inbuf_offset;
uint8_t* buffers[2];
uint32_t len;
uint32_t frame_buffer_size;
uint32_t sample_rate;
pyb_file_obj_t* file;
uint8_t buffer_index;
uint8_t channel_count;
bool eof;
uint16_t read_count;
uint16_t channel_read_count[2];
} audiomp3_mp3file_obj_t;
// These are not available from Python because it may be called in an interrupt.
void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t* self,
bool single_channel,
uint8_t channel);
audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t* self,
bool single_channel,
uint8_t channel,
uint8_t** buffer,
uint32_t* buffer_length); // length in bytes
void audiomp3_mp3file_get_buffer_structure(audiomp3_mp3file_obj_t* self, bool single_channel,
bool* single_buffer, bool* samples_signed,
uint32_t* max_buffer_length, uint8_t* spacing);
#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MP3FILE_H

Some files were not shown because too many files have changed in this diff Show More