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/fwk_keyboard/board.c
@@ -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.
10 changes: 10 additions & 0 deletions ports/raspberrypi/boards/fwk_keyboard/mpconfigboard.h
@@ -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
64 changes: 64 additions & 0 deletions ports/raspberrypi/boards/fwk_keyboard/mpconfigboard.mk
@@ -0,0 +1,64 @@
USB_VID = 0x32AC
USB_PID = 0x0013
Copy link
Author

Choose a reason for hiding this comment

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

TODO: I think I want to rename the board and use a different PID.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Changed to draft.

USB_PRODUCT = "Ledmatrix Laptop 16 Keyboard (CircuitPython)"
USB_MANUFACTURER = "Framework Computer Inc"

CHIP_VARIANT = RP2040
CHIP_FAMILY = rp2

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

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 hav 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
4 changes: 4 additions & 0 deletions ports/raspberrypi/boards/fwk_keyboard/pico-sdk-configboard.h
@@ -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/fwk_keyboard/pins.c
@@ -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) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
4 changes: 4 additions & 0 deletions ports/raspberrypi/supervisor/internal_flash.c
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
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