Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fl16-inputmodules/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ pub mod minimal_hal;
pub mod qtpy_hal;

pub mod control;
pub mod picotool_reset;
pub mod serialnum;
93 changes: 93 additions & 0 deletions fl16-inputmodules/src/picotool_reset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//! USB reset interface used by picotool to enter the RP2040 bootloader.
//!
//! Adapted from https://github.com/ithinuel/usbd-picotool-reset (v0.3.0).

// MIT License
//
// Copyright (c) 2023 rp-rs organization
//
// 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.

use core::marker::PhantomData;
use usb_device::{class_prelude::*, control, LangID};

const RESET_REQUEST_BOOTSEL: u8 = 0x01;

pub struct PicoToolReset<B: UsbBus> {
interface: InterfaceNumber,
string: StringIndex,
_bus: PhantomData<B>,
}

impl<B: UsbBus> PicoToolReset<B> {
pub fn new(allocator: &UsbBusAllocator<B>) -> Self {
Self {
interface: allocator.interface(),
string: allocator.string(),
_bus: PhantomData,
}
}

fn is_reset_interface(&self, request: &control::Request) -> bool {
request.request_type == control::RequestType::Class
&& request.recipient == control::Recipient::Interface
&& request.index == u16::from(u8::from(self.interface))
}
}

impl<B: UsbBus> UsbClass<B> for PicoToolReset<B> {
fn get_configuration_descriptors(
&self,
writer: &mut DescriptorWriter,
) -> usb_device::Result<()> {
// Pico SDK reset interface: vendor class, subclass 0, protocol 1.
writer.interface_alt(self.interface, 0, 0xff, 0, 1, Some(self.string))
}

fn get_string(&self, index: StringIndex, _lang_id: LangID) -> Option<&str> {
(index == self.string).then_some("Reset")
}

fn control_out(&mut self, transfer: ControlOut<B>) {
let request = transfer.request();
if !self.is_reset_interface(request) {
return;
}
if request.request != RESET_REQUEST_BOOTSEL {
let _ = transfer.reject();
return;
}

// Bit 8 enables the activity LED; bits 9..13 select its GPIO.
let gpio_mask = if request.value & 0x100 != 0 {
1 << (request.value >> 9)
} else {
0
};
// Forward the bootloader interface flags supplied by picotool.
rp2040_hal::rom_data::reset_to_usb_boot(gpio_mask, u32::from(request.value & 0x7f));
unreachable!();
}

fn control_in(&mut self, transfer: ControlIn<B>) {
if self.is_reset_interface(transfer.request()) {
let _ = transfer.reject();
}
}
}
1 change: 1 addition & 0 deletions fwupd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.cab
3 changes: 3 additions & 0 deletions fwupd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
qtpy.cab: firmware.metainfo.xml
cp ../target/thumbv6m-none-eabi/release/qtpy.uf2 .
gcab -c -v $@ qtpy.uf2 firmware.metainfo.xml
43 changes: 43 additions & 0 deletions fwupd/firmware.metainfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="firmware">
<id>work.frame.inputmodule.qtpy</id>
<name>Framework QT Py</name>
<summary>Firmware for the Framework QT Py</summary>
<description>
<p>
Updating the firmware on your Framework QT Py improves performance and
adds new features.
</p>
</description>
<provides>
<!-- 32ac:0012 -->
<firmware type="flashed">5a5b58d0-9cb4-5f8b-a449-e7b7c820b0cb</firmware>
</provides>
<url type="homepage">https://github.com/FrameworkComputer/inputmodule-rs</url>
<metadata_license>CC0-1.0</metadata_license>
<project_license>proprietary</project_license>
<categories>
<category>X-Device</category>
</categories>
<releases>
<release urgency="normal" version="0.20" date="2024-11-17" install_duration="40">
<checksum filename="qtpy.uf2" target="content"/>
<description>
New firmware!
</description>
</release>
</releases>
<requires>{{ min_ver }}
<id compare="ge" version="1.9.2">org.freedesktop.fwupd</id>
</requires>
<custom>
<!--<value key="LVFS::VersionFormat">{{ version_format }}</value>-->
<value key="LVFS::UpdateProtocol">com.microsoft.uf2</value>
</custom>
<!--
<keywords>
<keyword>{{ keyword }}</keyword>
<keyword>{{ id }}</keyword>
</keywords>
-->
</component>
4 changes: 3 additions & 1 deletion ledmatrix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ use fl16_inputmodules::control::*;
use fl16_inputmodules::games::{pong, snake};
use fl16_inputmodules::matrix::*;
use fl16_inputmodules::patterns::*;
use fl16_inputmodules::picotool_reset::PicoToolReset;
use fl16_inputmodules::serialnum::{device_release, get_serialnum};

// FRA - Framwork
Expand Down Expand Up @@ -201,6 +202,7 @@ fn main() -> ! {

// Set up the USB Communications Class Device driver
let mut serial = SerialPort::new(&usb_bus);
let mut picotool = PicoToolReset::new(&usb_bus);

let serialnum = if let Some(serialnum) = get_serialnum() {
serialnum.serialnum
Expand Down Expand Up @@ -412,7 +414,7 @@ fn main() -> ! {
}

// Check for new data
if usb_dev.poll(&mut [&mut serial]) {
if usb_dev.poll(&mut [&mut serial, &mut picotool]) {
match usb_dev.state() {
// Default: Device has just been created or reset
// Addressed: Device has received an address for the host
Expand Down
6 changes: 5 additions & 1 deletion qtpy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ use usb_device::{class_prelude::*, prelude::*};
// USB Communications Class Device support
use usbd_serial::{SerialPort, USB_CLASS_CDC};

use fl16_inputmodules::picotool_reset::PicoToolReset;

// Used to demonstrate writing formatted strings
// use core::fmt::Write;
// use heapless::String;
Expand Down Expand Up @@ -99,6 +101,8 @@ fn main() -> ! {
&mut pac.RESETS,
));

let mut picotool: PicoToolReset<_> = PicoToolReset::new(&usb_bus);

// Set up the USB Communications Class Device driver
let mut serial = SerialPort::new(&usb_bus);

Expand Down Expand Up @@ -147,7 +151,7 @@ fn main() -> ! {
}

// Check for new data
if usb_dev.poll(&mut [&mut serial]) {
if usb_dev.poll(&mut [&mut picotool, &mut serial]) {
let mut buf = [0u8; 64];
match serial.read(&mut buf) {
Err(_e) => {
Expand Down
Loading