reform

MNT Reform: Open Source Portable Computer
Log (Feed) | Files | Refs (Tags) | README

commit 3ea6117979e686d6098e6f0f393ea3b4d2075747
parent e07cb294fa1781e1694efce7815e0a9985607a94
Author: Valtteri Koskivuori <vkoskiv@gmail.com>
Date:   Thu, 19 Oct 2023 18:05:27 +0300

trackpad-fw: Add hidraw cmd to set trackpad into bootloader mode

A new 'xJTBL' command can be sent from the host, which causes the
trackpad to jump to the bootloader.
The flash.sh script now sends this command, waits for the trackpad for a
bit, then flashes the new firmware.
With this change, one no longer needs to disassemble the Reform to
access the mode switch and reset button on the back of the trackpad
unit.

Diffstat:
Mreform2-trackpad-fw/Mouse.c | 14++++++++++++++
Mreform2-trackpad-fw/flash.sh | 4++++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/reform2-trackpad-fw/Mouse.c b/reform2-trackpad-fw/Mouse.c @@ -146,6 +146,7 @@ int touched_time = 0; int last_num_fingers = 0; int start_num_fingers = 0; int report_lift = 0; +bool g_want_bootloader = false; #define PRESS_TIME 6 #define MOTION_CLIP 127 @@ -291,6 +292,13 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn return true; } +#define BOOTLOADER_START_ADDRESS ((0x8000 - 0x1000) >> 1) +void jump_to_bootloader(void) { + ((void (*)(void))BOOTLOADER_START_ADDRESS)(); +} + +#define cmd(_s) (*(uint32_t *)(_s)) +#define CMD_JUMP_TO_BOOTLOADER cmd("JTBL") /** HID class driver callback function for the processing of HID reports from the host. * * \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced @@ -306,6 +314,11 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI const uint16_t ReportSize) { // Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports + // if (ReportSize < 4) return; + const uint32_t command = *(uint32_t *)ReportData; + if (command == CMD_JUMP_TO_BOOTLOADER) { + g_want_bootloader = true; + } } @@ -318,5 +331,6 @@ int main(void) { HID_Device_USBTask(&Mouse_HID_Interface); USB_USBTask(); + if (g_want_bootloader) jump_to_bootloader(); } } diff --git a/reform2-trackpad-fw/flash.sh b/reform2-trackpad-fw/flash.sh @@ -1,4 +1,8 @@ +#!/bin/bash +# Kick trackpad into bootloader mode, and wait a bit +echo -ne 'xJTBL' > /dev/hidraw2 +sleep 2 dfu-programmer atmega32u2 erase --suppress-bootloader-mem