Skip to content
Snippets Groups Projects
Commit 4ecf2eab authored by minute's avatar minute
Browse files

Merge branch 'trackball-autoflash' into 'master'

trackball: Add automatic flashing command

See merge request reform/reform!52
parents f2e949b0 944be561
Branches
No related tags found
Loading
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
#define LiftCutoff_Tune2 0x65 #define LiftCutoff_Tune2 0x65
uint8_t adns_init_complete=0; uint8_t adns_init_complete=0;
uint8_t g_want_bootloader = 0;
volatile int xydat[2]; volatile int xydat[2];
#include "Mouse.h" #include "Mouse.h"
...@@ -320,6 +321,15 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn ...@@ -320,6 +321,15 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
return false; 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. /** 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 * \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced
...@@ -335,11 +345,15 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI ...@@ -335,11 +345,15 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI
const uint16_t ReportSize) const uint16_t ReportSize)
{ {
if (ReportSize < 4) return; if (ReportSize < 4) return;
const uint32_t command = *(uint32_t *)ReportData;
if (command == CMD_SET_LEDS) {
char* d = (char *)ReportData; char* d = (char *)ReportData;
if (d[0]=='L' && d[1]=='E' && d[2]=='D' && d[3]=='S') {
uint8_t bits = ((d[4]=='1')<<4)|((d[5]=='1')<<3)|((d[6]=='1')<<2)|((d[7]=='1')<<1)|(d[8]=='1'); 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); led_set(bits);
} }
if (command == CMD_JUMP_TO_BOOTLOADER) {
g_want_bootloader = 1;
}
} }
int main(void) int main(void)
...@@ -353,6 +367,7 @@ int main(void) ...@@ -353,6 +367,7 @@ int main(void)
HID_Device_USBTask(&Mouse_HID_Interface); HID_Device_USBTask(&Mouse_HID_Interface);
USB_USBTask(); USB_USBTask();
if (g_want_bootloader) jump_to_bootloader();
if (!sensor_initialized) { if (!sensor_initialized) {
init_sensor(); init_sensor();
sensor_initialized = 1; sensor_initialized = 1;
......
#!/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 erase --suppress-bootloader-mem
dfu-programmer atmega32u2 flash ./Mouse.hex --suppress-bootloader-mem dfu-programmer atmega32u2 flash ./Mouse.hex --suppress-bootloader-mem
dfu-programmer atmega32u2 start dfu-programmer atmega32u2 start
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment