You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.5 KiB
86 lines
2.5 KiB
5 years ago
|
/* -*- mode: c++ -*-
|
||
|
* kaleidoscope::device::dygma::Raise -- Kaleidoscope device plugin for Dygma Raise
|
||
|
* Copyright (C) 2017-2019 Keyboard.io, Inc
|
||
|
* Copyright (C) 2017-2019 Dygma Lab S.L.
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify it under
|
||
|
* the terms of the GNU General Public License as published by the Free Software
|
||
|
* Foundation, version 3.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
|
* details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License along with
|
||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
#ifdef ARDUINO_SAMD_RAISE
|
||
|
|
||
5 years ago
|
#include "kaleidoscope/Runtime.h"
|
||
|
#include "kaleidoscope/plugin.h"
|
||
5 years ago
|
|
||
|
namespace kaleidoscope {
|
||
|
namespace device {
|
||
|
namespace dygma {
|
||
|
namespace raise {
|
||
|
|
||
|
template <typename _Firmware>
|
||
|
class SideFlash : public kaleidoscope::Plugin {
|
||
|
private:
|
||
|
_Firmware firmware;
|
||
|
public:
|
||
|
EventHandlerResult onFocusEvent(const char *command) {
|
||
|
if (::Focus.handleHelp(command, PSTR("hardware.flash_left_side\nhardware.flash_right_side\nhardware.verify_left_side\nhardware.verify_right_side")))
|
||
|
return EventHandlerResult::OK;
|
||
|
|
||
|
if (strncmp_P(command, PSTR("hardware."), 9) != 0)
|
||
|
return EventHandlerResult::OK;
|
||
|
|
||
5 years ago
|
auto sideFlasher = Runtime.device().sideFlasher();
|
||
|
uint8_t left_boot_address = Runtime.device().side.left_boot_address;
|
||
|
uint8_t right_boot_address = Runtime.device().side.right_boot_address;
|
||
5 years ago
|
enum {
|
||
|
FLASH,
|
||
|
VERIFY
|
||
|
} sub_command;
|
||
|
uint8_t address = 0;
|
||
|
|
||
|
if (strcmp_P(command + 9, PSTR("flash_left_side")) == 0) {
|
||
|
sub_command = FLASH;
|
||
|
address = left_boot_address;
|
||
|
} else if (strcmp_P(command + 9, PSTR("flash_right_side")) == 0) {
|
||
|
sub_command = FLASH;
|
||
|
address = right_boot_address;
|
||
|
} else if (strcmp_P(command + 9, PSTR("verify_left_side")) == 0) {
|
||
|
sub_command = VERIFY;
|
||
|
address = left_boot_address;
|
||
|
} else if (strcmp_P(command + 9, PSTR("verify_right_side")) == 0) {
|
||
|
sub_command = VERIFY;
|
||
|
address = right_boot_address;
|
||
|
} else {
|
||
|
return EventHandlerResult::OK;
|
||
|
}
|
||
|
|
||
|
bool result;
|
||
5 years ago
|
Runtime.device().side.prepareForFlash();
|
||
5 years ago
|
if (sub_command == FLASH)
|
||
|
result = sideFlasher.flash(address, firmware);
|
||
|
else
|
||
|
result = sideFlasher.verify(address, firmware);
|
||
|
::Focus.send(result);
|
||
|
|
||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|