reform

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

commit 944be5616c9aa5a1181fd2a07de8afef9c16bd70
parent abd26239c5bd4a61c5c87e661b60b8ddb6262340
Author: Valtteri Koskivuori <vkoskiv@gmail.com>
Date:   Mon, 23 Oct 2023 19:44:55 +0300

trackball: Add automatic flashing command

Same as for the trackpad, a new 'JTBL' command can kick the device into
bootloader mode, to make flashing much more ergonomic. No need to access
the programming switch and reset button, just run flash.sh

Diffstat:
Mreform2-trackball-fw/Mouse.c | 21++++++++++++++++++---
Mreform2-trackball-fw/flash.sh | 6++++--
2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/reform2-trackball-fw/Mouse.c b/reform2-trackball-fw/Mouse.c @@ -96,6 +96,7 @@ #define LiftCutoff_Tune2 0x65 uint8_t adns_init_complete=0; +uint8_t g_want_bootloader = 0; volatile int xydat[2]; #include "Mouse.h" @@ -320,6 +321,15 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn return false; } +#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_SET_LEDS cmd("LEDS") +#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 @@ -334,12 +344,16 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI const void* ReportData, const uint16_t ReportSize) { - if (ReportSize<4) return; - char* d = (char*)ReportData; - if (d[0]=='L' && d[1]=='E' && d[2]=='D' && d[3]=='S') { + if (ReportSize < 4) return; + const uint32_t command = *(uint32_t *)ReportData; + if (command == CMD_SET_LEDS) { + char* d = (char *)ReportData; uint8_t bits = ((d[4]=='1')<<4)|((d[5]=='1')<<3)|((d[6]=='1')<<2)|((d[7]=='1')<<1)|(d[8]=='1'); led_set(bits); } + if (command == CMD_JUMP_TO_BOOTLOADER) { + g_want_bootloader = 1; + } } int main(void) @@ -353,6 +367,7 @@ int main(void) HID_Device_USBTask(&Mouse_HID_Interface); USB_USBTask(); + if (g_want_bootloader) jump_to_bootloader(); if (!sensor_initialized) { init_sensor(); sensor_initialized = 1; diff --git a/reform2-trackball-fw/flash.sh b/reform2-trackball-fw/flash.sh @@ -1,7 +1,9 @@ +#!/bin/bash +# Kick trackball into bootloader mode, and wait a bit +echo -ne 'xJTBL' > /dev/hidraw2 +sleep 2 dfu-programmer atmega32u2 erase --suppress-bootloader-mem - dfu-programmer atmega32u2 flash ./Mouse.hex --suppress-bootloader-mem - dfu-programmer atmega32u2 start