8000 Merge branch 'master' into circuitpython-nickzoic-716-pulseio-esp8266 · sparkfun/circuitpython@972b038 · GitHub
[go: up one dir, main page]

Skip to content

Commit 972b038

Browse files
committed
Merge branch 'master' into circuitpython-nickzoic-716-pulseio-esp8266
2 parents 6af1fba + b2d98ed commit 972b038

File tree

42 files changed

+826
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+826
-79
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
- TRAVIS_BOARD=feather_m0_rfm69
1313
- TRAVIS_BOARD=feather_m0_rfm9x
1414
- TRAVIS_BOARD=feather_m0_express
15+
- TRAVIS_BOARD=feather_m0_express_crickit
1516
- TRAVIS_BOARD=feather_m4_express
1617
- TRAVIS_BOARD=itsybitsy_m0_express
1718
- TRAVIS_BOARD=itsybitsy_m4_express

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Differences from `MicroPython <https://github.com/micropython/micropython>`__
104104
CircuitPython:
105105

106106
- includes a ports for MicroChip SAMD21 (Commonly known as M0 in Adafruit
107-
product names and SAMD51 (M4).
107+
product names) and SAMD51 (M4).
108108
- supports only SAMD21, SAMD51, and ESP8266 ports. An nRF port is under
109109
development.
110110
- tracks MicroPython's releases (not master).

main.c

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -233,40 +233,7 @@ bool start_mp(safe_mode_t safe_mode) {
233233
}
234234
}
235235

236-
int __attribute__((used)) main(void) {
237-
// initialise the cpu and peripherals
238-
safe_mode_t safe_mode = port_init();
239-
240-
rgb_led_status_init();
241-
242-
// Stack limit should be less than real stack size, so we have a chance
243-
// to recover from limit hit. (Limit is measured in bytes.)
244-
mp_stack_ctrl_init();
245-
mp_stack_set_limit((char*)&_estack - (char*)&_ebss - 1024);
246-
247-
#if MICROPY_MAX_STACK_USAGE
248-
// _ezero (same as _ebss) is an int, so start 4 bytes above it.
249-
mp_stack_set_bottom(&_ezero + 1);
250-
mp_stack_fill_with_sentinel();
251-
#endif
252-
253-
// Create a new filesystem only if we're not in a safe mode.
254-
// A power brownout here could make it appear as if there's
255-
// no SPI flash filesystem, and we might erase the existing one.
256-
filesystem_init(safe_mode == NO_SAFE_MODE, false);
257-
258-
// Reset everything and prep MicroPython to run boot.py.
259-
reset_port();
260-
reset_board();
261-
reset_mp();
262-
263-
// Turn on autoreload by default but before boot.py in case it wants to change it.
264-
autoreload_enable();
265-
266-
// By default our internal flash is readonly to local python code and
267-
// writable over USB. Set it here so that boot.py can change it.
268-
filesystem_writable_by_python(false);
269-
236+
void run_boot_py(safe_mode_t safe_mode) {
270237
// If not in safe mode, run boot before initing USB and capture output in a
271238
// file.
272239
if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) {
@@ -338,6 +305,43 @@ int __attribute__((used)) main(void) {
338305
reset_port();
339306
reset_mp();
340307
}
308+
}
309+
310+
int __attribute__((used)) main(void) {
311+
// initialise the cpu and peripherals
312+
safe_mode_t safe_mode = port_init();
313+
314+
rgb_led_status_init();
315+
316+
// Stack limit should be less than real stack size, so we have a chance
317+
// to recover from limit hit. (Limit is measured in bytes.)
318+
mp_stack_set_top((char*)&_estack);
319+
mp_stack_set_limit((char*)&_estack - (char*)&_ebss - 1024);
320+
321+
#if MICROPY_MAX_STACK_USAGE
322+
// _ezero (same as _ebss) is an int, so start 4 bytes above it.
323+
mp_stack_set_bottom(&_ezero + 1);
324+
mp_stack_fill_with_sentinel();
325+
#endif
326+
327+
// Create a new filesystem only if we're not in a safe mode.
328+
// A power brownout here could make it appear as if there's
329+
// no SPI flash filesystem, and we might erase the existing one.
330+
filesystem_init(safe_mode == NO_SAFE_MODE, false);
331+
332+
// Reset everything and prep MicroPython to run boot.py.
333+
reset_port();
334+
reset_board();
335+
reset_mp();
336+
337+
// Turn on autoreload by default but before boot.py in case it wants to change it.
338+
autoreload_enable();
339+
340+
// By default our internal flash is readonly to local python code and
341+
// writable over USB. Set it here so that boot.py can change it.
342+
filesystem_writable_by_python(false);
343+
344+
run_boot_py(safe_mode);
341345

342346
// Start serial and HID after giving boot.py a chance to tweak behavior.
343347
serial_init();

ports/atmel-samd/background.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@
2626
#include "background.h"
2727

2828
#include "audio_dma.h"
29+
#include "tick.h"
2930
#include "usb.h"
3031
#include "usb_mass_storage.h"
3132

33+
volatile uint64_t last_finished_tick = 0;
34+
3235
void run_background_tasks(void) {
3336
audio_dma_background();
3437
usb_msc_background();
3538
usb_cdc_background();
39+
last_finished_tick = ticks_ms;
40+
}
41+
42+
bool background_tasks_ok(void) {
43+
return ticks_ms - last_finished_tick < 1000;
3644
}

ports/atmel-samd/background.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H
2828
#define MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H
2929

30+
#include <stdbool.h>
31+
3032
void run_background_tasks(void);
33+
bool background_tasks_ok(void);
3134

3235
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H

ports/atmel-samd/bindings/samd/Clock.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,7 @@
4747
STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
4848
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
4949

50-
mp_printf(print, "%q.%q.%s(", MP_QSTR_samd, MP_QSTR_clock, self->name);
51-
if (clock_get_enabled(self->type, self->index)) {
52-
mp_printf(print, "frequency=%u", clock_get_frequency(self->type, self->index));
53-
uint32_t calibration = clock_get_calibration(self->type, self->index);
54-
if (calibration) {
55-
mp_printf(print, ", calibration=%u", calibration);
56-
}
57-
}
58-
mp_printf(print, ")");
50+
mp_printf(print, "%q.%q.%q", MP_QSTR_samd, MP_QSTR_clock, self->name);
5951
}
6052

6153
//| .. attribute:: enabled

ports/atmel-samd/bindings/samd/Clock.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,39 @@
3131

3232
typedef struct {
3333
mp_obj_base_t base;
34-
const char *name;
34+
qstr name;
3535
uint8_t type;
3636
uint8_t index;
3737
} samd_clock_obj_t;
3838

3939
#define CLOCK(_name, _type, _index) \
4040
const samd_clock_obj_t clock_ ## _name = { \
4141
{ &samd_clock_type }, \
42-
.name = #_name, \
42+
.name = MP_QSTR_ ## _name, \
4343
.type = _type, \
4444
.index = _index, \
4545
}
4646

