Compare commits

...

15 Commits
main ... 1.x

Author SHA1 Message Date
Scott Shawcroft
f1e2afbea0 docs: Minor updates before 1.0.0 2017-07-19 15:15:23 -04:00
Scott Shawcroft
63ade77635 docs: tweak css so a horizontal scroll bar shows up on the wide pinout tables. Fixes #166 2017-07-14 11:33:17 -07:00
Scott Shawcroft
34cc304fda atmel-samd: Update README and add pinout tables that map MCU names
to names in the board module and explain pin capabilities.

Fixes #149
2017-07-13 16:07:02 -07:00
Scott Shawcroft
cc0cf717da shared-bindings: Fix neopixel_write example. I forgot to save in the editor. Fixes #163 2017-07-12 14:59:45 -07:00
Scott Shawcroft
a91592df52 shared-bindings: Add neopixel_write example. Fixes #163 2017-07-12 11:32:46 -07:00
Scott Shawcroft
5d732f45bb atmel-samd: Reboot to bootloader when a 1200 baud serial connection is
closed. This is how Arduino triggers the bootloader.
2017-07-06 13:41:13 -07:00
Scott Shawcroft
0c4b273f24 atmel-samd: Give the on board flash filesystem a unique volume ID. This is useful for identifying filesystem mounts and matching them up to hardware. 2017-07-06 10:45:42 -07:00
Scott Shawcroft
32cad8c0f8 atmel-samd: Add Trinket Rev D support. 2017-07-05 11:43:12 -07:00
Scott Shawcroft
e904697991 atmel-samd: Add TX/RX and SCL/SDA pins names for Gemma M0. 2017-07-03 12:11:16 -07:00
Scott Shawcroft
76d2c28e4e atmel-samd: Switch streams to non-blocking mode. Fixes #159. 2017-07-03 12:02:03 -07:00
Scott Shawcroft
a4aa8b0ef7 atmel-samd: Update Gemma M0 USB device name. 2017-07-03 11:24:41 -07:00
Scott Shawcroft
3cd710c890 atmel-samd: Update Gemma M0 for release revision. 2017-07-03 11:05:03 -07:00
Scott Shawcroft
0eea8f24b9 atmel-samd: Add IR_TX and IR_RX pin names for REMOTEOUT and REMOTEIN to the CircuitPlayground Express pins to match the silkscreen. 2017-06-30 09:40:17 -07:00
Dan Halbert
bd827807cc Fix USB Busy error for kbd hid. Made kbd USB report descriptor be
COMPILER_WORD_ALIGNED as done in #118 for mouse. Added COMPILER_WORD_ALIGNED
to other UDC_DESC_STORAGE declarations that might have the same issue in
the future.
2017-06-29 21:47:30 -07:00
Scott Shawcroft
9eadda68b8 atmel-samd: Fix AudioOut buffer playback by supporting bytes_per_sample.
Thanks to @ntoll for finding this bug!
2017-06-20 11:18:46 -07:00
46 changed files with 751 additions and 265 deletions

View File

