From 24c994647ebbc07b4d1e579ca3cb7e6de7d67962 Mon Sep 17 00:00:00 2001 From: brendanvanbreda Date: Wed, 18 Apr 2018 09:29:38 +0200 Subject: [PATCH 01/38] Create board.mk --- boards/CC03/board.mk | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 boards/CC03/board.mk diff --git a/boards/CC03/board.mk b/boards/CC03/board.mk new file mode 100644 index 00000000..0a90fdf6 --- /dev/null +++ b/boards/CC03/board.mk @@ -0,0 +1,2 @@ +CHIP_FAMILY = samd21 +CHIP_VARIANT = SAMD21G18A From a10516ec1eb65f5683c313f392d57df3ba1f48d8 Mon Sep 17 00:00:00 2001 From: brendanvanbreda Date: Wed, 18 Apr 2018 09:30:18 +0200 Subject: [PATCH 02/38] Create board_config.h --- boards/CC03/board_config.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 boards/CC03/board_config.h diff --git a/boards/CC03/board_config.h b/boards/CC03/board_config.h new file mode 100644 index 00000000..b689334a --- /dev/null +++ b/boards/CC03/board_config.h @@ -0,0 +1,16 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "XinaBox Limited" +#define PRODUCT_NAME "CC03" +#define VOLUME_LABEL "CC03" +#define INDEX_URL "https://xinabox.cc/products/cc03" + +#define BOARD_ID "SAMD21G18A-CC03-v0" + +//#define USB_VID 0x2341 +//#define USB_PID 0x024D + +#define LED_PIN PIN_PA07 + +#endif From 349664da9b88a69fb04e9f8410cbe9e08be34bc4 Mon Sep 17 00:00:00 2001 From: brendanvanbreda Date: Wed, 18 Apr 2018 09:30:52 +0200 Subject: [PATCH 03/38] Create board.mk --- boards/CS11/board.mk | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 boards/CS11/board.mk diff --git a/boards/CS11/board.mk b/boards/CS11/board.mk new file mode 100644 index 00000000..0a90fdf6 --- /dev/null +++ b/boards/CS11/board.mk @@ -0,0 +1,2 @@ +CHIP_FAMILY = samd21 +CHIP_VARIANT = SAMD21G18A From df9936d8e069119ef222624b12165b62fc60d640 Mon Sep 17 00:00:00 2001 From: brendanvanbreda Date: Wed, 18 Apr 2018 09:31:49 +0200 Subject: [PATCH 04/38] Create board_config.h --- boards/CS11/board_config.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 boards/CS11/board_config.h diff --git a/boards/CS11/board_config.h b/boards/CS11/board_config.h new file mode 100644 index 00000000..4e796d7e --- /dev/null +++ b/boards/CS11/board_config.h @@ -0,0 +1,16 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "XinaBox Limited" +#define PRODUCT_NAME "CS11" +#define VOLUME_LABEL "CS11" +#define INDEX_URL "https://xinabox.cc/products/cc11" + +#define BOARD_ID "SAMD21G18A-CS11-v0" + +//#define USB_VID 0x2341 +//#define USB_PID 0x024D + +#define LED_PIN PIN_PA08 + +#endif From 9a319c005dcffe0d67ea34ca51abf968ebe5def4 Mon Sep 17 00:00:00 2001 From: brendanvanbreda Date: Wed, 18 Apr 2018 09:33:04 +0200 Subject: [PATCH 05/38] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 30a05a49..e0ace91d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ Thus, it's really easy for the microcontroller to recognize a block of a UF2 file is written and immediately write it to flash. * **UF2 specification repo:** https://github.com/Microsoft/uf2 -* [#DeskOfLadyada UF24U ! LIVE @adafruit #adafruit #programming](https://youtu.be/WxCuB6jxLs0) ## Features From e915f77a18d3c25bf6fac41d8eba275abe14c1dc Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Sat, 9 Jun 2018 11:10:22 +0800 Subject: [PATCH 06/38] Allowed Bootloader to build WITHOUT a LED_PIN defined. --- inc/uf2.h | 9 ++++++++- src/utils.c | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/inc/uf2.h b/inc/uf2.h index c906fac5..ed668047 100644 --- a/inc/uf2.h +++ b/inc/uf2.h @@ -17,7 +17,7 @@ #undef DISABLE #undef ENABLE -// always go for crystalless - smaller and more compatiable +// always go for crystalless - smaller and more compatible #ifndef CRYSTALLESS #define CRYSTALLESS 1 #endif @@ -249,9 +249,16 @@ void led_signal(void); void led_init(void); void RGBLED_set_color(uint32_t color); +// Not all targets have a LED +#if defined(LED_PIN) #define LED_MSC_OFF() PINOP(LED_PIN, OUTCLR) #define LED_MSC_ON() PINOP(LED_PIN, OUTSET) #define LED_MSC_TGL() PINOP(LED_PIN, OUTTGL) +#else +#define LED_MSC_OFF() +#define LED_MSC_ON() +#define LED_MSC_TGL() +#endif extern uint32_t timerHigh, resetHorizon; void timerTick(void); diff --git a/src/utils.c b/src/utils.c index 7a8c6133..20ae6562 100644 --- a/src/utils.c +++ b/src/utils.c @@ -141,7 +141,9 @@ void led_signal() { } void led_init() { +#if defined(LED_PIN) PINOP(LED_PIN, DIRSET); +#endif LED_MSC_ON(); #if defined(BOARD_RGBLED_CLOCK_PIN) From 3d28a31356da9842bb4442f2bdd407531bf11701 Mon Sep 17 00:00:00 2001 From: brendanvanbreda Date: Tue, 10 Jul 2018 14:25:24 +0200 Subject: [PATCH 07/38] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e0ace91d..30a05a49 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Thus, it's really easy for the microcontroller to recognize a block of a UF2 file is written and immediately write it to flash. * **UF2 specification repo:** https://github.com/Microsoft/uf2 +* [#DeskOfLadyada UF24U ! LIVE @adafruit #adafruit #programming](https://youtu.be/WxCuB6jxLs0) ## Features From aa3e166332788d8491b016c3368aa6a05e042be4 Mon Sep 17 00:00:00 2001 From: PTS93 Date: Tue, 31 Jul 2018 18:05:15 +0200 Subject: [PATCH 08/38] Added link to ARM Toolchain download page This is causing quite a bit of confusion as versions coming with the OS is often outdated and does not work with the latest git state. F.e. https://github.com/Microsoft/uf2-samdx1/issues/24 and https://github.com/Microsoft/uf2-samdx1/issues/50 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30a05a49..b595b526 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ to temporarily turn off the protection. In gdb the command is: * `make` and an Unix environment * `node`.js in path (optional) -* `arm-none-eabi-gcc` in the path (the one coming with Yotta will do just fine) +* `arm-none-eabi-gcc` in the path (the one coming with Yotta will do just fine). You can get the latest version from ARM: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads * `openocd` - you can use the one coming with Arduino (after your install the M0 board support) Atmel Studio is not supported. From f5fd25e9f7261477b501984f47ebaf63fa181353 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 26 Sep 2018 12:47:47 -0700 Subject: [PATCH 09/38] Allow for storing configuration in the bootloader area --- inc/config_data.h | 108 ++++++++++++++++++++++++++++++++++++++++++++++ inc/uf2.h | 5 +++ inc/uf2format.h | 2 +- src/msc.c | 13 ++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 inc/config_data.h diff --git a/inc/config_data.h b/inc/config_data.h new file mode 100644 index 00000000..68f2f777 --- /dev/null +++ b/inc/config_data.h @@ -0,0 +1,108 @@ +#ifndef __CONFIG_DATA_H +#define __CONFIG_DATA_H + +#define CFG_PIN_ACCELEROMETER_INT 1 +#define CFG_PIN_ACCELEROMETER_SCL 2 +#define CFG_PIN_ACCELEROMETER_SDA 3 +#define CFG_PIN_BTN_A 4 +#define CFG_PIN_BTN_B 5 +#define CFG_PIN_BTN_SLIDE 6 +#define CFG_PIN_DOTSTAR_CLOCK 7 +#define CFG_PIN_DOTSTAR_DATA 8 +#define CFG_PIN_FLASH_CS 9 +#define CFG_PIN_FLASH_MISO 10 +#define CFG_PIN_FLASH_MOSI 11 +#define CFG_PIN_FLASH_SCK 12 +#define CFG_PIN_LED 13 +#define CFG_PIN_LIGHT 14 +#define CFG_PIN_MICROPHONE 15 +#define CFG_PIN_MIC_CLOCK 16 +#define CFG_PIN_MIC_DATA 17 +#define CFG_PIN_MISO 18 +#define CFG_PIN_MOSI 19 +#define CFG_PIN_NEOPIXEL 20 +#define CFG_PIN_RX 21 +#define CFG_PIN_RXLED 22 +#define CFG_PIN_SCK 23 +#define CFG_PIN_SCL 24 +#define CFG_PIN_SDA 25 +#define CFG_PIN_SPEAKER_AMP 26 +#define CFG_PIN_TEMPERATURE 27 +#define CFG_PIN_TX 28 +#define CFG_PIN_TXLED 29 +#define CFG_PIN_IR_OUT 30 +#define CFG_PIN_IR_IN 31 +#define CFG_PIN_DISPLAY_SCK 32 +#define CFG_PIN_DISPLAY_MISO 33 +#define CFG_PIN_DISPLAY_MOSI 34 +#define CFG_PIN_DISPLAY_CS 35 +#define CFG_PIN_DISPLAY_DC 36 +#define CFG_DISPLAY_WIDTH 37 +#define CFG_DISPLAY_HEIGHT 38 +#define CFG_DISPLAY_CFG0 39 +#define CFG_DISPLAY_CFG1 40 +#define CFG_DISPLAY_CFG2 41 +#define CFG_DISPLAY_CFG3 42 +#define CFG_PIN_DISPLAY_RST 43 +#define CFG_PIN_DISPLAY_BL 44 +#define CFG_PIN_SERVO_1 45 +#define CFG_PIN_SERVO_2 46 +#define CFG_PIN_BTN_LEFT 47 +#define CFG_PIN_BTN_RIGHT 48 +#define CFG_PIN_BTN_UP 49 +#define CFG_PIN_BTN_DOWN 50 +#define CFG_PIN_BTN_MENU 51 +#define CFG_PIN_LED_R 52 +#define CFG_PIN_LED_G 53 +#define CFG_PIN_LED_B 54 +#define CFG_PIN_LED1 55 +#define CFG_PIN_LED2 56 +#define CFG_PIN_LED3 57 +#define CFG_PIN_LED4 58 +#define CFG_SPEAKER_VOLUME 59 + +#define CFG_PIN_A0 100 +#define CFG_PIN_A1 101 +#define CFG_PIN_A2 102 +#define CFG_PIN_A3 103 +#define CFG_PIN_A4 104 +#define CFG_PIN_A5 105 +#define CFG_PIN_A6 106 +#define CFG_PIN_A7 107 +#define CFG_PIN_A8 108 +#define CFG_PIN_A9 109 +#define CFG_PIN_A10 110 +#define CFG_PIN_A11 111 +#define CFG_PIN_A12 112 +#define CFG_PIN_A13 113 +#define CFG_PIN_A14 114 +#define CFG_PIN_A15 115 + +#define CFG_PIN_D0 150 +#define CFG_PIN_D1 151 +#define CFG_PIN_D2 152 +#define CFG_PIN_D3 153 +#define CFG_PIN_D4 154 +#define CFG_PIN_D5 155 +#define CFG_PIN_D6 156 +#define CFG_PIN_D7 157 +#define CFG_PIN_D8 158 +#define CFG_PIN_D9 159 +#define CFG_PIN_D10 160 +#define CFG_PIN_D11 161 +#define CFG_PIN_D12 162 +#define CFG_PIN_D13 163 +#define CFG_PIN_D14 164 +#define CFG_PIN_D15 165 + +#define CFG_NUM_NEOPIXELS 200 +#define CFG_NUM_DOTSTARS 201 +#define CFG_DEFAULT_BUTTON_MODE 202 +#define CFG_SWD_ENABLED 203 +#define CFG_FLASH_BYTES 204 + +#define CFG(k, v) CFG_ ## k, v, + +#define CONFIG_DATA_MAGIC 0xbe3fd5ce + +#endif diff --git a/inc/uf2.h b/inc/uf2.h index ed668047..6941f718 100644 --- a/inc/uf2.h +++ b/inc/uf2.h @@ -233,8 +233,13 @@ void padded_memcpy(char *dst, const char *src, int len); #define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef #if USE_SINGLE_RESET +#ifdef SAMD21 #define SINGLE_RESET() (*((uint32_t *)0x20B4) == 0x87eeb07c) #endif +#ifdef SAMD51 +#define SINGLE_RESET() (*((uint32_t *)0x4268) == 0x87eeb07c) +#endif +#endif void resetIntoApp(void); void resetIntoBootloader(void); diff --git a/inc/uf2format.h b/inc/uf2format.h index 42282cbf..e66c49f4 100644 --- a/inc/uf2format.h +++ b/inc/uf2format.h @@ -54,7 +54,7 @@ typedef void (*UF2_HID_Handover_Handler)(int ep); // this is required to be exactly 16 bytes long by the linker script typedef struct { - void *reserved0; + const uint32_t *config_data; UF2_HID_Handover_Handler handoverHID; UF2_MSC_Handover_Handler handoverMSC; const char *info_uf2; diff --git a/src/msc.c b/src/msc.c index 18fb6fa5..3640ee8c 100644 --- a/src/msc.c +++ b/src/msc.c @@ -44,6 +44,8 @@ #include "uf2.h" +#include "config_data.h" + #include "lib/usb_msc/sbc_protocol.h" #include "lib/usb_msc/spc_protocol.h" #include "lib/usb_msc/usb_protocol.h" @@ -863,7 +865,18 @@ static void handover(UF2_HandoverArgs *args) { } #endif +#ifdef CONFIG_DATA +static const uint32_t config_data[] = { + CONFIG_DATA_MAGIC, + CONFIG_DATA + 0, 0 +}; +#endif + __attribute__((section(".binfo"))) __attribute__((__used__)) const UF2_BInfo binfo = { +#ifdef CONFIG_DATA + .config_data = config_data, +#endif #if USE_MSC_HANDOVER .handoverMSC = handover, #endif From 7c2f33d3d1cd08f316fa3bec0c6e0fd68bd64e01 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 26 Sep 2018 12:47:58 -0700 Subject: [PATCH 10/38] Add Itsy-based Arcade board --- boards/arcade_51/board.mk | 2 + boards/arcade_51/board_config.h | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 boards/arcade_51/board.mk create mode 100644 boards/arcade_51/board_config.h diff --git a/boards/arcade_51/board.mk b/boards/arcade_51/board.mk new file mode 100644 index 00000000..0d8d74a9 --- /dev/null +++ b/boards/arcade_51/board.mk @@ -0,0 +1,2 @@ +CHIP_FAMILY = samd51 +CHIP_VARIANT = SAMD51G19A diff --git a/boards/arcade_51/board_config.h b/boards/arcade_51/board_config.h new file mode 100644 index 00000000..a887e403 --- /dev/null +++ b/boards/arcade_51/board_config.h @@ -0,0 +1,76 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "Adafruit Industries" +#define PRODUCT_NAME "Arcade 51" +#define VOLUME_LABEL "ARCADE" +#define INDEX_URL "http://adafru.it/" +#define BOARD_ID "SAMD51G19A-Arcade-51" + +#define USB_VID 0x239A +#define USB_PID 0x002B + +#define LED_PIN PIN_PA22 + +#define BOARD_RGBLED_CLOCK_PIN PIN_PB02 +#define BOARD_RGBLED_DATA_PIN PIN_PB03 + +#define BOOT_USART_MODULE SERCOM3 +#define BOOT_USART_MASK APBAMASK +#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 +#define BOOT_USART_PAD_SETTINGS UART_RX_PAD1_TX_PAD0 +#define BOOT_USART_PAD3 PINMUX_UNUSED +#define BOOT_USART_PAD2 PINMUX_UNUSED +#define BOOT_USART_PAD1 PINMUX_PA22C_SERCOM3_PAD0 +#define BOOT_USART_PAD0 PINMUX_PA23C_SERCOM3_PAD1 +#define BOOT_GCLK_ID_CORE SERCOM3_GCLK_ID_CORE +#define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW + +#define PIN_A0 PIN_PA02 +#define PIN_A1 PIN_PA05 +#define PIN_A2 PIN_PB08 +#define PIN_A3 PIN_PB09 +#define PIN_A4 PIN_PA04 +#define PIN_A5 PIN_PA06 +#define PIN_RX PIN_PA16 +#define PIN_TX PIN_PA17 +#define PIN_D2 PIN_PA07 +#define PIN_D3 PIN_PB22 +#define PIN_D4 PIN_PA14 +#define PIN_D5 PIN_PA15 +#define PIN_D7 PIN_PA18 +#define PIN_D9 PIN_PA19 +#define PIN_D10 PIN_PA20 +#define PIN_D11 PIN_PA21 +#define PIN_D12 PIN_PA23 +#define PIN_LED PIN_PA22 +#define PIN_SCK PIN_PA01 +#define PIN_MISO PIN_PB23 +#define PIN_MOSI PIN_PA00 +#define PIN_SDA PIN_PA12 +#define PIN_SCL PIN_PA13 + +#define CONFIG_DATA \ + CFG(PIN_BTN_LEFT, PIN_D11) \ + CFG(PIN_BTN_UP, PIN_D10) \ + CFG(PIN_BTN_RIGHT, PIN_D9) \ + CFG(PIN_BTN_DOWN, PIN_D12) \ + CFG(PIN_BTN_A, PIN_SCL) \ + CFG(PIN_BTN_B, PIN_D7) \ + CFG(PIN_BTN_MENU, PIN_SDA) \ + CFG(PIN_DISPLAY_CS, PIN_A2) \ + CFG(PIN_DISPLAY_SCK, PIN_SCK) \ + CFG(PIN_DISPLAY_MOSI, PIN_MOSI) \ + CFG(PIN_DISPLAY_DC, PIN_A3) \ + CFG(PIN_DISPLAY_RST, PIN_A4) \ + CFG(PIN_DISPLAY_MISO, PIN_MISO) \ + CFG(PIN_DISPLAY_BL, PIN_A5) \ + CFG(PIN_SPEAKER_AMP, PIN_D2) \ + CFG(SPEAKER_VOLUME, 512) \ + CFG(DISPLAY_CFG0, 0x00000090) \ + CFG(DISPLAY_CFG1, 0x000e14ff) \ + CFG(DISPLAY_CFG2, 24) \ + CFG(DISPLAY_WIDTH, 160) \ + CFG(DISPLAY_HEIGHT, 128) + +#endif From f65c3238fc54a625942f19b677c3903a352c36d9 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Fri, 30 Nov 2018 17:55:14 -0800 Subject: [PATCH 11/38] Add alternative button mapping --- boards/arcade_51/board_config.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/boards/arcade_51/board_config.h b/boards/arcade_51/board_config.h index a887e403..819b6fff 100644 --- a/boards/arcade_51/board_config.h +++ b/boards/arcade_51/board_config.h @@ -50,14 +50,30 @@ #define PIN_SDA PIN_PA12 #define PIN_SCL PIN_PA13 -#define CONFIG_DATA \ +#if 0 +// game controller make +#define BUTTONS \ + CFG(PIN_BTN_LEFT, PIN_SDA) \ + CFG(PIN_BTN_UP, PIN_D7) \ + CFG(PIN_BTN_RIGHT, PIN_SCL) \ + CFG(PIN_BTN_DOWN, PIN_D9) \ + CFG(PIN_BTN_A, PIN_D10) \ + CFG(PIN_BTN_B, PIN_D11) \ + CFG(PIN_BTN_MENU, PIN_D12) +#else +// breadboarded Itsy +#define BUTTONS \ CFG(PIN_BTN_LEFT, PIN_D11) \ CFG(PIN_BTN_UP, PIN_D10) \ CFG(PIN_BTN_RIGHT, PIN_D9) \ CFG(PIN_BTN_DOWN, PIN_D12) \ CFG(PIN_BTN_A, PIN_SCL) \ CFG(PIN_BTN_B, PIN_D7) \ - CFG(PIN_BTN_MENU, PIN_SDA) \ + CFG(PIN_BTN_MENU, PIN_SDA) +#endif + +#define CONFIG_DATA \ + BUTTONS \ CFG(PIN_DISPLAY_CS, PIN_A2) \ CFG(PIN_DISPLAY_SCK, PIN_SCK) \ CFG(PIN_DISPLAY_MOSI, PIN_MOSI) \ From 4bf0d7b4659fb4b7839b5d288d139690b33886a0 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Fri, 30 Nov 2018 17:59:35 -0800 Subject: [PATCH 12/38] Add support for another arcade board --- boards/smallarcade/board.mk | 2 + boards/smallarcade/board_config.h | 121 ++++++++++++++++++++++++++++++ inc/config_data.h | 19 +++++ scripts/dbgtool.js | 2 +- src/utils.c | 22 ++++-- 5 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 boards/smallarcade/board.mk create mode 100644 boards/smallarcade/board_config.h diff --git a/boards/smallarcade/board.mk b/boards/smallarcade/board.mk new file mode 100644 index 00000000..c17f5fba --- /dev/null +++ b/boards/smallarcade/board.mk @@ -0,0 +1,2 @@ +CHIP_FAMILY = samd51 +CHIP_VARIANT = SAMD51J19A diff --git a/boards/smallarcade/board_config.h b/boards/smallarcade/board_config.h new file mode 100644 index 00000000..41a8186e --- /dev/null +++ b/boards/smallarcade/board_config.h @@ -0,0 +1,121 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "Adafruit Industries" +#define PRODUCT_NAME "ItsyBitsy-M4" +#define VOLUME_LABEL "ARCADE" +#define INDEX_URL "http://adafru.it/" +#define BOARD_ID "SAMD51J19A-Arcade-Small-v0" + +#define USB_VID 0x239A +#define USB_PID 0x002B + +#define LED_PIN PIN_PA23 + +#define BOARD_NEOPIXEL_PIN PIN_PA15 +#define BOARD_NEOPIXEL_COUNT 5 + +#define BOOT_USART_MODULE SERCOM3 +#define BOOT_USART_MASK APBAMASK +#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 +#define BOOT_USART_PAD_SETTINGS UART_RX_PAD1_TX_PAD0 +#define BOOT_USART_PAD3 PINMUX_UNUSED +#define BOOT_USART_PAD2 PINMUX_UNUSED +#define BOOT_USART_PAD1 PINMUX_PA22C_SERCOM3_PAD0 +#define BOOT_USART_PAD0 PINMUX_PA23C_SERCOM3_PAD1 +#define BOOT_GCLK_ID_CORE SERCOM3_GCLK_ID_CORE +#define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW + +#define PIN_A0 PIN_PA02 +#define PIN_A1 PIN_PA05 +#define PIN_A2 PIN_PB08 +#define PIN_A3 PIN_PB09 +#define PIN_A4 PIN_PA04 +#define PIN_A5 PIN_PA06 + +#define PIN_D2 PIN_PB03 +#define PIN_D3 PIN_PB02 +#define PIN_D4 PIN_PA14 +#define PIN_D5 PIN_PA16 +#define PIN_D6 PIN_PA18 +#define PIN_D9 PIN_PA19 +#define PIN_D10 PIN_PA20 +#define PIN_D11 PIN_PA21 +#define PIN_D12 PIN_PA22 +#define PIN_D13 PIN_PA23 +#define PIN_LED PIN_D13 + +#define PIN_RX PIN_PA17 +#define PIN_TX PIN_PA16 + +#define PIN_SCK PIN_PA17 +#define PIN_MISO PIN_PB22 +#define PIN_MOSI PIN_PB23 +#define PIN_SDA PIN_PA12 +#define PIN_SCL PIN_PA13 + +#define PIN_DISPLAY_BL PIN_PA00 +#define PIN_DISPLAY_CS PIN_PB07 +#define PIN_DISPLAY_SCK PIN_PB13 +#define PIN_DISPLAY_MOSI PIN_PB12 +#define PIN_DISPLAY_DC PIN_PB05 +#define PIN_DISPLAY_RST PIN_PA01 + +#define CONFIG_DATA \ + CFG(PIN_BTN_LEFT, 100) \ + CFG(PIN_BTN_UP, 101) \ + CFG(PIN_BTN_RIGHT, 103) \ + CFG(PIN_BTN_DOWN, 102) \ + CFG(PIN_BTN_A, 107) \ + CFG(PIN_BTN_B, 106) \ + CFG(PIN_BTN_MENU, 104) \ + CFG(PIN_BTN_SOFT_RESET, 105) \ + CFG(PIN_DISPLAY_CS, PIN_DISPLAY_CS) \ + CFG(PIN_DISPLAY_SCK, PIN_DISPLAY_SCK) \ + CFG(PIN_DISPLAY_MOSI, PIN_DISPLAY_MOSI) \ + CFG(PIN_DISPLAY_DC, PIN_DISPLAY_DC) \ + CFG(PIN_DISPLAY_RST, PIN_DISPLAY_RST) \ + CFG(PIN_DISPLAY_MISO, -1) \ + CFG(PIN_DISPLAY_BL, PIN_DISPLAY_BL) \ + CFG(PIN_SPEAKER_AMP, -1) \ + CFG(PIN_JACK_SND, PIN_A0) \ + CFG(PIN_JACK_TX, PIN_TX) \ + CFG(PIN_BTNMX_LATCH, PIN_PB00) \ + CFG(PIN_BTNMX_CLOCK, PIN_PB31) \ + CFG(PIN_BTNMX_DATA, PIN_PB30) \ + CFG(SPEAKER_VOLUME, 512) \ + CFG(DISPLAY_CFG0, 0x00000080) \ + CFG(DISPLAY_CFG1, 0x00012C2D) \ + CFG(DISPLAY_CFG2, 24) \ + CFG(DISPLAY_WIDTH, 160) \ + CFG(DISPLAY_HEIGHT, 128) \ + CFG(PIN_A0, PIN_A0) \ + CFG(PIN_A1, PIN_A1) \ + CFG(PIN_A2, PIN_A2) \ + CFG(PIN_A3, PIN_A3) \ + CFG(PIN_A4, PIN_A4) \ + CFG(PIN_A5, PIN_A5) \ + CFG(PIN_D2, PIN_D2) \ + CFG(PIN_D3, PIN_D3) \ + CFG(PIN_D4, PIN_D4) \ + CFG(PIN_D5, PIN_D5) \ + CFG(PIN_D6, PIN_D6) \ + CFG(PIN_D9, PIN_D9) \ + CFG(PIN_D10, PIN_D10) \ + CFG(PIN_D11, PIN_D11) \ + CFG(PIN_D12, PIN_D12) \ + CFG(PIN_D13, PIN_D13) \ + CFG(PIN_LED, PIN_LED) \ + CFG(PIN_SCK, PIN_SCK) \ + CFG(PIN_MISO, PIN_MISO) \ + CFG(PIN_MOSI, PIN_MOSI) \ + CFG(PIN_SDA, PIN_SDA) \ + CFG(PIN_SCL, PIN_SCL) \ + CFG(PIN_NEOPIXEL, BOARD_NEOPIXEL_PIN) \ + CFG(NUM_NEOPIXELS, BOARD_NEOPIXEL_COUNT) \ + CFG(PIN_ACCELEROMETER_INT, PIN_PB14) \ + CFG(PIN_ACCELEROMETER_SCL, PIN_SCL) \ + CFG(PIN_ACCELEROMETER_SDA, PIN_SDA) \ + CFG(ACCELEROMETER_TYPE, ACCELEROMETER_TYPE_LIS3DH) + +#endif diff --git a/inc/config_data.h b/inc/config_data.h index 68f2f777..3d5d9c81 100644 --- a/inc/config_data.h +++ b/inc/config_data.h @@ -61,6 +61,25 @@ #define CFG_PIN_LED4 58 #define CFG_SPEAKER_VOLUME 59 +#define CFG_PIN_JACK_TX 60 +#define CFG_PIN_JACK_SENSE 61 +#define CFG_PIN_JACK_HPEN 62 +#define CFG_PIN_JACK_BZEN 63 +#define CFG_PIN_JACK_PWREN 64 +#define CFG_PIN_JACK_SND 65 + +#define CFG_PIN_BTNMX_LATCH 66 +#define CFG_PIN_BTNMX_CLOCK 67 +#define CFG_PIN_BTNMX_DATA 68 +#define CFG_PIN_BTN_SOFT_RESET 69 +#define CFG_ACCELEROMETER_TYPE 70 + +#define ACCELEROMETER_TYPE_LIS3DH 0x32 +#define ACCELEROMETER_TYPE_MMA8453 0x38 +#define ACCELEROMETER_TYPE_FXOS8700 0x3C +#define ACCELEROMETER_TYPE_MMA8653 0x3A +#define ACCELEROMETER_TYPE_MSA300 0x4C + #define CFG_PIN_A0 100 #define CFG_PIN_A1 101 #define CFG_PIN_A2 102 diff --git a/scripts/dbgtool.js b/scripts/dbgtool.js index 3c57916f..ef7f5253 100755 --- a/scripts/dbgtool.js +++ b/scripts/dbgtool.js @@ -71,7 +71,7 @@ function main() { if (process.platform == "win32") openocdBin += ".exe" - let zeroCfg = pkgDir + "hardware/samd/1.6.17/variants/arduino_zero/openocd_scripts/arduino_zero.cfg" + let zeroCfg = pkgDir + "hardware/samd/1.6.16/variants/arduino_zero/openocd_scripts/arduino_zero.cfg" let cmd = `telnet_port disabled; init; halt; ` if (mode == "map") diff --git a/src/utils.c b/src/utils.c index 20ae6562..ef492495 100644 --- a/src/utils.c +++ b/src/utils.c @@ -5,14 +5,14 @@ static uint32_t timerLow; uint32_t timerHigh, resetHorizon; void delay(uint32_t ms) { - // SAMD21 starts up at 1mhz by default. - #ifdef SAMD21 +// SAMD21 starts up at 1mhz by default. +#ifdef SAMD21 ms <<= 8; - #endif - // SAMD51 starts up at 48mhz by default. - #ifdef SAMD51 +#endif +// SAMD51 starts up at 48mhz by default. +#ifdef SAMD51 ms <<= 12; - #endif +#endif for (int i = 1; i < ms; ++i) { asm("nop"); } @@ -141,9 +141,9 @@ void led_signal() { } void led_init() { -#if defined(LED_PIN) +#if defined(LED_PIN) PINOP(LED_PIN, DIRSET); -#endif +#endif LED_MSC_ON(); #if defined(BOARD_RGBLED_CLOCK_PIN) @@ -154,6 +154,12 @@ void led_init() { // This won't work for neopixel, because we're running at 1MHz or thereabouts... RGBLED_set_color(COLOR_LEAVE); #endif + +#if defined(PIN_DISPLAY_BL) + // turn display backlight + PINOP(PIN_DISPLAY_BL, DIRSET); + PINOP(PIN_DISPLAY_BL, OUTCLR); +#endif } #if defined(BOARD_RGBLED_CLOCK_PIN) From 201566000bc6c0b78d7455418e883ffd1d848192 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Fri, 30 Nov 2018 18:49:10 -0800 Subject: [PATCH 13/38] Check optional familyID field when flashing --- inc/uf2format.h | 8 +++++++- src/fat.c | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/inc/uf2format.h b/inc/uf2format.h index e66c49f4..179f900c 100644 --- a/inc/uf2format.h +++ b/inc/uf2format.h @@ -9,9 +9,11 @@ // if you increase that, you will also need to update the linker script file #ifdef SAMD21 #define APP_START_ADDRESS 0x00002000 +#define UF2_FAMILY 0x68ed2b88 #endif #ifdef SAMD51 #define APP_START_ADDRESS 0x00004000 +#define UF2_FAMILY 0x55114460 #endif #define UF2_MAGIC_START0 0x0A324655UL // "UF2\n" @@ -20,6 +22,10 @@ // If set, the block is "comment" and should not be flashed to the device #define UF2_FLAG_NOFLASH 0x00000001 +#define UF2_FLAG_FAMILYID_PRESENT 0x00002000 + +#define UF2_IS_MY_FAMILY(bl) \ + (((bl)->flags & UF2_FLAG_FAMILYID_PRESENT) == 0 || (bl)->familyID == UF2_FAMILY) typedef struct { // 32 byte header @@ -30,7 +36,7 @@ typedef struct { uint32_t payloadSize; uint32_t blockNo; uint32_t numBlocks; - uint32_t reserved; + uint32_t familyID; // raw data; uint8_t data[476]; diff --git a/src/fat.c b/src/fat.c index b1b0c8e2..fd8a70c3 100644 --- a/src/fat.c +++ b/src/fat.c @@ -201,7 +201,8 @@ void write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state } if ((bl->flags & UF2_FLAG_NOFLASH) || bl->payloadSize != 256 || (bl->targetAddr & 0xff) || - bl->targetAddr < APP_START_ADDRESS || bl->targetAddr >= FLASH_SIZE) { + bl->targetAddr < APP_START_ADDRESS || bl->targetAddr >= FLASH_SIZE || + !UF2_IS_MY_FAMILY(bl)) { #if USE_DBG_MSC if (!quiet) logval("invalid target addr", bl->targetAddr); From e0dfbe4877540cd35caddbe54b9a3c3b08f0ab73 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Fri, 30 Nov 2018 19:24:27 -0800 Subject: [PATCH 14/38] Check familyID before other stuff --- src/fat.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/fat.c b/src/fat.c index fd8a70c3..a5510151 100644 --- a/src/fat.c +++ b/src/fat.c @@ -196,13 +196,12 @@ void read_block(uint32_t block_no, uint8_t *data) { void write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state) { UF2_Block *bl = (void *)data; - if (!is_uf2_block(bl)) { + if (!is_uf2_block(bl) || !UF2_IS_MY_FAMILY(bl)) { return; } if ((bl->flags & UF2_FLAG_NOFLASH) || bl->payloadSize != 256 || (bl->targetAddr & 0xff) || - bl->targetAddr < APP_START_ADDRESS || bl->targetAddr >= FLASH_SIZE || - !UF2_IS_MY_FAMILY(bl)) { + bl->targetAddr < APP_START_ADDRESS || bl->targetAddr >= FLASH_SIZE) { #if USE_DBG_MSC if (!quiet) logval("invalid target addr", bl->targetAddr); From c1df3a53e92c6b6fd1252af3014e54ba1fcb8d07 Mon Sep 17 00:00:00 2001 From: Teddy Seyed Date: Sat, 29 Dec 2018 20:33:47 -0800 Subject: [PATCH 15/38] Adding alternate config for non adafruit screens for arcade, and an arcade bootloader for the Feather --- boards/arcade_51_alt/board.mk | 2 + boards/arcade_51_alt/board_config.h | 92 +++++++++++++++++++++++ boards/arcade_feather_m4/board.mk | 2 + boards/arcade_feather_m4/board_config.h | 97 +++++++++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 boards/arcade_51_alt/board.mk create mode 100644 boards/arcade_51_alt/board_config.h create mode 100644 boards/arcade_feather_m4/board.mk create mode 100644 boards/arcade_feather_m4/board_config.h diff --git a/boards/arcade_51_alt/board.mk b/boards/arcade_51_alt/board.mk new file mode 100644 index 00000000..0d8d74a9 --- /dev/null +++ b/boards/arcade_51_alt/board.mk @@ -0,0 +1,2 @@ +CHIP_FAMILY = samd51 +CHIP_VARIANT = SAMD51G19A diff --git a/boards/arcade_51_alt/board_config.h b/boards/arcade_51_alt/board_config.h new file mode 100644 index 00000000..9a98e803 --- /dev/null +++ b/boards/arcade_51_alt/board_config.h @@ -0,0 +1,92 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "Adafruit Industries" +#define PRODUCT_NAME "Arcade 51" +#define VOLUME_LABEL "ARCADE" +#define INDEX_URL "http://adafru.it/" +#define BOARD_ID "SAMD51G19A-Arcade-51" + +#define USB_VID 0x239A +#define USB_PID 0x002B + +#define LED_PIN PIN_PA22 + +#define BOARD_RGBLED_CLOCK_PIN PIN_PB02 +#define BOARD_RGBLED_DATA_PIN PIN_PB03 + +#define BOOT_USART_MODULE SERCOM3 +#define BOOT_USART_MASK APBAMASK +#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 +#define BOOT_USART_PAD_SETTINGS UART_RX_PAD1_TX_PAD0 +#define BOOT_USART_PAD3 PINMUX_UNUSED +#define BOOT_USART_PAD2 PINMUX_UNUSED +#define BOOT_USART_PAD1 PINMUX_PA22C_SERCOM3_PAD0 +#define BOOT_USART_PAD0 PINMUX_PA23C_SERCOM3_PAD1 +#define BOOT_GCLK_ID_CORE SERCOM3_GCLK_ID_CORE +#define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW + +#define PIN_A0 PIN_PA02 +#define PIN_A1 PIN_PA05 +#define PIN_A2 PIN_PB08 +#define PIN_A3 PIN_PB09 +#define PIN_A4 PIN_PA04 +#define PIN_A5 PIN_PA06 +#define PIN_RX PIN_PA16 +#define PIN_TX PIN_PA17 +#define PIN_D2 PIN_PA07 +#define PIN_D3 PIN_PB22 +#define PIN_D4 PIN_PA14 +#define PIN_D5 PIN_PA15 +#define PIN_D7 PIN_PA18 +#define PIN_D9 PIN_PA19 +#define PIN_D10 PIN_PA20 +#define PIN_D11 PIN_PA21 +#define PIN_D12 PIN_PA23 +#define PIN_LED PIN_PA22 +#define PIN_SCK PIN_PA01 +#define PIN_MISO PIN_PB23 +#define PIN_MOSI PIN_PA00 +#define PIN_SDA PIN_PA12 +#define PIN_SCL PIN_PA13 + +#if 0 +// game controller make +#define BUTTONS \ + CFG(PIN_BTN_LEFT, PIN_SDA) \ + CFG(PIN_BTN_UP, PIN_D7) \ + CFG(PIN_BTN_RIGHT, PIN_SCL) \ + CFG(PIN_BTN_DOWN, PIN_D9) \ + CFG(PIN_BTN_A, PIN_D10) \ + CFG(PIN_BTN_B, PIN_D11) \ + CFG(PIN_BTN_MENU, PIN_D12) +#else +// breadboarded Itsy +#define BUTTONS \ + CFG(PIN_BTN_LEFT, PIN_D11) \ + CFG(PIN_BTN_UP, PIN_D10) \ + CFG(PIN_BTN_RIGHT, PIN_D9) \ + CFG(PIN_BTN_DOWN, PIN_D12) \ + CFG(PIN_BTN_A, PIN_SCL) \ + CFG(PIN_BTN_B, PIN_D7) \ + CFG(PIN_BTN_MENU, PIN_SDA) +#endif + +#define CONFIG_DATA \ + BUTTONS \ + CFG(PIN_DISPLAY_CS, PIN_A2) \ + CFG(PIN_DISPLAY_SCK, PIN_SCK) \ + CFG(PIN_DISPLAY_MOSI, PIN_MOSI) \ + CFG(PIN_DISPLAY_DC, PIN_A3) \ + CFG(PIN_DISPLAY_RST, PIN_A4) \ + CFG(PIN_DISPLAY_MISO, PIN_MISO) \ + CFG(PIN_DISPLAY_BL, PIN_A5) \ + CFG(PIN_SPEAKER_AMP, PIN_D2) \ + CFG(SPEAKER_VOLUME, 512) \ + CFG(DISPLAY_CFG0, 0x01000080) \ + CFG(DISPLAY_CFG1, 0x00000603) \ + CFG(DISPLAY_CFG2, 24) \ + CFG(DISPLAY_WIDTH, 160) \ + CFG(DISPLAY_HEIGHT, 128) + +#endif diff --git a/boards/arcade_feather_m4/board.mk b/boards/arcade_feather_m4/board.mk new file mode 100644 index 00000000..c17f5fba --- /dev/null +++ b/boards/arcade_feather_m4/board.mk @@ -0,0 +1,2 @@ +CHIP_FAMILY = samd51 +CHIP_VARIANT = SAMD51J19A diff --git a/boards/arcade_feather_m4/board_config.h b/boards/arcade_feather_m4/board_config.h new file mode 100644 index 00000000..3653a74c --- /dev/null +++ b/boards/arcade_feather_m4/board_config.h @@ -0,0 +1,97 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "Adafruit Industries" +#define PRODUCT_NAME "Arcade 51 Feather" +#define VOLUME_LABEL "ARCADE" +#define INDEX_URL "http://adafru.it/" +#define BOARD_ID "SAMD51J19A-Arcade51" + +#define USB_VID 0x239A +#define USB_PID 0x0022 + +#define LED_PIN PIN_PA23 + +#define BOARD_NEOPIXEL_PIN PIN_PB03 +#define BOARD_NEOPIXEL_COUNT 1 + +#define BOOT_USART_MODULE SERCOM0 +#define BOOT_USART_MASK APBAMASK +#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBAMASK_SERCOM0 +#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD0 +#define BOOT_USART_PAD3 PINMUX_PA07D_SERCOM0_PAD3 +#define BOOT_USART_PAD2 PINMUX_UNUSED +#define BOOT_USART_PAD1 PINMUX_UNUSED +#define BOOT_USART_PAD0 PINMUX_PA04D_SERCOM0_PAD0 +#define BOOT_GCLK_ID_CORE SERCOM0_GCLK_ID_CORE +#define BOOT_GCLK_ID_SLOW SERCOM0_GCLK_ID_SLOW + +#define PIN_A0 PIN_PA02 +#define PIN_A1 PIN_PA05 +#define PIN_A2 PIN_PB08 +#define PIN_A3 PIN_PB09 +#define PIN_A4 PIN_PA04 +#define PIN_A5 PIN_PA06 + +#define PIN_TX PIN_PB16 +#define PIN_RX PIN_PB17 + +#define PIN_D0 PIN_PB17 //RX +#define PIN_D1 PIN_PB16 //TX +#define PIN_D4 PIN_PA14 +#define PIN_D5 PIN_PA16 +#define PIN_D6 PIN_PA18 +#define PIN_D9 PIN_PA19 +#define PIN_D10 PIN_PA20 +#define PIN_D11 PIN_PA21 +#define PIN_D12 PIN_PA22 +#define PIN_D13 PIN_PA23 + +#define PIN_LED PIN_PA23 +#define PIN_SCK PIN_PA17 +#define PIN_MISO PIN_PB22 +#define PIN_MOSI PIN_PB23 +#define PIN_SDA PIN_PA12 +#define PIN_SCL PIN_PA13 + + +#if 0 +// game controller make +#define BUTTONS \ + CFG(PIN_BTN_LEFT, PIN_SDA) \ + CFG(PIN_BTN_UP, PIN_D6) \ + CFG(PIN_BTN_RIGHT, PIN_SCL) \ + CFG(PIN_BTN_DOWN, PIN_D9) \ + CFG(PIN_BTN_A, PIN_D10) \ + CFG(PIN_BTN_B, PIN_D11) \ + CFG(PIN_BTN_MENU, PIN_D12) +#else +// breadboarded Itsy +#define BUTTONS \ + CFG(PIN_BTN_LEFT, PIN_D11) \ + CFG(PIN_BTN_UP, PIN_D10) \ + CFG(PIN_BTN_RIGHT, PIN_D9) \ + CFG(PIN_BTN_DOWN, PIN_D12) \ + CFG(PIN_BTN_A, PIN_SCL) \ + CFG(PIN_BTN_B, PIN_D6) \ + CFG(PIN_BTN_MENU, PIN_SDA) +#endif + +#define CONFIG_DATA \ + BUTTONS \ + CFG(PIN_DISPLAY_CS, PIN_A2) \ + CFG(PIN_DISPLAY_SCK, PIN_SCK) \ + CFG(PIN_DISPLAY_MOSI, PIN_MOSI) \ + CFG(PIN_DISPLAY_DC, PIN_A3) \ + CFG(PIN_DISPLAY_RST, PIN_A4) \ + CFG(PIN_DISPLAY_MISO, PIN_MISO) \ + CFG(PIN_DISPLAY_BL, PIN_A5) \ + CFG(PIN_SPEAKER_AMP, PIN_D4) \ + CFG(SPEAKER_VOLUME, 512) \ + CFG(DISPLAY_CFG0, 0x00000090) \ + CFG(DISPLAY_CFG1, 0x000e14ff) \ + CFG(DISPLAY_CFG2, 24) \ + CFG(DISPLAY_WIDTH, 160) \ + CFG(DISPLAY_HEIGHT, 128) + +#endif From 209d7957920fa1b6cd96ce7c6c24af5f2e8281d2 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Sun, 6 Jan 2019 14:06:16 +0000 Subject: [PATCH 16/38] Tweak DeviceInterfaceGUIDs a bit --- src/cdc_enumerate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cdc_enumerate.c b/src/cdc_enumerate.c index c72aa840..b05795fc 100644 --- a/src/cdc_enumerate.c +++ b/src/cdc_enumerate.c @@ -354,7 +354,7 @@ static char msOS20Descriptor[] = { // '{', 0, '9', 0, '2', 0, 'C', 0, 'E', 0, '6', 0, '4', 0, '6', 0, '2', 0, '-', 0, '9', 0, 'C', 0, '7', 0, '7', 0, '-', 0, '4', 0, '6', 0, 'F', 0, 'E', 0, '-', 0, '9', 0, '3', 0, '3', 0, 'B', 0, - '-', 0, '3', 0, '1', 0, 'C', 0, 'B', 0, '9', 0, 'C', 0, '5', 0, 'A', 0, 'A', 0, '3', 0, 'B', 0, + '-', 0, '3', 0, '1', 0, 'C', 0, 'B', 0, '9', 0, 'C', 0, '5', 0, 'B', 0, 'B', 0, '3', 0, 'B', 0, '9', 0, '}', 0, 0, 0, 0, 0}; STATIC_ASSERT(sizeof(msOS20Descriptor) == WINUSB_SIZE); From 9b5d358a32ddf268a1f93e6d8e60c43723d354f0 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 7 Jan 2019 16:52:33 +0000 Subject: [PATCH 17/38] Use CF2 patcher for configuration data --- boards/arcade_51/board_config.h | 92 ------------ boards/arcade_51_alt/board.mk | 2 - boards/arcade_51_alt/board_config.h | 92 ------------ boards/{smallarcade => arcade_badge}/board.mk | 0 boards/arcade_badge/board_config.h | 110 ++++++++++++++ boards/arcade_feather_m4/board_config.h | 139 +++++++++--------- boards/arcade_itsybitsy_m4/altkeys.cf2 | 7 + boards/arcade_itsybitsy_m4/altscreen.cf2 | 2 + .../board.mk | 0 boards/arcade_itsybitsy_m4/board_config.h | 110 ++++++++++++++ boards/smallarcade/board_config.h | 121 --------------- inc/{config_data.h => configkeys.h} | 54 +++++-- inc/uf2.h | 1 + src/msc.c | 14 +- 14 files changed, 344 insertions(+), 400 deletions(-) delete mode 100644 boards/arcade_51/board_config.h delete mode 100644 boards/arcade_51_alt/board.mk delete mode 100644 boards/arcade_51_alt/board_config.h rename boards/{smallarcade => arcade_badge}/board.mk (100%) create mode 100644 boards/arcade_badge/board_config.h create mode 100644 boards/arcade_itsybitsy_m4/altkeys.cf2 create mode 100644 boards/arcade_itsybitsy_m4/altscreen.cf2 rename boards/{arcade_51 => arcade_itsybitsy_m4}/board.mk (100%) create mode 100644 boards/arcade_itsybitsy_m4/board_config.h delete mode 100644 boards/smallarcade/board_config.h rename inc/{config_data.h => configkeys.h} (70%) diff --git a/boards/arcade_51/board_config.h b/boards/arcade_51/board_config.h deleted file mode 100644 index 819b6fff..00000000 --- a/boards/arcade_51/board_config.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef BOARD_CONFIG_H -#define BOARD_CONFIG_H - -#define VENDOR_NAME "Adafruit Industries" -#define PRODUCT_NAME "Arcade 51" -#define VOLUME_LABEL "ARCADE" -#define INDEX_URL "http://adafru.it/" -#define BOARD_ID "SAMD51G19A-Arcade-51" - -#define USB_VID 0x239A -#define USB_PID 0x002B - -#define LED_PIN PIN_PA22 - -#define BOARD_RGBLED_CLOCK_PIN PIN_PB02 -#define BOARD_RGBLED_DATA_PIN PIN_PB03 - -#define BOOT_USART_MODULE SERCOM3 -#define BOOT_USART_MASK APBAMASK -#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 -#define BOOT_USART_PAD_SETTINGS UART_RX_PAD1_TX_PAD0 -#define BOOT_USART_PAD3 PINMUX_UNUSED -#define BOOT_USART_PAD2 PINMUX_UNUSED -#define BOOT_USART_PAD1 PINMUX_PA22C_SERCOM3_PAD0 -#define BOOT_USART_PAD0 PINMUX_PA23C_SERCOM3_PAD1 -#define BOOT_GCLK_ID_CORE SERCOM3_GCLK_ID_CORE -#define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW - -#define PIN_A0 PIN_PA02 -#define PIN_A1 PIN_PA05 -#define PIN_A2 PIN_PB08 -#define PIN_A3 PIN_PB09 -#define PIN_A4 PIN_PA04 -#define PIN_A5 PIN_PA06 -#define PIN_RX PIN_PA16 -#define PIN_TX PIN_PA17 -#define PIN_D2 PIN_PA07 -#define PIN_D3 PIN_PB22 -#define PIN_D4 PIN_PA14 -#define PIN_D5 PIN_PA15 -#define PIN_D7 PIN_PA18 -#define PIN_D9 PIN_PA19 -#define PIN_D10 PIN_PA20 -#define PIN_D11 PIN_PA21 -#define PIN_D12 PIN_PA23 -#define PIN_LED PIN_PA22 -#define PIN_SCK PIN_PA01 -#define PIN_MISO PIN_PB23 -#define PIN_MOSI PIN_PA00 -#define PIN_SDA PIN_PA12 -#define PIN_SCL PIN_PA13 - -#if 0 -// game controller make -#define BUTTONS \ - CFG(PIN_BTN_LEFT, PIN_SDA) \ - CFG(PIN_BTN_UP, PIN_D7) \ - CFG(PIN_BTN_RIGHT, PIN_SCL) \ - CFG(PIN_BTN_DOWN, PIN_D9) \ - CFG(PIN_BTN_A, PIN_D10) \ - CFG(PIN_BTN_B, PIN_D11) \ - CFG(PIN_BTN_MENU, PIN_D12) -#else -// breadboarded Itsy -#define BUTTONS \ - CFG(PIN_BTN_LEFT, PIN_D11) \ - CFG(PIN_BTN_UP, PIN_D10) \ - CFG(PIN_BTN_RIGHT, PIN_D9) \ - CFG(PIN_BTN_DOWN, PIN_D12) \ - CFG(PIN_BTN_A, PIN_SCL) \ - CFG(PIN_BTN_B, PIN_D7) \ - CFG(PIN_BTN_MENU, PIN_SDA) -#endif - -#define CONFIG_DATA \ - BUTTONS \ - CFG(PIN_DISPLAY_CS, PIN_A2) \ - CFG(PIN_DISPLAY_SCK, PIN_SCK) \ - CFG(PIN_DISPLAY_MOSI, PIN_MOSI) \ - CFG(PIN_DISPLAY_DC, PIN_A3) \ - CFG(PIN_DISPLAY_RST, PIN_A4) \ - CFG(PIN_DISPLAY_MISO, PIN_MISO) \ - CFG(PIN_DISPLAY_BL, PIN_A5) \ - CFG(PIN_SPEAKER_AMP, PIN_D2) \ - CFG(SPEAKER_VOLUME, 512) \ - CFG(DISPLAY_CFG0, 0x00000090) \ - CFG(DISPLAY_CFG1, 0x000e14ff) \ - CFG(DISPLAY_CFG2, 24) \ - CFG(DISPLAY_WIDTH, 160) \ - CFG(DISPLAY_HEIGHT, 128) - -#endif diff --git a/boards/arcade_51_alt/board.mk b/boards/arcade_51_alt/board.mk deleted file mode 100644 index 0d8d74a9..00000000 --- a/boards/arcade_51_alt/board.mk +++ /dev/null @@ -1,2 +0,0 @@ -CHIP_FAMILY = samd51 -CHIP_VARIANT = SAMD51G19A diff --git a/boards/arcade_51_alt/board_config.h b/boards/arcade_51_alt/board_config.h deleted file mode 100644 index 9a98e803..00000000 --- a/boards/arcade_51_alt/board_config.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef BOARD_CONFIG_H -#define BOARD_CONFIG_H - -#define VENDOR_NAME "Adafruit Industries" -#define PRODUCT_NAME "Arcade 51" -#define VOLUME_LABEL "ARCADE" -#define INDEX_URL "http://adafru.it/" -#define BOARD_ID "SAMD51G19A-Arcade-51" - -#define USB_VID 0x239A -#define USB_PID 0x002B - -#define LED_PIN PIN_PA22 - -#define BOARD_RGBLED_CLOCK_PIN PIN_PB02 -#define BOARD_RGBLED_DATA_PIN PIN_PB03 - -#define BOOT_USART_MODULE SERCOM3 -#define BOOT_USART_MASK APBAMASK -#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 -#define BOOT_USART_PAD_SETTINGS UART_RX_PAD1_TX_PAD0 -#define BOOT_USART_PAD3 PINMUX_UNUSED -#define BOOT_USART_PAD2 PINMUX_UNUSED -#define BOOT_USART_PAD1 PINMUX_PA22C_SERCOM3_PAD0 -#define BOOT_USART_PAD0 PINMUX_PA23C_SERCOM3_PAD1 -#define BOOT_GCLK_ID_CORE SERCOM3_GCLK_ID_CORE -#define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW - -#define PIN_A0 PIN_PA02 -#define PIN_A1 PIN_PA05 -#define PIN_A2 PIN_PB08 -#define PIN_A3 PIN_PB09 -#define PIN_A4 PIN_PA04 -#define PIN_A5 PIN_PA06 -#define PIN_RX PIN_PA16 -#define PIN_TX PIN_PA17 -#define PIN_D2 PIN_PA07 -#define PIN_D3 PIN_PB22 -#define PIN_D4 PIN_PA14 -#define PIN_D5 PIN_PA15 -#define PIN_D7 PIN_PA18 -#define PIN_D9 PIN_PA19 -#define PIN_D10 PIN_PA20 -#define PIN_D11 PIN_PA21 -#define PIN_D12 PIN_PA23 -#define PIN_LED PIN_PA22 -#define PIN_SCK PIN_PA01 -#define PIN_MISO PIN_PB23 -#define PIN_MOSI PIN_PA00 -#define PIN_SDA PIN_PA12 -#define PIN_SCL PIN_PA13 - -#if 0 -// game controller make -#define BUTTONS \ - CFG(PIN_BTN_LEFT, PIN_SDA) \ - CFG(PIN_BTN_UP, PIN_D7) \ - CFG(PIN_BTN_RIGHT, PIN_SCL) \ - CFG(PIN_BTN_DOWN, PIN_D9) \ - CFG(PIN_BTN_A, PIN_D10) \ - CFG(PIN_BTN_B, PIN_D11) \ - CFG(PIN_BTN_MENU, PIN_D12) -#else -// breadboarded Itsy -#define BUTTONS \ - CFG(PIN_BTN_LEFT, PIN_D11) \ - CFG(PIN_BTN_UP, PIN_D10) \ - CFG(PIN_BTN_RIGHT, PIN_D9) \ - CFG(PIN_BTN_DOWN, PIN_D12) \ - CFG(PIN_BTN_A, PIN_SCL) \ - CFG(PIN_BTN_B, PIN_D7) \ - CFG(PIN_BTN_MENU, PIN_SDA) -#endif - -#define CONFIG_DATA \ - BUTTONS \ - CFG(PIN_DISPLAY_CS, PIN_A2) \ - CFG(PIN_DISPLAY_SCK, PIN_SCK) \ - CFG(PIN_DISPLAY_MOSI, PIN_MOSI) \ - CFG(PIN_DISPLAY_DC, PIN_A3) \ - CFG(PIN_DISPLAY_RST, PIN_A4) \ - CFG(PIN_DISPLAY_MISO, PIN_MISO) \ - CFG(PIN_DISPLAY_BL, PIN_A5) \ - CFG(PIN_SPEAKER_AMP, PIN_D2) \ - CFG(SPEAKER_VOLUME, 512) \ - CFG(DISPLAY_CFG0, 0x01000080) \ - CFG(DISPLAY_CFG1, 0x00000603) \ - CFG(DISPLAY_CFG2, 24) \ - CFG(DISPLAY_WIDTH, 160) \ - CFG(DISPLAY_HEIGHT, 128) - -#endif diff --git a/boards/smallarcade/board.mk b/boards/arcade_badge/board.mk similarity index 100% rename from boards/smallarcade/board.mk rename to boards/arcade_badge/board.mk diff --git a/boards/arcade_badge/board_config.h b/boards/arcade_badge/board_config.h new file mode 100644 index 00000000..434befd4 --- /dev/null +++ b/boards/arcade_badge/board_config.h @@ -0,0 +1,110 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "Adafruit Industries" +#define PRODUCT_NAME "Arcade D51" +#define VOLUME_LABEL "ARCD-D51" +#define INDEX_URL "http://adafru.it/" +#define BOARD_ID "SAMD51J19A-Arcade-D51" + +#define USB_VID 0x239A +#define USB_PID 0x002B + +#define LED_PIN PIN_PA23 + +#define BOARD_NEOPIXEL_PIN PIN_PA15 +#define BOARD_NEOPIXEL_COUNT 5 + +#define BOOT_USART_MODULE SERCOM3 +#define BOOT_USART_MASK APBAMASK +#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 +#define BOOT_USART_PAD_SETTINGS UART_RX_PAD1_TX_PAD0 +#define BOOT_USART_PAD3 PINMUX_UNUSED +#define BOOT_USART_PAD2 PINMUX_UNUSED +#define BOOT_USART_PAD1 PINMUX_PA22C_SERCOM3_PAD0 +#define BOOT_USART_PAD0 PINMUX_PA23C_SERCOM3_PAD1 +#define BOOT_GCLK_ID_CORE SERCOM3_GCLK_ID_CORE +#define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW + + +#define HAS_CONFIG_DATA 1 + +// This configuration data should be edited at https://microsoft.github.io/uf2/patcher/ +// Just drop this file there. +// Alternatively, it can be also binary edited there after the bootloader is compiled. + +#ifdef DEFINE_CONFIG_DATA +const uint32_t config_data[] = { + /* CF2 START */ + 513675505, 539130489, // magic + 60, 100, // used entries, total entries + 1, 0x2e, // PIN_ACCELEROMETER_INT = PB14 + 2, 0xd, // PIN_ACCELEROMETER_SCL = PIN_SCL + 3, 0xc, // PIN_ACCELEROMETER_SDA = PIN_SDA + 4, 0x6b, // PIN_BTN_A = PD11 + 5, 0x6a, // PIN_BTN_B = PD10 + 13, 0x17, // PIN_LED = PIN_D13 + 18, 0x36, // PIN_MISO = PB22 + 19, 0x37, // PIN_MOSI = PB23 + 20, 0xf, // PIN_NEOPIXEL = PA15 + 21, 0x11, // PIN_RX = PA17 + 23, 0x11, // PIN_SCK = PA17 + 24, 0xd, // PIN_SCL = PA13 + 25, 0xc, // PIN_SDA = PA12 + 28, 0x10, // PIN_TX = PA16 + 32, 0x2d, // PIN_DISPLAY_SCK = PB13 + 34, 0x2c, // PIN_DISPLAY_MOSI = PB12 + 35, 0x27, // PIN_DISPLAY_CS = PB07 + 36, 0x25, // PIN_DISPLAY_DC = PB05 + 37, 0xa0, // DISPLAY_WIDTH = 160 + 38, 0x80, // DISPLAY_HEIGHT = 128 + 39, 0x80, // DISPLAY_CFG0 = 0x80 + 40, 0x12c2d, // DISPLAY_CFG1 = 0x12c2d + 41, 0x18, // DISPLAY_CFG2 = 0x18 + 43, 0x1, // PIN_DISPLAY_RST = PA01 + 44, 0x0, // PIN_DISPLAY_BL = PA00 + 47, 0x64, // PIN_BTN_LEFT = PD04 + 48, 0x67, // PIN_BTN_RIGHT = PD07 + 49, 0x65, // PIN_BTN_UP = PD05 + 50, 0x66, // PIN_BTN_DOWN = PD06 + 51, 0x68, // PIN_BTN_MENU = PD08 + 59, 0x200, // SPEAKER_VOLUME = 512 + 60, 0x10, // PIN_JACK_TX = PIN_D5 + 65, 0x2, // PIN_JACK_SND = PIN_A0 + 66, 0x20, // PIN_BTNMX_LATCH = PB00 + 67, 0x3f, // PIN_BTNMX_CLOCK = PB31 + 68, 0x3e, // PIN_BTNMX_DATA = PB30 + 69, 0x69, // PIN_BTN_SOFT_RESET = PD09 + 70, 0x32, // ACCELEROMETER_TYPE = LIS3DH + 100, 0x2, // PIN_A0 = PA02 + 101, 0x5, // PIN_A1 = PA05 + 102, 0x28, // PIN_A2 = PB08 + 103, 0x29, // PIN_A3 = PB09 + 104, 0x4, // PIN_A4 = PA04 + 105, 0x6, // PIN_A5 = PA06 + 152, 0x23, // PIN_D2 = PB03 + 153, 0x22, // PIN_D3 = PB02 + 154, 0xe, // PIN_D4 = PA14 + 155, 0x10, // PIN_D5 = PA16 + 156, 0x12, // PIN_D6 = PA18 + 159, 0x13, // PIN_D9 = PA19 + 160, 0x14, // PIN_D10 = PA20 + 161, 0x15, // PIN_D11 = PA21 + 162, 0x16, // PIN_D12 = PA22 + 163, 0x17, // PIN_D13 = PA23 + 200, 0x5, // NUM_NEOPIXELS = 5 + 204, 0x80000, // FLASH_BYTES = 0x80000 + 205, 0x30000, // RAM_BYTES = 0x30000 + 208, 0x18591ab9, // BOOTLOADER_BOARD_ID = 0x18591ab9 + 209, 0x55114460, // UF2_FAMILY = ATSAMD51 + 210, 0x20, // PINS_PORT_SIZE = PA_32 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* CF2 END */ +}; +#endif + +#endif + + diff --git a/boards/arcade_feather_m4/board_config.h b/boards/arcade_feather_m4/board_config.h index 3653a74c..15f15f05 100644 --- a/boards/arcade_feather_m4/board_config.h +++ b/boards/arcade_feather_m4/board_config.h @@ -2,10 +2,11 @@ #define BOARD_CONFIG_H #define VENDOR_NAME "Adafruit Industries" -#define PRODUCT_NAME "Arcade 51 Feather" -#define VOLUME_LABEL "ARCADE" -#define INDEX_URL "http://adafru.it/" -#define BOARD_ID "SAMD51J19A-Arcade51" +#define PRODUCT_NAME "Feather Arcade D51" +#define VOLUME_LABEL "ARCD-D51" +#define INDEX_URL "https://arcade.makecode.com/" +#define BOARD_ID "SAMD51J19A-Feather-Arcade-D51" + #define USB_VID 0x239A #define USB_PID 0x0022 @@ -26,72 +27,76 @@ #define BOOT_GCLK_ID_CORE SERCOM0_GCLK_ID_CORE #define BOOT_GCLK_ID_SLOW SERCOM0_GCLK_ID_SLOW -#define PIN_A0 PIN_PA02 -#define PIN_A1 PIN_PA05 -#define PIN_A2 PIN_PB08 -#define PIN_A3 PIN_PB09 -#define PIN_A4 PIN_PA04 -#define PIN_A5 PIN_PA06 - -#define PIN_TX PIN_PB16 -#define PIN_RX PIN_PB17 - -#define PIN_D0 PIN_PB17 //RX -#define PIN_D1 PIN_PB16 //TX -#define PIN_D4 PIN_PA14 -#define PIN_D5 PIN_PA16 -#define PIN_D6 PIN_PA18 -#define PIN_D9 PIN_PA19 -#define PIN_D10 PIN_PA20 -#define PIN_D11 PIN_PA21 -#define PIN_D12 PIN_PA22 -#define PIN_D13 PIN_PA23 +#define HAS_CONFIG_DATA 1 -#define PIN_LED PIN_PA23 -#define PIN_SCK PIN_PA17 -#define PIN_MISO PIN_PB22 -#define PIN_MOSI PIN_PB23 -#define PIN_SDA PIN_PA12 -#define PIN_SCL PIN_PA13 +// This configuration data should be edited at https://microsoft.github.io/uf2/patcher/ +// Just drop this file there. +// Alternatively, it can be also binary edited there after the bootloader is compiled. +#ifdef DEFINE_CONFIG_DATA +const uint32_t config_data[] = { + /* CF2 START */ + 513675505, 539130489, // magic + 52, 100, // used entries, total entries + 4, 0xd, // PIN_BTN_A = PIN_SCL + 5, 0x12, // PIN_BTN_B = PIN_D6 + 13, 0x17, // PIN_LED = PIN_D13 + 18, 0x36, // PIN_MISO = PB22 + 19, 0x37, // PIN_MOSI = PB23 + 20, 0x23, // PIN_NEOPIXEL = PB03 + 21, 0x31, // PIN_RX = PB17 + 23, 0x11, // PIN_SCK = PA17 + 24, 0xd, // PIN_SCL = PA13 + 25, 0xc, // PIN_SDA = PA12 + 26, 0xe, // PIN_SPEAKER_AMP = PIN_D4 + 28, 0x30, // PIN_TX = PB16 + 32, 0x11, // PIN_DISPLAY_SCK = PIN_SCK + 33, 0x36, // PIN_DISPLAY_MISO = PIN_MISO + 34, 0x37, // PIN_DISPLAY_MOSI = PIN_MOSI + 35, 0x28, // PIN_DISPLAY_CS = PIN_A2 + 36, 0x29, // PIN_DISPLAY_DC = PIN_A3 + 37, 0xa0, // DISPLAY_WIDTH = 160 + 38, 0x80, // DISPLAY_HEIGHT = 128 + 39, 0x90, // DISPLAY_CFG0 = 0x90 + 40, 0xe14ff, // DISPLAY_CFG1 = 0xe14ff + 41, 0x18, // DISPLAY_CFG2 = 0x18 + 43, 0x4, // PIN_DISPLAY_RST = PIN_A4 + 44, 0x6, // PIN_DISPLAY_BL = PIN_A5 + 47, 0x15, // PIN_BTN_LEFT = PIN_D11 + 48, 0x13, // PIN_BTN_RIGHT = PIN_D9 + 49, 0x14, // PIN_BTN_UP = PIN_D10 + 50, 0x16, // PIN_BTN_DOWN = PIN_D12 + 51, 0xc, // PIN_BTN_MENU = PIN_SDA + 59, 0x200, // SPEAKER_VOLUME = 512 + 100, 0x2, // PIN_A0 = PA02 + 101, 0x5, // PIN_A1 = PA05 + 102, 0x28, // PIN_A2 = PB08 + 103, 0x29, // PIN_A3 = PB09 + 104, 0x4, // PIN_A4 = PA04 + 105, 0x6, // PIN_A5 = PA06 + 150, 0x31, // PIN_D0 = PB17 + 151, 0x30, // PIN_D1 = PB16 + 154, 0xe, // PIN_D4 = PA14 + 155, 0x10, // PIN_D5 = PA16 + 156, 0x12, // PIN_D6 = PA18 + 159, 0x13, // PIN_D9 = PA19 + 160, 0x14, // PIN_D10 = PA20 + 161, 0x15, // PIN_D11 = PA21 + 162, 0x16, // PIN_D12 = PA22 + 163, 0x17, // PIN_D13 = PA23 + 200, 0x1, // NUM_NEOPIXELS = 1 + 204, 0x80000, // FLASH_BYTES = 0x80000 + 205, 0x30000, // RAM_BYTES = 0x30000 + 208, 0x2b9e3d05, // BOOTLOADER_BOARD_ID = 0x2b9e3d05 + 209, 0x55114460, // UF2_FAMILY = ATSAMD51 + 210, 0x20, // PINS_PORT_SIZE = PA_32 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* CF2 END */ +}; +#endif -#if 0 -// game controller make -#define BUTTONS \ - CFG(PIN_BTN_LEFT, PIN_SDA) \ - CFG(PIN_BTN_UP, PIN_D6) \ - CFG(PIN_BTN_RIGHT, PIN_SCL) \ - CFG(PIN_BTN_DOWN, PIN_D9) \ - CFG(PIN_BTN_A, PIN_D10) \ - CFG(PIN_BTN_B, PIN_D11) \ - CFG(PIN_BTN_MENU, PIN_D12) -#else -// breadboarded Itsy -#define BUTTONS \ - CFG(PIN_BTN_LEFT, PIN_D11) \ - CFG(PIN_BTN_UP, PIN_D10) \ - CFG(PIN_BTN_RIGHT, PIN_D9) \ - CFG(PIN_BTN_DOWN, PIN_D12) \ - CFG(PIN_BTN_A, PIN_SCL) \ - CFG(PIN_BTN_B, PIN_D6) \ - CFG(PIN_BTN_MENU, PIN_SDA) #endif -#define CONFIG_DATA \ - BUTTONS \ - CFG(PIN_DISPLAY_CS, PIN_A2) \ - CFG(PIN_DISPLAY_SCK, PIN_SCK) \ - CFG(PIN_DISPLAY_MOSI, PIN_MOSI) \ - CFG(PIN_DISPLAY_DC, PIN_A3) \ - CFG(PIN_DISPLAY_RST, PIN_A4) \ - CFG(PIN_DISPLAY_MISO, PIN_MISO) \ - CFG(PIN_DISPLAY_BL, PIN_A5) \ - CFG(PIN_SPEAKER_AMP, PIN_D4) \ - CFG(SPEAKER_VOLUME, 512) \ - CFG(DISPLAY_CFG0, 0x00000090) \ - CFG(DISPLAY_CFG1, 0x000e14ff) \ - CFG(DISPLAY_CFG2, 24) \ - CFG(DISPLAY_WIDTH, 160) \ - CFG(DISPLAY_HEIGHT, 128) -#endif diff --git a/boards/arcade_itsybitsy_m4/altkeys.cf2 b/boards/arcade_itsybitsy_m4/altkeys.cf2 new file mode 100644 index 00000000..36ea9744 --- /dev/null +++ b/boards/arcade_itsybitsy_m4/altkeys.cf2 @@ -0,0 +1,7 @@ +PIN_BTN_A = PIN_D10 +PIN_BTN_B = PIN_D11 +PIN_BTN_LEFT = PIN_SDA +PIN_BTN_UP = PIN_D7 +PIN_BTN_RIGHT = PIN_SCL +PIN_BTN_DOWN = PIN_D9 +PIN_BTN_MENU = PIN_D12 diff --git a/boards/arcade_itsybitsy_m4/altscreen.cf2 b/boards/arcade_itsybitsy_m4/altscreen.cf2 new file mode 100644 index 00000000..56396489 --- /dev/null +++ b/boards/arcade_itsybitsy_m4/altscreen.cf2 @@ -0,0 +1,2 @@ +DISPLAY_CFG0 = 0x01000080 +DISPLAY_CFG1 = 0x00000603 diff --git a/boards/arcade_51/board.mk b/boards/arcade_itsybitsy_m4/board.mk similarity index 100% rename from boards/arcade_51/board.mk rename to boards/arcade_itsybitsy_m4/board.mk diff --git a/boards/arcade_itsybitsy_m4/board_config.h b/boards/arcade_itsybitsy_m4/board_config.h new file mode 100644 index 00000000..d29d6824 --- /dev/null +++ b/boards/arcade_itsybitsy_m4/board_config.h @@ -0,0 +1,110 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "Adafruit Industries" +#define PRODUCT_NAME "Itsy Arcade D51" +#define VOLUME_LABEL "ARCD-D51" +#define INDEX_URL "https://arcade.makecode.com/" +#define BOARD_ID "SAMD51G19A-Itsy-Arcade-D51" + +#define USB_VID 0x239A +#define USB_PID 0x002B + +#define LED_PIN PIN_PA22 + +#define BOARD_RGBLED_CLOCK_PIN PIN_PB02 +#define BOARD_RGBLED_DATA_PIN PIN_PB03 + +#define BOOT_USART_MODULE SERCOM3 +#define BOOT_USART_MASK APBAMASK +#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 +#define BOOT_USART_PAD_SETTINGS UART_RX_PAD1_TX_PAD0 +#define BOOT_USART_PAD3 PINMUX_UNUSED +#define BOOT_USART_PAD2 PINMUX_UNUSED +#define BOOT_USART_PAD1 PINMUX_PA22C_SERCOM3_PAD0 +#define BOOT_USART_PAD0 PINMUX_PA23C_SERCOM3_PAD1 +#define BOOT_GCLK_ID_CORE SERCOM3_GCLK_ID_CORE +#define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW + +#define HAS_CONFIG_DATA 1 + +// This configuration data should be edited at https://microsoft.github.io/uf2/patcher/ +// Just drop this file there. +// Alternatively, it can be also binary edited there after the bootloader is compiled. + +#ifdef DEFINE_CONFIG_DATA +const uint32_t config_data[] = { + /* CF2 START */ + 513675505, 539130489, // magic + 59, 100, // used entries, total entries + 4, 0xd, // PIN_BTN_A = PIN_SCL + 5, 0x12, // PIN_BTN_B = PIN_D7 + 7, 0x22, // PIN_DOTSTAR_CLOCK = PB02 + 8, 0x23, // PIN_DOTSTAR_DATA = PB03 + 9, 0x2b, // PIN_FLASH_CS = PB11 + 10, 0x9, // PIN_FLASH_MISO = PA09 + 11, 0x8, // PIN_FLASH_MOSI = PA08 + 12, 0x2a, // PIN_FLASH_SCK = PB10 + 13, 0x16, // PIN_LED = PIN_D13 + 18, 0x37, // PIN_MISO = PB23 + 19, 0x0, // PIN_MOSI = PA00 + 21, 0x10, // PIN_RX = PA16 + 23, 0x1, // PIN_SCK = PA01 + 24, 0xd, // PIN_SCL = PA13 + 25, 0xc, // PIN_SDA = PA12 + 26, 0x7, // PIN_SPEAKER_AMP = PIN_D2 + 28, 0x11, // PIN_TX = PA17 + 32, 0x1, // PIN_DISPLAY_SCK = PIN_SCK + 33, 0x37, // PIN_DISPLAY_MISO = PIN_MISO + 34, 0x0, // PIN_DISPLAY_MOSI = PIN_MOSI + 35, 0x28, // PIN_DISPLAY_CS = PIN_A2 + 36, 0x29, // PIN_DISPLAY_DC = PIN_A3 + 37, 0xa0, // DISPLAY_WIDTH = 160 + 38, 0x80, // DISPLAY_HEIGHT = 128 + 39, 0x90, // DISPLAY_CFG0 = 0x90 + 40, 0xe14ff, // DISPLAY_CFG1 = 0xe14ff + 41, 0x18, // DISPLAY_CFG2 = 0x18 + 43, 0x4, // PIN_DISPLAY_RST = PIN_A4 + 44, 0x6, // PIN_DISPLAY_BL = PIN_A5 + 47, 0x15, // PIN_BTN_LEFT = PIN_D11 + 48, 0x13, // PIN_BTN_RIGHT = PIN_D9 + 49, 0x14, // PIN_BTN_UP = PIN_D10 + 50, 0x17, // PIN_BTN_DOWN = PIN_D12 + 51, 0xc, // PIN_BTN_MENU = PIN_SDA + 59, 0x200, // SPEAKER_VOLUME = 512 + 100, 0x2, // PIN_A0 = PA02 + 101, 0x5, // PIN_A1 = PA05 + 102, 0x28, // PIN_A2 = PB08 + 103, 0x29, // PIN_A3 = PB09 + 104, 0x4, // PIN_A4 = PA04 + 105, 0x6, // PIN_A5 = PA06 + 150, 0x10, // PIN_D0 = PA16 + 151, 0x11, // PIN_D1 = PA17 + 152, 0x7, // PIN_D2 = PA07 + 153, 0x36, // PIN_D3 = PB22 + 154, 0xe, // PIN_D4 = PA14 + 155, 0xf, // PIN_D5 = PA15 + 157, 0x12, // PIN_D7 = PA18 + 159, 0x13, // PIN_D9 = PA19 + 160, 0x14, // PIN_D10 = PA20 + 161, 0x15, // PIN_D11 = PA21 + 162, 0x17, // PIN_D12 = PA23 + 163, 0x16, // PIN_D13 = PA22 + 201, 0x1, // NUM_DOTSTARS = 1 + 204, 0x80000, // FLASH_BYTES = 0x80000 + 205, 0x30000, // RAM_BYTES = 0x30000 + 208, 0x7a236324, // BOOTLOADER_BOARD_ID = 0x7a236324 + 209, 0x55114460, // UF2_FAMILY = ATSAMD51 + 210, 0x20, // PINS_PORT_SIZE = PA_32 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* CF2 END */ +}; +#endif + +#endif + + + + diff --git a/boards/smallarcade/board_config.h b/boards/smallarcade/board_config.h deleted file mode 100644 index 41a8186e..00000000 --- a/boards/smallarcade/board_config.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef BOARD_CONFIG_H -#define BOARD_CONFIG_H - -#define VENDOR_NAME "Adafruit Industries" -#define PRODUCT_NAME "ItsyBitsy-M4" -#define VOLUME_LABEL "ARCADE" -#define INDEX_URL "http://adafru.it/" -#define BOARD_ID "SAMD51J19A-Arcade-Small-v0" - -#define USB_VID 0x239A -#define USB_PID 0x002B - -#define LED_PIN PIN_PA23 - -#define BOARD_NEOPIXEL_PIN PIN_PA15 -#define BOARD_NEOPIXEL_COUNT 5 - -#define BOOT_USART_MODULE SERCOM3 -#define BOOT_USART_MASK APBAMASK -#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 -#define BOOT_USART_PAD_SETTINGS UART_RX_PAD1_TX_PAD0 -#define BOOT_USART_PAD3 PINMUX_UNUSED -#define BOOT_USART_PAD2 PINMUX_UNUSED -#define BOOT_USART_PAD1 PINMUX_PA22C_SERCOM3_PAD0 -#define BOOT_USART_PAD0 PINMUX_PA23C_SERCOM3_PAD1 -#define BOOT_GCLK_ID_CORE SERCOM3_GCLK_ID_CORE -#define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW - -#define PIN_A0 PIN_PA02 -#define PIN_A1 PIN_PA05 -#define PIN_A2 PIN_PB08 -#define PIN_A3 PIN_PB09 -#define PIN_A4 PIN_PA04 -#define PIN_A5 PIN_PA06 - -#define PIN_D2 PIN_PB03 -#define PIN_D3 PIN_PB02 -#define PIN_D4 PIN_PA14 -#define PIN_D5 PIN_PA16 -#define PIN_D6 PIN_PA18 -#define PIN_D9 PIN_PA19 -#define PIN_D10 PIN_PA20 -#define PIN_D11 PIN_PA21 -#define PIN_D12 PIN_PA22 -#define PIN_D13 PIN_PA23 -#define PIN_LED PIN_D13 - -#define PIN_RX PIN_PA17 -#define PIN_TX PIN_PA16 - -#define PIN_SCK PIN_PA17 -#define PIN_MISO PIN_PB22 -#define PIN_MOSI PIN_PB23 -#define PIN_SDA PIN_PA12 -#define PIN_SCL PIN_PA13 - -#define PIN_DISPLAY_BL PIN_PA00 -#define PIN_DISPLAY_CS PIN_PB07 -#define PIN_DISPLAY_SCK PIN_PB13 -#define PIN_DISPLAY_MOSI PIN_PB12 -#define PIN_DISPLAY_DC PIN_PB05 -#define PIN_DISPLAY_RST PIN_PA01 - -#define CONFIG_DATA \ - CFG(PIN_BTN_LEFT, 100) \ - CFG(PIN_BTN_UP, 101) \ - CFG(PIN_BTN_RIGHT, 103) \ - CFG(PIN_BTN_DOWN, 102) \ - CFG(PIN_BTN_A, 107) \ - CFG(PIN_BTN_B, 106) \ - CFG(PIN_BTN_MENU, 104) \ - CFG(PIN_BTN_SOFT_RESET, 105) \ - CFG(PIN_DISPLAY_CS, PIN_DISPLAY_CS) \ - CFG(PIN_DISPLAY_SCK, PIN_DISPLAY_SCK) \ - CFG(PIN_DISPLAY_MOSI, PIN_DISPLAY_MOSI) \ - CFG(PIN_DISPLAY_DC, PIN_DISPLAY_DC) \ - CFG(PIN_DISPLAY_RST, PIN_DISPLAY_RST) \ - CFG(PIN_DISPLAY_MISO, -1) \ - CFG(PIN_DISPLAY_BL, PIN_DISPLAY_BL) \ - CFG(PIN_SPEAKER_AMP, -1) \ - CFG(PIN_JACK_SND, PIN_A0) \ - CFG(PIN_JACK_TX, PIN_TX) \ - CFG(PIN_BTNMX_LATCH, PIN_PB00) \ - CFG(PIN_BTNMX_CLOCK, PIN_PB31) \ - CFG(PIN_BTNMX_DATA, PIN_PB30) \ - CFG(SPEAKER_VOLUME, 512) \ - CFG(DISPLAY_CFG0, 0x00000080) \ - CFG(DISPLAY_CFG1, 0x00012C2D) \ - CFG(DISPLAY_CFG2, 24) \ - CFG(DISPLAY_WIDTH, 160) \ - CFG(DISPLAY_HEIGHT, 128) \ - CFG(PIN_A0, PIN_A0) \ - CFG(PIN_A1, PIN_A1) \ - CFG(PIN_A2, PIN_A2) \ - CFG(PIN_A3, PIN_A3) \ - CFG(PIN_A4, PIN_A4) \ - CFG(PIN_A5, PIN_A5) \ - CFG(PIN_D2, PIN_D2) \ - CFG(PIN_D3, PIN_D3) \ - CFG(PIN_D4, PIN_D4) \ - CFG(PIN_D5, PIN_D5) \ - CFG(PIN_D6, PIN_D6) \ - CFG(PIN_D9, PIN_D9) \ - CFG(PIN_D10, PIN_D10) \ - CFG(PIN_D11, PIN_D11) \ - CFG(PIN_D12, PIN_D12) \ - CFG(PIN_D13, PIN_D13) \ - CFG(PIN_LED, PIN_LED) \ - CFG(PIN_SCK, PIN_SCK) \ - CFG(PIN_MISO, PIN_MISO) \ - CFG(PIN_MOSI, PIN_MOSI) \ - CFG(PIN_SDA, PIN_SDA) \ - CFG(PIN_SCL, PIN_SCL) \ - CFG(PIN_NEOPIXEL, BOARD_NEOPIXEL_PIN) \ - CFG(NUM_NEOPIXELS, BOARD_NEOPIXEL_COUNT) \ - CFG(PIN_ACCELEROMETER_INT, PIN_PB14) \ - CFG(PIN_ACCELEROMETER_SCL, PIN_SCL) \ - CFG(PIN_ACCELEROMETER_SDA, PIN_SDA) \ - CFG(ACCELEROMETER_TYPE, ACCELEROMETER_TYPE_LIS3DH) - -#endif diff --git a/inc/config_data.h b/inc/configkeys.h similarity index 70% rename from inc/config_data.h rename to inc/configkeys.h index 3d5d9c81..f975005f 100644 --- a/inc/config_data.h +++ b/inc/configkeys.h @@ -1,5 +1,8 @@ -#ifndef __CONFIG_DATA_H -#define __CONFIG_DATA_H +#ifndef __CONFIGKEYS_H +#define __CONFIGKEYS_H 1 + +#define CFG_MAGIC0 0x1e9e10f1 +#define CFG_MAGIC1 0x20227a79 #define CFG_PIN_ACCELEROMETER_INT 1 #define CFG_PIN_ACCELEROMETER_SCL 2 @@ -60,26 +63,19 @@ #define CFG_PIN_LED3 57 #define CFG_PIN_LED4 58 #define CFG_SPEAKER_VOLUME 59 - #define CFG_PIN_JACK_TX 60 #define CFG_PIN_JACK_SENSE 61 #define CFG_PIN_JACK_HPEN 62 #define CFG_PIN_JACK_BZEN 63 #define CFG_PIN_JACK_PWREN 64 #define CFG_PIN_JACK_SND 65 - +#define CFG_PIN_JACK_BUSLED 66 +#define CFG_PIN_JACK_COMMLED 67 #define CFG_PIN_BTNMX_LATCH 66 #define CFG_PIN_BTNMX_CLOCK 67 #define CFG_PIN_BTNMX_DATA 68 #define CFG_PIN_BTN_SOFT_RESET 69 #define CFG_ACCELEROMETER_TYPE 70 - -#define ACCELEROMETER_TYPE_LIS3DH 0x32 -#define ACCELEROMETER_TYPE_MMA8453 0x38 -#define ACCELEROMETER_TYPE_FXOS8700 0x3C -#define ACCELEROMETER_TYPE_MMA8653 0x3A -#define ACCELEROMETER_TYPE_MSA300 0x4C - #define CFG_PIN_A0 100 #define CFG_PIN_A1 101 #define CFG_PIN_A2 102 @@ -96,7 +92,6 @@ #define CFG_PIN_A13 113 #define CFG_PIN_A14 114 #define CFG_PIN_A15 115 - #define CFG_PIN_D0 150 #define CFG_PIN_D1 151 #define CFG_PIN_D2 152 @@ -113,15 +108,42 @@ #define CFG_PIN_D13 163 #define CFG_PIN_D14 164 #define CFG_PIN_D15 165 - #define CFG_NUM_NEOPIXELS 200 #define CFG_NUM_DOTSTARS 201 #define CFG_DEFAULT_BUTTON_MODE 202 #define CFG_SWD_ENABLED 203 #define CFG_FLASH_BYTES 204 +#define CFG_RAM_BYTES 205 +#define CFG_SYSTEM_HEAP_BYTES 206 +#define CFG_LOW_MEM_SIMULATION_KB 207 +#define CFG_BOOTLOADER_BOARD_ID 208 +#define CFG_UF2_FAMILY 209 +#define CFG_PINS_PORT_SIZE 210 + +#define ACCELEROMETER_TYPE_LIS3DH 0x32 +#define ACCELEROMETER_TYPE_MMA8453 0x38 +#define ACCELEROMETER_TYPE_FXOS8700 0x3c +#define ACCELEROMETER_TYPE_MMA8653 0x3a +#define ACCELEROMETER_TYPE_MSA300 0x4c + +#define UF2_FAMILY_ATSAMD21 0x68ed2b88 +#define UF2_FAMILY_ATSAMD51 0x55114460 +#define UF2_FAMILY_NRF52840 0x1b57745f +#define UF2_FAMILY_STM32F103 0x5ee21072 +#define UF2_FAMILY_STM32F401 0x57755a57 +#define UF2_FAMILY_ATMEGA32 0x16573617 +#define UF2_FAMILY_CYPRESS_FX2 0x5a18069b -#define CFG(k, v) CFG_ ## k, v, +#define PINS_PORT_SIZE_PA_16 0x10 +#define PINS_PORT_SIZE_PA_32 0x20 +#define PINS_PORT_SIZE_P0_16 0x1010 +#define PINS_PORT_SIZE_P0_32 0x1020 -#define CONFIG_DATA_MAGIC 0xbe3fd5ce +#define DEFAULT_BUTTON_MODE_ACTIVE_HIGH_PULL_DOWN 0x11 +#define DEFAULT_BUTTON_MODE_ACTIVE_HIGH_PULL_UP 0x21 +#define DEFAULT_BUTTON_MODE_ACTIVE_HIGH_PULL_NONE 0x31 +#define DEFAULT_BUTTON_MODE_ACTIVE_LOW_PULL_DOWN 0x10 +#define DEFAULT_BUTTON_MODE_ACTIVE_LOW_PULL_UP 0x20 +#define DEFAULT_BUTTON_MODE_ACTIVE_LOW_PULL_NONE 0x30 -#endif +#endif // __CONFIGKEYS_H diff --git a/inc/uf2.h b/inc/uf2.h index 6941f718..7c253c14 100644 --- a/inc/uf2.h +++ b/inc/uf2.h @@ -1,6 +1,7 @@ #ifndef UF2_H #define UF2_H 1 +#include #include "board_config.h" #include "sam.h" diff --git a/src/msc.c b/src/msc.c index 3640ee8c..eb0f5de8 100644 --- a/src/msc.c +++ b/src/msc.c @@ -42,9 +42,11 @@ */ +#define DEFINE_CONFIG_DATA 1 + #include "uf2.h" -#include "config_data.h" +#include "configkeys.h" #include "lib/usb_msc/sbc_protocol.h" #include "lib/usb_msc/spc_protocol.h" @@ -865,16 +867,8 @@ static void handover(UF2_HandoverArgs *args) { } #endif -#ifdef CONFIG_DATA -static const uint32_t config_data[] = { - CONFIG_DATA_MAGIC, - CONFIG_DATA - 0, 0 -}; -#endif - __attribute__((section(".binfo"))) __attribute__((__used__)) const UF2_BInfo binfo = { -#ifdef CONFIG_DATA +#ifdef HAS_CONFIG_DATA .config_data = config_data, #endif #if USE_MSC_HANDOVER From 889385d13d88d680e8eb473319e0514c4fbc8113 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 7 Jan 2019 16:57:32 +0000 Subject: [PATCH 18/38] Use different encoding for multiplexed buttons --- boards/arcade_badge/board_config.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/boards/arcade_badge/board_config.h b/boards/arcade_badge/board_config.h index 434befd4..e684308c 100644 --- a/boards/arcade_badge/board_config.h +++ b/boards/arcade_badge/board_config.h @@ -41,8 +41,8 @@ const uint32_t config_data[] = { 1, 0x2e, // PIN_ACCELEROMETER_INT = PB14 2, 0xd, // PIN_ACCELEROMETER_SCL = PIN_SCL 3, 0xc, // PIN_ACCELEROMETER_SDA = PIN_SDA - 4, 0x6b, // PIN_BTN_A = PD11 - 5, 0x6a, // PIN_BTN_B = PD10 + 4, 0x3ef, // PIN_BTN_A = P_1007 + 5, 0x3ee, // PIN_BTN_B = P_1006 13, 0x17, // PIN_LED = PIN_D13 18, 0x36, // PIN_MISO = PB22 19, 0x37, // PIN_MOSI = PB23 @@ -63,18 +63,18 @@ const uint32_t config_data[] = { 41, 0x18, // DISPLAY_CFG2 = 0x18 43, 0x1, // PIN_DISPLAY_RST = PA01 44, 0x0, // PIN_DISPLAY_BL = PA00 - 47, 0x64, // PIN_BTN_LEFT = PD04 - 48, 0x67, // PIN_BTN_RIGHT = PD07 - 49, 0x65, // PIN_BTN_UP = PD05 - 50, 0x66, // PIN_BTN_DOWN = PD06 - 51, 0x68, // PIN_BTN_MENU = PD08 + 47, 0x3e8, // PIN_BTN_LEFT = P_1000 + 48, 0x3eb, // PIN_BTN_RIGHT = P_1003 + 49, 0x3e9, // PIN_BTN_UP = P_1001 + 50, 0x3ea, // PIN_BTN_DOWN = P_1002 + 51, 0x3ec, // PIN_BTN_MENU = P_1004 59, 0x200, // SPEAKER_VOLUME = 512 60, 0x10, // PIN_JACK_TX = PIN_D5 65, 0x2, // PIN_JACK_SND = PIN_A0 66, 0x20, // PIN_BTNMX_LATCH = PB00 67, 0x3f, // PIN_BTNMX_CLOCK = PB31 68, 0x3e, // PIN_BTNMX_DATA = PB30 - 69, 0x69, // PIN_BTN_SOFT_RESET = PD09 + 69, 0x3ed, // PIN_BTN_SOFT_RESET = P_1005 70, 0x32, // ACCELEROMETER_TYPE = LIS3DH 100, 0x2, // PIN_A0 = PA02 101, 0x5, // PIN_A1 = PA05 @@ -106,5 +106,3 @@ const uint32_t config_data[] = { #endif #endif - - From 27f21856e00cc8cbd2854b68ffcdcb954df72532 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 7 Jan 2019 20:33:57 +0000 Subject: [PATCH 19/38] Remove --warn-unresolved-symbols - it should be error not warning --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 12d48bbd..f878accf 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ endif LDFLAGS= $(COMMON_FLAGS) \ -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common \ --Wl,--warn-section-align -Wl,--warn-unresolved-symbols \ +-Wl,--warn-section-align \ -save-temps -nostartfiles \ --specs=nano.specs --specs=nosys.specs BUILD_PATH=build/$(BOARD) @@ -64,6 +64,8 @@ COMMON_SRC = \ src/init_$(CHIP_FAMILY).c \ src/startup_$(CHIP_FAMILY).c \ src/usart_sam_ba.c \ + src/screen.c \ + src/images.c \ src/utils.c SOURCES = $(COMMON_SRC) \ From 4c9dfd1fd14db5bdb1af7498f29a0adc2860ac8f Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 7 Jan 2019 20:35:12 +0000 Subject: [PATCH 20/38] Add screen support --- boards/arcade_badge/board_config.h | 2 + boards/arcade_feather_m4/board_config.h | 2 + boards/arcade_itsybitsy_m4/board_config.h | 1 + inc/uf2.h | 18 + src/images.c | 118 ++++++ src/main.c | 12 +- src/msc.c | 2 - src/screen.c | 452 ++++++++++++++++++++++ src/utils.c | 5 +- 9 files changed, 603 insertions(+), 9 deletions(-) create mode 100644 src/images.c create mode 100644 src/screen.c diff --git a/boards/arcade_badge/board_config.h b/boards/arcade_badge/board_config.h index e684308c..d8d37e07 100644 --- a/boards/arcade_badge/board_config.h +++ b/boards/arcade_badge/board_config.h @@ -15,6 +15,8 @@ #define BOARD_NEOPIXEL_PIN PIN_PA15 #define BOARD_NEOPIXEL_COUNT 5 +#define BOARD_SCREEN 1 + #define BOOT_USART_MODULE SERCOM3 #define BOOT_USART_MASK APBAMASK #define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBBMASK_SERCOM3 diff --git a/boards/arcade_feather_m4/board_config.h b/boards/arcade_feather_m4/board_config.h index 15f15f05..3def25ae 100644 --- a/boards/arcade_feather_m4/board_config.h +++ b/boards/arcade_feather_m4/board_config.h @@ -28,6 +28,8 @@ #define BOOT_GCLK_ID_SLOW SERCOM0_GCLK_ID_SLOW #define HAS_CONFIG_DATA 1 +#define BOARD_SCREEN 1 + // This configuration data should be edited at https://microsoft.github.io/uf2/patcher/ // Just drop this file there. diff --git a/boards/arcade_itsybitsy_m4/board_config.h b/boards/arcade_itsybitsy_m4/board_config.h index d29d6824..067cf7b6 100644 --- a/boards/arcade_itsybitsy_m4/board_config.h +++ b/boards/arcade_itsybitsy_m4/board_config.h @@ -27,6 +27,7 @@ #define BOOT_GCLK_ID_SLOW SERCOM3_GCLK_ID_SLOW #define HAS_CONFIG_DATA 1 +#define BOARD_SCREEN 1 // This configuration data should be edited at https://microsoft.github.io/uf2/patcher/ // Just drop this file there. diff --git a/inc/uf2.h b/inc/uf2.h index 7c253c14..f2ed8487 100644 --- a/inc/uf2.h +++ b/inc/uf2.h @@ -15,6 +15,10 @@ #include #include + +#include "configkeys.h" + + #undef DISABLE #undef ENABLE @@ -56,6 +60,12 @@ // Doesn't yet disable code, just enumeration #define USE_MSC 1 +#ifdef BOARD_SCREEN +#define USE_SCREEN 1 +#else +#define USE_SCREEN 0 +#endif + // If enabled, bootloader will start on power-on and every reset. A second reset // will start the app. This only happens if the app says it wants that (see SINGLE_RESET() below). // If disabled here or by the app, the bootloader will only start with double-click of the reset @@ -284,4 +294,12 @@ STATIC_ASSERT(FLASH_NUM_ROWS * 4 == FLASH_NB_OF_PAGES); extern const char infoUf2File[]; +#if USE_SCREEN +void draw_screen(void); +void draw_hf2(void); +void draw_drag(void); +void screen_init(void); +void screen_early_init(void); +#endif + #endif diff --git a/src/images.c b/src/images.c new file mode 100644 index 00000000..34beb967 --- /dev/null +++ b/src/images.c @@ -0,0 +1,118 @@ +#include + +// all https://makecode.com/_FDFFVsKaTUfF + +// https://makecode.com/_7VxXm3JMPXfM - file +// https://makecode.com/_LuEUCsPEKUbs - download +const uint8_t fileLogo[] = { +32, 32, 71, 140, 201, 151, 1, 2, 146, 1, 2, 146, 63, 2, 151, 9, 153, 9, 153, 9, 146, 1, 9, 146, 3, 9, 146, 7, 9, 137, 205, 72, 140, 206, 36, 139, 207, 18, 138, 206, 36, 139, 205, 72, 149, 7, 9, 146, 3, 9, 146, 1, 9, 153, 9, 153, 9, 153, 9, 148, 63, 2, 146, 1, 2, 146, 1, 2, 146, 201, 191, 191, 191, 174 +}; + +// https://makecode.com/_9b0RcK5yRa12 +const uint8_t pendriveLogo[] = { +32, 32, 59, 137, 215, 137, 1, 143, 1, 8, 146, 203, 149, 3, 8, 146, 3, 8, 146, 115, 8, 146, 115, 8, 146, 3, 8, 146, 3, 8, 146, 115, 8, 146, 115, 8, 146, 3, 8, 146, 3, 8, 146, 203, 149, 1, 8, 146, 1, 8, 146, 1, 120, 211, 191, 191, 191, 191, 191, 191, 191, 135 +}; + +// https://makecode.com/_TTqbj705L4mr +const uint8_t arrowLogo[] = { +32, 32, 54, 137, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 151, 201, 146, 211, 142, 209, 144, 207, 146, 205, 148, 203, 150, 201, 152, 199, 154, 31, 154, 7, 154, 1, 191, 191, 191, 175 +}; + +const uint8_t font8[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x06, 0x5f, 0x5f, 0x06, 0x00, 0x00, +0x00, 0x03, 0x03, 0x00, 0x03, 0x03, 0x00, 0x00, +0x14, 0x7f, 0x7f, 0x14, 0x7f, 0x7f, 0x14, 0x00, +0x24, 0x2e, 0x6b, 0x6b, 0x3a, 0x12, 0x00, 0x00, +0x46, 0x66, 0x30, 0x18, 0x0c, 0x66, 0x62, 0x00, +0x30, 0x7a, 0x4f, 0x5d, 0x37, 0x7a, 0x48, 0x00, +0x04, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x1c, 0x3e, 0x63, 0x41, 0x00, 0x00, 0x00, +0x00, 0x41, 0x63, 0x3e, 0x1c, 0x00, 0x00, 0x00, +0x08, 0x2a, 0x3e, 0x1c, 0x1c, 0x3e, 0x2a, 0x08, +0x08, 0x08, 0x3e, 0x3e, 0x08, 0x08, 0x00, 0x00, +0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, 0x00, +0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, +0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, +0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x01, 0x00, +0x3e, 0x7f, 0x71, 0x59, 0x4d, 0x7f, 0x3e, 0x00, +0x40, 0x42, 0x7f, 0x7f, 0x40, 0x40, 0x00, 0x00, +0x62, 0x73, 0x59, 0x49, 0x6f, 0x66, 0x00, 0x00, +0x22, 0x63, 0x49, 0x49, 0x7f, 0x36, 0x00, 0x00, +0x18, 0x1c, 0x16, 0x53, 0x7f, 0x7f, 0x50, 0x00, +0x27, 0x67, 0x45, 0x45, 0x7d, 0x39, 0x00, 0x00, +0x3c, 0x7e, 0x4b, 0x49, 0x79, 0x30, 0x00, 0x00, +0x03, 0x03, 0x71, 0x79, 0x0f, 0x07, 0x00, 0x00, +0x36, 0x7f, 0x49, 0x49, 0x7f, 0x36, 0x00, 0x00, +0x06, 0x4f, 0x49, 0x69, 0x3f, 0x1e, 0x00, 0x00, +0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0xe6, 0x66, 0x00, 0x00, 0x00, 0x00, +0x08, 0x1c, 0x36, 0x63, 0x41, 0x00, 0x00, 0x00, +0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, +0x00, 0x41, 0x63, 0x36, 0x1c, 0x08, 0x00, 0x00, +0x02, 0x03, 0x51, 0x59, 0x0f, 0x06, 0x00, 0x00, +0x3e, 0x7f, 0x41, 0x5d, 0x5d, 0x1f, 0x1e, 0x00, +0x7c, 0x7e, 0x13, 0x13, 0x7e, 0x7c, 0x00, 0x00, +0x41, 0x7f, 0x7f, 0x49, 0x49, 0x7f, 0x36, 0x00, +0x1c, 0x3e, 0x63, 0x41, 0x41, 0x63, 0x22, 0x00, +0x41, 0x7f, 0x7f, 0x41, 0x63, 0x3e, 0x1c, 0x00, +0x41, 0x7f, 0x7f, 0x49, 0x5d, 0x41, 0x63, 0x00, +0x41, 0x7f, 0x7f, 0x49, 0x1d, 0x01, 0x03, 0x00, +0x1c, 0x3e, 0x63, 0x41, 0x51, 0x73, 0x72, 0x00, +0x7f, 0x7f, 0x08, 0x08, 0x7f, 0x7f, 0x00, 0x00, +0x00, 0x41, 0x7f, 0x7f, 0x41, 0x00, 0x00, 0x00, +0x30, 0x70, 0x40, 0x41, 0x7f, 0x3f, 0x01, 0x00, +0x41, 0x7f, 0x7f, 0x08, 0x1c, 0x77, 0x63, 0x00, +0x41, 0x7f, 0x7f, 0x41, 0x40, 0x60, 0x70, 0x00, +0x7f, 0x7f, 0x0e, 0x1c, 0x0e, 0x7f, 0x7f, 0x00, +0x7f, 0x7f, 0x06, 0x0c, 0x18, 0x7f, 0x7f, 0x00, +0x1c, 0x3e, 0x63, 0x41, 0x63, 0x3e, 0x1c, 0x00, +0x41, 0x7f, 0x7f, 0x49, 0x09, 0x0f, 0x06, 0x00, +0x1e, 0x3f, 0x21, 0x71, 0x7f, 0x5e, 0x00, 0x00, +0x41, 0x7f, 0x7f, 0x09, 0x19, 0x7f, 0x66, 0x00, +0x26, 0x6f, 0x4d, 0x59, 0x73, 0x32, 0x00, 0x00, +0x03, 0x41, 0x7f, 0x7f, 0x41, 0x03, 0x00, 0x00, +0x7f, 0x7f, 0x40, 0x40, 0x7f, 0x7f, 0x00, 0x00, +0x1f, 0x3f, 0x60, 0x60, 0x3f, 0x1f, 0x00, 0x00, +0x7f, 0x7f, 0x30, 0x18, 0x30, 0x7f, 0x7f, 0x00, +0x43, 0x67, 0x3c, 0x18, 0x3c, 0x67, 0x43, 0x00, +0x07, 0x4f, 0x78, 0x78, 0x4f, 0x07, 0x00, 0x00, +0x47, 0x63, 0x71, 0x59, 0x4d, 0x67, 0x73, 0x00, +0x00, 0x7f, 0x7f, 0x41, 0x41, 0x00, 0x00, 0x00, +0x01, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, +0x00, 0x41, 0x41, 0x7f, 0x7f, 0x00, 0x00, 0x00, +0x08, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x08, 0x00, +0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, +0x00, 0x00, 0x03, 0x07, 0x04, 0x00, 0x00, 0x00, +0x20, 0x74, 0x54, 0x54, 0x3c, 0x78, 0x40, 0x00, +0x41, 0x7f, 0x3f, 0x48, 0x48, 0x78, 0x30, 0x00, +0x38, 0x7c, 0x44, 0x44, 0x6c, 0x28, 0x00, 0x00, +0x30, 0x78, 0x48, 0x49, 0x3f, 0x7f, 0x40, 0x00, +0x38, 0x7c, 0x54, 0x54, 0x5c, 0x18, 0x00, 0x00, +0x48, 0x7e, 0x7f, 0x49, 0x03, 0x02, 0x00, 0x00, +0x98, 0xbc, 0xa4, 0xa4, 0xf8, 0x7c, 0x04, 0x00, +0x41, 0x7f, 0x7f, 0x08, 0x04, 0x7c, 0x78, 0x00, +0x00, 0x44, 0x7d, 0x7d, 0x40, 0x00, 0x00, 0x00, +0x60, 0xe0, 0x80, 0x80, 0xfd, 0x7d, 0x00, 0x00, +0x41, 0x7f, 0x7f, 0x10, 0x38, 0x6c, 0x44, 0x00, +0x00, 0x41, 0x7f, 0x7f, 0x40, 0x00, 0x00, 0x00, +0x7c, 0x7c, 0x18, 0x38, 0x1c, 0x7c, 0x78, 0x00, +0x7c, 0x7c, 0x04, 0x04, 0x7c, 0x78, 0x00, 0x00, +0x38, 0x7c, 0x44, 0x44, 0x7c, 0x38, 0x00, 0x00, +0x84, 0xfc, 0xf8, 0xa4, 0x24, 0x3c, 0x18, 0x00, +0x18, 0x3c, 0x24, 0xa4, 0xf8, 0xfc, 0x84, 0x00, +0x44, 0x7c, 0x78, 0x4c, 0x04, 0x1c, 0x18, 0x00, +0x48, 0x5c, 0x54, 0x54, 0x74, 0x24, 0x00, 0x00, +0x00, 0x04, 0x3e, 0x7f, 0x44, 0x24, 0x00, 0x00, +0x3c, 0x7c, 0x40, 0x40, 0x3c, 0x7c, 0x40, 0x00, +0x1c, 0x3c, 0x60, 0x60, 0x3c, 0x1c, 0x00, 0x00, +0x3c, 0x7c, 0x70, 0x38, 0x70, 0x7c, 0x3c, 0x00, +0x44, 0x6c, 0x38, 0x10, 0x38, 0x6c, 0x44, 0x00, +0x9c, 0xbc, 0xa0, 0xa0, 0xfc, 0x7c, 0x00, 0x00, +0x4c, 0x64, 0x74, 0x5c, 0x4c, 0x64, 0x00, 0x00, +0x08, 0x08, 0x3e, 0x77, 0x41, 0x41, 0x00, 0x00, +0x00, 0x00, 0x00, 0x77, 0x77, 0x00, 0x00, 0x00, +0x41, 0x41, 0x77, 0x3e, 0x08, 0x08, 0x00, 0x00, +0x02, 0x03, 0x01, 0x03, 0x02, 0x03, 0x01, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; diff --git a/src/main.c b/src/main.c index cdcfcbd6..7349cafe 100644 --- a/src/main.c +++ b/src/main.c @@ -72,7 +72,7 @@ * to use the interrupt vectors of the application @0x2000.<- not required as * application code is taking care of this * -*/ + */ #include "uf2.h" @@ -109,8 +109,7 @@ static void check_start_application(void) { #if USE_SINGLE_RESET if (SINGLE_RESET()) { - if (RESET_CONTROLLER->RCAUSE.bit.POR || - *DBL_TAP_PTR != DBL_TAP_MAGIC_QUICK_BOOT) { + if (RESET_CONTROLLER->RCAUSE.bit.POR || *DBL_TAP_PTR != DBL_TAP_MAGIC_QUICK_BOOT) { // the second tap on reset will go into app *DBL_TAP_PTR = DBL_TAP_MAGIC_QUICK_BOOT; // this will be cleared after succesful USB enumeration @@ -162,7 +161,7 @@ int main(void) { while (1) { } -#if (USB_VID == 0x239a) && (USB_PID == 0x0013) // Adafruit Metro M0 +#if (USB_VID == 0x239a) && (USB_PID == 0x0013) // Adafruit Metro M0 // Delay a bit so SWD programmer can have time to attach. delay(15); #endif @@ -209,6 +208,11 @@ int main(void) { #endif RGBLED_set_color(COLOR_USB); led_tick_step = 1; + +#if USE_SCREEN + screen_init(); + draw_drag(); +#endif } main_b_cdc_enable = true; diff --git a/src/msc.c b/src/msc.c index eb0f5de8..fe1cb9cf 100644 --- a/src/msc.c +++ b/src/msc.c @@ -46,8 +46,6 @@ #include "uf2.h" -#include "configkeys.h" - #include "lib/usb_msc/sbc_protocol.h" #include "lib/usb_msc/spc_protocol.h" #include "lib/usb_msc/usb_protocol.h" diff --git a/src/screen.c b/src/screen.c new file mode 100644 index 00000000..b2ba6a57 --- /dev/null +++ b/src/screen.c @@ -0,0 +1,452 @@ +#include "uf2.h" + +#if USE_SCREEN + +#include + +#define DISPLAY_WIDTH 160 +#define DISPLAY_HEIGHT 128 + +#define ST7735_NOP 0x00 +#define ST7735_SWRESET 0x01 +#define ST7735_RDDID 0x04 +#define ST7735_RDDST 0x09 + +#define ST7735_SLPIN 0x10 +#define ST7735_SLPOUT 0x11 +#define ST7735_PTLON 0x12 +#define ST7735_NORON 0x13 + +#define ST7735_INVOFF 0x20 +#define ST7735_INVON 0x21 +#define ST7735_DISPOFF 0x28 +#define ST7735_DISPON 0x29 +#define ST7735_CASET 0x2A +#define ST7735_RASET 0x2B +#define ST7735_RAMWR 0x2C +#define ST7735_RAMRD 0x2E + +#define ST7735_PTLAR 0x30 +#define ST7735_COLMOD 0x3A +#define ST7735_MADCTL 0x36 + +#define ST7735_FRMCTR1 0xB1 +#define ST7735_FRMCTR2 0xB2 +#define ST7735_FRMCTR3 0xB3 +#define ST7735_INVCTR 0xB4 +#define ST7735_DISSET5 0xB6 + +#define ST7735_PWCTR1 0xC0 +#define ST7735_PWCTR2 0xC1 +#define ST7735_PWCTR3 0xC2 +#define ST7735_PWCTR4 0xC3 +#define ST7735_PWCTR5 0xC4 +#define ST7735_VMCTR1 0xC5 + +#define ST7735_RDID1 0xDA +#define ST7735_RDID2 0xDB +#define ST7735_RDID3 0xDC +#define ST7735_RDID4 0xDD + +#define ST7735_PWCTR6 0xFC + +#define ST7735_GMCTRP1 0xE0 +#define ST7735_GMCTRN1 0xE1 + +uint32_t lookupCfg(uint32_t key, uint32_t defl); +#define CFG(v) lookupCfg(CFG_##v, 0x42) + +uint32_t lookupCfg(uint32_t key, uint32_t defl) { + const uint32_t *ptr = UF2_BINFO->config_data; + if (!ptr || (((uint32_t)ptr) & 3) || *ptr != CFG_MAGIC0) { + // no config data! + } else { + ptr += 4; + while (*ptr) { + if (*ptr == key) + return ptr[1]; + ptr += 2; + } + } + if (defl == 0x42) + while (1) + ; + return defl; +} + +void pin_set(int pincfg, int v) { + int pin = lookupCfg(pincfg, -1); + if (pin < 0) + return; + if (v) { + PINOP(pin, OUTSET); + } else { + PINOP(pin, OUTCLR); + } +} + +void setup_output_pin(int pincfg) { + int pin = lookupCfg(pincfg, -1); + if (pin < 0) + return; + PINOP(pin, DIRSET); + PINOP(pin, OUTCLR); +} + +#define PINPORT(pin) PORT->Group[(pin) / 32] +#define pinmask(pin) (1 << (pin & 0x1f)) + +void transfer(uint8_t *ptr, uint32_t len) { + int mosi = CFG(PIN_DISPLAY_MOSI); + int sck = CFG(PIN_DISPLAY_SCK); + + volatile uint32_t *mosi_set = &PINPORT(mosi).OUTSET.reg; + volatile uint32_t *mosi_clr = &PINPORT(mosi).OUTCLR.reg; + volatile uint32_t *sck_tgl = &PINPORT(sck).OUTTGL.reg; + + uint32_t mosi_mask = pinmask(mosi); + uint32_t sck_mask = pinmask(sck); + + PINOP(sck, OUTCLR); + + uint8_t mask = 0, b; + for (;;) { + if (!mask) { + if (!len--) + break; + mask = 0x80; + b = *ptr++; + } + if (b & mask) + *mosi_set = mosi_mask; + else + *mosi_clr = mosi_mask; + *sck_tgl = sck_mask; + mask >>= 1; + *sck_tgl = sck_mask; + } +} + +#define DELAY 0x80 + +// clang-format off +static const uint8_t initCmds[] = { + ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay + 120, // 150 ms delay + ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay + 120, // 500 ms delay + ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay + ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay: + 0x05, // 16-bit color + ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay: + 0x02, 0x1c, 0x07, 0x12, + 0x37, 0x32, 0x29, 0x2d, + 0x29, 0x25, 0x2B, 0x39, + 0x00, 0x01, 0x03, 0x10, + ST7735_NORON , DELAY, // 3: Normal display on, no args, w/delay + 10, // 10 ms delay + ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay + 10, + 0, 0 // END +}; +// clang-format on + +static uint8_t cmdBuf[20]; + +#define SET_DC(v) pin_set(CFG_PIN_DISPLAY_DC, v) +#define SET_CS(v) pin_set(CFG_PIN_DISPLAY_CS, v) + +static void scr_delay(unsigned msec) { + int k = msec * 15000; + while (k--) + asm("nop"); +} + +static void sendCmd(uint8_t *buf, int len) { + // make sure cmd isn't on stack + if (buf != cmdBuf) + memcpy(cmdBuf, buf, len); + buf = cmdBuf; + + SET_DC(0); + SET_CS(0); + + transfer(buf, 1); + + SET_DC(1); + + len--; + buf++; + if (len > 0) + transfer(buf, len); + + SET_CS(1); +} + +static void sendCmdSeq(const uint8_t *buf) { + while (*buf) { + cmdBuf[0] = *buf++; + int v = *buf++; + int len = v & ~DELAY; + // note that we have to copy to RAM + memcpy(cmdBuf + 1, buf, len); + sendCmd(cmdBuf, len + 1); + buf += len; + if (v & DELAY) { + scr_delay(*buf++); + } + } +} + +static uint32_t palXOR; + +static void setAddrWindow(int x, int y, int w, int h) { + uint8_t cmd0[] = {ST7735_RASET, 0, (uint8_t)x, 0, (uint8_t)(x + w - 1)}; + uint8_t cmd1[] = {ST7735_CASET, 0, (uint8_t)y, 0, (uint8_t)(y + h - 1)}; + sendCmd(cmd1, sizeof(cmd1)); + sendCmd(cmd0, sizeof(cmd0)); +} + +static void configure(uint8_t madctl, uint32_t frmctr1) { + uint8_t cmd0[] = {ST7735_MADCTL, madctl}; + uint8_t cmd1[] = {ST7735_FRMCTR1, (uint8_t)(frmctr1 >> 16), (uint8_t)(frmctr1 >> 8), + (uint8_t)frmctr1}; + sendCmd(cmd0, sizeof(cmd0)); + sendCmd(cmd1, cmd1[3] == 0xff ? 3 : 4); +} + +#define COL0(r, g, b) ((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3)) +#define COL(c) COL0((c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff) + +const uint16_t palette[] = { + COL(0x000000), // 0 + COL(0xffffff), // 1 + COL(0xff2121), // 2 + COL(0xff93c4), // 3 + COL(0xff8135), // 4 + COL(0xfff609), // 5 + COL(0x249ca3), // 6 + COL(0x78dc52), // 7 + COL(0x003fad), // 8 + COL(0x87f2ff), // 9 + COL(0x8e2ec4), // 10 + COL(0xa4839f), // 11 + COL(0x5c406c), // 12 + COL(0xe5cdc4), // 13 + COL(0x91463d), // 14 + COL(0x000000), // 15 +}; + +uint8_t fb[168 * 128]; +extern const uint8_t font8[]; +extern const uint8_t fileLogo[]; +extern const uint8_t pendriveLogo[]; +extern const uint8_t arrowLogo[]; + +static void printch(int x, int y, int col, const uint8_t *fnt) { + for (int i = 0; i < 8; ++i) { + uint8_t *p = fb + (x + i) * DISPLAY_HEIGHT + y; + uint8_t mask = 0x01; + for (int j = 0; j < 8; ++j) { + if (*fnt & mask) + *p = col; + p++; + mask <<= 1; + } + fnt++; + } +} + +static void printch4(int x, int y, int col, const uint8_t *fnt) { + for (int i = 0; i < 8 * 4; ++i) { + uint8_t *p = fb + (x + i) * DISPLAY_HEIGHT + y; + uint8_t mask = 0x01; + for (int j = 0; j < 8; ++j) { + for (int k = 0; k < 4; ++k) { + if (*fnt & mask) + *p = col; + p++; + } + mask <<= 1; + } + if ((i & 3) == 3) + fnt++; + } +} + +void printicon(int x, int y, int col, const uint8_t *icon) { + int w = *icon++; + int h = *icon++; + int sz = *icon++; + + uint8_t mask = 0x80; + int runlen = 0; + int runbit = 0; + uint8_t lastb = 0x00; + + for (int i = 0; i < w; ++i) { + uint8_t *p = fb + (x + i) * DISPLAY_HEIGHT + y; + for (int j = 0; j < h; ++j) { + int c = 0; + if (mask != 0x80) { + if (lastb & mask) + c = 1; + mask <<= 1; + } else if (runlen) { + if (runbit) + c = 1; + runlen--; + } else { + if (sz-- <= 0) + panic(10); + lastb = *icon++; + if (lastb & 0x80) { + runlen = lastb & 63; + runbit = lastb & 0x40; + } else { + mask = 0x01; + } + --j; + continue; // restart + } + if (c) + *p = col; + p++; + } + } +} + +void print(int x, int y, int col, const char *text) { + int x0 = x; + while (*text) { + char c = *text++; + if (c == '\r') + continue; + if (c == '\n') { + x = x0; + y += 10; + continue; + } + /* + if (x + 8 > DISPLAY_WIDTH) { + x = x0; + y += 10; + } + */ + if (c < ' ') + c = '?'; + if (c >= 0x7f) + c = '?'; + c -= ' '; + printch(x, y, col, &font8[c * 8]); + x += 8; + } +} + +void print4(int x, int y, int col, const char *text) { + while (*text) { + char c = *text++; + c -= ' '; + printch4(x, y, col, &font8[c * 8]); + x += 8 * 4; + } +} + +void draw_screen() { + if (lookupCfg(CFG_PIN_DISPLAY_SCK, 1000) == 1000) + return; + + cmdBuf[0] = ST7735_RAMWR; + sendCmd(cmdBuf, 1); + + SET_DC(1); + SET_CS(0); + + uint8_t *p = fb; + for (int i = 0; i < DISPLAY_WIDTH; ++i) { + for (int j = 0; j < DISPLAY_HEIGHT; ++j) { + uint16_t color = palette[*p++ & 0xf]; + uint8_t cc[] = {color >> 8, color & 0xff}; + transfer(cc, 2); + } + } + + SET_CS(1); +} + +void drawBar(int y, int h, int c) { + for (int x = 0; x < DISPLAY_WIDTH; ++x) { + memset(fb + x * DISPLAY_HEIGHT + y, c, h); + } +} + +void draw_hf2() { + print4(20, 22, 5, "<-->"); + print(40, 110, 7, "flashing..."); + draw_screen(); +} + +void draw_drag() { + drawBar(0, 52, 7); + drawBar(52, 55, 8); + drawBar(107, 14, 4); + + print4(40, 10, 1, "D51"); + print(37, 43, 6, "UF2 " UF2_VERSION_BASE); + print(3, 110, 1, "arcade.makecode.com"); + +#define DRAG 70 +#define DRAGX 10 + printicon(DRAGX + 20, DRAG + 5, 1, fileLogo); + printicon(DRAGX + 66, DRAG, 1, arrowLogo); + printicon(DRAGX + 108, DRAG, 1, pendriveLogo); + print(2, DRAG - 12, 1, "arcade.uf2"); + print(95, DRAG - 12, 1, "ARCD-D51"); + + draw_screen(); +} + +void screen_early_init() { + setup_output_pin(CFG_PIN_DISPLAY_BL); +} + +void screen_init() { + if (lookupCfg(CFG_PIN_DISPLAY_SCK, 1000) == 1000) + return; + + setup_output_pin(CFG_PIN_DISPLAY_SCK); + setup_output_pin(CFG_PIN_DISPLAY_MOSI); + setup_output_pin(CFG_PIN_DISPLAY_BL); + setup_output_pin(CFG_PIN_DISPLAY_DC); + setup_output_pin(CFG_PIN_DISPLAY_RST); + setup_output_pin(CFG_PIN_DISPLAY_CS); + + SET_CS(1); + SET_DC(1); + + pin_set(CFG_PIN_DISPLAY_BL, 1); + + pin_set(CFG_PIN_DISPLAY_RST, 0); + scr_delay(20); + pin_set(CFG_PIN_DISPLAY_RST, 1); + scr_delay(20); + + sendCmdSeq(initCmds); + + uint32_t cfg0 = CFG(DISPLAY_CFG0); + //uint32_t cfg2 = CFG(DISPLAY_CFG2); + uint32_t frmctr1 = CFG(DISPLAY_CFG1); + palXOR = (cfg0 & 0x1000000) ? 0xffffff : 0x000000; + uint32_t madctl = cfg0 & 0xff; + uint32_t offX = (cfg0 >> 8) & 0xff; + uint32_t offY = (cfg0 >> 16) & 0xff; + //uint32_t freq = (cfg2 & 0xff); + + // DMESG("configure screen: FRMCTR1=%p MADCTL=%p SPI at %dMHz", frmctr1, madctl, freq); + configure(madctl, frmctr1); + setAddrWindow(offX, offY, CFG(DISPLAY_WIDTH), CFG(DISPLAY_HEIGHT)); + + memset(fb, 0, sizeof(fb)); +} + +#endif \ No newline at end of file diff --git a/src/utils.c b/src/utils.c index ef492495..9cc05a0b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -155,10 +155,9 @@ void led_init() { RGBLED_set_color(COLOR_LEAVE); #endif -#if defined(PIN_DISPLAY_BL) +#if USE_SCREEN // turn display backlight - PINOP(PIN_DISPLAY_BL, DIRSET); - PINOP(PIN_DISPLAY_BL, OUTCLR); + screen_early_init(); #endif } From 6098ca498ea45d712d7c7fe2078d914b7a8e2618 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 7 Jan 2019 22:20:13 +0000 Subject: [PATCH 21/38] Fix key codes for BTNMX --- boards/arcade_badge/board_config.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boards/arcade_badge/board_config.h b/boards/arcade_badge/board_config.h index d8d37e07..02200232 100644 --- a/boards/arcade_badge/board_config.h +++ b/boards/arcade_badge/board_config.h @@ -73,11 +73,11 @@ const uint32_t config_data[] = { 59, 0x200, // SPEAKER_VOLUME = 512 60, 0x10, // PIN_JACK_TX = PIN_D5 65, 0x2, // PIN_JACK_SND = PIN_A0 - 66, 0x20, // PIN_BTNMX_LATCH = PB00 - 67, 0x3f, // PIN_BTNMX_CLOCK = PB31 - 68, 0x3e, // PIN_BTNMX_DATA = PB30 69, 0x3ed, // PIN_BTN_SOFT_RESET = P_1005 70, 0x32, // ACCELEROMETER_TYPE = LIS3DH + 71, 0x20, // PIN_BTNMX_LATCH = PB00 + 72, 0x3f, // PIN_BTNMX_CLOCK = PB31 + 73, 0x3e, // PIN_BTNMX_DATA = PB30 100, 0x2, // PIN_A0 = PA02 101, 0x5, // PIN_A1 = PA05 102, 0x28, // PIN_A2 = PB08 From 98c2743a9af9bc5c091ed15b2de78b9a09d2e579 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 9 Jan 2019 13:24:49 +0000 Subject: [PATCH 22/38] Send out UF2 family in HF2_CMD_BININFO --- inc/uf2hid.h | 1 + src/hid.c | 1 + 2 files changed, 2 insertions(+) diff --git a/inc/uf2hid.h b/inc/uf2hid.h index 78554e63..90077b7b 100644 --- a/inc/uf2hid.h +++ b/inc/uf2hid.h @@ -10,6 +10,7 @@ struct HF2_BININFO_Result { uint32_t flash_page_size; uint32_t flash_num_pages; uint32_t max_message_size; + uint32_t uf2_family; }; #define HF2_CMD_INFO 0x0002 diff --git a/src/hid.c b/src/hid.c index d70d9f88..9ba8c53b 100644 --- a/src/hid.c +++ b/src/hid.c @@ -138,6 +138,7 @@ void process_core(HID_InBuffer *pkt) { resp->bininfo.flash_page_size = FLASH_ROW_SIZE; resp->bininfo.flash_num_pages = FLASH_SIZE / FLASH_ROW_SIZE; resp->bininfo.max_message_size = sizeof(pkt->buf); + resp->bininfo.uf2_family = UF2_FAMILY; send_hf2_response(pkt, sizeof(resp->bininfo)); return; From 5c7bf80cbb5b0cc9154c7c9e256a653683248aec Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 9 Jan 2019 14:26:07 +0000 Subject: [PATCH 23/38] Account for CPU speed --- inc/uf2.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inc/uf2.h b/inc/uf2.h index f2ed8487..d5e330a0 100644 --- a/inc/uf2.h +++ b/inc/uf2.h @@ -136,7 +136,13 @@ // End of config #define USE_MONITOR (USE_CDC || USE_UART) + +#ifdef SAMD51 +// 51 also runs at 48MHz in bootloader mode, but it's still faster +#define TIMER_STEP 2000 +#else #define TIMER_STEP 1500 +#endif #ifdef BOARD_NEOPIXEL_PIN #define COLOR_START 0x040000 From b977d70c04cfe709e0e820443c00398cb6868324 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 10 Jan 2019 21:44:10 +0000 Subject: [PATCH 24/38] Speed up screen refresh --- src/screen.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/screen.c b/src/screen.c index b2ba6a57..14af05b3 100644 --- a/src/screen.c +++ b/src/screen.c @@ -364,11 +364,14 @@ void draw_screen() { uint8_t *p = fb; for (int i = 0; i < DISPLAY_WIDTH; ++i) { + uint8_t cc[DISPLAY_HEIGHT * 2]; + uint32_t dst = 0; for (int j = 0; j < DISPLAY_HEIGHT; ++j) { uint16_t color = palette[*p++ & 0xf]; - uint8_t cc[] = {color >> 8, color & 0xff}; - transfer(cc, 2); + cc[dst++] = color >> 8; + cc[dst++] = color & 0xff; } + transfer(cc, sizeof(cc)); } SET_CS(1); From 310e335e604473293306c5b3b2026839d52f49ea Mon Sep 17 00:00:00 2001 From: Teddy Seyed Date: Tue, 15 Jan 2019 10:39:37 -0800 Subject: [PATCH 25/38] Adding jacdac pin to bootloader --- boards/arcade_itsybitsy_m4/board_config.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/boards/arcade_itsybitsy_m4/board_config.h b/boards/arcade_itsybitsy_m4/board_config.h index 067cf7b6..de28d2ff 100644 --- a/boards/arcade_itsybitsy_m4/board_config.h +++ b/boards/arcade_itsybitsy_m4/board_config.h @@ -73,6 +73,7 @@ const uint32_t config_data[] = { 50, 0x17, // PIN_BTN_DOWN = PIN_D12 51, 0xc, // PIN_BTN_MENU = PIN_SDA 59, 0x200, // SPEAKER_VOLUME = 512 + 60, 0x11, // PIN_JACK_TX = PIN_D1 / TX 100, 0x2, // PIN_A0 = PA02 101, 0x5, // PIN_A1 = PA05 102, 0x28, // PIN_A2 = PB08 @@ -104,8 +105,4 @@ const uint32_t config_data[] = { }; #endif -#endif - - - - +#endif \ No newline at end of file From 7f6f361e41075f9f392480f94b9c44b75df4bf27 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 17 Jan 2019 22:29:27 +0000 Subject: [PATCH 26/38] Fix config entry --- boards/arcade_itsybitsy_m4/board_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/arcade_itsybitsy_m4/board_config.h b/boards/arcade_itsybitsy_m4/board_config.h index de28d2ff..2cc693d0 100644 --- a/boards/arcade_itsybitsy_m4/board_config.h +++ b/boards/arcade_itsybitsy_m4/board_config.h @@ -37,7 +37,7 @@ const uint32_t config_data[] = { /* CF2 START */ 513675505, 539130489, // magic - 59, 100, // used entries, total entries + 60, 100, // used entries, total entries 4, 0xd, // PIN_BTN_A = PIN_SCL 5, 0x12, // PIN_BTN_B = PIN_D7 7, 0x22, // PIN_DOTSTAR_CLOCK = PB02 From 43d2e442b114e26055e41526289aa17d6b46816b Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 17 Jan 2019 22:31:19 +0000 Subject: [PATCH 27/38] Revert accidentail version change --- scripts/dbgtool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dbgtool.js b/scripts/dbgtool.js index ef7f5253..3c57916f 100755 --- a/scripts/dbgtool.js +++ b/scripts/dbgtool.js @@ -71,7 +71,7 @@ function main() { if (process.platform == "win32") openocdBin += ".exe" - let zeroCfg = pkgDir + "hardware/samd/1.6.16/variants/arduino_zero/openocd_scripts/arduino_zero.cfg" + let zeroCfg = pkgDir + "hardware/samd/1.6.17/variants/arduino_zero/openocd_scripts/arduino_zero.cfg" let cmd = `telnet_port disabled; init; halt; ` if (mode == "map") From fc4760b3515a267bc8c0f200c59f4e47e2514eab Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 23 Jan 2019 16:42:39 +0000 Subject: [PATCH 28/38] Fix format of CF2 data --- boards/arcade_feather_m4/board_config.h | 6 ++++-- boards/arcade_itsybitsy_m4/board_config.h | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/boards/arcade_feather_m4/board_config.h b/boards/arcade_feather_m4/board_config.h index 3def25ae..060c26d0 100644 --- a/boards/arcade_feather_m4/board_config.h +++ b/boards/arcade_feather_m4/board_config.h @@ -39,7 +39,7 @@ const uint32_t config_data[] = { /* CF2 START */ 513675505, 539130489, // magic - 52, 100, // used entries, total entries + 53, 100, // used entries, total entries 4, 0xd, // PIN_BTN_A = PIN_SCL 5, 0x12, // PIN_BTN_B = PIN_D6 13, 0x17, // PIN_LED = PIN_D13 @@ -70,6 +70,7 @@ const uint32_t config_data[] = { 50, 0x16, // PIN_BTN_DOWN = PIN_D12 51, 0xc, // PIN_BTN_MENU = PIN_SDA 59, 0x200, // SPEAKER_VOLUME = 512 + 60, 0x30, // PIN_JACK_TX = PIN_D1 100, 0x2, // PIN_A0 = PA02 101, 0x5, // PIN_A1 = PA05 102, 0x28, // PIN_A2 = PB08 @@ -94,7 +95,7 @@ const uint32_t config_data[] = { 210, 0x20, // PINS_PORT_SIZE = PA_32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* CF2 END */ }; #endif @@ -102,3 +103,4 @@ const uint32_t config_data[] = { #endif + diff --git a/boards/arcade_itsybitsy_m4/board_config.h b/boards/arcade_itsybitsy_m4/board_config.h index 2cc693d0..721da534 100644 --- a/boards/arcade_itsybitsy_m4/board_config.h +++ b/boards/arcade_itsybitsy_m4/board_config.h @@ -73,7 +73,7 @@ const uint32_t config_data[] = { 50, 0x17, // PIN_BTN_DOWN = PIN_D12 51, 0xc, // PIN_BTN_MENU = PIN_SDA 59, 0x200, // SPEAKER_VOLUME = 512 - 60, 0x11, // PIN_JACK_TX = PIN_D1 / TX + 60, 0x11, // PIN_JACK_TX = PIN_D1 100, 0x2, // PIN_A0 = PA02 101, 0x5, // PIN_A1 = PA05 102, 0x28, // PIN_A2 = PB08 @@ -100,9 +100,9 @@ const uint32_t config_data[] = { 210, 0x20, // PINS_PORT_SIZE = PA_32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* CF2 END */ }; #endif -#endif \ No newline at end of file +#endif From dec2fb702c5389d6b2a188446778ea3ca07473e3 Mon Sep 17 00:00:00 2001 From: Sabas Date: Thu, 31 Jan 2019 17:24:59 +0100 Subject: [PATCH 29/38] add arduino mkr1300 (#66) --- boards/mkr1300/board.mk | 2 ++ boards/mkr1300/board_config.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 boards/mkr1300/board.mk create mode 100644 boards/mkr1300/board_config.h diff --git a/boards/mkr1300/board.mk b/boards/mkr1300/board.mk new file mode 100644 index 00000000..0a90fdf6 --- /dev/null +++ b/boards/mkr1300/board.mk @@ -0,0 +1,2 @@ +CHIP_FAMILY = samd21 +CHIP_VARIANT = SAMD21G18A diff --git a/boards/mkr1300/board_config.h b/boards/mkr1300/board_config.h new file mode 100644 index 00000000..00e1212f --- /dev/null +++ b/boards/mkr1300/board_config.h @@ -0,0 +1,15 @@ +#ifndef BOARD_CONFIG_H +#define BOARD_CONFIG_H + +#define VENDOR_NAME "Arduino LLC" +#define PRODUCT_NAME "Arduino MKR1300" +#define VOLUME_LABEL "MKR1300" + +#define BOARD_ID "SAMD21G18A-MKR1300-v0" + +#define USB_VID 0x2341 +#define USB_PID 0x8053 + +#define LED_PIN PIN_PA20 + +#endif From 17cf5763a98e04b40e747d8a8971e030ee0fb4f4 Mon Sep 17 00:00:00 2001 From: Henry Gabryjelski Date: Thu, 14 Mar 2019 16:12:38 -0700 Subject: [PATCH 30/38] Add familyID and fix FAT16 bug Add many comments and static compile-time assertions, which do not add to code size, but document unwritten presumptions of the code. Code changes: 1. Set boot sector .PhysicalDriveNum to 0x80 2. Set a valid date for file creation and update. This fixes ability to list files in DOS / CMD. 3. Add the family ID to the generated UF2 file. --- src/fat.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/fat.c b/src/fat.c index a5510151..d8ff8349 100644 --- a/src/fat.c +++ b/src/fat.c @@ -72,6 +72,8 @@ const char indexFile[] = // "\n"; #endif +// WARNING -- code presumes only one NULL .content for .UF2 file +// and requires it be the last element of the array static const struct TextFile info[] = { {.name = "INFO_UF2TXT", .content = infoUf2File}, #if USE_INDEX_HTM @@ -79,11 +81,12 @@ static const struct TextFile info[] = { #endif {.name = "CURRENT UF2"}, }; -#define NUM_INFO (sizeof(info) / sizeof(info[0])) +#define NUM_FILES (sizeof(info) / sizeof(info[0])) +#define NUM_DIRENTRIES (NUM_FILES + 1) // Code adds volume label as first root directory entry #define UF2_SIZE (FLASH_SIZE * 2) #define UF2_SECTORS (UF2_SIZE / 512) -#define UF2_FIRST_SECTOR (NUM_INFO + 1) +#define UF2_FIRST_SECTOR (NUM_FILES + 1) // WARNING -- code presumes each non-UF2 file content fits in single sector #define UF2_LAST_SECTOR (UF2_FIRST_SECTOR + UF2_SECTORS - 1) #endif @@ -96,6 +99,12 @@ static const struct TextFile info[] = { #define START_ROOTDIR (START_FAT1 + SECTORS_PER_FAT) #define START_CLUSTERS (START_ROOTDIR + ROOT_DIR_SECTORS) +// all directory entries must fit in a single sector +// because otherwise current code overflows buffer +#define DIRENTRIES_PER_SECTOR (512/sizeof(DirEntry)) +STATIC_ASSERT(NUM_DIRENTRIES < DIRENTRIES_PER_SECTOR * ROOT_DIR_SECTORS); + + static const FAT_BootBlock BootBlock = { .JumpInstruction = {0xeb, 0x3c, 0x90}, .OEMInfo = "UF2 UF2 ", @@ -103,12 +112,13 @@ static const FAT_BootBlock BootBlock = { .SectorsPerCluster = 1, .ReservedSectors = RESERVED_SECTORS, .FATCopies = 2, - .RootDirectoryEntries = (ROOT_DIR_SECTORS * 512 / 32), + .RootDirectoryEntries = (ROOT_DIR_SECTORS * 512 / DIRENTRIES_PER_SECTOR), .TotalSectors16 = NUM_FAT_BLOCKS - 2, .MediaDescriptor = 0xF8, .SectorsPerFAT = SECTORS_PER_FAT, .SectorsPerTrack = 1, .Heads = 1, + .PhysicalDriveNum = 0x80, // to match MediaDescriptor of 0xF8 .ExtendedBootSig = 0x29, .VolumeSerialNumber = 0x00420042, .VolumeLabel = VOLUME_LABEL, @@ -129,24 +139,27 @@ void read_block(uint32_t block_no, uint8_t *data) { memset(data, 0, 512); uint32_t sectionIdx = block_no; - if (block_no == 0) { + if (block_no == 0) { // Requested boot block memcpy(data, &BootBlock, sizeof(BootBlock)); data[510] = 0x55; data[511] = 0xaa; // logval("data[0]", data[0]); - } else if (block_no < START_ROOTDIR) { + } else if (block_no < START_ROOTDIR) { // Requested FAT table sector sectionIdx -= START_FAT0; // logval("sidx", sectionIdx); if (sectionIdx >= SECTORS_PER_FAT) - sectionIdx -= SECTORS_PER_FAT; + sectionIdx -= SECTORS_PER_FAT; // second FAT is same as the first... #if USE_FAT if (sectionIdx == 0) { data[0] = 0xf0; - for (int i = 1; i < NUM_INFO * 2 + 4; ++i) { + // WARNING -- code presumes only one NULL .content for .UF2 file + // and all non-NULL .content fit in one sector + // and requires it be the last element of the array + for (int i = 1; i < NUM_FILES * 2 + 4; ++i) { data[i] = 0xff; } } - for (int i = 0; i < 256; ++i) { + for (int i = 0; i < 256; ++i) { // Generate the FAT chain for the firmware "file" uint32_t v = sectionIdx * 256 + i; if (UF2_FIRST_SECTOR <= v && v <= UF2_LAST_SECTOR) ((uint16_t *)(void *)data)[i] = v == UF2_LAST_SECTOR ? 0xffff : v + 1; @@ -157,26 +170,29 @@ void read_block(uint32_t block_no, uint8_t *data) { #endif } #if USE_FAT - else if (block_no < START_CLUSTERS) { + else if (block_no < START_CLUSTERS) { // Requested sector of the root directory sectionIdx -= START_ROOTDIR; if (sectionIdx == 0) { DirEntry *d = (void *)data; padded_memcpy(d->name, BootBlock.VolumeLabel, 11); d->attrs = 0x28; - for (int i = 0; i < NUM_INFO; ++i) { + for (int i = 0; i < NUM_FILES; ++i) { d++; const struct TextFile *inf = &info[i]; d->size = inf->content ? strlen(inf->content) : UF2_SIZE; d->startCluster = i + 2; padded_memcpy(d->name, inf->name, 11); + d->createDate = 0x4d99; + d->updateDate = 0x4d99; } } - } else { + } else { // Requested sector from file space sectionIdx -= START_CLUSTERS; - if (sectionIdx < NUM_INFO - 1) { + // WARNING -- code presumes all but last file take exactly one sector + if (sectionIdx < NUM_FILES - 1) { memcpy(data, info[sectionIdx].content, strlen(info[sectionIdx].content)); } else { - sectionIdx -= NUM_INFO - 1; + sectionIdx -= NUM_FILES - 1; uint32_t addr = sectionIdx * 256; if (addr < FLASH_SIZE) { UF2_Block *bl = (void *)data; @@ -187,6 +203,8 @@ void read_block(uint32_t block_no, uint8_t *data) { bl->numBlocks = FLASH_SIZE / 256; bl->targetAddr = addr; bl->payloadSize = 256; + bl->flags |= UF2_FLAG_FAMILYID_PRESENT; + bl->familyID = UF2_FAMILY; memcpy(bl->data, (void *)addr, bl->payloadSize); } } From cca088cf0636d1220ff63b717431b9c56ca75f01 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 28 Mar 2019 16:38:49 -0700 Subject: [PATCH 31/38] Fix #69 - RootDirEntires computation --- src/fat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fat.c b/src/fat.c index d8ff8349..c1dd1077 100644 --- a/src/fat.c +++ b/src/fat.c @@ -112,7 +112,7 @@ static const FAT_BootBlock BootBlock = { .SectorsPerCluster = 1, .ReservedSectors = RESERVED_SECTORS, .FATCopies = 2, - .RootDirectoryEntries = (ROOT_DIR_SECTORS * 512 / DIRENTRIES_PER_SECTOR), + .RootDirectoryEntries = (ROOT_DIR_SECTORS * DIRENTRIES_PER_SECTOR), .TotalSectors16 = NUM_FAT_BLOCKS - 2, .MediaDescriptor = 0xF8, .SectorsPerFAT = SECTORS_PER_FAT, From 34689e380f9d901809510b476df4fa6e106b58b7 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 28 Mar 2019 16:44:43 -0700 Subject: [PATCH 32/38] Use smaller font, rearragne boot screen a bit --- src/images.c | 192 +++++++++++++++++++++++++-------------------------- src/screen.c | 22 +++--- 2 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/images.c b/src/images.c index 34beb967..c5250dac 100644 --- a/src/images.c +++ b/src/images.c @@ -19,100 +19,100 @@ const uint8_t arrowLogo[] = { }; const uint8_t font8[] = { -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x06, 0x5f, 0x5f, 0x06, 0x00, 0x00, -0x00, 0x03, 0x03, 0x00, 0x03, 0x03, 0x00, 0x00, -0x14, 0x7f, 0x7f, 0x14, 0x7f, 0x7f, 0x14, 0x00, -0x24, 0x2e, 0x6b, 0x6b, 0x3a, 0x12, 0x00, 0x00, -0x46, 0x66, 0x30, 0x18, 0x0c, 0x66, 0x62, 0x00, -0x30, 0x7a, 0x4f, 0x5d, 0x37, 0x7a, 0x48, 0x00, -0x04, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x1c, 0x3e, 0x63, 0x41, 0x00, 0x00, 0x00, -0x00, 0x41, 0x63, 0x3e, 0x1c, 0x00, 0x00, 0x00, -0x08, 0x2a, 0x3e, 0x1c, 0x1c, 0x3e, 0x2a, 0x08, -0x08, 0x08, 0x3e, 0x3e, 0x08, 0x08, 0x00, 0x00, -0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, 0x00, -0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, -0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, -0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x01, 0x00, -0x3e, 0x7f, 0x71, 0x59, 0x4d, 0x7f, 0x3e, 0x00, -0x40, 0x42, 0x7f, 0x7f, 0x40, 0x40, 0x00, 0x00, -0x62, 0x73, 0x59, 0x49, 0x6f, 0x66, 0x00, 0x00, -0x22, 0x63, 0x49, 0x49, 0x7f, 0x36, 0x00, 0x00, -0x18, 0x1c, 0x16, 0x53, 0x7f, 0x7f, 0x50, 0x00, -0x27, 0x67, 0x45, 0x45, 0x7d, 0x39, 0x00, 0x00, -0x3c, 0x7e, 0x4b, 0x49, 0x79, 0x30, 0x00, 0x00, -0x03, 0x03, 0x71, 0x79, 0x0f, 0x07, 0x00, 0x00, -0x36, 0x7f, 0x49, 0x49, 0x7f, 0x36, 0x00, 0x00, -0x06, 0x4f, 0x49, 0x69, 0x3f, 0x1e, 0x00, 0x00, -0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, -0x00, 0x80, 0xe6, 0x66, 0x00, 0x00, 0x00, 0x00, -0x08, 0x1c, 0x36, 0x63, 0x41, 0x00, 0x00, 0x00, -0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, -0x00, 0x41, 0x63, 0x36, 0x1c, 0x08, 0x00, 0x00, -0x02, 0x03, 0x51, 0x59, 0x0f, 0x06, 0x00, 0x00, -0x3e, 0x7f, 0x41, 0x5d, 0x5d, 0x1f, 0x1e, 0x00, -0x7c, 0x7e, 0x13, 0x13, 0x7e, 0x7c, 0x00, 0x00, -0x41, 0x7f, 0x7f, 0x49, 0x49, 0x7f, 0x36, 0x00, -0x1c, 0x3e, 0x63, 0x41, 0x41, 0x63, 0x22, 0x00, -0x41, 0x7f, 0x7f, 0x41, 0x63, 0x3e, 0x1c, 0x00, -0x41, 0x7f, 0x7f, 0x49, 0x5d, 0x41, 0x63, 0x00, -0x41, 0x7f, 0x7f, 0x49, 0x1d, 0x01, 0x03, 0x00, -0x1c, 0x3e, 0x63, 0x41, 0x51, 0x73, 0x72, 0x00, -0x7f, 0x7f, 0x08, 0x08, 0x7f, 0x7f, 0x00, 0x00, -0x00, 0x41, 0x7f, 0x7f, 0x41, 0x00, 0x00, 0x00, -0x30, 0x70, 0x40, 0x41, 0x7f, 0x3f, 0x01, 0x00, -0x41, 0x7f, 0x7f, 0x08, 0x1c, 0x77, 0x63, 0x00, -0x41, 0x7f, 0x7f, 0x41, 0x40, 0x60, 0x70, 0x00, -0x7f, 0x7f, 0x0e, 0x1c, 0x0e, 0x7f, 0x7f, 0x00, -0x7f, 0x7f, 0x06, 0x0c, 0x18, 0x7f, 0x7f, 0x00, -0x1c, 0x3e, 0x63, 0x41, 0x63, 0x3e, 0x1c, 0x00, -0x41, 0x7f, 0x7f, 0x49, 0x09, 0x0f, 0x06, 0x00, -0x1e, 0x3f, 0x21, 0x71, 0x7f, 0x5e, 0x00, 0x00, -0x41, 0x7f, 0x7f, 0x09, 0x19, 0x7f, 0x66, 0x00, -0x26, 0x6f, 0x4d, 0x59, 0x73, 0x32, 0x00, 0x00, -0x03, 0x41, 0x7f, 0x7f, 0x41, 0x03, 0x00, 0x00, -0x7f, 0x7f, 0x40, 0x40, 0x7f, 0x7f, 0x00, 0x00, -0x1f, 0x3f, 0x60, 0x60, 0x3f, 0x1f, 0x00, 0x00, -0x7f, 0x7f, 0x30, 0x18, 0x30, 0x7f, 0x7f, 0x00, -0x43, 0x67, 0x3c, 0x18, 0x3c, 0x67, 0x43, 0x00, -0x07, 0x4f, 0x78, 0x78, 0x4f, 0x07, 0x00, 0x00, -0x47, 0x63, 0x71, 0x59, 0x4d, 0x67, 0x73, 0x00, -0x00, 0x7f, 0x7f, 0x41, 0x41, 0x00, 0x00, 0x00, -0x01, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, -0x00, 0x41, 0x41, 0x7f, 0x7f, 0x00, 0x00, 0x00, -0x08, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x08, 0x00, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x00, 0x00, 0x03, 0x07, 0x04, 0x00, 0x00, 0x00, -0x20, 0x74, 0x54, 0x54, 0x3c, 0x78, 0x40, 0x00, -0x41, 0x7f, 0x3f, 0x48, 0x48, 0x78, 0x30, 0x00, -0x38, 0x7c, 0x44, 0x44, 0x6c, 0x28, 0x00, 0x00, -0x30, 0x78, 0x48, 0x49, 0x3f, 0x7f, 0x40, 0x00, -0x38, 0x7c, 0x54, 0x54, 0x5c, 0x18, 0x00, 0x00, -0x48, 0x7e, 0x7f, 0x49, 0x03, 0x02, 0x00, 0x00, -0x98, 0xbc, 0xa4, 0xa4, 0xf8, 0x7c, 0x04, 0x00, -0x41, 0x7f, 0x7f, 0x08, 0x04, 0x7c, 0x78, 0x00, -0x00, 0x44, 0x7d, 0x7d, 0x40, 0x00, 0x00, 0x00, -0x60, 0xe0, 0x80, 0x80, 0xfd, 0x7d, 0x00, 0x00, -0x41, 0x7f, 0x7f, 0x10, 0x38, 0x6c, 0x44, 0x00, -0x00, 0x41, 0x7f, 0x7f, 0x40, 0x00, 0x00, 0x00, -0x7c, 0x7c, 0x18, 0x38, 0x1c, 0x7c, 0x78, 0x00, -0x7c, 0x7c, 0x04, 0x04, 0x7c, 0x78, 0x00, 0x00, -0x38, 0x7c, 0x44, 0x44, 0x7c, 0x38, 0x00, 0x00, -0x84, 0xfc, 0xf8, 0xa4, 0x24, 0x3c, 0x18, 0x00, -0x18, 0x3c, 0x24, 0xa4, 0xf8, 0xfc, 0x84, 0x00, -0x44, 0x7c, 0x78, 0x4c, 0x04, 0x1c, 0x18, 0x00, -0x48, 0x5c, 0x54, 0x54, 0x74, 0x24, 0x00, 0x00, -0x00, 0x04, 0x3e, 0x7f, 0x44, 0x24, 0x00, 0x00, -0x3c, 0x7c, 0x40, 0x40, 0x3c, 0x7c, 0x40, 0x00, -0x1c, 0x3c, 0x60, 0x60, 0x3c, 0x1c, 0x00, 0x00, -0x3c, 0x7c, 0x70, 0x38, 0x70, 0x7c, 0x3c, 0x00, -0x44, 0x6c, 0x38, 0x10, 0x38, 0x6c, 0x44, 0x00, -0x9c, 0xbc, 0xa0, 0xa0, 0xfc, 0x7c, 0x00, 0x00, -0x4c, 0x64, 0x74, 0x5c, 0x4c, 0x64, 0x00, 0x00, -0x08, 0x08, 0x3e, 0x77, 0x41, 0x41, 0x00, 0x00, -0x00, 0x00, 0x00, 0x77, 0x77, 0x00, 0x00, 0x00, -0x41, 0x41, 0x77, 0x3e, 0x08, 0x08, 0x00, 0x00, -0x02, 0x03, 0x01, 0x03, 0x02, 0x03, 0x01, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x5e, 0x00, 0x00, 0x00, +0x00, 0x0e, 0x00, 0x0e, 0x00, 0x00, +0x28, 0xfe, 0x28, 0xfe, 0x28, 0x00, +0x4c, 0x92, 0xff, 0x92, 0x64, 0x00, +0x02, 0x65, 0x12, 0x48, 0xa6, 0x40, +0x6c, 0x92, 0x92, 0x6c, 0xa0, 0x00, +0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, +0x00, 0x00, 0x7c, 0x82, 0x00, 0x00, +0x00, 0x00, 0x82, 0x7c, 0x00, 0x00, +0x54, 0x38, 0x10, 0x38, 0x54, 0x00, +0x10, 0x10, 0x7c, 0x10, 0x10, 0x00, +0x00, 0x00, 0x90, 0x70, 0x00, 0x00, +0x10, 0x10, 0x10, 0x10, 0x10, 0x00, +0x00, 0x00, 0x60, 0x60, 0x00, 0x00, +0x00, 0x60, 0x10, 0x08, 0x06, 0x00, +0x00, 0x3c, 0x42, 0x42, 0x3c, 0x00, +0x00, 0x44, 0x7e, 0x40, 0x00, 0x00, +0x00, 0x44, 0x62, 0x52, 0x4c, 0x00, +0x00, 0x42, 0x4a, 0x4e, 0x32, 0x00, +0x30, 0x28, 0x24, 0x7e, 0x20, 0x00, +0x00, 0x4e, 0x4a, 0x4a, 0x32, 0x00, +0x00, 0x3c, 0x4a, 0x4a, 0x30, 0x00, +0x00, 0x02, 0x62, 0x12, 0x0e, 0x00, +0x00, 0x34, 0x4a, 0x4a, 0x34, 0x00, +0x00, 0x0c, 0x52, 0x52, 0x3c, 0x00, +0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, +0x00, 0x00, 0x96, 0x76, 0x00, 0x00, +0x10, 0x28, 0x28, 0x44, 0x44, 0x00, +0x28, 0x28, 0x28, 0x28, 0x28, 0x00, +0x44, 0x44, 0x28, 0x28, 0x10, 0x00, +0x00, 0x02, 0x59, 0x09, 0x06, 0x00, +0x3c, 0x42, 0x5a, 0x56, 0x08, 0x00, +0x78, 0x14, 0x12, 0x14, 0x78, 0x00, +0x7e, 0x4a, 0x4a, 0x4a, 0x34, 0x00, +0x00, 0x3c, 0x42, 0x42, 0x24, 0x00, +0x00, 0x7e, 0x42, 0x42, 0x3c, 0x00, +0x00, 0x7e, 0x4a, 0x4a, 0x42, 0x00, +0x00, 0x7e, 0x0a, 0x0a, 0x02, 0x00, +0x00, 0x3c, 0x42, 0x52, 0x34, 0x00, +0x00, 0x7e, 0x08, 0x08, 0x7e, 0x00, +0x00, 0x42, 0x7e, 0x42, 0x00, 0x00, +0x20, 0x40, 0x42, 0x3e, 0x02, 0x00, +0x00, 0x7e, 0x08, 0x14, 0x62, 0x00, +0x00, 0x7e, 0x40, 0x40, 0x40, 0x00, +0x7e, 0x04, 0x18, 0x04, 0x7e, 0x00, +0x00, 0x7e, 0x04, 0x08, 0x7e, 0x00, +0x3c, 0x42, 0x42, 0x42, 0x3c, 0x00, +0x00, 0x7e, 0x12, 0x12, 0x0c, 0x00, +0x00, 0x3c, 0x52, 0x62, 0xbc, 0x00, +0x00, 0x7e, 0x12, 0x12, 0x6c, 0x00, +0x00, 0x24, 0x4a, 0x52, 0x24, 0x00, +0x02, 0x02, 0x7e, 0x02, 0x02, 0x00, +0x00, 0x3e, 0x40, 0x40, 0x3e, 0x00, +0x00, 0x1e, 0x70, 0x70, 0x1e, 0x00, +0x7e, 0x20, 0x18, 0x20, 0x7e, 0x00, +0x42, 0x24, 0x18, 0x24, 0x42, 0x00, +0x06, 0x08, 0x70, 0x08, 0x06, 0x00, +0x00, 0x62, 0x52, 0x4a, 0x46, 0x00, +0x00, 0x7e, 0x42, 0x42, 0x00, 0x00, +0x00, 0x06, 0x08, 0x10, 0x60, 0x00, +0x00, 0x42, 0x42, 0x7e, 0x00, 0x00, +0x08, 0x04, 0x02, 0x04, 0x08, 0x00, +0x80, 0x80, 0x80, 0x80, 0x80, 0x00, +0x00, 0x00, 0x02, 0x04, 0x00, 0x00, +0x00, 0x30, 0x48, 0x48, 0x78, 0x00, +0x00, 0x7e, 0x48, 0x48, 0x30, 0x00, +0x00, 0x30, 0x48, 0x48, 0x48, 0x00, +0x00, 0x30, 0x48, 0x48, 0x7e, 0x00, +0x00, 0x30, 0x68, 0x58, 0x50, 0x00, +0x00, 0x10, 0x7c, 0x12, 0x04, 0x00, +0x00, 0x18, 0xa4, 0xa4, 0x78, 0x00, +0x00, 0x7e, 0x08, 0x08, 0x70, 0x00, +0x00, 0x48, 0x7a, 0x40, 0x00, 0x00, +0x00, 0x40, 0x84, 0x7d, 0x00, 0x00, +0x00, 0x7e, 0x10, 0x28, 0x40, 0x00, +0x00, 0x42, 0x7e, 0x40, 0x00, 0x00, +0x78, 0x08, 0x30, 0x08, 0x70, 0x00, +0x00, 0x78, 0x08, 0x08, 0x70, 0x00, +0x00, 0x30, 0x48, 0x48, 0x30, 0x00, +0x00, 0xfc, 0x24, 0x24, 0x18, 0x00, +0x00, 0x18, 0x24, 0x24, 0xfc, 0x00, +0x00, 0x78, 0x10, 0x08, 0x10, 0x00, +0x00, 0x50, 0x58, 0x68, 0x28, 0x00, +0x00, 0x08, 0x3e, 0x48, 0x20, 0x00, +0x00, 0x38, 0x40, 0x40, 0x78, 0x00, +0x00, 0x18, 0x60, 0x60, 0x18, 0x00, +0x38, 0x40, 0x30, 0x40, 0x38, 0x00, +0x00, 0x48, 0x30, 0x30, 0x48, 0x00, +0x00, 0x5c, 0xa0, 0xa0, 0x7c, 0x00, +0x00, 0x48, 0x68, 0x58, 0x48, 0x00, +0x00, 0x08, 0x36, 0x41, 0x00, 0x00, +0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, +0x00, 0x41, 0x36, 0x08, 0x00, 0x00, +0x00, 0x08, 0x04, 0x08, 0x04, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; diff --git a/src/screen.c b/src/screen.c index 14af05b3..54f49522 100644 --- a/src/screen.c +++ b/src/screen.c @@ -244,7 +244,7 @@ extern const uint8_t pendriveLogo[]; extern const uint8_t arrowLogo[]; static void printch(int x, int y, int col, const uint8_t *fnt) { - for (int i = 0; i < 8; ++i) { + for (int i = 0; i < 6; ++i) { uint8_t *p = fb + (x + i) * DISPLAY_HEIGHT + y; uint8_t mask = 0x01; for (int j = 0; j < 8; ++j) { @@ -258,7 +258,7 @@ static void printch(int x, int y, int col, const uint8_t *fnt) { } static void printch4(int x, int y, int col, const uint8_t *fnt) { - for (int i = 0; i < 8 * 4; ++i) { + for (int i = 0; i < 6 * 4; ++i) { uint8_t *p = fb + (x + i) * DISPLAY_HEIGHT + y; uint8_t mask = 0x01; for (int j = 0; j < 8; ++j) { @@ -338,8 +338,8 @@ void print(int x, int y, int col, const char *text) { if (c >= 0x7f) c = '?'; c -= ' '; - printch(x, y, col, &font8[c * 8]); - x += 8; + printch(x, y, col, &font8[c * 6]); + x += 6; } } @@ -347,8 +347,8 @@ void print4(int x, int y, int col, const char *text) { while (*text) { char c = *text++; c -= ' '; - printch4(x, y, col, &font8[c * 8]); - x += 8 * 4; + printch4(x, y, col, &font8[c * 6]); + x += 6 * 4; } } @@ -394,17 +394,17 @@ void draw_drag() { drawBar(52, 55, 8); drawBar(107, 14, 4); - print4(40, 10, 1, "D51"); - print(37, 43, 6, "UF2 " UF2_VERSION_BASE); - print(3, 110, 1, "arcade.makecode.com"); + print4(108, 5, 1, "D5"); + print(112, 40, 6, UF2_VERSION_BASE); + print(23, 110, 1, "arcade.makecode.com"); #define DRAG 70 #define DRAGX 10 printicon(DRAGX + 20, DRAG + 5, 1, fileLogo); printicon(DRAGX + 66, DRAG, 1, arrowLogo); printicon(DRAGX + 108, DRAG, 1, pendriveLogo); - print(2, DRAG - 12, 1, "arcade.uf2"); - print(95, DRAG - 12, 1, "ARCD-D51"); + print(10, DRAG - 12, 1, "arcade.uf2"); + print(98, DRAG - 12, 1, "ARCADE-D5"); draw_screen(); } From a698ed4ad79b2f487b4465da3495042ed4fa8099 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 28 Mar 2019 16:44:57 -0700 Subject: [PATCH 33/38] Use ARCADE-D5 as drive label --- boards/arcade_badge/board_config.h | 2 +- boards/arcade_feather_m4/board_config.h | 2 +- boards/arcade_itsybitsy_m4/board_config.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/boards/arcade_badge/board_config.h b/boards/arcade_badge/board_config.h index 02200232..cad639d9 100644 --- a/boards/arcade_badge/board_config.h +++ b/boards/arcade_badge/board_config.h @@ -3,7 +3,7 @@ #define VENDOR_NAME "Adafruit Industries" #define PRODUCT_NAME "Arcade D51" -#define VOLUME_LABEL "ARCD-D51" +#define VOLUME_LABEL "ARCADE-D5" #define INDEX_URL "http://adafru.it/" #define BOARD_ID "SAMD51J19A-Arcade-D51" diff --git a/boards/arcade_feather_m4/board_config.h b/boards/arcade_feather_m4/board_config.h index 060c26d0..6ce94a4c 100644 --- a/boards/arcade_feather_m4/board_config.h +++ b/boards/arcade_feather_m4/board_config.h @@ -3,7 +3,7 @@ #define VENDOR_NAME "Adafruit Industries" #define PRODUCT_NAME "Feather Arcade D51" -#define VOLUME_LABEL "ARCD-D51" +#define VOLUME_LABEL "ARCADE-D5" #define INDEX_URL "https://arcade.makecode.com/" #define BOARD_ID "SAMD51J19A-Feather-Arcade-D51" diff --git a/boards/arcade_itsybitsy_m4/board_config.h b/boards/arcade_itsybitsy_m4/board_config.h index 721da534..54ce7117 100644 --- a/boards/arcade_itsybitsy_m4/board_config.h +++ b/boards/arcade_itsybitsy_m4/board_config.h @@ -3,7 +3,7 @@ #define VENDOR_NAME "Adafruit Industries" #define PRODUCT_NAME "Itsy Arcade D51" -#define VOLUME_LABEL "ARCD-D51" +#define VOLUME_LABEL "ARCADE-D5" #define INDEX_URL "https://arcade.makecode.com/" #define BOARD_ID "SAMD51G19A-Itsy-Arcade-D51" From c0f3813d7738b58a654a03f841e8fc479e282a94 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 28 Mar 2019 17:12:45 -0700 Subject: [PATCH 34/38] Fix URL to screen mockup script --- src/images.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/images.c b/src/images.c index c5250dac..ad25a816 100644 --- a/src/images.c +++ b/src/images.c @@ -1,6 +1,6 @@ #include -// all https://makecode.com/_FDFFVsKaTUfF +// all https://makecode.com/_VrfEKzV4xfvq // https://makecode.com/_7VxXm3JMPXfM - file // https://makecode.com/_LuEUCsPEKUbs - download From 1e9d3f6d14234c8145b74aa69133d74215cf58b1 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 11 Apr 2019 15:55:19 -0700 Subject: [PATCH 35/38] Add bootloader flashing loop --- Makefile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Makefile b/Makefile index f878accf..00f77a7a 100644 --- a/Makefile +++ b/Makefile @@ -102,6 +102,27 @@ burn: all run: burn wait logs +# This currently only works on macOS with a BMP debugger attached. +# It's meant to flash the bootloader in a loop. +BMP = $(shell ls -1 /dev/cu.usbmodem* | head -1) +BMP_ARGS = --nx -ex "set mem inaccessible-by-default off" -ex "set confirm off" -ex "target extended-remote $(BMP)" -ex "mon swdp_scan" -ex "attach 1" +GDB = arm-none-eabi-gdb + +bmp-flash: $(BUILD_PATH)/$(NAME).bin + @test "X$(BMP)" != "X" + $(GDB) $(BMP_ARGS) -ex "load" -ex "quit" $(BUILD_PATH)/$(NAME).elf | tee build/flash.log + @grep -q "Transfer rate" build/flash.log + +bmp-flashone: + while : ; do $(MAKE) bmp-flash && exit 0 ; sleep 1 ; done + afplay /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/Error.aiff + +bmp-loop: + while : ; do $(MAKE) bmp-flashone ; sleep 5 ; done + +bmp-gdb: $(BUILD_PATH)/$(NAME).bin + $(GDB) $(BMP_ARGS) $(BUILD_PATH)/$(NAME).elf + wait: sleep 5 From 4c2e73e7a0324de02e7aee6bc31430a7028c0934 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 11 Apr 2019 15:56:19 -0700 Subject: [PATCH 36/38] Use a more reliable and longer USB delay (this applies to PXT apps which enter the bootloader with single reset) --- src/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 7349cafe..afc909e5 100644 --- a/src/main.c +++ b/src/main.c @@ -114,7 +114,7 @@ static void check_start_application(void) { *DBL_TAP_PTR = DBL_TAP_MAGIC_QUICK_BOOT; // this will be cleared after succesful USB enumeration // this is around 1.5s - resetHorizon = timerHigh + 300; + resetHorizon = timerHigh + 50; return; } } @@ -244,5 +244,10 @@ int main(void) { process_msc(); } #endif + + if (!main_b_cdc_enable) { + // get more predictable timings before the USB is enumerated + delay(1); + } } } From 61b7505c0e148dfd282446e0c8697ca6c8fb497b Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Fri, 12 Apr 2019 06:44:24 -0700 Subject: [PATCH 37/38] Make sure startup delay is similar on SAMD51 --- src/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index afc909e5..6c0e4d70 100644 --- a/src/main.c +++ b/src/main.c @@ -247,7 +247,9 @@ int main(void) { if (!main_b_cdc_enable) { // get more predictable timings before the USB is enumerated - delay(1); + for (int i = 1; i < 256; ++i) { + asm("nop"); + } } } } From a2fa250358b79c0ba8c0273bedfd31e919ff7c12 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 14 Apr 2019 18:17:35 -0400 Subject: [PATCH 38/38] Repair fuses: if they have been set to all 1's, set them to reasonable values --- inc/uf2.h | 8 ++++---- src/selfmain.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/inc/uf2.h b/inc/uf2.h index b4513715..56aba541 100644 --- a/inc/uf2.h +++ b/inc/uf2.h @@ -272,14 +272,14 @@ void led_init(void); void RGBLED_set_color(uint32_t color); // Not all targets have a LED -#if defined(LED_PIN) +#if defined(LED_PIN) #define LED_MSC_OFF() PINOP(LED_PIN, OUTCLR) #define LED_MSC_ON() PINOP(LED_PIN, OUTSET) #define LED_MSC_TGL() PINOP(LED_PIN, OUTTGL) #else -#define LED_MSC_OFF() -#define LED_MSC_ON() -#define LED_MSC_TGL() +#define LED_MSC_OFF() +#define LED_MSC_ON() +#define LED_MSC_TGL() #endif extern uint32_t timerHigh, resetHorizon; diff --git a/src/selfmain.c b/src/selfmain.c index be74c5a8..764844d1 100644 --- a/src/selfmain.c +++ b/src/selfmain.c @@ -47,15 +47,37 @@ void setBootProt(int v) { fuses[0] = *((uint32_t *)NVM_FUSE_ADDR); fuses[1] = *(((uint32_t *)NVM_FUSE_ADDR) + 1); + bool repair_fuses = false; + // Check for damaged fuses. If the NVM user page was accidentally erased, there + // will be 1's in wrong places. This would enable the watchdog timer and cause other + // problems. So check for all ones outside of the SAMD21/51 BOOTPROT fields, or all ones + // in fuses[1]. If it appears the fuses page was erased, replace fuses with reasonable values. + if ((fuses[0] & 0x03fffff0) == 0x03fffff0 || fuses[1] == 0xffffffff) { + repair_fuses = true; + + // These canonical fuse values taken from working Adafruit SAMD21 and SAMD51 boards. + #ifdef SAMD21 + fuses[0] = 0xD8E0C7FA; + fuses[1] = 0xFFFFFC5D; + #endif + #ifdef SAMD51 + fuses[0] = 0xF69A9239; + fuses[1] = 0xAEECFF80; + #endif + } + uint32_t bootprot = (fuses[0] & NVMCTRL_FUSES_BOOTPROT_Msk) >> NVMCTRL_FUSES_BOOTPROT_Pos; + logval("repair_fuses", repair_fuses); logval("fuse0", fuses[0]); logval("fuse1", fuses[1]); logval("bootprot", bootprot); logval("needed", v); - if (bootprot == v) + // Don't write if nothing will be changed. + if (bootprot == v && !repair_fuses) { return; + } fuses[0] = (fuses[0] & ~NVMCTRL_FUSES_BOOTPROT_Msk) | (v << NVMCTRL_FUSES_BOOTPROT_Pos); @@ -102,14 +124,15 @@ int main(void) { logmsg("Before main loop"); #ifdef SAMD21 - setBootProt(7); // 0k + // Disable BOOTPROT while updating bootloader. + setBootProt(7); // 0k - See "Table 22-2 Boot Loader Size" in datasheet. #endif #ifdef SAMD51 // We only need to set the BOOTPROT once on the SAMD51. For updates, we can // temporarily turn the protection off instead. - if (NVMCTRL->STATUS.bit.BOOTPROT != 13) { - setBootProt(13); // 16k - } + // setBootProt() will only write BOOTPROT if it is not already correct. + // setBootProt() will also fix the fuse values if they appear to be all ones. + setBootProt(13); // 16k. See "Table 25-10 Boot Loader Size" in datasheet. exec_cmd(NVMCTRL_CTRLB_CMD_SBPDIS); NVMCTRL->CTRLA.bit.CACHEDIS0 = true; NVMCTRL->CTRLA.bit.CACHEDIS1 = true; @@ -155,6 +178,7 @@ int main(void) { LED_MSC_OFF(); #ifdef SAMD21 + // Re-enable BOOTPROT setBootProt(2); // 8k #endif // For the SAMD51, the boot protection will automatically be re-enabled on