Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

framework_inputmodule: Add new rp2040 based board #8233

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions ports/raspberrypi/boards/framework_inputmodule/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2023 Daniel Schaefer for Framework Computer Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "supervisor/board.h"

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
1 change: 1 addition & 0 deletions ports/raspberrypi/boards/framework_inputmodule/link.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
firmware_size = 512k;
10 changes: 10 additions & 0 deletions ports/raspberrypi/boards/framework_inputmodule/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#define MICROPY_HW_BOARD_NAME "Framework Laptop 16 Keyboard (CircuitPython)"
#define MICROPY_HW_MCU_NAME "rp2040"

#define CIRCUITPY_BOARD_I2C (1)
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO27, .sda = &pin_GPIO26}}
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO27)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO26)
// pin_GPIO0 sleep
// pin_GPIO28 INTB
// pin_GPIO29 SDB
65 changes: 65 additions & 0 deletions ports/raspberrypi/boards/framework_inputmodule/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
USB_VID = 0x32AC
USB_PID = 0x001F
USB_PRODUCT = "Generic Framework 16 Inputmodule"
USB_MANUFACTURER = "Framework Computer"

CHIP_VARIANT = RP2040
CHIP_FAMILY = rp2

QSPI_FLASH_FILESYSTEM = 1
#EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = "W25Q80DV"

# TODO: This is currently not in circuitpython as a frozen directory
# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_IS31FL3731

# Flash is only 1M, reduce firmware to half, so there's space for the CIRCUITPY drive
# Must be accompanied by a linker script change
CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(512 * 1024)'

#CIRCUITPY_DISPLAULAB_HAS_USER_MODULEYIO = 1
CIRCUITPY_TOUCHIO = 1
#CIRCUITPY_PWMIO = 1

# Boards have limited IO, only
# - IS31FL3741/IS31FL3731 LED matrix
# - USB 2.0
# - PWM backlight
# - Capslock LED
#CIRCUITPY_ANALOGIO = 0 # TODO: Might want this
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOBUSIO_I2SOUT = 0
CIRCUITPY_AUDIOCORE = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_AUDIOMIXER = 0
CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_AUDIOPWMIO = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RAINBOWIO = 0
CIRCUITPY_BLEIO_HCI=0
CIRCUITPY_BLEIO=0
CIRCUITPY_PS2IO = 0

CIRCUITPY_MSGPACK = 0
CIRCUITPY_RTC = 1
CIRCUITPY_FRAMEBUFFERIO = 0 # TODO: Might want this
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_TERMINALIO = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_ULAB = 0 # Like numpy for circuitpython
CIRCUITPY_USB_MIDI=0

#CIRCUITPY_BITBANG_APA102 = 0
#CIRCUITPY_BITBANGIO = 1 # Need for I2C
#CIRCUITPY_BITMAPTOOLS = 0
#CIRCUITPY_BUSDEVICE = 1 # TODO: What's this?
#CIRCUITPY_FREQUENCYIO = 0
#CIRCUITPY_I2CTARGET = 1
#CIRCUITPY_NEOPIXEL_WRITE = 0
#CIRCUITPY_NVM = 0
#CIRCUITPY_PIXELBUF = 0
#CIRCUITPY_PULSEIO = 0
#CIRCUITPY_RGBMATRIX = 0
#CIRCUITPY_SAMD = 0
#CIRCUITPY_USB_HID = 0 # TODO: Might want this
#CIRCUITPY_USB_VENDOR = 0 # TODO: Might want this
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Put board-specific pico-sdk definitions here. This file must exist.

// Allow extra time for xosc to start.
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
24 changes: 24 additions & 0 deletions ports/raspberrypi/boards/framework_inputmodule/pins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "shared-bindings/board/__init__.h"

STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS

// SLEEP#
{ MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) },
// INTB
{ MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) },
// SDB
{ MP_ROM_QSTR(MP_QSTR_GP29), MP_ROM_PTR(&pin_GPIO29) },

// PWM
{ MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) },
// Capslock
{ MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24) },

// LED Controller I2C
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO27) },

{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
// Add GP6 and GP7
{ MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) },
// KSO Pins (Key Scan Output)
{ MP_ROM_QSTR(MP_QSTR_KSO0), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_KSO1), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_KSO2), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_KSO3), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_KSO4), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_KSO5), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_KSO6), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_KSO7), MP_ROM_PTR(&pin_GPIO15) },
// Additional KSO pins
{ MP_ROM_QSTR(MP_QSTR_KSO8), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_KSO9), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_KSO10), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_KSO11), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_KSO12), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_KSO13), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_KSO14), MP_ROM_PTR(&pin_GPIO23) },
{ MP_ROM_QSTR(MP_QSTR_KSO15), MP_ROM_PTR(&pin_GPIO22) },
// MUX pins (Multiplexer control)
{ MP_ROM_QSTR(MP_QSTR_MUX_ENABLE), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_MUX_A), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_MUX_B), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_MUX_C), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_BOOT_DONE), MP_ROM_PTR(&pin_GPIO5) },

Adding in the missing changes I believe are necessary to get the board working from FrameworkComputer/Framework_Inputmodule_CircuitPython#2 (comment)

};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
4 changes: 4 additions & 0 deletions ports/raspberrypi/supervisor/internal_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ void port_internal_flash_flush(void) {
// Make sure we don't have an interrupt while we do flash operations.
common_hal_mcu_disable_interrupts();
// and audio DMA must be paused as well
#if CIRCUITPY_AUDIOCORE
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a separate PR for this: #8271

uint32_t channel_mask = audio_dma_pause_all();
#endif
flash_range_erase(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + _cache_lba, SECTOR_SIZE);
flash_range_program(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + _cache_lba, _cache, SECTOR_SIZE);
_cache_lba = NO_CACHE;
#if CIRCUITPY_AUDIOCORE
audio_dma_unpause_mask(channel_mask);
#endif
common_hal_mcu_enable_interrupts();
}

Expand Down