@ -1,15 +1,33 @@
# Contributing # Contributing
Please note that this project is released with a
[Contributor Code of Conduct](https://github.com/adafruit/circuitpython/blob/master/CODE_OF_CONDUCT.md).
By participating in this project you agree to abide by its terms. Participation
covers any forum used to converse about CircuitPython including unofficial and official spaces. Failure to do
so will result in corrective actions such as time out or ban from the project.
Please note that this project is released with a Contributor Code of ## Developer contact
Conduct. By participating in this project you agree to abide by its terms. [@tannewt](https://github.com/tannewt) is the main developer of CircuitPython
and is sponsored by [Adafruit Industries LLC](https://adafruit.com). He is
reachable on [Discord](https://adafru.it/discord) as tannewt and
[Gitter](gitter.im/adafruit/circuitpython) as tannewt during US West Coast
working hours. He also checks GitHub issues and the [Adafruit support forum](https://forums.adafruit.com/viewforum.php?f=60).
https://github.com/adafruit/micropython/blob/master/CODE_OF_CONDUCT.md ## Licensing
By contributing to this repository you are certifying that you have all necessary
permissions to license the code under an MIT License. You still retain the
copyright but are granting many permissions under the MIT License.
When reporting an issue and especially submitting a pull request, please If you have an employment contract with your employer please make sure that they
make sure that you are acquainted with Contributor Guidelines: don't automatically own your work product. Make sure to get any necessary approvals
before contributing. Another term for this contribution off-hours is moonlighting.
https://github.com/micropython/micropython/wiki/ContributorGuidelines ## Code guidelines
We aim to keep our code and commit style compatible with MicroPython upstream.
Please review their
[code conventions](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md) to do so.
Familiarity with their [design philosophy](https://github.com/micropython/micropython/wiki/ContributorGuidelines)
is also useful though not always applicable to CircuitPython.
and Code Conventions: Furthermore, CircuitPython has a
[design guide](https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html)
https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md that covers a variety of different topics. Please read it as well.

View File

@ -190,6 +190,7 @@ SRC_C = \
main.c \ main.c \
moduos.c \ moduos.c \
mphalport.c \ mphalport.c \
reset.c \
samd21_pins.c \ samd21_pins.c \
shared_dma.c \ shared_dma.c \
rgb_led_status.c \ rgb_led_status.c \

View File

@ -1,18 +1,131 @@
SAMD21x18 SAMD21x18
========= =========
This port brings MicroPython to SAMD21x18 based development boards including the This port brings MicroPython to SAMD21x18 based development boards under the name
Arduino Zero, Adafruit Feather M0 Basic and Adafruit M0 Bluefruit LE. CircuitPython. Supported boards include the Adafruit CircuitPlayground Express,
Adafruit Feather M0 Express, Adafruit Metro M0 Express, Arduino Zero, Adafruit
Feather M0 Basic and Adafruit M0 Bluefruit LE.
Pinout
------
All of the boards share the same core pin functionality but call pins by
different names. The table below matches the pin order in
`the datasheet <http://ww1.microchip.com/downloads/en/DeviceDoc/40001882A.pdf>`_
and omits the pins only available on the largest package because all supported
boards use smaller version.
===================== =============== =========================== ==================== ================ ================== ========================= ================ ================
`microcontroller.pin` `board`
--------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Datasheet arduino_zero circuitplayground_express feather_m0_adalogger feather_m0_basic feather_m0_express gemma_m0 metro_m0_express trinket_m0
===================== =============== =========================== ==================== ================ ================== ========================= ================ ================
PA00 ``ACCELEROMETER_SDA`` ``APA102_MOSI`` ``APA102_MOSI``
PA01 ``ACCELEROMETER_SCL`` ``APA102_SCK`` ``APA102_SCK``
PA02 ``A0`` ``A0`` / ``SPEAKER`` ``A0`` ``A0`` ``A0`` ``A0`` / ``D1`` ``A0`` ``D1`` / ``A0``
PA03
PB08 ``A1`` ``A7`` / ``TX`` ``A1`` ``A1`` ``A1`` ``A1``
PB09 ``A2`` ``A6`` / ``RX`` ``A2`` ``A2`` ``A2`` ``A2``
PA04 ``A3`` ``IR_PROXIMITY`` ``A3`` ``A3`` ``A3`` ``D0`` / ``TX`` / ``SDA`` ``A3``
PA05 ``A4`` ``A1`` ``A4`` ``A4`` ``A4`` ``D2`` / ``RX`` / ``SCL`` ``A4``
PA06 ``D8`` ``A2`` ``NEOPIXEL`` ``D8`` ``D4`` / ``TX``
PA07 ``D9`` ``A3`` ``D9`` ``D9`` ``D9`` ``D9`` ``D3`` / ``RX``
PA08 ``D4`` ``MICROPHONE_DO`` ``SD_CS`` ``D4`` ``D0`` / ``SDA``
PA09 ``D3`` ``TEMPERATURE`` / ``A9`` ``D3`` ``D2`` / ``SCL``
PA10 ``D1`` / ``TX`` ``MICROPHONE_SCK`` ``D1`` / ``TX`` ``D1`` / ``TX`` ``D1`` / ``TX`` ``D1`` / ``TX`` ``D13``
PA11 ``D0`` / ``RX`` ``LIGHT`` / ``A8`` ``D0`` / ``RX`` ``D0`` / ``RX`` ``D0`` / ``RX`` ``D0`` / ``RX``
PB10 ``MOSI`` ``MOSI`` ``MOSI`` ``MOSI`` ``MOSI``
PB11 ``SCK`` ``SCK`` ``SCK`` ``SCK`` ``SCK``
PA12 ``MISO`` ``REMOTEIN`` / ``IR_RX`` ``MISO`` ``MISO`` ``MISO`` ``MISO``
PA13 ``ACCELEROMETER_INTERRUPT`` ``FLASH_CS``
PA14 ``D2`` ``BUTTON_B`` / ``D5`` ``D2``
PA15 ``D5`` ``SLIDE_SWITCH`` / ``D7`` ``D5`` ``D5`` ``D5`` ``D5``
PA16 ``D11`` ``MISO`` ``D11`` ``D11`` ``D11`` ``D11``
PA17 ``D13`` ``D13`` ``D13`` ``D13`` ``D13`` ``D13``
PA18 ``D10`` ``D10`` ``D10`` ``D10`` ``D10``
PA19 ``D12`` ``D12`` ``D12`` ``D12`` ``D12``
PA20 ``D6`` ``MOSI`` ``D6`` ``D6`` ``D6`` ``D6``
PA21 ``D7`` ``SCK`` ``D7``
PA22 ``SDA`` ``SDA`` ``SDA`` ``SDA`` ``SDA``
PA23 ``SCL`` ``REMOTEOUT`` / ``IR_TX`` ``SCL`` ``SCL`` ``SCL`` ``L`` / ``D13`` ``SCL``
PA24
PA25
PB22 ``FLASH_CS``
PB23 ``NEOPIXEL`` / ``D8``
PA27
PA28 ``BUTTON_A`` / ``D4``
PA29
PA30 ``SPEAKER_ENABLE`` ``NEOPIXEL``
PA31
PB02 ``A5`` ``A5`` / ``SDA`` ``A5`` ``A5`` ``A5`` ``A5``
PB03 ``A4`` / ``SCL``
===================== =============== =========================== ==================== ================ ================== ========================= ================ ================
Here is a table about which pins can do what in CircuitPython terms. However,
just because something is listed, doesn't mean it will always work. Existing use
of other pins and functionality will impact your ability to use a pin for your
desired purpose. For example, only certain combinations of SPI pins will work
because they use shared hardware internally.
===================== ======== ========= ========= ======= ======= ======= ========= ========= ======= ========== ========== ========= ========= ========= ============ ======= ======= =========
`microcontroller.pin` `analogio` `audioio` `bitbangio` `busio` `digitalio` `pulseio` `touchio`
--------------------- ------------------- --------- ------------------------- -------------------------------------------------------------------------------------- ------------ ---------------- ---------
Datasheet AnalogIn AnalogOut AudioOut I2C OneWire SPI I2C - SDA I2C - SCL OneWire SPI - MISO SPI - MOSI SPI - SCK UART - RX UART - TX DigitalInOut PulseIn PWMOut TouchIn
===================== ======== ========= ========= ======= ======= ======= ========= ========= ======= ========== ========== ========= ========= ========= ============ ======= ======= =========
PA00 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA01 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA02 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA03 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PB08 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PB09 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA04 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA05 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA06 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA07 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA08 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA09 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA10 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA11 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PB10 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PB11 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA12 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA13 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA14 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA15 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA16 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA17 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA18 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA19 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA20 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA21 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA22 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA23 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA24
PA25
PB22 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PB23 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA27 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA28 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA29 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA30 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PA31 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PB02 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
PB03 **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes** **Yes**
===================== ======== ========= ========= ======= ======= ======= ========= ========= ======= ========== ========== ========= ========= ========= ============ ======= ======= =========
Building Building
-------- --------
To build for the Arduino Zero: To build for the Arduino Zero:
.. code-block:: shell
make make
To build for other boards you must change it by setting ``BOARD``. For example: To build for other boards you must change it by setting ``BOARD``. For example:
.. code-block:: shell
make BOARD=feather_m0_basic make BOARD=feather_m0_basic
Board names are the directory names in the `boards <https://github.com/adafruit/circuitpython/tree/master/atmel-samd/boards>`_ folder. Board names are the directory names in the `boards <https://github.com/adafruit/circuitpython/tree/master/atmel-samd/boards>`_ folder.
@ -41,7 +154,7 @@ platforms.
openocd -f ~/Library/Arduino15/packages/arduino/hardware/samd/1.6.6/variants/arduino_zero/openocd_scripts/arduino_zero.cfg openocd -f ~/Library/Arduino15/packages/arduino/hardware/samd/1.6.6/variants/arduino_zero/openocd_scripts/arduino_zero.cfg
In another terminal from `micropython/atmel-samd`: In another terminal from ``micropython/atmel-samd``:
arm-none-eabi-gdb build-arduino_zero/firmware.elf arm-none-eabi-gdb build-arduino_zero/firmware.elf
(gdb) tar ext :3333 (gdb) tar ext :3333
@ -70,7 +183,7 @@ Mass storage
^^^^^^^^^^^^ ^^^^^^^^^^^^
All boards will also show up as a mass storage device. Make sure to eject it All boards will also show up as a mass storage device. Make sure to eject it
before referring to any files. before resetting or disconnecting the board.
Port Specific modules Port Specific modules
--------------------- ---------------------

View File

@ -90,12 +90,14 @@ void udi_cdc_data_disable(void);
bool udi_cdc_data_setup(void); bool udi_cdc_data_setup(void);
uint8_t udi_cdc_getsetting(void); uint8_t udi_cdc_getsetting(void);
void udi_cdc_data_sof_notify(void); void udi_cdc_data_sof_notify(void);
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_api_t udi_api_cdc_comm = { UDC_DESC_STORAGE udi_api_t udi_api_cdc_comm = {
.enable = udi_cdc_comm_enable, .enable = udi_cdc_comm_enable,
.disable = udi_cdc_comm_disable, .disable = udi_cdc_comm_disable,
.setup = udi_cdc_comm_setup, .setup = udi_cdc_comm_setup,
.getsetting = udi_cdc_getsetting, .getsetting = udi_cdc_getsetting,
}; };
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_api_t udi_api_cdc_data = { UDC_DESC_STORAGE udi_api_t udi_api_cdc_data = {
.enable = udi_cdc_data_enable, .enable = udi_cdc_data_enable,
.disable = udi_cdc_data_disable, .disable = udi_cdc_data_disable,

View File

@ -154,6 +154,7 @@ UDC_DESC_STORAGE udc_config_speed_t udc_config_fshs[1] = { {
}}; }};
//! Add all information about USB Device in global structure for UDC //! Add all information about USB Device in global structure for UDC
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udc_config_t udc_config = { UDC_DESC_STORAGE udc_config_t udc_config = {
.confdev_lsfs = &udc_device_desc, .confdev_lsfs = &udc_device_desc,
.conf_lsfs = udc_config_fshs, .conf_lsfs = udc_config_fshs,

View File

@ -67,6 +67,8 @@ bool udi_hid_kbd_setup(void);
uint8_t udi_hid_kbd_getsetting(void); uint8_t udi_hid_kbd_getsetting(void);
//! Global structure which contains standard UDI interface for UDC //! Global structure which contains standard UDI interface for UDC
// CircuitPython fix: UDC_DESC_STORAGE must be COMPILER_WORD_ALIGNED
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_api_t udi_api_hid_kbd = { UDC_DESC_STORAGE udi_api_t udi_api_hid_kbd = {
.enable = (bool(*)(void))udi_hid_kbd_enable, .enable = (bool(*)(void))udi_hid_kbd_enable,
.disable = (void (*)(void))udi_hid_kbd_disable, .disable = (void (*)(void))udi_hid_kbd_disable,
@ -117,6 +119,8 @@ COMPILER_WORD_ALIGNED
//@} //@}
//! HID report descriptor for standard HID keyboard //! HID report descriptor for standard HID keyboard
// CircuitPython fix: UDC_DESC_STORAGE must be COMPILER_WORD_ALIGNED
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_hid_kbd_report_desc_t udi_hid_kbd_report_desc = { UDC_DESC_STORAGE udi_hid_kbd_report_desc_t udi_hid_kbd_report_desc = {
{ {
0x05, 0x01, /* Usage Page (Generic Desktop) */ 0x05, 0x01, /* Usage Page (Generic Desktop) */

View File

@ -66,6 +66,7 @@ bool udi_hid_mouse_setup(void);
uint8_t udi_hid_mouse_getsetting(void); uint8_t udi_hid_mouse_getsetting(void);
//! Global structure which contains standard UDI interface for UDC //! Global structure which contains standard UDI interface for UDC
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_api_t udi_api_hid_mouse = { UDC_DESC_STORAGE udi_api_t udi_api_hid_mouse = {
.enable = (bool(*)(void))udi_hid_mouse_enable, .enable = (bool(*)(void))udi_hid_mouse_enable,
.disable = (void (*)(void))udi_hid_mouse_disable, .disable = (void (*)(void))udi_hid_mouse_disable,

View File

@ -134,6 +134,7 @@ struct udc_string_desc_t {
le16_t string[Max(Max(USB_DEVICE_MANUFACTURE_NAME_SIZE, \ le16_t string[Max(Max(USB_DEVICE_MANUFACTURE_NAME_SIZE, \
USB_DEVICE_PRODUCT_NAME_SIZE), USB_DEVICE_SERIAL_NAME_SIZE)]; USB_DEVICE_PRODUCT_NAME_SIZE), USB_DEVICE_SERIAL_NAME_SIZE)];
}; };
COMPILER_WORD_ALIGNED
static UDC_DESC_STORAGE struct udc_string_desc_t udc_string_desc = { static UDC_DESC_STORAGE struct udc_string_desc_t udc_string_desc = {
.header.bDescriptorType = USB_DT_STRING .header.bDescriptorType = USB_DT_STRING
}; };
@ -141,6 +142,7 @@ static UDC_DESC_STORAGE struct udc_string_desc_t udc_string_desc = {
/** /**
* \brief Language ID of USB device (US ID by default) * \brief Language ID of USB device (US ID by default)
*/ */
COMPILER_WORD_ALIGNED
static UDC_DESC_STORAGE usb_str_lgid_desc_t udc_string_desc_languageid = { static UDC_DESC_STORAGE usb_str_lgid_desc_t udc_string_desc_languageid = {
.desc.bLength = sizeof(usb_str_lgid_desc_t), .desc.bLength = sizeof(usb_str_lgid_desc_t),
.desc.bDescriptorType = USB_DT_STRING, .desc.bDescriptorType = USB_DT_STRING,

View File

@ -2,6 +2,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
#ifndef CONF_USB_H_INCLUDED #ifndef CONF_USB_H_INCLUDED
#define CONF_USB_H_INCLUDED #define CONF_USB_H_INCLUDED
@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void); void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg) #define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) #define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set); void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) #define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

View File

@ -2,6 +2,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
#ifndef CONF_USB_H_INCLUDED #ifndef CONF_USB_H_INCLUDED
#define CONF_USB_H_INCLUDED #define CONF_USB_H_INCLUDED
@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void); void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg) #define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) #define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set); void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) #define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

View File

@ -1,56 +1,5 @@
#include "samd21_pins.h" #include "samd21_pins.h"
// STATIC const mp_map_elem_t board_global_dict_table[] = {
// // Rev C
// // { MP_OBJ_NEW_QSTR(MP_QSTR_D10), (mp_obj_t)&pin_PA06 },
// // { MP_OBJ_NEW_QSTR(MP_QSTR_D9), (mp_obj_t)&pin_PA07 },
// // { MP_OBJ_NEW_QSTR(MP_QSTR_D6), (mp_obj_t)&pin_PA04 },
// // { MP_OBJ_NEW_QSTR(MP_QSTR_D12), (mp_obj_t)&pin_PA05 },
// //
// // { MP_OBJ_NEW_QSTR(MP_QSTR_D0), (mp_obj_t)&pin_PB09 },
// // //{ MP_OBJ_NEW_QSTR(MP_QSTR_RX), (mp_obj_t)&pin_PA11 },
// // { MP_OBJ_NEW_QSTR(MP_QSTR_D1), (mp_obj_t)&pin_PB08 },
// // //{ MP_OBJ_NEW_QSTR(MP_QSTR_TX), (mp_obj_t)&pin_PA10 },
//
// // Rev D
// { MP_OBJ_NEW_QSTR(MP_QSTR_A11), (mp_obj_t)&pin_PA06 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_A10), (mp_obj_t)&pin_PA07 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_A9), (mp_obj_t)&pin_PA04 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_A8), (mp_obj_t)&pin_PA05 },
//
// { MP_OBJ_NEW_QSTR(MP_QSTR_A6), (mp_obj_t)&pin_PB09 },
// //{ MP_OBJ_NEW_QSTR(MP_QSTR_RX), (mp_obj_t)&pin_PA11 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_A7), (mp_obj_t)&pin_PB08 },
// //{ MP_OBJ_NEW_QSTR(MP_QSTR_TX), (mp_obj_t)&pin_PA10 },
//
// { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), (mp_obj_t)&pin_PB23 },
//
// { MP_OBJ_NEW_QSTR(MP_QSTR_MICROPHONE), (mp_obj_t)&pin_PA08 },
//
// { MP_OBJ_NEW_QSTR(MP_QSTR_ACCELEROMETER_INTERRUPT), (mp_obj_t)&pin_PA09 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_ACCELEROMETER_SDA), (mp_obj_t)&pin_PA00 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_ACCELEROMETER_SCL), (mp_obj_t)&pin_PA01 },
//
// { MP_OBJ_NEW_QSTR(MP_QSTR_LEFT_BUTTON), (mp_obj_t)&pin_PA28 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_RIGHT_BUTTON), (mp_obj_t)&pin_PA14 },
//
// { MP_OBJ_NEW_QSTR(MP_QSTR_SLIDE_SWITCH), (mp_obj_t)&pin_PA15 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_SPEAKER), (mp_obj_t)&pin_PA02 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_LIGHT), (mp_obj_t)&pin_PA11 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_TEMPERATURE), (mp_obj_t)&pin_PA10 },
//
// { MP_OBJ_NEW_QSTR(MP_QSTR_D13), (mp_obj_t)&pin_PA17 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), (mp_obj_t)&pin_PB02 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_A5), (mp_obj_t)&pin_PB02 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), (mp_obj_t)&pin_PB03 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_A4), (mp_obj_t)&pin_PB03 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_SCK), (mp_obj_t)&pin_PB11 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_MOSI), (mp_obj_t)&pin_PB10 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_MISO), (mp_obj_t)&pin_PA12 },
// { MP_OBJ_NEW_QSTR(MP_QSTR_FLASH_CS), (mp_obj_t)&pin_PB22 },
// };
// Rev G - Purple
STATIC const mp_map_elem_t board_global_dict_table[] = { STATIC const mp_map_elem_t board_global_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_A0), (mp_obj_t)&pin_PA02 }, { MP_OBJ_NEW_QSTR(MP_QSTR_A0), (mp_obj_t)&pin_PA02 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SPEAKER), (mp_obj_t)&pin_PA02 }, { MP_OBJ_NEW_QSTR(MP_QSTR_SPEAKER), (mp_obj_t)&pin_PA02 },
@ -82,7 +31,9 @@ STATIC const mp_map_elem_t board_global_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_D13), (mp_obj_t)&pin_PA17 }, { MP_OBJ_NEW_QSTR(MP_QSTR_D13), (mp_obj_t)&pin_PA17 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_REMOTEIN), (mp_obj_t)&pin_PA12 }, { MP_OBJ_NEW_QSTR(MP_QSTR_REMOTEIN), (mp_obj_t)&pin_PA12 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IR_RX), (mp_obj_t)&pin_PA12 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_REMOTEOUT), (mp_obj_t)&pin_PA23 }, { MP_OBJ_NEW_QSTR(MP_QSTR_REMOTEOUT), (mp_obj_t)&pin_PA23 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IR_TX), (mp_obj_t)&pin_PA23 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IR_PROXIMITY), (mp_obj_t)&pin_PA04 }, { MP_OBJ_NEW_QSTR(MP_QSTR_IR_PROXIMITY), (mp_obj_t)&pin_PA04 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MICROPHONE_SCK), (mp_obj_t)&pin_PA10 }, { MP_OBJ_NEW_QSTR(MP_QSTR_MICROPHONE_SCK), (mp_obj_t)&pin_PA10 },

View File

@ -2,6 +2,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
#ifndef CONF_USB_H_INCLUDED #ifndef CONF_USB_H_INCLUDED
#define CONF_USB_H_INCLUDED #define CONF_USB_H_INCLUDED
@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void); void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg) #define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) #define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set); void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) #define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

View File

@ -2,6 +2,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
#ifndef CONF_USB_H_INCLUDED #ifndef CONF_USB_H_INCLUDED
#define CONF_USB_H_INCLUDED #define CONF_USB_H_INCLUDED
@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void); void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg) #define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) #define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set); void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) #define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