4747
#define CLOCK_SOURCE(_name) \
4848
const samd_clock_obj_t clock_ ## _name = { \
4949
{ &samd_clock_type }, \
50-
.name = #_name, \
50+
.name = MP_QSTR_ ## _name, \
5151
.type = 0, \
5252
.index = GCLK_SOURCE_ ## _name, \
5353
}
5454

5555
#define CLOCK_GCLK(_name) \
5656
const samd_clock_obj_t clock_ ## _name = { \
5757
{ &samd_clock_type }, \
58-
.name = #_name, \
58+
.name = MP_QSTR_ ## _name, \
5959
.type = 1, \
6060
.index = _name ## _GCLK_ID, \
6161
}
6262

6363
#define CLOCK_GCLK_(_name, _extra) \
6464
const samd_clock_obj_t clock_ ## _name ## _ ## _extra = { \
6565
{ &samd_clock_type }, \
66-
.name = #_name "_" #_extra, \
66+
.name = MP_QSTR_ ## _name ## _ ## _extra, \
6767
.type = 1, \
6868
.index = _name ## _GCLK_ID_ ## _extra, \
6969
}

ports/atmel-samd/boards/arduino_zero/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@
2424

2525
#define DEFAULT_UART_BUS_RX (&pin_PA11)
2626
#define DEFAULT_UART_BUS_TX (&pin_PA10)
27+
28+
// USB is always used internally so skip the pin objects for it.
29+
#define IGNORE_PIN_PA24 1
30+
#define IGNORE_PIN_PA25 1

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@
6868

6969
#define DEFAULT_UART_BUS_RX (&pin_PB09)
7070
#define DEFAULT_UART_BUS_TX (&pin_PB08)
71+
72+
// USB is always used internally so skip the pin objects for it.
73+
#define IGNORE_PIN_PA24 1
74+
#define IGNORE_PIN_PA25 1

ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@
7171

7272
#define DEFAULT_UART_BUS_RX (&pin_PB09)
7373
#define DEFAULT_UART_BUS_TX (&pin_PB08)
74+
75+
// USB is always used internally so skip the pin objects for it.
76+
#define IGNORE_PIN_PA24 1
77+
#define IGNORE_PIN_PA25 1

ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222

2323
#define DEFAULT_UART_BUS_RX (&pin_PA11)
2424
#define DEFAULT_UART_BUS_TX (&pin_PA10)
25+
26+
// USB is always used internally so skip the pin objects for it.
27+
#define IGNORE_PIN_PA24 1
28+
#define IGNORE_PIN_PA25 1

ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@
2323

2424
#define DEFAULT_UART_BUS_RX (&pin_PA11)
2525
#define DEFAULT_UART_BUS_TX (&pin_PA10)
26+
27+
// USB is always used internally so skip the pin objects for it.
28+
#define IGNORE_PIN_PA24 1
29+
#define IGNORE_PIN_PA25 1

ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@
5858

