Skip to content

Commit e5e132a

Browse files
committed
add blm_badge; add CIRCUITPY_AUDIOBUSIOIO_I2SOUT
1 parent 7ab5c52 commit e5e132a

File tree

11 files changed

+197
-10
lines changed

11 files changed

+197
-10
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "boards/board.h"
28+
#include "supervisor/shared/board.h"
29+
30+
void board_init(void) {
31+
}
32+
33+
bool board_requests_safe_mode(void) {
34+
return false;
35+
}
36+
37+
void reset_board(void) {
38+
board_reset_user_neopixels();
39+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#define MICROPY_HW_BOARD_NAME "Adafruit BLM Badge"
2+
#define MICROPY_HW_MCU_NAME "samd21e18"
3+
4+
#define MICROPY_HW_LED_STATUS (&pin_PA03)
5+
6+
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
7+
#define MICROPY_PORT_B (0)
8+
#define MICROPY_PORT_C (0)
9+
10+
#define DEFAULT_I2C_BUS_SCL (&pin_PA01)
11+
#define DEFAULT_I2C_BUS_SDA (&pin_PA00)
12+
13+
#define DEFAULT_UART_BUS_RX (&pin_PA01)
14+
#define DEFAULT_UART_BUS_TX (&pin_PA00)
15+
16+
#define USER_NEOPIXELS_PIN (&pin_PA05)
17+
18+
#define IGNORE_PIN_PA09 1
19+
#define IGNORE_PIN_PA12 1
20+
#define IGNORE_PIN_PA13 1
21+
#define IGNORE_PIN_PA14 1
22+
#define IGNORE_PIN_PA15 1
23+
#define IGNORE_PIN_PA16 1
24+
#define IGNORE_PIN_PA17 1
25+
#define IGNORE_PIN_PA18 1
26+
#define IGNORE_PIN_PA19 1
27+
#define IGNORE_PIN_PA20 1
28+
#define IGNORE_PIN_PA21 1
29+
#define IGNORE_PIN_PA22 1
30+
#define IGNORE_PIN_PA23 1
31+
// USB is always used.
32+
#define IGNORE_PIN_PA24 1
33+
#define IGNORE_PIN_PA25 1
34+
#define IGNORE_PIN_PA27 1
35+
#define IGNORE_PIN_PA28 1
36+
#define IGNORE_PIN_PA30 1
37+
#define IGNORE_PIN_PA31 1
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
USB_VID = 0x239A
2+
USB_PID = 0x80C0
3+
USB_PRODUCT = "BLM Badge"
4+
USB_MANUFACTURER = "Adafruit Industries LLC"
5+
6+
CHIP_VARIANT = SAMD21E18A
7+
CHIP_FAMILY = samd21
8+
9+
INTERNAL_FLASH_FILESYSTEM = 1
10+
LONGINT_IMPL = NONE
11+
CIRCUITPY_FULL_BUILD = 0
12+
13+
CIRCUITPY_AUDIOIO = 1
14+
CIRCUITPY_AUDIOBUSIO = 1
15+
# Pins for I2SOut are not available.
16+
CIRCUITPY_AUDIOBUSIO_I2SOUT = 0
17+
CIRCUITPY_PULSEIO = 0
18+
CIRCUITPY_ROTARYIO = 0
19+
CIRCUITPY_RTC = 0
20+
CIRCUITPY_SAMD = 0
21+
CIRCUITPY_USB_HID = 1
22+
CIRCUITPY_USB_MIDI = 0
23+
24+
SUPEROPT_GC = 0
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
4+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA01) },
5+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA01) }, // pad 1
6+
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA01) },
7+
8+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA00) },
9+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA00) }, // pad 0
10+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA00) },
11+
12+
{ MP_ROM_QSTR(MP_QSTR_CAP1), MP_ROM_PTR(&pin_PA02) },
13+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA02) },
14+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) },
15+
16+
{ MP_ROM_QSTR(MP_QSTR_CAP2), MP_ROM_PTR(&pin_PA04) },
17+
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA04) },
18+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA04) },
19+
20+
{ MP_ROM_QSTR(MP_QSTR_CAP3), MP_ROM_PTR(&pin_PA06) },
21+
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA06) },
22+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) },
23+
24+
{ MP_ROM_QSTR(MP_QSTR_CAP4), MP_ROM_PTR(&pin_PA07) },
25+
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA07) },
26+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA07) },
27+
28+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA05) },
29+
{ MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA05) },
30+
31+
{ MP_ROM_QSTR(MP_QSTR_MICROPHONE_CLOCK), MP_ROM_PTR(&pin_PA10) },
32+
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA10) },
33+
34+
{ MP_ROM_QSTR(MP_QSTR_MICROPHONE_DATA), MP_ROM_PTR(&pin_PA08) },
35+
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA08) },
36+
37+
{ MP_ROM_QSTR(MP_QSTR_LIGHT), MP_ROM_PTR(&pin_PA11) },
38+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA11) },
39+
40+
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_PA03) },
41+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA03) },
42+
};
43+
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/common-hal/audiobusio/I2SOut.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#include <stdint.h>
2828
#include <string.h>
2929

30+
#include "mpconfigport.h"
31+
32+
// Some boards don't implement I2SOut, so suppress any routines from here.
33+
#if CIRCUITPY_AUDIOBUSIO_I2SOUT
34+
3035
#include "extmod/vfs_fat.h"
3136
#include "py/gc.h"
3237
#include "py/mperrno.h"
@@ -382,3 +387,5 @@ bool common_hal_audiobusio_i2sout_get_playing(audiobusio_i2sout_obj_t* self) {
382387
}
383388
return still_playing;
384389
}
390+
391+
#endif // CIRCUITPY_AUDIOBUSIO_I2SOUT

ports/atmel-samd/common-hal/audiobusio/I2SOut.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include "audio_dma.h"
3333
#include "py/obj.h"
3434

35+
// Some boards don't implement I2SOut, so suppress any routines from here.
36+
#if CIRCUITPY_AUDIOBUSIO_I2SOUT
37+
3538
// We don't bit pack because we'll only have two at most. Its better to save code size instead.
3639
typedef struct {
3740
mp_obj_base_t base;
@@ -48,4 +51,6 @@ typedef struct {
4851

4952
void i2sout_reset(void);
5053

54+
#endif // CIRCUITPY_AUDIOBUSIO_I2SOUT
55+
5156
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_AUDIOBUSIO_I2SOUT_H

ports/atmel-samd/common-hal/audiobusio/PDMIn.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
8484
self->clock_pin = clock_pin; // PA10, PA20 -> SCK0, PB11 -> SCK1
8585
#ifdef SAMD21
8686
if (clock_pin == &pin_PA10
87-
#ifdef PIN_PA20
87+
#if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20)
8888
|| clock_pin == &pin_PA20
8989
#endif
9090
) {
9191
self->clock_unit = 0;
92-
#ifdef PIN_PB11
92+
#if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11)
9393
} else if (clock_pin == &pin_PB11) {
9494
self->clock_unit = 1;
9595
#endif
@@ -98,7 +98,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
9898
if (clock_pin == &pin_PA10 || clock_pin == &pin_PB16) {
9999
self->clock_unit = 0;
100100
} else if (clock_pin == &pin_PB12
101-
#ifdef PIN_PB28
101+
#if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28)
102102
|| data_pin == &pin_PB28) {
103103
#else
104104
) {
@@ -112,14 +112,24 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
112112
self->data_pin = data_pin; // PA07, PA19 -> SD0, PA08, PB16 -> SD1
113113

114114
#ifdef SAMD21
115-
if (data_pin == &pin_PA07 || data_pin == &pin_PA19) {
116-
self->serializer = 0;
117-
} else if (data_pin == &pin_PA08
118-
#ifdef PIN_PB16
119-
|| data_pin == &pin_PB16) {
120-
#else
115+
if (false
116+
#if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07)
117+
|| data_pin == &pin_PA07
118+
#endif
119+
#if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19)
120+
|| data_pin == &pin_PA19
121+
#endif
121122
) {
123+
self->serializer = 0;
124+
}
125+
else if (false
126+
#if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08)
127+
|| data_pin == &pin_PA08
122128
#endif
129+
#if defined (PIN_PB16) && !defined(IGNORE_PIN_PB16)
130+
|| data_pin == &pin_PB16
131+
#endif
132+
) {
123133
self->serializer = 1;
124134
#endif
125135
#ifdef SAM_D5X_E5X

ports/atmel-samd/supervisor/port.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,11 @@ void reset_port(void) {
322322
audioout_reset();
323323
#endif
324324
#if CIRCUITPY_AUDIOBUSIO
325-
i2sout_reset();
326325
//pdmin_reset();
327326
#endif
327+
#if CIRCUITPY_AUDIOBUSIO_I2SOUT
328+
i2sout_reset();
329+
#endif
328330

329331
#if CIRCUITPY_TOUCHIO && CIRCUITPY_TOUCHIO_USE_NATIVE
330332
touchin_reset();

py/circuitpy_mpconfig.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ CFLAGS += -DCIRCUITPY_ANALOGIO=$(CIRCUITPY_ANALOGIO)
4242
CIRCUITPY_AUDIOBUSIO ?= $(CIRCUITPY_FULL_BUILD)
4343
CFLAGS += -DCIRCUITPY_AUDIOBUSIO=$(CIRCUITPY_AUDIOBUSIO)
4444

45+
# Some boards have PDMIn but do not implement I2SOut.
46+
CIRCUITPY_AUDIOBUSIO_I2SOUT ?= $(CIRCUITPY_AUDIOBUSIO)
47+
CFLAGS += -DCIRCUITPY_AUDIOBUSIO_I2SOUT=$(CIRCUITPY_AUDIOBUSIO_I2SOUT)
48+
4549
CIRCUITPY_AUDIOIO ?= $(CIRCUITPY_FULL_BUILD)
4650
CFLAGS += -DCIRCUITPY_AUDIOIO=$(CIRCUITPY_AUDIOIO)
4751

shared-bindings/audiobusio/I2SOut.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@
9191
//| ...
9292
//|
9393
STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
94+
#if !CIRCUITPY_AUDIOBUSIO_I2SOUT
95+
mp_raise_NotImplementedError(translate("I2SOut not available"));
96+
return NULL; // Not reachable.
97+
#else
9498
enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified };
9599
static const mp_arg_t allowed_args[] = {
96100
{ MP_QSTR_bit_clock, MP_ARG_OBJ | MP_ARG_REQUIRED },
@@ -110,8 +114,11 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
110114
common_hal_audiobusio_i2sout_construct(self, bit_clock, word_select, data, args[ARG_left_justified].u_bool);
111115

112116
return MP_OBJ_FROM_PTR(self);
117+
#endif
113118
}
114119

120+
#if CIRCUITPY_AUDIOBUSIO_I2SOUT
121+
115122
//| def deinit(self) -> None:
116123
//| """Deinitialises the I2SOut and releases any hardware resources for reuse."""
117124
//| ...
@@ -120,6 +127,7 @@ STATIC mp_obj_t audiobusio_i2sout_deinit(mp_obj_t self_in) {
120127
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
121128
common_hal_audiobusio_i2sout_deinit(self);
122129
return mp_const_none;
130+
123131
}
124132
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_deinit_obj, audiobusio_i2sout_deinit);
125133

@@ -251,9 +259,11 @@ const mp_obj_property_t audiobusio_i2sout_paused_obj = {
251259
(mp_obj_t)&mp_const_none_obj,
252260
(mp_obj_t)&mp_const_none_obj},
253261
};
262+
#endif // CIRCUITPY_AUDIOBUSIO_I2SOUT
254263

255264
STATIC const mp_rom_map_elem_t audiobusio_i2sout_locals_dict_table[] = {
256265
// Methods
266+
#if CIRCUITPY_AUDIOBUSIO_I2SOUT
257267
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&audiobusio_i2sout_deinit_obj) },
258268
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiobusio_i2sout_deinit_obj) },
259269
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
@@ -266,6 +276,7 @@ STATIC const mp_rom_map_elem_t audiobusio_i2sout_locals_dict_table[] = {
266276
// Properties
267277
{ MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiobusio_i2sout_playing_obj) },
268278
{ MP_ROM_QSTR(MP_QSTR_paused), MP_ROM_PTR(&audiobusio_i2sout_paused_obj) },
279+
#endif // CIRCUITPY_AUDIOBUSIO_I2SOUT
269280
};
270281
STATIC MP_DEFINE_CONST_DICT(audiobusio_i2sout_locals_dict, audiobusio_i2sout_locals_dict_table);
271282

0 commit comments

Comments
 (0)