View File

@ -2,6 +2,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
#ifndef CONF_USB_H_INCLUDED #ifndef CONF_USB_H_INCLUDED
#define CONF_USB_H_INCLUDED #define CONF_USB_H_INCLUDED
@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void); void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg) #define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) #define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set); void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) #define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

View File

@ -2,6 +2,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
#ifndef CONF_USB_H_INCLUDED #ifndef CONF_USB_H_INCLUDED
#define CONF_USB_H_INCLUDED #define CONF_USB_H_INCLUDED
@ -19,9 +21,9 @@
#endif #endif
#ifndef USB_DEVICE_PRODUCT_NAME #ifndef USB_DEVICE_PRODUCT_NAME
# define USB_DEVICE_PRODUCT_NAME "Metro M0 with Flash (Experimental)" # define USB_DEVICE_PRODUCT_NAME "Gemma M0"
#endif #endif
// #define USB_DEVICE_SERIAL_NAME "12...EF"
#define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number #define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number
#define USB_DEVICE_GET_SERIAL_NAME_LENGTH 32 #define USB_DEVICE_GET_SERIAL_NAME_LENGTH 32
extern char serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH]; extern char serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH];
@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void); void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg) #define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) #define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set); void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) #define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

View File

@ -3,12 +3,12 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Gemma M0" #define MICROPY_HW_BOARD_NAME "Adafruit Gemma M0"
#define MICROPY_HW_MCU_NAME "samd21e18" #define MICROPY_HW_MCU_NAME "samd21e18"
#define MICROPY_HW_APA102_MOSI (&pin_PA04) #define MICROPY_HW_APA102_MOSI (&pin_PA00)
#define MICROPY_HW_APA102_SCK (&pin_PA05) #define MICROPY_HW_APA102_SCK (&pin_PA01)
// #define CIRCUITPY_BITBANG_APA102 // #define CIRCUITPY_BITBANG_APA102
#define MICROPY_PORT_A (PORT_PA04 | PORT_PA05 | PORT_PA24 | PORT_PA25) #define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA24 | PORT_PA25)
#define MICROPY_PORT_B (0) #define MICROPY_PORT_B (0)
#include "internal_flash.h" #include "internal_flash.h"

View File

@ -1,6 +1,6 @@
LD_FILE = boards/samd21x18-bootloader.ld LD_FILE = boards/samd21x18-bootloader.ld
USB_VID = 0x239A USB_VID = 0x239A
USB_PID = 0x8015 USB_PID = 0x801D
FLASH_IMPL = internal_flash.c FLASH_IMPL = internal_flash.c

View File

@ -1,11 +1,23 @@
#include "samd21_pins.h" #include "samd21_pins.h"
STATIC const mp_map_elem_t board_global_dict_table[] = { STATIC const mp_map_elem_t board_global_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_A1), (mp_obj_t)&pin_PA05 }, // pad 1
{ MP_OBJ_NEW_QSTR(MP_QSTR_D2), (mp_obj_t)&pin_PA05 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_RX), (mp_obj_t)&pin_PA05 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SCL), (mp_obj_t)&pin_PA05 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_A2), (mp_obj_t)&pin_PA04 }, // pad 0
{ MP_OBJ_NEW_QSTR(MP_QSTR_D0), (mp_obj_t)&pin_PA04 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_TX), (mp_obj_t)&pin_PA04 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SDA), (mp_obj_t)&pin_PA04 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_A0), (mp_obj_t)&pin_PA02 }, { MP_OBJ_NEW_QSTR(MP_QSTR_A0), (mp_obj_t)&pin_PA02 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D1), (mp_obj_t)&pin_PA02 }, { MP_OBJ_NEW_QSTR(MP_QSTR_D1), (mp_obj_t)&pin_PA02 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D2), (mp_obj_t)&pin_PA09 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D0), (mp_obj_t)&pin_PA08 }, { MP_OBJ_NEW_QSTR(MP_QSTR_L), (mp_obj_t)&pin_PA23 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_MOSI), (mp_obj_t)&pin_PA04 }, { MP_OBJ_NEW_QSTR(MP_QSTR_D13), (mp_obj_t)&pin_PA23 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_SCK), (mp_obj_t)&pin_PA05 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_MOSI), (mp_obj_t)&pin_PA00 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_SCK), (mp_obj_t)&pin_PA01 },
}; };
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -2,6 +2,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
#ifndef CONF_USB_H_INCLUDED #ifndef CONF_USB_H_INCLUDED
#define CONF_USB_H_INCLUDED #define CONF_USB_H_INCLUDED
@ -19,7 +21,7 @@
#endif #endif
#ifndef USB_DEVICE_PRODUCT_NAME #ifndef USB_DEVICE_PRODUCT_NAME
# define USB_DEVICE_PRODUCT_NAME "Metro M0 with Flash (Experimental)" # define USB_DEVICE_PRODUCT_NAME "Metro M0 Express"
#endif #endif
// #define USB_DEVICE_SERIAL_NAME "12...EF" // #define USB_DEVICE_SERIAL_NAME "12...EF"
#define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number #define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number
@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void); void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg) #define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) #define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set); void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) #define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