5959
#define DEFAULT_UART_BUS_RX (&pin_PA11)
6060
#define DEFAULT_UART_BUS_TX (&pin_PA10)
61+
62+
// USB is always used internally so skip the pin objects for it.
63+
#define IGNORE_PIN_PA24 1
64+
#define IGNORE_PIN_PA25 1
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4 10000 +
* 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+
29+
void board_init(void)
30+
{
31+
}
32+
33+
bool board_requests_safe_mode(void) {
34+
return false;
35+
}
36+
37+
void reset_board(void) {
38+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#define MICROPY_HW_BOARD_NAME "Adafruit Feather M0 Express with Crickit libraries"
2+
#define MICROPY_HW_MCU_NAME "samd21g18"
3+
4+
#define MICROPY_HW_NEOPIXEL (&pin_PA06)
5+
6+
// Clock rates are off: Salae reads 12MHz which is the limit even though we set it to the safer 8MHz.
7+
#define SPI_FLASH_BAUDRATE (8000000)
8+
9+
#define SPI_FLASH_MOSI_PIN PIN_PA08
10+
#define SPI_FLASH_MISO_PIN PIN_PA14
11+
#define SPI_FLASH_SCK_PIN PIN_PA09
12+
#define SPI_FLASH_CS_PIN PIN_PA13
13+
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA08D_SERCOM2_PAD0
14+
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA14C_SERCOM2_PAD2
15+
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA09D_SERCOM2_PAD1
16+
#define SPI_FLASH_SERCOM SERCOM2
17+
#define SPI_FLASH_SERCOM_INDEX 2
18+
#define SPI_FLASH_MOSI_PAD 0
19+
#define SPI_FLASH_MISO_PAD 2
20+
#define SPI_FLASH_SCK_PAD 1
21+
// <o> Transmit Data Pinout
22+
// <0x0=>PAD[0,1]_DO_SCK
23+
// <0x1=>PAD[2,3]_DO_SCK
24+
// <0x2=>PAD[3,1]_DO_SCK
25+
// <0x3=>PAD[0,3]_DO_SCK
26+
#define SPI_FLASH_DOPO 0
27+
#define SPI_FLASH_DIPO 2 // same as MISO pad
28+
29+
// These are pins not to reset.
30+
#define MICROPY_PORT_A (PORT_PA06 | PORT_PA08 | PORT_PA09 | PORT_PA13 | PORT_PA14 | PORT_PA24 | PORT_PA25)
31+
#define MICROPY_PORT_B ( 0 )
32+
#define MICROPY_PORT_C ( 0 )
33+
34+
#include "external_flash/external_flash.h"
35+
36+
// If you change this, then make sure to update the linker scripts as well to
37+
// make sure you don't overwrite code.
38+
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
39+
40+
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
41+
42+
#include "external_flash/devices.h"
43+
44+
#define EXTERNAL_FLASH_DEVICE_COUNT 2
45+
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
46+
GD25Q16C
47+
48+
#include "external_flash/external_flash.h"
49+
50+
#define BOARD_HAS_CRYSTAL 1
51+
52+
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
53+
#define DEFAULT_I2C_BUS_SDA (&pin_PA22)
54+
55+
#define DEFAULT_SPI_BUS_SCK (&pin_PB11)
56+
#define DEFAULT_SPI_BUS_MOSI (&pin_PB10)
57+
#define DEFAULT_SPI_BUS_MISO (&pin_PA12)
58+
59+
#define DEFAULT_UART_BUS_RX (&pin_PA11)
60+
#define DEFAULT_UART_BUS_TX (&pin_PA10)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
LD_FILE = boards/samd21x18-bootloader-external-flash.ld
2+
USB_VID = 0x239A
3+
USB_PID = 0x8023
4+
USB_PRODUCT = "Feather M0 Express"
5+
USB_MANUFACTURER = "Adafruit Industries LLC"
6+
7+
SPI_FLASH_FILESYSTEM = 1
8+
LONGINT_IMPL = MPZ
9+
10+
CHIP_VARIANT = SAMD21G18A
11+
CHIP_FAMILY = samd21
12+
13+
# Include these Python libraries in firmware.
14+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice
15+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Motor
16+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
17+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_seesaw
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
#include "board_busses.h"
4+
5+
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
6+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) },
7+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) },
8+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB09) },
9+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) },
10+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) },
11+
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB02) },
12+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) },
13+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) },
14+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) },
15+
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) },
16+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) },
17+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) },
18+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) },
19+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) },
20+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) },
21+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA15) },
22+
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) },
23+
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) },
24+
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) },
25+
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) },
26+
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) },
27+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) },
28+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) },
29+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
30+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
31+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
32+
};
33+
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

0 commit comments

Comments
 (0)
0