View File

@ -2,6 +2,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
#ifndef CONF_USB_H_INCLUDED #ifndef CONF_USB_H_INCLUDED
#define CONF_USB_H_INCLUDED #define CONF_USB_H_INCLUDED
@ -19,7 +21,7 @@
#endif #endif
#ifndef USB_DEVICE_PRODUCT_NAME #ifndef USB_DEVICE_PRODUCT_NAME
# define USB_DEVICE_PRODUCT_NAME "Metro M0 with Flash (Experimental)" # define USB_DEVICE_PRODUCT_NAME "Trinket M0"
#endif #endif
// #define USB_DEVICE_SERIAL_NAME "12...EF" // #define USB_DEVICE_SERIAL_NAME "12...EF"
#define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number #define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number
@ -55,7 +57,9 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void); void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg)
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) #define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set); void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) #define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

View File

@ -4,10 +4,10 @@
#define MICROPY_HW_MCU_NAME "samd21e18" #define MICROPY_HW_MCU_NAME "samd21e18"
// Rev B - Black // Rev B - Black
#define MICROPY_HW_APA102_MOSI (&pin_PA04) #define MICROPY_HW_APA102_MOSI (&pin_PA00)
#define MICROPY_HW_APA102_SCK (&pin_PA05) #define MICROPY_HW_APA102_SCK (&pin_PA01)
#define MICROPY_PORT_A (PORT_PA04 | PORT_PA05 | PORT_PA24 | PORT_PA25) #define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA24 | PORT_PA25)
#define MICROPY_PORT_B (0) #define MICROPY_PORT_B (0)
#include "internal_flash.h" #include "internal_flash.h"

View File

@ -1,6 +1,6 @@
LD_FILE = boards/samd21x18-bootloader.ld LD_FILE = boards/samd21x18-bootloader.ld
USB_VID = 0x239A USB_VID = 0x239A
USB_PID = 0x8015 USB_PID = 0x801F
FLASH_IMPL = internal_flash.c FLASH_IMPL = internal_flash.c

View File

@ -1,13 +1,18 @@
#include "samd21_pins.h" #include "samd21_pins.h"
STATIC const mp_map_elem_t board_global_dict_table[] = { STATIC const mp_map_elem_t board_global_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_D0), (mp_obj_t)&pin_PA04 }, { MP_OBJ_NEW_QSTR(MP_QSTR_D0), (mp_obj_t)&pin_PA08 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SDA), (mp_obj_t)&pin_PA08 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D1), (mp_obj_t)&pin_PA02 }, { MP_OBJ_NEW_QSTR(MP_QSTR_D1), (mp_obj_t)&pin_PA02 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D2), (mp_obj_t)&pin_PA05 }, { MP_OBJ_NEW_QSTR(MP_QSTR_A0), (mp_obj_t)&pin_PA02 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D2), (mp_obj_t)&pin_PA09 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SCL), (mp_obj_t)&pin_PA09 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D4), (mp_obj_t)&pin_PA06 }, { MP_OBJ_NEW_QSTR(MP_QSTR_D4), (mp_obj_t)&pin_PA06 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_TX), (mp_obj_t)&pin_PA06 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D3), (mp_obj_t)&pin_PA07 }, { MP_OBJ_NEW_QSTR(MP_QSTR_D3), (mp_obj_t)&pin_PA07 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_RX), (mp_obj_t)&pin_PA07 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D13),(mp_obj_t)&pin_PA10 }, { MP_OBJ_NEW_QSTR(MP_QSTR_D13),(mp_obj_t)&pin_PA10 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_MOSI), (mp_obj_t)&pin_PA04 }, { MP_OBJ_NEW_QSTR(MP_QSTR_APA102_MOSI), (mp_obj_t)&pin_PA00 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_SCK), (mp_obj_t)&pin_PA05 }, { MP_OBJ_NEW_QSTR(MP_QSTR_APA102_SCK), (mp_obj_t)&pin_PA01 },
}; };
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -103,6 +103,7 @@ void audioout_reset(void) {
void audioout_background(void) { void audioout_background(void) {
if (MP_STATE_VM(audioout_block_counter) != NULL && if (MP_STATE_VM(audioout_block_counter) != NULL &&
active_audioout != NULL && active_audioout != NULL &&
active_audioout->second_buffer != NULL &&
active_audioout->last_loaded_block < tc_get_count_value(MP_STATE_VM(audioout_block_counter))) { active_audioout->last_loaded_block < tc_get_count_value(MP_STATE_VM(audioout_block_counter))) {
uint8_t* buffer; uint8_t* buffer;
if (tc_get_count_value(MP_STATE_VM(audioout_block_counter)) % 2 == 1) { if (tc_get_count_value(MP_STATE_VM(audioout_block_counter)) % 2 == 1) {
@ -132,6 +133,7 @@ void audioout_background(void) {
descriptor = active_audioout->second_descriptor; descriptor = active_audioout->second_descriptor;
} }
descriptor->BTCNT.reg = length_read / active_audioout->bytes_per_sample; descriptor->BTCNT.reg = length_read / active_audioout->bytes_per_sample;
descriptor->SRCADDR.reg = ((uint32_t) buffer) + length_read;
descriptor->DESCADDR.reg = 0; descriptor->DESCADDR.reg = 0;
} }
} }
@ -348,7 +350,8 @@ static void shared_construct(audioio_audioout_obj_t* self, const mcu_pin_obj_t*
void common_hal_audioio_audioout_construct_from_buffer(audioio_audioout_obj_t* self, void common_hal_audioio_audioout_construct_from_buffer(audioio_audioout_obj_t* self,
const mcu_pin_obj_t* pin, const mcu_pin_obj_t* pin,
uint16_t* buffer, uint16_t* buffer,
uint32_t len) { uint32_t len,
uint8_t bytes_per_sample) {
self->pin = pin; self->pin = pin;
if (pin != &pin_PA02) { if (pin != &pin_PA02) {
mp_raise_ValueError("Invalid pin"); mp_raise_ValueError("Invalid pin");
@ -360,8 +363,8 @@ void common_hal_audioio_audioout_construct_from_buffer(audioio_audioout_obj_t* s
self->buffer = (uint8_t*) buffer; self->buffer = (uint8_t*) buffer;
self->second_buffer = NULL; self->second_buffer = NULL;
// Input len is a count. Internal len is in bytes. self->bytes_per_sample = bytes_per_sample;
self->len = 2 * len; self->len = len;
self->frequency = 8000; self->frequency = 8000;
} }

View File

@ -95,7 +95,15 @@ void init_flash_fs(void) {
if (res == FR_NO_FILESYSTEM) { if (res == FR_NO_FILESYSTEM) {
// no filesystem so create a fresh one // no filesystem so create a fresh one
res = f_mkfs("/flash", 0, 0); // XOR the serial number together to create a 32-bit id.
uint32_t volume_id = 0;
uint32_t* addresses[4] = {(uint32_t *) 0x0080A00C, (uint32_t *) 0x0080A040,
(uint32_t *) 0x0080A044, (uint32_t *) 0x0080A048};
for (int i = 0; i < 4; i++) {
volume_id ^= *(addresses[i]);
}
res = f_mkfs("/flash", 0, 0, volume_id);
// Flush the new file system to make sure its repaired immediately. // Flush the new file system to make sure its repaired immediately.
flash_flush(); flash_flush();
if (res != FR_OK) { if (res != FR_OK) {

View File

@ -60,6 +60,7 @@
#define MICROPY_CPYTHON_COMPAT (0) #define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_STREAMS_NON_BLOCK (1)
// fatfs configuration used in ffconf.h // fatfs configuration used in ffconf.h
#define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_ENABLE_LFN (1)

View File

@ -39,38 +39,42 @@ extern struct usart_module usart_instance;
// Read by main to know when USB is connected. // Read by main to know when USB is connected.
volatile bool mp_msc_enabled = false; volatile bool mp_msc_enabled = false;
bool mp_msc_enable() bool mp_msc_enable() {
{
mp_msc_enabled = true; mp_msc_enabled = true;
return true; return true;
} }
void mp_msc_disable() void mp_msc_disable() {
{
mp_msc_enabled = false; mp_msc_enabled = false;
} }
bool mp_cdc_enable(uint8_t port) bool mp_cdc_enable(uint8_t port) {
{
mp_cdc_enabled = false; mp_cdc_enabled = false;
return true; return true;
} }
void mp_cdc_disable(uint8_t port) void mp_cdc_disable(uint8_t port) {
{
mp_cdc_enabled = false; mp_cdc_enabled = false;
} }
volatile bool reset_on_disconnect = false;
void usb_dtr_notify(uint8_t port, bool set) { void usb_dtr_notify(uint8_t port, bool set) {
mp_cdc_enabled = set; mp_cdc_enabled = set;
if (!set && reset_on_disconnect) {
reset_to_bootloader();
}
} }
void usb_rts_notify(uint8_t port, bool set) { void usb_rts_notify(uint8_t port, bool set) {
return; return;
} }
void usb_rx_notify(void) void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding) {
{ reset_on_disconnect = coding->dwDTERate == 1200;
}
void usb_rx_notify(void) {
irqflags_t flags; irqflags_t flags;
if (mp_cdc_enabled) { if (mp_cdc_enabled) {
while (udi_cdc_is_rx_ready()) { while (udi_cdc_is_rx_ready()) {

40
atmel-samd/reset.c Normal file
View File

@ -0,0 +1,40 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft 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 "flash_api.h"
#include "reset.h"
#include "asf/sam0/utils/cmsis/samd21/include/samd21.h"
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
#define DBL_TAP_PTR ((volatile uint32_t *)(HMCRAMC0_ADDR + HMCRAMC0_SIZE - 4))
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
void reset_to_bootloader(void) {
flash_flush();
*DBL_TAP_PTR = DBL_TAP_MAGIC;
NVIC_SystemReset();
}

31
atmel-samd/reset.h Normal file
View File

@ -0,0 +1,31 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft 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_ATMEL_SAMD_RESET_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_RESET_H__
void reset_to_bootloader(void);
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_RESET_H__

View File

@ -0,0 +1,224 @@
# This file is part of the Micro Python project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright (c) 2017 Scott Shawcroft 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.
# This helper generates the pinout tables in ../README.rst.
import os
import os.path
pins = ["PA00", "PA01", "PA02", "PA03", "PB08", "PB09", "PA04", "PA05", "PA06",
"PA07", "PA08", "PA09", "PA10", "PA11", "PB10", "PB11", "PA12", "PA13",
"PA14", "PA15", "PA16", "PA17", "PA18", "PA19", "PA20", "PA21", "PA22",
"PA23", "PA24", "PA25", "PB22", "PB23", "PA27", "PA28", "PA29", "PA30",
"PA31", "PB02", "PB03"]
# Dictionary keys: [board][pin] = list of pin names
mapping = {}
QSTR = " { MP_OBJ_NEW_QSTR(MP_QSTR_"
for board in os.listdir("boards"):
if not os.path.isdir("boards/" + board):
continue
mapping[board] = {}
with open("boards/" + board + "/pins.c", "r") as f:
for line in f:
if line.startswith(QSTR):
board_name, _, pin = line.split(")")
board_name = board_name[len(QSTR):]
pin = pin[-8:-4]
if pin not in mapping[board]:
mapping[board][pin] = []
mapping[board][pin].append(board_name)
column_width = {}
for board in mapping:
column_width[board] = len(board)
for pin in mapping[board]:
l = len(" / ".join("``" + x + "``" for x in mapping[board][pin]))
column_width[board] = max(l, column_width[board])
first_column_width = len("`microcontroller.pin`")
print("=" * first_column_width, end="")
total_board_width = -2
for board in column_width:
column = " " + "=" * column_width[board]
total_board_width += len(column)
print(column, end="")
print()
print("`microcontroller.pin` `board`")
print("-" * first_column_width + " " + "-" * total_board_width)
print("Datasheet".ljust(first_column_width), end="")
for board in column_width:
print(" " + board.ljust(column_width[board]), end="")
print()
print("=" * first_column_width, end="")
for board in column_width:
column = " " + "=" * column_width[board]
print(column, end="")
print()
for pin in pins:
print(pin.ljust(first_column_width), end="")
for board in column_width:
if pin in mapping[board]:
names = " / ".join("``" + x + "``" for x in mapping[board][pin])
print(" " + names.ljust(column_width[board]), end="")
else:
print(" " * (column_width[board] + 2), end="")
print()
print("=" * first_column_width, end="")
for board in column_width:
column = " " + "=" * column_width[board]
print(column, end="")
print()
print()
print()
# Generate pin capabilities too.
ALL_BUT_USB = list(pins)
ALL_BUT_USB.remove("PA24")
ALL_BUT_USB.remove("PA25")
# dictionary is [module][class] = [pins]
capabilities = {
"analogio" : {
"AnalogIn" : ["PA02", "PA03", "PB08", "PB09", "PA04", "PA05", "PA06",
"PA07", "PA08", "PA09", "PA10", "PA11", "PB02", "PB03"],
"AnalogOut": ["PA02"]
},
"audioio" : {
"AudioOut": ["PA02"]
},
"bitbangio": {
"I2C": ALL_BUT_USB,
"OneWire": ALL_BUT_USB,
"SPI": ALL_BUT_USB
},
"busio": {
"I2C - SDA": ["PA00", "PB08", "PA08", "PA12", "PA16", "PA22", "PB02"], # SERCOM pad 0
"I2C - SCL": ["PA01", "PB09", "PA09", "PA13", "PA17", "PA23", "PB03"], # SERCOM pad 1
"OneWire": ALL_BUT_USB,
"SPI - MISO": ["PA00", "PA01", "PB08", "PB09", "PA04", "PA05", "PA06",
"PA07", "PA08", "PA09", "PA10", "PA11", "PB10", "PB11",
"PA12", "PA13", "PA14", "PA15", "PA16", "PA17", "PA18",
"PA19", "PA20", "PA21", "PA22", "PA23", "PB22", "PB23",
"PA30", "PA31", "PB02", "PB03"], # any SERCOM pad
"SPI - MOSI": ["PA00", "PB08", "PA04", "PA06", "PA08", "PA10", "PA11",
"PB10", "PB11", "PA14", "PA15", "PA16", "PA18", "PA19",
"PA20", "PA21", "PA22", "PB22", "PB23", "PA30", "PA31",
"PB02"], # any pad but 1
"SPI - SCK": ["PA01", "PB09", "PA05", "PA07", "PA09", "PA11", "PB11",
"PA13", "PA15", "PA17", "PA19", "PA21", "PA23", "PB23",
"PA31", "PB03"], # 1 or 3
"UART - RX": ["PA00", "PA01", "PB08", "PB09", "PA04", "PA05", "PA06",
"PA07", "PA08", "PA09", "PA10", "PA11", "PB10", "PB11",
"PA12", "PA13", "PA14", "PA15", "PA16", "PA17", "PA18",
"PA19", "PA20", "PA21", "PA22", "PA23", "PB22", "PB23",
"PA30", "PA31", "PB02", "PB03"], # any pad
"UART - TX": ["PA00", "PB08", "PA04", "PA06", "PA08", "PA10", "PB10",
"PA12", "PA14", "PA16", "PA18", "PA20", "PA22", "PB22",
"PA30", "PB02"] # pad 0 or 2
},
"digitalio": {
"DigitalInOut": ALL_BUT_USB
},
"pulseio": {
"PulseIn": ALL_BUT_USB,
"PWMOut": ["PA01", "PB09", "PA04", "PA05", "PA06", "PA07", "PA08",
"PA09", "PA10", "PA11", "PB10", "PB11", "PA12", "PA13",
"PA14", "PA15", "PA16", "PA17", "PA18", "PA19", "PA20",
"PA21", "PA22", "PA23", "PA30", "PA31"]
},
"touchio": {
"TouchIn": ["PA02", "PA03", "PB08", "PB09", "PA04", "PA05", "PA06",
"PA07", "PB02", "PB03"]
}
}
column_width = {}
for module in capabilities:
for c in capabilities[module]:
column_width[module + c] = max(len("**Yes**"), len(c))
module_width = {}
for module in capabilities:
module_width[module] = 0
for c in capabilities[module]:
module_width[module] += column_width[module + c] + 2
module_width[module] -= 2
if module_width[module] < (len(module) + 2):
column_width[module + c] += (len(module) + 2 - module_width[module])
module_width[module] = len(module) + 2
first_column_width = len("`microcontroller.pin`")
print("=" * first_column_width, end="")
for module in capabilities:
for c in capabilities[module]:
print(" " + "=" * column_width[module + c], end="")
print()
print("`microcontroller.pin`", end="")
for module in capabilities:
print(" " + ("`" + module + "`").ljust(module_width[module]), end="")
print()
print("-" * first_column_width, end="")
for module in capabilities:
print(" " + "-" * module_width[module], end="")
print()
print("Datasheet".ljust(first_column_width), end="")
for module in capabilities:
for c in capabilities[module]:
print(" " + c.ljust(column_width[module + c]), end="")
print()
print("=" * first_column_width, end="")
for module in capabilities:
for c in capabilities[module]:
print(" " + "=" * column_width[module + c], end="")
print()
for pin in pins:
print(pin.ljust(first_column_width), end="")
for module in capabilities:
for c in capabilities[module]:
if pin in capabilities[module][c]:
print(" " + "**Yes**".ljust(column_width[module + c]), end="")
else:
print(" " * (column_width[module + c] + 2), end="")
print()
print("=" * first_column_width, end="")
for module in capabilities:
for c in capabilities[module]:
print(" " + "=" * column_width[module + c], end="")
print()

View File

@ -83,4 +83,5 @@ The last step is actually implementing each function in a port specific way. I c
### Testing ### Testing
Woohoo! You are almost done. After you implement everything, lots of drivers and sample code should just work. There are a number of drivers and examples written for Adafruit's Feather ecosystem. Here are places to start: Woohoo! You are almost done. After you implement everything, lots of drivers and sample code should just work. There are a number of drivers and examples written for Adafruit's Feather ecosystem. Here are places to start:
* https://github.com/adafruit?utf8=%E2%9C%93&q=Adafruit_MicroPython&type=&language= * [Adafruit repos with CircuitPython topic](https://github.com/search?q=topic%3Acircuitpython+org%3Aadafruit+fork%3Atrue)
* [Adafruit driver bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle)

View File

@ -132,7 +132,7 @@ When adding extra functionality to CircuitPython to mimic what a normal
operating system would do, either copy an existing CPython API (for example file operating system would do, either copy an existing CPython API (for example file
writing) or create a separate module to achieve what you want. For example, writing) or create a separate module to achieve what you want. For example,
mounting and unmount drives is not a part of CPython so it should be done in a mounting and unmount drives is not a part of CPython so it should be done in a
module, such as a new ``filesystem``, that is only available in CircuitPython. module, such as a new ``storage`` module, that is only available in CircuitPython.
That way when someone moves the code to CPython they know what parts need to be That way when someone moves the code to CPython they know what parts need to be
adapted. adapted.
@ -235,12 +235,13 @@ Renders as:
Use BusDevice Use BusDevice
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
BusDevice is an awesome foundational library that manages talking on a shared [BusDevice](https://github.com/adafruit/Adafruit_CircuitPython_BusDevice) is an
I2C or SPI device for you. The devices manage locking which ensures that a awesome foundational library that manages talking on a shared I2C or SPI device
transfer is done as a single unit despite CircuitPython internals and, in the for you. The devices manage locking which ensures that a transfer is done as a
future, other Python threads. For I2C, the device also manages the device single unit despite CircuitPython internals and, in the future, other Python
address. The SPI device, manages baudrate settings, chip select line and extra threads. For I2C, the device also manages the device address. The SPI device,
post-transaction clock cycles. manages baudrate settings, chip select line and extra post-transaction clock
cycles.
I2C Example I2C Example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -38,7 +38,7 @@ the ``lib/`` directory. Some drivers may not work without them.
Helper Libraries Helper Libraries
------- -------
These libraries build on top of the low level APIS to simplify common tasks. These libraries build on top of the low level APIs to simplify common tasks.
.. toctree:: .. toctree::
USB Human Interface Device (Keyboard and Mouse) <https://circuitpython.readthedocs.io/projects/hid/en/latest/> USB Human Interface Device (Keyboard and Mouse) <https://circuitpython.readthedocs.io/projects/hid/en/latest/>

View File

@ -8,3 +8,19 @@
.admonition-difference-to-cpython .admonition-title { .admonition-difference-to-cpython .admonition-title {
margin: 4px; margin: 4px;
} }
/* override table width restrictions */
@media screen and (min-width: 767px) {
.wy-table-responsive table td {
/* !important prevents the common CSS stylesheets from overriding
this as on RTD they are loaded after this stylesheet */
white-space: normal !important;
}
.wy-table-responsive {
overflow: visible !important;
}
}

View File

@ -122,7 +122,7 @@ fs_user_mount_t *fatfs_mount_mkfs(mp_uint_t n_args, const mp_obj_t *pos_args, mp
} }
} else if (res == FR_NO_FILESYSTEM && args[1].u_bool) { } else if (res == FR_NO_FILESYSTEM && args[1].u_bool) {
mkfs: mkfs:
res = f_mkfs(vfs->str, 1, 0); res = f_mkfs(vfs->str, 1, 0, 0x12345678);
if (res != FR_OK) { if (res != FR_OK) {
mkfs_error: mkfs_error:
MP_STATE_PORT(fs_user_mount)[i] = NULL; MP_STATE_PORT(fs_user_mount)[i] = NULL;

View File

@ -4054,7 +4054,8 @@ FRESULT f_forward (
FRESULT f_mkfs ( FRESULT f_mkfs (
const TCHAR* path, /* Logical drive number */ const TCHAR* path, /* Logical drive number */
BYTE sfd, /* Partitioning rule 0:FDISK, 1:SFD */ BYTE sfd, /* Partitioning rule 0:FDISK, 1:SFD */
UINT au /* Size of allocation unit in unit of byte or sector */ UINT au, /* Size of allocation unit in unit of byte or sector */
DWORD volume_id
) )
{ {
static const WORD vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0}; static const WORD vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0};
@ -4218,7 +4219,7 @@ FRESULT f_mkfs (
ST_DWORD(tbl + BPB_HiddSec, b_vol); /* Hidden sectors */ ST_DWORD(tbl + BPB_HiddSec, b_vol); /* Hidden sectors */
n = GET_FATTIME(); /* Use current time as VSN */ n = GET_FATTIME(); /* Use current time as VSN */
if (fmt == FS_FAT32) { if (fmt == FS_FAT32) {
ST_DWORD(tbl + BS_VolID32, n); /* VSN */ ST_DWORD(tbl + BS_VolID32, volume_id); /* VSN */
ST_DWORD(tbl + BPB_FATSz32, n_fat); /* Number of sectors per FAT */ ST_DWORD(tbl + BPB_FATSz32, n_fat); /* Number of sectors per FAT */
ST_DWORD(tbl + BPB_RootClus, 2); /* Root directory start cluster (2) */ ST_DWORD(tbl + BPB_RootClus, 2); /* Root directory start cluster (2) */
ST_WORD(tbl + BPB_FSInfo, 1); /* FSINFO record offset (VBR + 1) */ ST_WORD(tbl + BPB_FSInfo, 1); /* FSINFO record offset (VBR + 1) */
@ -4227,7 +4228,7 @@ FRESULT f_mkfs (
tbl[BS_BootSig32] = 0x29; /* Extended boot signature */ tbl[BS_BootSig32] = 0x29; /* Extended boot signature */
mem_cpy(tbl + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */ mem_cpy(tbl + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */
} else { } else {
ST_DWORD(tbl + BS_VolID, n); /* VSN */ ST_DWORD(tbl + BS_VolID, volume_id); /* VSN */
ST_WORD(tbl + BPB_FATSz16, n_fat); /* Number of sectors per FAT */ ST_WORD(tbl + BPB_FATSz16, n_fat); /* Number of sectors per FAT */
tbl[BS_DrvNum] = 0x80; /* Drive number */ tbl[BS_DrvNum] = 0x80; /* Drive number */
tbl[BS_BootSig] = 0x29; /* Extended boot signature */ tbl[BS_BootSig] = 0x29; /* Extended boot signature */

View File

@ -236,7 +236,7 @@ FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get numbe
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */ FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */ FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */ FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */ FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au, DWORD volume_id); /* Create a file system on the volume */
FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */ FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */ int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */

View File

@ -27,6 +27,7 @@
#include <stdint.h> #include <stdint.h>
#include "lib/utils/context_manager_helpers.h" #include "lib/utils/context_manager_helpers.h"
#include "py/binary.h"
#include "py/objproperty.h" #include "py/objproperty.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
@ -62,11 +63,11 @@
//| //|
//| # Generate one period of sine wav. //| # Generate one period of sine wav.
//| length = 8000 // 440 //| length = 8000 // 440
//| b = array.array("H", [0] * length) //| sine_wave = array.array("H", [0] * length)
//| for i in range(length): //| for i in range(length):
//| b[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15) //| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
//| //|
//| sample = audioio.AudioOut(board.SPEAKER, sin_wave) //| sample = audioio.AudioOut(board.SPEAKER, sine_wave)
//| sample.play(loop=True) //| sample.play(loop=True)
//| time.sleep(1) //| time.sleep(1)
//| sample.stop() //| sample.stop()
@ -106,12 +107,15 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
if (MP_OBJ_IS_TYPE(args[1], &fatfs_type_fileio)) { if (MP_OBJ_IS_TYPE(args[1], &fatfs_type_fileio)) {
common_hal_audioio_audioout_construct_from_file(self, pin, MP_OBJ_TO_PTR(args[1])); common_hal_audioio_audioout_construct_from_file(self, pin, MP_OBJ_TO_PTR(args[1]));
} else if (mp_get_buffer(args[1], &bufinfo, MP_BUFFER_READ)) { } else if (mp_get_buffer(args[1], &bufinfo, MP_BUFFER_READ)) {
if (bufinfo.len % 2 == 1) { uint8_t bytes_per_sample = 1;
mp_raise_ValueError("sample_source must be an even number of bytes (two per sample)"); if (bufinfo.typecode == 'H') {
bytes_per_sample = 2;
} else if (bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
mp_raise_ValueError("sample_source buffer must be a bytearray or array of type 'H' or 'B'");
} }
common_hal_audioio_audioout_construct_from_buffer(self, pin, ((uint16_t*)bufinfo.buf), bufinfo.len / 2); common_hal_audioio_audioout_construct_from_buffer(self, pin, ((uint16_t*)bufinfo.buf), bufinfo.len, bytes_per_sample);
} else { } else {
mp_raise_TypeError("sample_source must be a file or bytes-like object."); mp_raise_TypeError("sample_source must be a file or bytes-like object");
} }
return MP_OBJ_FROM_PTR(self); return MP_OBJ_FROM_PTR(self);

View File

@ -33,8 +33,10 @@
extern const mp_obj_type_t audioio_audioout_type; extern const mp_obj_type_t audioio_audioout_type;
void common_hal_audioio_audioout_construct_from_buffer(audioio_audioout_obj_t* self, const mcu_pin_obj_t* pin, uint16_t* buffer, uint32_t len); void common_hal_audioio_audioout_construct_from_buffer(audioio_audioout_obj_t* self,
void common_hal_audioio_audioout_construct_from_file(audioio_audioout_obj_t* self, const mcu_pin_obj_t* pin, pyb_file_obj_t* file); const mcu_pin_obj_t* pin, uint16_t* buffer, uint32_t len, uint8_t bytes_per_sample);
void common_hal_audioio_audioout_construct_from_file(audioio_audioout_obj_t* self,
const mcu_pin_obj_t* pin, pyb_file_obj_t* file);
void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self); void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self);
void common_hal_audioio_audioout_play(audioio_audioout_obj_t* self, bool loop); void common_hal_audioio_audioout_play(audioio_audioout_obj_t* self, bool loop);

View File

@ -41,6 +41,20 @@
//| The `neopixel_write` module contains a helper method to write out bytes in //| The `neopixel_write` module contains a helper method to write out bytes in
//| the 800khz neopixel protocol. //| the 800khz neopixel protocol.
//| //|
//| For example, to turn off a single neopixel (like the status pixel on Express
//| boards.)
//|
//| .. code-block:: python
//|
//| import board
//| import neopixel_write
//| import digitalio
//|
//| pin = digitalio.DigitalInOut(board.NEOPIXEL)
//| pin.direction = digitalio.Direction.OUTPUT
//| pixel_off = bytearray([0, 0, 0])
//| neopixel_write.neopixel_write(pin, pixel_off)
//|
//| .. method:: neopixel_write.neopixel_write(digitalinout, buf) //| .. method:: neopixel_write.neopixel_write(digitalinout, buf)
//| //|
//| Write buf out on the given DigitalInOut. //| Write buf out on the given DigitalInOut.

View File

@ -187,7 +187,8 @@ MP_NOINLINE STATIC void init_flash_fs(uint reset_mode) {
led_state(PYB_LED_R2, 1); led_state(PYB_LED_R2, 1);
uint32_t start_tick = HAL_GetTick(); uint32_t start_tick = HAL_GetTick();
res = f_mkfs("/flash", 0, 0); // TODO(tannewt): Provide a volume id thats based on the MCU id.
res = f_mkfs("/flash", 0, 0, 0x12345678);
if (res == FR_OK) { if (res == FR_OK) {
// success creating fresh LFS // success creating fresh LFS
} else { } else {