[usb | recovery] Make the code works

This commit is contained in:
Laury
2021-11-26 23:41:53 +01:00
parent d2ec87d9fd
commit fb4b2ffdfa
59 changed files with 232 additions and 769 deletions

View File

@@ -138,7 +138,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
Ion::LED::updateColorWithPlugAndCharge(); Ion::LED::updateColorWithPlugAndCharge();
} }
if (event == Ion::Events::USBEnumeration) { if (event == Ion::Events::USBEnumeration) {
if (Ion::USB::isPlugged() && GlobalPreferences::sharedGlobalPreferences()->getDfuLevel() != 3) { if (Ion::USB::isPlugged()) {
App::Snapshot * activeSnapshot = (s_activeApp == nullptr ? appSnapshotAtIndex(0) : s_activeApp->snapshot()); App::Snapshot * activeSnapshot = (s_activeApp == nullptr ? appSnapshotAtIndex(0) : s_activeApp->snapshot());
/* Just after a software update, the battery timer does not have time to /* Just after a software update, the battery timer does not have time to
* fire before the calculator enters DFU mode. As the DFU mode blocks the * fire before the calculator enters DFU mode. As the DFU mode blocks the
@@ -147,8 +147,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
* pictogram. */ * pictogram. */
updateBatteryState(); updateBatteryState();
if (switchTo(usbConnectedAppSnapshot())) { if (switchTo(usbConnectedAppSnapshot())) {
Ion::USB::DFU(true, GlobalPreferences::sharedGlobalPreferences()->dfuStatus(), GlobalPreferences::sharedGlobalPreferences()->getDfuLevel()); Ion::USB::DFU(true, GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked(), GlobalPreferences::sharedGlobalPreferences()->dfuLevel());
GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false);
// Update LED when exiting DFU mode // Update LED when exiting DFU mode
Ion::LED::updateColorWithPlugAndCharge(); Ion::LED::updateColorWithPlugAndCharge();
bool switched = switchTo(activeSnapshot); bool switched = switchTo(activeSnapshot);

View File

@@ -30,10 +30,10 @@ public:
void setTempExamMode(ExamMode examMode); void setTempExamMode(ExamMode examMode);
bool showPopUp() const { return m_showPopUp; } bool showPopUp() const { return m_showPopUp; }
void setShowPopUp(bool showPopUp) { m_showPopUp = showPopUp; } void setShowPopUp(bool showPopUp) { m_showPopUp = showPopUp; }
bool dfuStatus() const { return m_dfuUnlocked; } bool dfuUnlocked() const { return m_dfuUnlocked; }
void setDfuStatus(bool status) { m_dfuUnlocked = status; } void setDfuUnlocked(bool unlocked) { m_dfuUnlocked = unlocked; }
int getDfuLevel() const { return m_dfuProtectLevel; } int dfuLevel() const { return m_dfuLevel; }
void setDfuLevel(int level) { m_dfuProtectLevel = level; } void setDfuLevel(int level) { m_dfuLevel = level; }
bool autocomplete() const { return m_autoComplete; } bool autocomplete() const { return m_autoComplete; }
void setAutocomplete(bool autocomple) { m_autoComplete = autocomple; } void setAutocomplete(bool autocomple) { m_autoComplete = autocomple; }
int brightnessLevel() const { return m_brightnessLevel; } int brightnessLevel() const { return m_brightnessLevel; }
@@ -41,7 +41,6 @@ public:
const KDFont * font() const { return m_font; } const KDFont * font() const { return m_font; }
void setFont(const KDFont * font) { m_font = font; } void setFont(const KDFont * font) { m_font = font; }
constexpr static int NumberOfBrightnessStates = 15; constexpr static int NumberOfBrightnessStates = 15;
constexpr static int DfuUnlockStep = 3;
private: private:
static_assert(I18n::NumberOfLanguages > 0, "I18n::NumberOfLanguages is not superior to 0"); // There should already have been an error when processing an empty EPSILON_I18N flag static_assert(I18n::NumberOfLanguages > 0, "I18n::NumberOfLanguages is not superior to 0"); // There should already have been an error when processing an empty EPSILON_I18N flag
static_assert(I18n::NumberOfCountries > 0, "I18n::NumberOfCountries is not superior to 0"); // There should already have been an error when processing an empty EPSILON_COUNTRIES flag static_assert(I18n::NumberOfCountries > 0, "I18n::NumberOfCountries is not superior to 0"); // There should already have been an error when processing an empty EPSILON_COUNTRIES flag
@@ -52,7 +51,7 @@ private:
m_tempExamMode(ExamMode::Standard), m_tempExamMode(ExamMode::Standard),
m_showPopUp(true), m_showPopUp(true),
m_dfuUnlocked(false), m_dfuUnlocked(false),
m_dfuProtectLevel(0), m_dfuLevel(0),
m_autoComplete(true), m_autoComplete(true),
m_brightnessLevel(Ion::Backlight::MaxBrightness), m_brightnessLevel(Ion::Backlight::MaxBrightness),
m_font(KDFont::LargeFont) {} m_font(KDFont::LargeFont) {}
@@ -64,8 +63,10 @@ private:
mutable ExamMode m_tempExamMode; mutable ExamMode m_tempExamMode;
bool m_showPopUp; bool m_showPopUp;
bool m_dfuUnlocked; bool m_dfuUnlocked;
uint8_t m_dfuLevel;
bool m_autoComplete; bool m_autoComplete;
int m_brightnessLevel; int m_brightnessLevel;
const KDFont * m_font;
}; };
#endif #endif

View File

@@ -2,5 +2,3 @@ Apps = "Anwendungen"
AppsCapital = "UPSILON" AppsCapital = "UPSILON"
ForbidenAppInExamMode1 = "Diese Anwendung ist im" ForbidenAppInExamMode1 = "Diese Anwendung ist im"
ForbidenAppInExamMode2 = "Prüfungsmodus nicht erlaubt." ForbidenAppInExamMode2 = "Prüfungsmodus nicht erlaubt."
DfuWarning1 = "DFU-Schutzwarnung"
DfuWarning2 = "Mehr Informationen: bit.ly/upsiDfu"

View File

@@ -2,5 +2,3 @@ Apps = "Applications"
AppsCapital = "UPSILON" AppsCapital = "UPSILON"
ForbidenAppInExamMode1 = "This application is" ForbidenAppInExamMode1 = "This application is"
ForbidenAppInExamMode2 = "forbidden in exam mode" ForbidenAppInExamMode2 = "forbidden in exam mode"
DfuWarning1 = "DFU Protection Warning"
DfuWarning2 = "More informations: bit.ly/upsiDfu"

View File

@@ -2,5 +2,3 @@ Apps = "Aplicaciones"
AppsCapital = "UPSILON" AppsCapital = "UPSILON"
ForbidenAppInExamMode1 = "Esta aplicación está prohibida" ForbidenAppInExamMode1 = "Esta aplicación está prohibida"
ForbidenAppInExamMode2 = "en el modo de examen" ForbidenAppInExamMode2 = "en el modo de examen"
DfuWarning1 = "Advertencia de protección DFU"
DfuWarning2 = "Más información: bit.ly/upsiDfu"

View File

@@ -2,5 +2,3 @@ Apps = "Applications"
AppsCapital = "UPSILON" AppsCapital = "UPSILON"
ForbidenAppInExamMode1 = "Cette application n'est" ForbidenAppInExamMode1 = "Cette application n'est"
ForbidenAppInExamMode2 = "pas autorisée en mode examen." ForbidenAppInExamMode2 = "pas autorisée en mode examen."
DfuWarning1 = "Alerte protection DFU"
DfuWarning2 = "Plus d'infos: bit.ly/upsiDfu"

View File

@@ -2,5 +2,3 @@ Apps = "Alkalmazások"
AppsCapital = "UPSILON" AppsCapital = "UPSILON"
ForbidenAppInExamMode1 = "Ez az alkalmazás" ForbidenAppInExamMode1 = "Ez az alkalmazás"
ForbidenAppInExamMode2 = "tilos vizsga módban" ForbidenAppInExamMode2 = "tilos vizsga módban"
DfuWarning1 = "DFU védelmi figyelmeztetés"
DfuWarning2 = "További információk: bit.ly/upsiDfu"

View File

@@ -2,5 +2,3 @@ Apps = "Applicazioni"
AppsCapital = "UPSILON" AppsCapital = "UPSILON"
ForbidenAppInExamMode1 = "Questa applicazione è" ForbidenAppInExamMode1 = "Questa applicazione è"
ForbidenAppInExamMode2 = "proibita nella modalità d'esame" ForbidenAppInExamMode2 = "proibita nella modalità d'esame"
DfuWarning1 = "Avviso protezione DFU"
DfuWarning2 = "Più informazioni: bit.ly/upsiDfu"

View File

@@ -2,5 +2,3 @@ Apps = "Applicaties"
AppsCapital = "UPSILON" AppsCapital = "UPSILON"
ForbidenAppInExamMode1 = "Deze applicatie is" ForbidenAppInExamMode1 = "Deze applicatie is"
ForbidenAppInExamMode2 = "uitgesloten in examenstand" ForbidenAppInExamMode2 = "uitgesloten in examenstand"
DfuWarning1 = "DFU-beveiligingswaarschuwing"
DfuWarning2 = "Meer informatie: bit.ly/upsiDfu"

View File

@@ -2,5 +2,3 @@ Apps = "Aplicações"
AppsCapital = "UPSILON" AppsCapital = "UPSILON"
ForbidenAppInExamMode1 = "Esta aplicação é" ForbidenAppInExamMode1 = "Esta aplicação é"
ForbidenAppInExamMode2 = "proibida no Modo de Exame" ForbidenAppInExamMode2 = "proibida no Modo de Exame"
DfuWarning1 = "Aviso de proteção DFU"
DfuWarning2 = "Mais informações: bit.ly/upsiDfu"

View File

@@ -87,33 +87,9 @@ Controller::Controller(Responder * parentResponder, SelectableTableViewDataSourc
} }
bool Controller::handleEvent(Ion::Events::Event event) { bool Controller::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Six) {
GlobalPreferences::sharedGlobalPreferences()->dfuIncreaseStep();
if (GlobalPreferences::sharedGlobalPreferences()->dfuCurrentStep() >= GlobalPreferences::DfuUnlockStep && !GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) {
if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
Ion::LED::setColor(KDColorPurple);
Ion::LED::setBlinking(500, 0.5f);
}
GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(true);
App::app()->displayWarning(I18n::Message::DfuWarning1, I18n::Message::DfuWarning2);
return true;
} else if (GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) {
if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
Ion::LED::setColor(KDColorBlack);
}
GlobalPreferences::sharedGlobalPreferences()->dfuResetStep();
GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false);
}
}
if (event == Ion::Events::OK || event == Ion::Events::EXE) { if (event == Ion::Events::OK || event == Ion::Events::EXE) {
AppsContainer * container = AppsContainer::sharedAppsContainer(); AppsContainer * container = AppsContainer::sharedAppsContainer();
if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
Ion::LED::setColor(KDColorBlack);
}
GlobalPreferences::sharedGlobalPreferences()->dfuResetStep();
GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false);
int index = selectionDataSource()->selectedRow()*k_numberOfColumns+selectionDataSource()->selectedColumn()+1; int index = selectionDataSource()->selectedRow()*k_numberOfColumns+selectionDataSource()->selectedColumn()+1;
#ifdef HOME_DISPLAY_EXTERNALS #ifdef HOME_DISPLAY_EXTERNALS
if (index >= container->numberOfApps()) { if (index >= container->numberOfApps()) {

View File

@@ -25,8 +25,7 @@ app_settings_src = $(addprefix apps/settings/,\
sub_menu/contributors_controller.cpp \ sub_menu/contributors_controller.cpp \
sub_menu/math_options_controller.cpp \ sub_menu/math_options_controller.cpp \
sub_menu/selectable_view_with_messages.cpp \ sub_menu/selectable_view_with_messages.cpp \
sub_menu/usb_info_controller.cpp \ sub_menu/usb_protection_controller.cpp \
sub_menu/usb_protection_level_controller.cpp \
) )
SFLAGS += -DOMEGA_STATE="$(OMEGA_STATE)" SFLAGS += -DOMEGA_STATE="$(OMEGA_STATE)"
@@ -34,6 +33,6 @@ SFLAGS += -DOMEGA_STATE="$(OMEGA_STATE)"
app_settings_src += $(app_settings_test_src) app_settings_src += $(app_settings_test_src)
apps_src += $(app_settings_src) apps_src += $(app_settings_src)
i18n_files += $(call i18n_without_universal_for,settings/base) i18n_files += $(call i18n_with_universal_for,settings/base)
$(eval $(call depends_on_image,apps/settings/app.cpp,apps/settings/settings_icon.png)) $(eval $(call depends_on_image,apps/settings/app.cpp,apps/settings/settings_icon.png))

View File

@@ -73,7 +73,7 @@ USBExplanation1= "USB-Schutz schützt Ihren"
USBExplanation2= "Taschenrechner vor" USBExplanation2= "Taschenrechner vor"
USBExplanation3= "unbeabsichtigter Verriegelung" USBExplanation3= "unbeabsichtigter Verriegelung"
USBProtection= "USB-Schutz" USBProtection= "USB-Schutz"
USBLevelProtect = "Akzeptierte Updates" USBProtectionLevel = "Akzeptierte Updates"
USBDefaultLevel = "Basierend auf Upsilon" USBDefaultLevel = "Basierend auf Upsilon"
USBLowLevel = "Basierend auf Omega" USBLowLevel = "Basierend auf Omega"
USBParanoidLevel = "Nichts" USBParanoidLevel = "Nichts"

View File

@@ -73,7 +73,7 @@ USBExplanation1= "The USB protection protects"
USBExplanation2= "the calculator from" USBExplanation2= "the calculator from"
USBExplanation3= "unintentional locking" USBExplanation3= "unintentional locking"
USBProtection= "USB Protection" USBProtection= "USB Protection"
USBLevelProtect = "Updates accepted" USBProtectionLevel = "Updates accepted"
USBDefaultLevel = "Based on Upsilon" USBDefaultLevel = "Based on Upsilon"
USBLowLevel = "Based on Omega" USBLowLevel = "Based on Omega"
USBParanoidLevel = "None" USBParanoidLevel = "None"

View File

@@ -73,7 +73,7 @@ USBExplanation1= "La protección USB protege"
USBExplanation2= "su calculadora del" USBExplanation2= "su calculadora del"
USBExplanation3= "bloqueo involuntario" USBExplanation3= "bloqueo involuntario"
USBProtection= "Protección USB" USBProtection= "Protección USB"
USBLevelProtect = "Actualizaciones aceptadas" USBProtectionLevel = "Actualizaciones aceptadas"
USBDefaultLevel = "Basado en Upsilon" USBDefaultLevel = "Basado en Upsilon"
USBLowLevel = "Basado en Omega" USBLowLevel = "Basado en Omega"
USBParanoidLevel = "Ninguno" USBParanoidLevel = "Ninguno"

View File

@@ -73,7 +73,7 @@ USBExplanation1= "La protection USB protège votre"
USBExplanation2= "calculatrice contre un verrouillage" USBExplanation2= "calculatrice contre un verrouillage"
USBExplanation3= "non-intentionnel" USBExplanation3= "non-intentionnel"
USBProtection= "Protection USB" USBProtection= "Protection USB"
USBLevelProtect = "Mise à jour acceptées" USBProtectionLevel = "Mise à jour acceptées"
USBDefaultLevel = "Basées sur Upsilon" USBDefaultLevel = "Basées sur Upsilon"
USBLowLevel = "Basées sur Omega" USBLowLevel = "Basées sur Omega"
USBParanoidLevel = "Aucune" USBParanoidLevel = "Aucune"

View File

@@ -73,8 +73,7 @@ USBExplanation1= "Az USB-védelem megvédi"
USBExplanation2= "a számológépet a nem" USBExplanation2= "a számológépet a nem"
USBExplanation3= "szándékos reteszeléstől" USBExplanation3= "szándékos reteszeléstől"
USBProtection= "USB védelem" USBProtection= "USB védelem"
USBLevelProtect = "Elfogadott frissítések" USBProtectionLevel = "Elfogadott frissítések"
USBDefaultLevel = "Upsilon alapján" USBDefaultLevel = "Upsilon alapján"
USBLowLevel = "Omega alapján" USBLowLevel = "Omega alapján"
USBParanoidLevel = "Egyik sem" USBParanoidLevel = "Egyik sem"

View File

@@ -73,7 +73,7 @@ USBExplanation1= "La protezione USB protegge"
USBExplanation2= "la calcolatrice dal" USBExplanation2= "la calcolatrice dal"
USBExplanation3= "blocco involontario" USBExplanation3= "blocco involontario"
USBProtection= "Protezione USB" USBProtection= "Protezione USB"
USBLevelProtect = "Aggiornamenti accettati" USBProtectionLevel = "Aggiornamenti accettati"
USBDefaultLevel = "Basato su Upsilon" USBDefaultLevel = "Basato su Upsilon"
USBLowLevel = "A base di Omega" USBLowLevel = "A base di Omega"
USBParanoidLevel = "Nessuno" USBParanoidLevel = "Nessuno"

View File

@@ -73,7 +73,7 @@ USBExplanation1= "USB-beveiliging beschermt uw"
USBExplanation2= "rekenmachine tegen" USBExplanation2= "rekenmachine tegen"
USBExplanation3= "onbedoelde vergrendeling" USBExplanation3= "onbedoelde vergrendeling"
USBProtection= "USB-beveiliging" USBProtection= "USB-beveiliging"
USBLevelProtect = "Updates geaccepteerd" USBProtectionLevel = "Updates geaccepteerd"
USBDefaultLevel = "Gebaseerd op Upsilon" USBDefaultLevel = "Gebaseerd op Upsilon"
USBLowLevel = "Op basis van Omega" USBLowLevel = "Op basis van Omega"
USBParanoidLevel = "Geen" USBParanoidLevel = "Geen"

View File

@@ -73,7 +73,7 @@ USBExplanation1= "A proteção USB protege"
USBExplanation2= "sua calculadora contra" USBExplanation2= "sua calculadora contra"
USBExplanation3= "bloqueios não intencionais" USBExplanation3= "bloqueios não intencionais"
USBProtection= "Proteção USB" USBProtection= "Proteção USB"
USBLevelProtect = "Atualizações aceitas" USBProtectionLevel = "Atualizações aceitas"
USBDefaultLevel = "Baseado em Upsilon" USBDefaultLevel = "Baseado em Upsilon"
USBLowLevel = "Baseado em Ômega" USBLowLevel = "Baseado em Ômega"
USBParanoidLevel = "Nenhum" USBParanoidLevel = "Nenhum"

View File

@@ -15,8 +15,8 @@ constexpr SettingsMessageTree s_modelFloatDisplayModeChildren[4] = {SettingsMess
constexpr SettingsMessageTree s_modelComplexFormatChildren[3] = {SettingsMessageTree(I18n::Message::Real), SettingsMessageTree(I18n::Message::Cartesian), SettingsMessageTree(I18n::Message::Polar)}; constexpr SettingsMessageTree s_modelComplexFormatChildren[3] = {SettingsMessageTree(I18n::Message::Real), SettingsMessageTree(I18n::Message::Cartesian), SettingsMessageTree(I18n::Message::Polar)};
constexpr SettingsMessageTree s_modelDateTimeChildren[3] = {SettingsMessageTree(I18n::Message::ActivateClock), SettingsMessageTree(I18n::Message::Date), SettingsMessageTree(I18n::Message::Time)}; constexpr SettingsMessageTree s_modelDateTimeChildren[3] = {SettingsMessageTree(I18n::Message::ActivateClock), SettingsMessageTree(I18n::Message::Date), SettingsMessageTree(I18n::Message::Time)};
constexpr SettingsMessageTree s_symbolChildren[4] = {SettingsMessageTree(I18n::Message::SymbolMultiplicationCross),SettingsMessageTree(I18n::Message::SymbolMultiplicationMiddleDot),SettingsMessageTree(I18n::Message::SymbolMultiplicationStar),SettingsMessageTree(I18n::Message::SymbolMultiplicationAutoSymbol)}; constexpr SettingsMessageTree s_symbolChildren[4] = {SettingsMessageTree(I18n::Message::SymbolMultiplicationCross),SettingsMessageTree(I18n::Message::SymbolMultiplicationMiddleDot),SettingsMessageTree(I18n::Message::SymbolMultiplicationStar),SettingsMessageTree(I18n::Message::SymbolMultiplicationAutoSymbol)};
constexpr SettingsMessageTree s_usbLevelSelector[3] = {SettingsMessageTree(I18n::Message::USBDefaultLevel), SettingsMessageTree(I18n::Message::USBLowLevel), SettingsMessageTree(I18n::Message::USBParanoidLevel)}; constexpr SettingsMessageTree s_usbProtectionChildren[2] = {SettingsMessageTree(I18n::Message::USBProtection), SettingsMessageTree(I18n::Message::USBProtectionLevel, s_usbProtectionLevelChildren)};
constexpr SettingsMessageTree s_usbSteps[2] = {SettingsMessageTree(I18n::Message::USBProtection), SettingsMessageTree(I18n::Message::USBLevelProtect, s_usbLevelSelector)}; constexpr SettingsMessageTree s_usbProtectionLevelChildren[3] = {SettingsMessageTree(I18n::Message::USBDefaultLevel), SettingsMessageTree(I18n::Message::USBLowLevel), SettingsMessageTree(I18n::Message::USBParanoidLevel)};
constexpr SettingsMessageTree s_symbolFunctionChildren[3] = {SettingsMessageTree(I18n::Message::SymbolDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgFunction)}; constexpr SettingsMessageTree s_symbolFunctionChildren[3] = {SettingsMessageTree(I18n::Message::SymbolDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgFunction)};
constexpr SettingsMessageTree s_modelMathOptionsChildren[6] = {SettingsMessageTree(I18n::Message::AngleUnit, s_modelAngleChildren), SettingsMessageTree(I18n::Message::DisplayMode, s_modelFloatDisplayModeChildren), SettingsMessageTree(I18n::Message::EditionMode, s_modelEditionModeChildren), SettingsMessageTree(I18n::Message::SymbolFunction, s_symbolFunctionChildren), SettingsMessageTree(I18n::Message::ComplexFormat, s_modelComplexFormatChildren), SettingsMessageTree(I18n::Message::SymbolMultiplication, s_symbolChildren)}; constexpr SettingsMessageTree s_modelMathOptionsChildren[6] = {SettingsMessageTree(I18n::Message::AngleUnit, s_modelAngleChildren), SettingsMessageTree(I18n::Message::DisplayMode, s_modelFloatDisplayModeChildren), SettingsMessageTree(I18n::Message::EditionMode, s_modelEditionModeChildren), SettingsMessageTree(I18n::Message::SymbolFunction, s_symbolFunctionChildren), SettingsMessageTree(I18n::Message::ComplexFormat, s_modelComplexFormatChildren), SettingsMessageTree(I18n::Message::SymbolMultiplication, s_symbolChildren)};
constexpr SettingsMessageTree s_accessibilityChildren[6] = {SettingsMessageTree(I18n::Message::AccessibilityInvertColors), SettingsMessageTree(I18n::Message::AccessibilityMagnify),SettingsMessageTree(I18n::Message::AccessibilityGamma),SettingsMessageTree(I18n::Message::AccessibilityGammaRed),SettingsMessageTree(I18n::Message::AccessibilityGammaGreen),SettingsMessageTree(I18n::Message::AccessibilityGammaBlue)}; constexpr SettingsMessageTree s_accessibilityChildren[6] = {SettingsMessageTree(I18n::Message::AccessibilityInvertColors), SettingsMessageTree(I18n::Message::AccessibilityMagnify),SettingsMessageTree(I18n::Message::AccessibilityGamma),SettingsMessageTree(I18n::Message::AccessibilityGammaRed),SettingsMessageTree(I18n::Message::AccessibilityGammaGreen),SettingsMessageTree(I18n::Message::AccessibilityGammaBlue)};

View File

@@ -12,7 +12,7 @@
#include "sub_menu/localization_controller.h" #include "sub_menu/localization_controller.h"
#include "sub_menu/math_options_controller.h" #include "sub_menu/math_options_controller.h"
#include "sub_menu/preferences_controller.h" #include "sub_menu/preferences_controller.h"
#include "sub_menu/usb_info_controller.h" #include "sub_menu/usb_protection_controller.h"
namespace Settings { namespace Settings {
@@ -29,8 +29,8 @@ extern const Shared::SettingsMessageTree s_modelDateTimeChildren[3];
extern const Shared::SettingsMessageTree s_accessibilityChildren[6]; extern const Shared::SettingsMessageTree s_accessibilityChildren[6];
extern const Shared::SettingsMessageTree s_contributorsChildren[23]; extern const Shared::SettingsMessageTree s_contributorsChildren[23];
extern const Shared::SettingsMessageTree s_modelAboutChildren[9]; extern const Shared::SettingsMessageTree s_modelAboutChildren[9];
extern const Shared::SettingsMessageTree s_usbLevelSelector[3]; extern const Shared::SettingsMessageTree s_usbProtectionChildren[2];
extern const Shared::SettingsMessageTree s_usbSteps[2]; extern const Shared::SettingsMessageTree s_usbProtectionLevelChildren[3];
extern const Shared::SettingsMessageTree s_model; extern const Shared::SettingsMessageTree s_model;
class MainController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource { class MainController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource {

View File

@@ -18,7 +18,7 @@ constexpr SettingsMessageTree s_modelMenu[] =
#endif #endif
SettingsMessageTree(I18n::Message::BetaPopUp), SettingsMessageTree(I18n::Message::BetaPopUp),
SettingsMessageTree(I18n::Message::About, s_modelAboutChildren), SettingsMessageTree(I18n::Message::About, s_modelAboutChildren),
SettingsMessageTree(I18n::Message::UsbSetting, s_usbSteps), SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren)}; SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren)};
constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu); constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu);

View File

@@ -17,14 +17,14 @@ constexpr SettingsMessageTree s_modelMenu[] =
#ifdef HAS_CODE #ifdef HAS_CODE
SettingsMessageTree(I18n::Message::CodeApp, s_codeChildren), SettingsMessageTree(I18n::Message::CodeApp, s_codeChildren),
#endif #endif
SettingsMessageTree(I18n::Message::UsbSetting, s_usbSteps), SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren), SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren),
SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)}; SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)};
constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu); constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu);
I18n::Message MainController::promptMessage() const { I18n::Message MainController::promptMessage() const {
return I18n::Message::Default; return I18n::Message::Default;
} }
} // namespace Settings }

View File

@@ -18,7 +18,7 @@ constexpr SettingsMessageTree s_modelMenu[] =
#endif #endif
SettingsMessageTree(I18n::Message::UpdatePopUp), SettingsMessageTree(I18n::Message::UpdatePopUp),
SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren), SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren),
SettingsMessageTree(I18n::Message::UsbSetting, s_usbSteps), SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)}; SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)};
constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu); constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu);

View File

@@ -170,6 +170,15 @@ Layout PreferencesController::layoutForPreferences(I18n::Message message) {
return LayoutHelper::String(text, strlen(text), font); return LayoutHelper::String(text, strlen(text), font);
} }
// DFU Protection level
case I18n::Message::USBDefaultLevel:
case I18n::Message::USBLowLevel:
case I18n::Message::USBParanoidLevel:
{
const char * text = " ";
return LayoutHelper::String(text, strlen(text), k_layoutFont);
}
default: default:
assert(false); assert(false);
return Layout(); return Layout();
@@ -213,6 +222,8 @@ void PreferencesController::setPreferenceWithValueIndex(I18n::Message message, i
preferences->setSymbolOfFunction((Preferences::SymbolFunction)valueIndex); preferences->setSymbolOfFunction((Preferences::SymbolFunction)valueIndex);
} else if (message == I18n::Message::FontSizes) { } else if (message == I18n::Message::FontSizes) {
GlobalPreferences::sharedGlobalPreferences()->setFont(valueIndex == 0 ? KDFont::LargeFont : KDFont::SmallFont); GlobalPreferences::sharedGlobalPreferences()->setFont(valueIndex == 0 ? KDFont::LargeFont : KDFont::SmallFont);
} else if (message == I18n::Message::USBProtectionLevel) {
GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(valueIndex);
} }
} }
@@ -239,6 +250,9 @@ int PreferencesController::valueIndexForPreference(I18n::Message message) const
if (message == I18n::Message::FontSizes) { if (message == I18n::Message::FontSizes) {
return GlobalPreferences::sharedGlobalPreferences()->font() == KDFont::LargeFont ? 0 : 1; return GlobalPreferences::sharedGlobalPreferences()->font() == KDFont::LargeFont ? 0 : 1;
} }
if (message == I18n::Message::USBProtectionLevel) {
return GlobalPreferences::sharedGlobalPreferences()->dfuLevel();
}
return 0; return 0;
} }

View File

@@ -1,32 +0,0 @@
#ifndef SETTINGS_USB_INFO_CONTROLLER_H
#define SETTINGS_USB_INFO_CONTROLLER_H
#include "generic_sub_controller.h"
#include "preferences_controller.h"
#include "selectable_view_with_messages.h"
#include "usb_protection_level_controller.h"
namespace Settings {
class UsbInfoController : public GenericSubController {
public:
UsbInfoController(Responder* parentResponder);
View* view() override { return &m_contentView; }
bool handleEvent(Ion::Events::Event event) override;
TELEMETRY_ID("UsbInfo");
void didEnterResponderChain(Responder* previousFirstResponder) override;
HighlightCell* reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
void willDisplayCellForIndex(HighlightCell* cell, int index) override;
private:
static constexpr int k_numberOfExplanationMessages = 3;
MessageTableCellWithSwitch m_switchCell;
UsbProtectionLevelController m_usbProtectionLevelController;
MessageTableCellWithChevronAndMessage m_dfuLevelCell;
};
}
#endif

View File

@@ -1,13 +1,10 @@
#include "usb_info_controller.h" #include "usb_protection_controller.h"
#include <apps/i18n.h> #include <apps/i18n.h>
#include <apps/settings/main_controller.h> #include <apps/settings/main_controller.h>
#include <assert.h> #include <assert.h>
#include <ion/storage.h> #include <ion/storage.h>
#include <poincare/preferences.h> #include <poincare/preferences.h>
#include <cmath>
#include "../../apps_container.h" #include "../../apps_container.h"
#include "../../global_preferences.h" #include "../../global_preferences.h"
@@ -19,37 +16,36 @@ namespace Settings {
UsbInfoController::UsbInfoController(Responder *parentResponder): UsbInfoController::UsbInfoController(Responder *parentResponder):
GenericSubController(parentResponder), GenericSubController(parentResponder),
m_usbProtectionLevelController(this), m_usbProtectionLevelController(this),
m_dfuLevel(KDFont::LargeFont, KDFont::SmallFont) m_contentView(&m_selectableTableView)
{ {
for (int i = 0; i < k_maxSwitchCells; i++) { m_switchCell.setMessageFont(KDFont::LargeFont);
m_switchCells[i].setMessageFont(KDFont::LargeFont); m_dfuLevelCell.setMessageFont(KDFont::LargeFont);
}
} }
bool UsbInfoController::handleEvent(Ion::Events::Event event) { bool UsbInfoController::handleEvent(Ion::Events::Event event) {
if ((Ion::Events::OK == event || Ion::Events::EXE == event) && selectedRow() == 0) { if ((Ion::Events::OK == event || Ion::Events::EXE == event) && selectedRow() == 0) {
if (!GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) { if (!GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked()) {
if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
Ion::LED::setColor(KDColorPurple); Ion::LED::setColor(KDColorPurple);
Ion::LED::setBlinking(500, 0.5f); Ion::LED::setBlinking(500, 0.5f);
} }
GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(true); GlobalPreferences::sharedGlobalPreferences()->setDfuUnlocked(true);
Container::activeApp()->displayWarning(I18n::Message::DfuWarning1, I18n::Message::DfuWarning2);
} else { } else {
if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
Ion::LED::setColor(KDColorBlack); Ion::LED::setColor(KDColorBlack);
} }
GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false); GlobalPreferences::sharedGlobalPreferences()->setDfuUnlocked(false);
} }
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); m_selectableTableView.reloadCellAtLocation(0, 0);
AppsContainer::sharedAppsContainer()->redrawWindow(true);
return true; return true;
} }
// We cannot use things like willExitResponderChain because this view can disappear due to an USB connection, // We cannot use things like willExitResponderChain because this view can disappear due to an USB connection,
// and in this case we must keep the DFU status. // and in this case we must keep the DFU status.
if ((Ion::Events::Left == event || Ion::Events::Home == event) && GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) { if ((Ion::Events::Left == event || Ion::Events::Home == event || Ion::Events::Back == event) && GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked()) {
Container::activeApp()->displayWarning(I18n::Message::USBProtectionReanabled); GlobalPreferences::sharedGlobalPreferences()->setDfuUnlocked(false);
GlobalPreferences::sharedGlobalPreferences()->setDfuStatus(false); m_selectableTableView.reloadCellAtLocation(0, 0);
Container::activeApp()->displayWarning(I18n::Message::USBProtectionReactivated);
return true;
} }
if ((Ion::Events::OK == event || Ion::Events::EXE == event) && selectedRow() == 1) { if ((Ion::Events::OK == event || Ion::Events::EXE == event) && selectedRow() == 1) {
GenericSubController *subController = &m_usbProtectionLevelController; GenericSubController *subController = &m_usbProtectionLevelController;
@@ -63,13 +59,16 @@ bool UsbInfoController::handleEvent(Ion::Events::Event event) {
} }
HighlightCell *UsbInfoController::reusableCell(int index, int type) { HighlightCell *UsbInfoController::reusableCell(int index, int type) {
assert(index == 0 || index == 1); if (index == 0) {
return index == 0 ? &m_switchCell : &m_dfuLevelCell; return &m_switchCell;
}
assert(index == 1);
return &m_dfuLevelCell;
} }
int UsbInfoController::reusableCellCount(int type) { int UsbInfoController::reusableCellCount(int type) {
assert(type == 0); assert(type == 0);
return 1; return 2;
} }
void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index) { void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index) {
@@ -78,10 +77,10 @@ void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index)
if (index == 0) { if (index == 0) {
MessageTableCellWithSwitch *myCell = (MessageTableCellWithSwitch *)cell; MessageTableCellWithSwitch *myCell = (MessageTableCellWithSwitch *)cell;
SwitchView *mySwitch = (SwitchView *)myCell->accessoryView(); SwitchView *mySwitch = (SwitchView *)myCell->accessoryView();
mySwitch->setState(!GlobalPreferences::sharedGlobalPreferences()->dfuStatus()); mySwitch->setState(!GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked());
} else if (index == 1) { } else if (index == 1) {
MessageTableCellWithChevronAndMessage *mcell = (MessageTableCellWithChevronAndMessage *)cell; MessageTableCellWithChevronAndMessage *mcell = (MessageTableCellWithChevronAndMessage *)cell;
int currentLevel = GlobalPreferences::sharedGlobalPreferences()->getDfuLevel(); int currentLevel = GlobalPreferences::sharedGlobalPreferences()->dfuLevel();
if (currentLevel == 0) { if (currentLevel == 0) {
mcell->setSubtitle(I18n::Message::USBDefaultLevelDesc); mcell->setSubtitle(I18n::Message::USBDefaultLevelDesc);
} else if (currentLevel == 1) {; } else if (currentLevel == 1) {;
@@ -94,8 +93,8 @@ void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index)
} }
void UsbInfoController::didEnterResponderChain(Responder *previousFirstResponder) { void UsbInfoController::didEnterResponderChain(Responder *previousFirstResponder) {
m_selectableTableView.reload(); m_contentView.reload();
I18n::Message infoMessages[] = {I18n::Message::USBExplanation1, I18n::Message::USBExplanation2, I18n::Message::USBExplanation3}; I18n::Message infoMessages[] = {I18n::Message::USBExplanation1, I18n::Message::USBExplanation2, I18n::Message::USBExplanation3};
m_selectableTableView.setMessages(infoMessages, k_numberOfExplanationMessages); m_contentView.setMessages(infoMessages, k_numberOfExplanationMessages);
} }
} }

View File

@@ -0,0 +1,30 @@
#ifndef SETTINGS_usb_protection_controller_H
#define SETTINGS_usb_protection_controller_H
#include "generic_sub_controller.h"
#include "preferences_controller.h"
#include "selectable_view_with_messages.h"
namespace Settings {
class UsbInfoController : public GenericSubController {
public:
UsbInfoController(Responder* parentResponder);
View* view() override { return &m_contentView; }
bool handleEvent(Ion::Events::Event event) override;
TELEMETRY_ID("UsbInfo");
void didEnterResponderChain(Responder* previousFirstResponder) override;
HighlightCell* reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
void willDisplayCellForIndex(HighlightCell* cell, int index) override;
private:
static constexpr int k_numberOfExplanationMessages = 3;
PreferencesController m_usbProtectionLevelController;
SelectableViewWithMessages m_contentView;
MessageTableCellWithSwitch m_switchCell;
MessageTableCellWithChevronAndMessage m_dfuLevelCell;
};
}
#endif

View File

@@ -1,77 +0,0 @@
#include "usb_protection_level_controller.h"
#include <apps/i18n.h>
#include <assert.h>
#include "../../apps_container.h"
#include "../../global_preferences.h"
using namespace Poincare;
using namespace Shared;
namespace Settings {
UsbProtectionLevelController::UsbProtectionLevelController(Responder *parentResponder) : GenericSubController(parentResponder) {
for (int i = 0; i < k_maxNumberOfCells; i++) {
m_cell[i].setMessageFont(KDFont::LargeFont);
m_cell[i].setAccessoryFont(KDFont::SmallFont);
}
}
bool UsbProtectionLevelController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
for (int i = 0; i < k_maxNumberOfCells; i++) {
m_cell[i].setAccessoryText("");
}
if (m_messageTreeModel->childAtIndex(selectedRow())->label() == I18n::Message::USBLowLevel) {
GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(1);
} else if (m_messageTreeModel->childAtIndex(selectedRow())->label() == I18n::Message::USBDefaultLevel) {
GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(0);
} else if (m_messageTreeModel->childAtIndex(selectedRow())->label() == I18n::Message::USBParanoidLevel) {
GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(2);
} else if (m_messageTreeModel->childAtIndex(selectedRow())->label() == I18n::Message::USBMegaParanoidLevel) {
GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(3);
}
StackViewController * stack = stackController();
stack->pop();
return true;
} else {
return GenericSubController::handleEvent(event);
}
}
HighlightCell *UsbProtectionLevelController::reusableCell(int index, int type) {
assert(index >= 0 && index < k_maxNumberOfCells);
return &m_cell[index];
}
int UsbProtectionLevelController::reusableCellCount(int type) {
return k_maxNumberOfCells;
}
void UsbProtectionLevelController::willDisplayCellForIndex(HighlightCell *cell, int index) {
GenericSubController::willDisplayCellForIndex(cell, index);
I18n::Message childLabel = m_messageTreeModel->childAtIndex(index)->label();
MessageTableCellWithBuffer *messageComp = (MessageTableCellWithBuffer *)cell;
int currentLevel = GlobalPreferences::sharedGlobalPreferences()->getDfuLevel();
if (childLabel == I18n::Message::USBLowLevel && currentLevel == 1) {
// messageComp->setTextColor(Palette::Green);
messageComp->setAccessoryText("");
} else if (childLabel == I18n::Message::USBDefaultLevel && currentLevel == 0) {
// messageComp->setTextColor(Palette::Green);
messageComp->setAccessoryText("");
} else if (childLabel == I18n::Message::USBParanoidLevel && currentLevel == 2) {
// messageComp->setTextColor(Palette::Green);
messageComp->setAccessoryText("");
} else if (childLabel == I18n::Message::USBMegaParanoidLevel && currentLevel == 3) {
// messageComp->setTextColor(Palette::Green);
messageComp->setAccessoryText("");
}
}
int UsbProtectionLevelController::typeAtLocation(int i, int j) {
return 0;
}
} // namespace Settings

View File

@@ -1,24 +0,0 @@
#ifndef SETTINGS_USB_PROTECTION_LEVEL_CONTROLLER_H
#define SETTINGS_USB_PROTECTION_LEVEL_CONTROLLER_H
#include "generic_sub_controller.h"
#include <escher.h>
namespace Settings {
class UsbProtectionLevelController : public GenericSubController {
public:
UsbProtectionLevelController(Responder * parentResponder);
bool handleEvent(Ion::Events::Event event) override;
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
int typeAtLocation(int i, int j) override;
private:
static constexpr int k_maxNumberOfCells = 3;
MessageTableCellWithBuffer m_cell[k_maxNumberOfCells];
};
}
#endif

View File

@@ -99,15 +99,3 @@ ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "Kein Symbol " ExamModeModeNoSym = "Kein Symbol "
ExamModeModeNoSymNoText = "Kein Symbol kein Text " ExamModeModeNoSymNoText = "Kein Symbol kein Text "
ExamModeModeDutch = "Niederländisch " ExamModeModeDutch = "Niederländisch "
USBE16_expl1= "USB-Schutz schützt Ihren"
USBE16_expl2= "Taschenrechner vor"
USBE16_expl3= "unbeabsichtigter Verriegelung"
USBProtection= "USB-Schutz"
USBSettingDeact = "Bitte schalte den Schutz ein"
USBLevelProtect = "Akzeptierte Updates"
USBDefaultLevel = "Basierend auf Upsilon"
USBLowLevel = "Basierend auf Omega"
USBParanoidLevel = "Nur Python"
USBMegaParanoidLevel = "Nichts"
USBDeacAlert1 = "Ändern Sie diesen Parameter nur,"
USBDeacAlert2 = "wenn Sie wissen, was Sie tun!"

View File

@@ -99,15 +99,3 @@ ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "No sym " ExamModeModeNoSym = "No sym "
ExamModeModeNoSymNoText = "No sym no text " ExamModeModeNoSymNoText = "No sym no text "
ExamModeModeDutch = "Dutch " ExamModeModeDutch = "Dutch "
USBE16_expl1= "The USB protection protects"
USBE16_expl2= "the calculator from"
USBE16_expl3= "unintentional locking"
USBProtection= "USB Protection"
USBSettingDeact = "Please turn on the protection"
USBLevelProtect = "Updates accepted"
USBDefaultLevel = "Based on Upsilon"
USBLowLevel = "Based on Omega"
USBParanoidLevel = "Python Only"
USBMegaParanoidLevel = "None"
USBDeacAlert1 = "Change this parameter only if"
USBDeacAlert2 = "you know what you are doing !"

View File

@@ -99,15 +99,3 @@ ExamModeModeStandard = "Estándar "
ExamModeModeNoSym = "Sin simbólico " ExamModeModeNoSym = "Sin simbólico "
ExamModeModeNoSymNoText = "Sin simbólico sin texto " ExamModeModeNoSymNoText = "Sin simbólico sin texto "
ExamModeModeDutch = "Holandés " ExamModeModeDutch = "Holandés "
USBE16_expl1= "La protección USB protege"
USBE16_expl2= "su calculadora del"
USBE16_expl3= "bloqueo involuntario"
USBProtection= "Protección USB"
USBSettingDeact = "Enciende la protección"
USBLevelProtect = "Actualizaciones aceptadas"
USBDefaultLevel = "Basado en Upsilon"
USBLowLevel = "Basado en Omega"
USBParanoidLevel = "Solo Python"
USBMegaParanoidLevel = "Ninguno"
USBDeacAlert1 = "¡Cambie este parámetro solo"
USBDeacAlert2 = "si sabe lo que está haciendo!"

View File

@@ -99,15 +99,3 @@ ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "Sans symbolique " ExamModeModeNoSym = "Sans symbolique "
ExamModeModeNoSymNoText = "Sans symbolique ni texte " ExamModeModeNoSymNoText = "Sans symbolique ni texte "
ExamModeModeDutch = "Dutch " ExamModeModeDutch = "Dutch "
USBE16_expl1= "La protection USB protège votre"
USBE16_expl2= "calculatrice contre un verrouillage"
USBE16_expl3= "non-intentionnel"
USBProtection= "Protection USB"
USBSettingDeact = "Veuillez activer la protection"
USBLevelProtect = "Mise à jour acceptées"
USBDefaultLevel = "Basées sur Upsilon"
USBLowLevel = "Basées sur Omega"
USBParanoidLevel = "Aucune"
USBMegaParanoidLevel = "Aucune"
USBDeacAlert1 = "Ne modifiez ce paramètre que"
USBDeacAlert2 = "si vous savez ce que vous faites !"

View File

@@ -99,15 +99,3 @@ ExamModeModeStandard = "Normál "
ExamModeModeNoSym = "Szimbólikus nélkül " ExamModeModeNoSym = "Szimbólikus nélkül "
ExamModeModeNoSymNoText = "Szimbólikus és szöveg nélkül " ExamModeModeNoSymNoText = "Szimbólikus és szöveg nélkül "
ExamModeModeDutch = "Holland " ExamModeModeDutch = "Holland "
USBE16_expl1= "Az USB-védelem megvédi"
USBE16_expl2= "a számológépet a nem"
USBE16_expl3= "szándékos reteszeléstől"
USBProtection= "USB védelem"
USBSettingDeact = "Kérjük, kapcsolja be a védelmet"
USBLevelProtect = "Elfogadott frissítések"
USBDefaultLevel = "Upsilon alapján"
USBLowLevel = "Omega alapján"
USBParanoidLevel = "Csak Python"
USBMegaParanoidLevel = "Egyik sem"
USBDeacAlert1 = "Csak akkor módosítsa ezt a"
USBDeacAlert2 = "paramétert, ha tudja, mit csinál!"

View File

@@ -99,15 +99,3 @@ ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "Nessun simbolo " ExamModeModeNoSym = "Nessun simbolo "
ExamModeModeNoSymNoText = "Nessun simbolo nessun testo " ExamModeModeNoSymNoText = "Nessun simbolo nessun testo "
ExamModeModeDutch = "Olandese " ExamModeModeDutch = "Olandese "
USBE16_expl1= "La protezione USB protegge"
USBE16_expl2= "la calcolatrice dal"
USBE16_expl3= "blocco involontario"
USBProtection= "Protezione USB"
USBSettingDeact = "Si prega di attivare la protezione"
USBLevelProtect = "Aggiornamenti accettati"
USBDefaultLevel = "Basato su Upsilon"
USBLowLevel = "A base di Omega"
USBParanoidLevel = "Solo Python"
USBMegaParanoidLevel = "Nessuno"
USBDeacAlert1 = "Cambia questo parametro solo"
USBDeacAlert2 = "se sai cosa stai facendo !"

View File

@@ -99,15 +99,3 @@ ExamModeModeStandard = "Standaard "
ExamModeModeNoSym = "Geen sym " ExamModeModeNoSym = "Geen sym "
ExamModeModeNoSymNoText = "Geen sym geen tekst " ExamModeModeNoSymNoText = "Geen sym geen tekst "
ExamModeModeDutch = "Nederlands " ExamModeModeDutch = "Nederlands "
USBE16_expl1= "USB-beveiliging beschermt uw"
USBE16_expl2= "rekenmachine tegen"
USBE16_expl3= "onbedoelde vergrendeling"
USBProtection= "USB-beveiliging"
USBSettingDeact = "Schakel a.u.b. de bescherming in"
USBLevelProtect = "Updates geaccepteerd"
USBDefaultLevel = "Gebaseerd op Upsilon"
USBLowLevel = "Op basis van Omega"
USBParanoidLevel = "Alleen Python"
USBMegaParanoidLevel = "Geen"
USBDeacAlert1 = "Wijzig deze parameter alleen"
USBDeacAlert2 = "als u weet wat u doet!"

View File

@@ -99,15 +99,3 @@ ExamModeModeStandard = "Padrão "
ExamModeModeNoSym = "Sem sym " ExamModeModeNoSym = "Sem sym "
ExamModeModeNoSymNoText = "Sem sym sem texto " ExamModeModeNoSymNoText = "Sem sym sem texto "
ExamModeModeDutch = "holandês " ExamModeModeDutch = "holandês "
USBE16_expl1= "A proteção USB protege"
USBE16_expl2= "sua calculadora contra"
USBE16_expl3= "bloqueios não intencionais"
USBProtection= "Proteção USB"
USBSettingDeact = "Por favor, ligue a proteção"
USBLevelProtect = "Atualizações aceitas"
USBDefaultLevel = "Baseado em Upsilon"
USBLowLevel = "Baseado em Ômega"
USBParanoidLevel = "Apenas Python"
USBMegaParanoidLevel = "Nenhum"
USBDeacAlert1 = "Mude este parâmetro somente"
USBDeacAlert2 = "se você souber o que está fazendo!"

View File

@@ -458,11 +458,6 @@ HartreeConstant = "4.3597447222071·10^-18_J"
MagneticFluxQuantum = "2.067833848·10^-15_Wb" MagneticFluxQuantum = "2.067833848·10^-15_Wb"
ConductanceQuantum = "7.748091729·10^-5_S" ConductanceQuantum = "7.748091729·10^-5_S"
CirculationQuantum = "3.6369475516·10^-4_m^2_s^-1" CirculationQuantum = "3.6369475516·10^-4_m^2_s^-1"
UsbSetting = "USB"
USBDefaultLevelDesc = "L0"
USBLowLevelDesc = "L1"
USBParanoidLevelDesc = "L2"
USBMegaParanoidLevelDesc = "L3"
Cndcvt_Silver = "6.30·10^7_S_m^-1" Cndcvt_Silver = "6.30·10^7_S_m^-1"
Cndcvt_Copper = "5.96·10^7_S_m^-1" Cndcvt_Copper = "5.96·10^7_S_m^-1"
Cndcvt_Gold = "4.11·10^7_S_m^-1" Cndcvt_Gold = "4.11·10^7_S_m^-1"

View File

@@ -1,7 +1,6 @@
app_usb_src = $(addprefix apps/usb/,\ app_usb_src = $(addprefix apps/usb/,\
app.cpp \ app.cpp \
usb_connected_controller.cpp \ usb_connected_controller.cpp \
usb_view.cpp \
) )
apps_src += $(app_usb_src) apps_src += $(app_usb_src)

View File

@@ -27,7 +27,6 @@ App::App(Snapshot * snapshot) :
} }
bool App::processEvent(Ion::Events::Event e) { bool App::processEvent(Ion::Events::Event e) {
// Impossible de gérer mes events ici lorsqu'on active le DFU
return false; return false;
} }

View File

@@ -11,3 +11,4 @@ DfuStatusUnprotected = "UNGESCHÜTZT"
USBProtectionLevel0 = "Standardschutz" USBProtectionLevel0 = "Standardschutz"
USBProtectionLevel1 = "Omega Schutz" USBProtectionLevel1 = "Omega Schutz"
USBProtectionLevel2 = "Systemschutz" USBProtectionLevel2 = "Systemschutz"
USBProtectionReactivated = "USB-Schutz wurde wieder aktiviert"

View File

@@ -11,3 +11,4 @@ DfuStatusUnprotected = "UNPROTECTED"
USBProtectionLevel0 = "Default Protection" USBProtectionLevel0 = "Default Protection"
USBProtectionLevel1 = "Omega Protection" USBProtectionLevel1 = "Omega Protection"
USBProtectionLevel2 = "System Protection" USBProtectionLevel2 = "System Protection"
USBProtectionReactivated = "USB Protection reactivated"

View File

@@ -11,3 +11,4 @@ DfuStatusUnprotected = "DESABRIGADO"
USBProtectionLevel0 = "Protección predeterminada" USBProtectionLevel0 = "Protección predeterminada"
USBProtectionLevel1 = "Protección Omega" USBProtectionLevel1 = "Protección Omega"
USBProtectionLevel2 = "Protección del sistema" USBProtectionLevel2 = "Protección del sistema"
USBProtectionReactivated = "La protección de la calculadora ha sido reactivada"

View File

@@ -11,3 +11,4 @@ DfuStatusUnprotected = "NON PROTÉGÉE"
USBProtectionLevel0 = "Default Protection" USBProtectionLevel0 = "Default Protection"
USBProtectionLevel1 = "Omega Protection" USBProtectionLevel1 = "Omega Protection"
USBProtectionLevel2 = "System Protection" USBProtectionLevel2 = "System Protection"
USBProtectionReactivated = "La protection USB a été réactivée"

View File

@@ -11,3 +11,4 @@ DfuStatusUnprotected = "VÉDTELEN"
USBProtectionLevel0 = "Alapértelmezett védelem" USBProtectionLevel0 = "Alapértelmezett védelem"
USBProtectionLevel1 = "Omega védelem" USBProtectionLevel1 = "Omega védelem"
USBProtectionLevel2 = "Rendszervédelem" USBProtectionLevel2 = "Rendszervédelem"
USBProtectionReactivated = "A védelem újra aktiválva"

View File

@@ -11,3 +11,4 @@ DfuStatusUnprotected = "INDIFESO"
USBProtectionLevel0 = "Protezione predefinita" USBProtectionLevel0 = "Protezione predefinita"
USBProtectionLevel1 = "Protezione Omega" USBProtectionLevel1 = "Protezione Omega"
USBProtectionLevel2 = "Protezione del sistema" USBProtectionLevel2 = "Protezione del sistema"
USBProtectionReactivated = "Protezione riattivata"

View File

@@ -11,3 +11,4 @@ DfuStatusUnprotected = "NIET BESCHERMD"
USBProtectionLevel0 = "Standaardbeveiliging" USBProtectionLevel0 = "Standaardbeveiliging"
USBProtectionLevel1 = "Omega Bescherming" USBProtectionLevel1 = "Omega Bescherming"
USBProtectionLevel2 = "Systeembeveiliging" USBProtectionLevel2 = "Systeembeveiliging"
USBProtectionReactivated = "USB-bescherming is geactiveerd"

View File

@@ -11,3 +11,4 @@ DfuStatusUnprotected = "DESPROTEGIDO"
USBProtectionLevel0 = "Proteção padrão" USBProtectionLevel0 = "Proteção padrão"
USBProtectionLevel1 = "Proteção Ômega" USBProtectionLevel1 = "Proteção Ômega"
USBProtectionLevel2 = "Proteção do sistema" USBProtectionLevel2 = "Proteção do sistema"
USBProtectionReactivated = "Proteção reativada"

View File

@@ -2,9 +2,9 @@
#include <apps/i18n.h> #include <apps/i18n.h>
#include "../global_preferences.h" #include "../global_preferences.h"
namespace USB namespace USB {
{
static constexpr I18n::Message sUSBConnectedMessages[k_numberOfUSBMessages] = { static constexpr I18n::Message sUSBConnectedMessages[] = {
I18n::Message::USBConnected, I18n::Message::USBConnected,
I18n::Message::ConnectedMessage1, I18n::Message::ConnectedMessage1,
I18n::Message::ConnectedMessage2, I18n::Message::ConnectedMessage2,
@@ -33,35 +33,35 @@ USBConnectedController::USBConnectedController() :
} }
USBConnectedController::ContentView::ContentView(KDColor * fgcolors, KDColor * bgcolors, uint8_t numberOfMessages) { USBConnectedController::ContentView::ContentView() {
// We set the styles of the messages // We set the styles of the messages
for (uint8_t i = 0; i < k_numberOfMessages; i++) { for (uint8_t i = 0; i < k_numberOfMessages; i++) {
m_messageTextViews[i].setFont(i == 0 ? KDFont::LargeFont : KDFont::SmallFont); m_messageTextViews[i].setFont(i == 0 ? KDFont::LargeFont : KDFont::SmallFont);
m_messageTextViews[i].setAlignment(0.5f, 0.5f); m_messageTextViews[i].setAlignment(0.5f, 0.5f);
m_messageTextViews[i].setTextColor(fgcolors[i]); m_messageTextViews[i].setTextColor(sUSBConnectedFGColors[i]);
m_messageTextViews[i].setBackgroundColor(Palette::BackgroundHard); m_messageTextViews[i].setBackgroundColor(Palette::BackgroundHard);
} }
// We set the texts of the firsts defaults messages // We set the texts of the firsts defaults messages
for (uint8_t i = 0; i < k_numberOfUSBMessages; i++) { for (uint8_t i = 0; i < k_numberOfUSBMessages; i++) {
m_messageTextViews[i].setText(sUSBConnectedMessages[i]); m_messageTextViews[i].setText(I18n::translate(sUSBConnectedMessages[i]));
} }
// Last message, depending of the USB protection level // Last message, depending of the USB protection level
if (GlobalPreferences::sharedGlobalPreferences()->dfuStatus()) { if (GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked()) {
m_messageTextViews[i].setText(DfuStatusUnprotected); m_messageTextViews[k_numberOfUSBMessages].setText(I18n::translate(I18n::Message::DfuStatusUnprotected));
} else { } else {
int protectionLevel = GlobalPreferences::sharedGlobalPreferences()->getDfuLevel(); int protectionLevel = GlobalPreferences::sharedGlobalPreferences()->dfuLevel();
switch (protectionLevel) { switch (protectionLevel) {
case 0: case 0:
m_messageTextViews[9].setText(USBProtectionLevel0); m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel0));
break; break;
case 1: case 1:
m_messageTextViews[9].setText(USBProtectionLevel1); m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel1));
break; break;
default: default:
assert(protectionLevel == 2); assert(protectionLevel == 2);
m_messageTextViews[9].setText(USBProtectionLevel2); m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel2));
break; break;
} }
} }

View File

@@ -8,11 +8,12 @@ namespace USB {
class USBConnectedController : public ViewController { class USBConnectedController : public ViewController {
public: public:
USBConnectedController(); USBConnectedController();
View * view() override { return &m_messageView; } View * view() override { return &m_contentView; }
USBView * getMessageView() {return &m_messageView; }
bool handleEvent(Ion::Events::Event event) override { return false; }; bool handleEvent(Ion::Events::Event event) override { return false; };
private:
class ContentView : public View {
public: public:
ContentView(KDColor * fgcolors, KDColor * bgcolors); ContentView();
void drawRect(KDContext * ctx, KDRect rect) const override; void drawRect(KDContext * ctx, KDRect rect) const override;
protected: protected:
int numberOfSubviews() const override { return k_numberOfMessages; } int numberOfSubviews() const override { return k_numberOfMessages; }

View File

@@ -1,8 +1,8 @@
import sys import sys
import os import os
MAGIK_CODE = [0x64, 0x6c, 0x31, 0x31, 0x23, 0x39, 0x38, 0x33, 0x35] MAGIK_CODE = [0x32, 0x30, 0x30, 0x36]
MAGIK_POS = [0x03, 0xb, 0x44f] MAGIK_POS = 0x44F
if len(sys.argv) > 1: if len(sys.argv) > 1:
print("Patching external bin...") print("Patching external bin...")
@@ -18,11 +18,7 @@ if len(sys.argv) > 1:
sys.exit(-1) sys.exit(-1)
for i in range(4): for i in range(4):
first_packet[MAGIK_POS[0] + i] = MAGIK_CODE[i] first_packet[MAGIK_POS + i] = MAGIK_CODE[i]
for i in range(4):
first_packet[MAGIK_POS[1] + i] = MAGIK_CODE[i + 5]
for i in range(len(MAGIK_CODE)):
first_packet[MAGIK_POS[2] + i] = MAGIK_CODE[i]
file.seek(0) file.seek(0)
file.write(first_packet) file.write(first_packet)

View File

@@ -27,11 +27,11 @@ $(BUILD_DIR)/%.map: $(BUILD_DIR)/%.elf
@echo "LDMAP $@" @echo "LDMAP $@"
$(Q) $(LD) $^ $(LDFLAGS) -Wl,-M -Wl,-Map=$@ -o /dev/null $(Q) $(LD) $^ $(LDFLAGS) -Wl,-M -Wl,-Map=$@ -o /dev/null
.PHONY: mapfile .PHONY: %_memory_map
mapfile: %_memory_map: $(BUILD_DIR)/%.map
$(BUILD_DIR)/%.map: $(BUILD_DIR)/%.elf @echo "========== MEMORY MAP ========="
@echo "LDMAP $@" $(Q) awk -f build/device/memory_map.awk < $<
$(Q) $(LD) $^ $(LDFLAGS) -Wl,-M -Wl,-Map=$@ -o /dev/null @echo "==============================="
.PHONY: openocd .PHONY: openocd
openocd: openocd:

View File

@@ -123,7 +123,7 @@ void init() {
initClocks(); initClocks();
// The bootloader leaves its own after flashing // The bootloader leaves its own after flashing
// SYSCFG.MEMRMP()->setMEM_MODE(SYSCFG::MEMRMP::MemMode::MainFlashmemory); //SYSCFG.MEMRMP()->setMEM_MODE(SYSCFG::MEMRMP::MemMode::MainFlashmemory);
// Ensure right location of interrupt vectors // Ensure right location of interrupt vectors
CORTEX.VTOR()->setVTOR((void*)&InitialisationVector); CORTEX.VTOR()->setVTOR((void*)&InitialisationVector);

View File

@@ -8,7 +8,7 @@ extern "C" {
void bf_abort(); void bf_abort();
void uf_abort(); void uf_abort();
void nmi_abort(); void nmi_abort();
// Here and below, we mean init the abort handler, not the opposite // Here and below, we are doing operations on the abort handler, not the opposite
void abort_init(); void abort_init();
void abort_core(const char *); void abort_core(const char *);
void abort_screen(const char *); void abort_screen(const char *);

View File

@@ -1,4 +1,3 @@
#include "isr.h"
#include <drivers/battery.h> #include <drivers/battery.h>
#include <drivers/cache.h> #include <drivers/cache.h>
#include <drivers/external_flash.h> #include <drivers/external_flash.h>
@@ -28,20 +27,20 @@
typedef void (*cxx_constructor)(); typedef void (*cxx_constructor)();
extern "C" { extern "C" {
extern char _data_section_start_flash; extern char _data_section_start_flash;
extern char _data_section_start_ram; extern char _data_section_start_ram;
extern char _data_section_end_ram; extern char _data_section_end_ram;
extern char _bss_section_start_ram; extern char _bss_section_start_ram;
extern char _bss_section_end_ram; extern char _bss_section_end_ram;
extern cxx_constructor _init_array_start; extern cxx_constructor _init_array_start;
extern cxx_constructor _init_array_end; extern cxx_constructor _init_array_end;
} }
/* In order to ensure that this method is execute from the external flash, we /* In order to ensure that this method is execute from the external flash, we
* forbid inlining it.*/ * forbid inlining it.*/
static void __attribute__((noinline)) external_flash_start() { static void __attribute__((noinline)) external_flash_start() {
/* Init the peripherals. We do not initialize the backlight in case there is /* Init the peripherals. We do not initialize the backlight in case there is
* an on boarding app: indeed, we don't want the user to see the LCD tests * an on boarding app: indeed, we don't want the user to see the LCD tests
* happening during the on boarding app. The backlight will be initialized * happening during the on boarding app. The backlight will be initialized
* after the Power-On Self-Test if there is one or before switching to the * after the Power-On Self-Test if there is one or before switching to the
@@ -69,155 +68,7 @@ static void __attribute__((noinline)) external_flash_start() {
* internal flash to the external flash. */ * internal flash to the external flash. */
static void __attribute__((noinline)) jump_to_external_flash() { static void __attribute__((noinline)) jump_to_external_flash() {
external_flash_start(); external_flash_start();
}
void __attribute__((noinline)) abort_init() {
Ion::Device::Board::shutdownPeripherals(true);
Ion::Device::Board::initPeripherals(false);
Ion::Timing::msleep(100);
Ion::Backlight::init();
Ion::LED::setColor(KDColorRed);
Ion::Backlight::setBrightness(180);
}
void __attribute__((noinline)) abort_economy() {
int brightness = Ion::Backlight::brightness();
bool plugged = Ion::USB::isPlugged();
while (brightness > 0) {
brightness--;
Ion::Backlight::setBrightness(brightness);
Ion::Timing::msleep(50);
if(plugged || (!plugged && Ion::USB::isPlugged())){
Ion::Backlight::setBrightness(180);
return;
}
}
Ion::Backlight::shutdown();
while (1) {
Ion::Device::Power::sleepConfiguration();
Ion::Device::WakeUp::onUSBPlugging();
Ion::Device::WakeUp::onChargingEvent();
Ion::Device::Power::internalFlashSuspend(true);
if (!plugged && Ion::USB::isPlugged()) {
break;
}
plugged = Ion::USB::isPlugged();
};
Ion::Device::Board::setStandardFrequency(Ion::Device::Board::Frequency::High);
Ion::Backlight::init();
Ion::Backlight::setBrightness(180);
}
void __attribute__((noinline)) abort_sleeping() {
if (Ion::Battery::level() != Ion::Battery::Charge::EMPTY) {
return;
}
// we don't use Ion::Power::suspend because we don't want to move the exam buffer into the internal
Ion::Device::Board::shutdownPeripherals(true);
bool plugged = Ion::USB::isPlugged();
while (1) {
Ion::Device::Battery::initGPIO();
Ion::Device::USB::initGPIO();
Ion::Device::LED::init();
Ion::Device::Power::sleepConfiguration();
Ion::Device::Board::shutdownPeripherals(true);
Ion::Device::WakeUp::onUSBPlugging();
Ion::Device::WakeUp::onChargingEvent();
Ion::Device::Power::internalFlashSuspend(true);
Ion::Device::USB::initGPIO();
if (!plugged && Ion::USB::isPlugged()) {
break;
}
plugged = Ion::USB::isPlugged();
}
Ion::Device::Board::setStandardFrequency(Ion::Device::Board::Frequency::High);
abort_init();
}
void __attribute__((noinline)) abort_core(const char * text) {
Ion::Timing::msleep(100);
int counting;
while (true) {
counting = 0;
if (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) {
abort_sleeping();
abort_screen(text);
}
Ion::USB::enable();
Ion::Battery::Charge previous_state = Ion::Battery::level();
while (!Ion::USB::isEnumerated()) {
if (Ion::Battery::level() == Ion::Battery::Charge::LOW) {
if (previous_state != Ion::Battery::Charge::LOW) {
previous_state = Ion::Battery::Charge::LOW;
counting = 0;
}
Ion::Timing::msleep(500);
if (counting >= 20) {
abort_sleeping();
abort_screen(text);
counting = -1;
}
counting++;
} else {
if (previous_state == Ion::Battery::Charge::LOW) {
previous_state = Ion::Battery::level();
counting = 0;
}
Ion::Timing::msleep(100);
if (counting >= 300) {
abort_economy();
counting = -1;
}
counting++;
}
}
Ion::USB::DFU(false, false, 0);
}
}
void __attribute__((noinline)) abort_screen(const char * text){
KDRect screen = KDRect(0, 0, Ion::Display::Width, Ion::Display::Height);
Ion::Display::pushRectUniform(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height), KDColor::RGB24(0xffffff));
KDContext* ctx = KDIonContext::sharedContext();
ctx->setOrigin(KDPointZero);
ctx->setClippingRect(screen);
ctx->drawString("UPSILON CRASH", KDPoint(90, 10), KDFont::LargeFont, KDColorRed, KDColor::RGB24(0xffffff));
ctx->drawString("An error occurred", KDPoint(10, 30), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString("If you have some important data, please", KDPoint(10, 45), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString("use bit.ly/upsiBackup to backup them.", KDPoint(10, 60), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString("YOU WILL LOSE ALL YOUR DATA", KDPoint(10, 85), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString("→ You can try to reboot by presssing the", KDPoint(10, 110), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString("reset button at the back of the calculator", KDPoint(10, 125), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString("→ If Upsilon keeps crashing, you can connect", KDPoint(10, 140), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString("the calculator to a computer or a phone", KDPoint(10, 160), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString("and try to reinstall Upsilon", KDPoint(10, 175), KDFont::SmallFont, KDColorBlack, KDColor::RGB24(0xffffff));
ctx->drawString(text, KDPoint(220, 200), KDFont::SmallFont, KDColorRed, KDColor::RGB24(0xffffff));
}
void __attribute__((noinline)) abort() {
abort_init();
abort_screen("HARDFAULT");
abort_core("HARDFAULT");
}
void __attribute__((noinline)) nmi_abort() {
abort_init();
abort_screen("NMIFAULT");
abort_core("NMIFAULT");
}
void __attribute__((noinline)) bf_abort() {
abort_init();
abort_screen("BUSFAULT");
abort_core("BUSFAULT");
}
void __attribute__((noinline)) uf_abort() {
abort_init();
abort_screen("USAGEFAULT");
abort_core("USAGEFAULT");
} }
void __attribute__((noinline)) abort_init() { void __attribute__((noinline)) abort_init() {
@@ -261,10 +112,10 @@ void __attribute__((noinline)) abort_sleeping() {
if (Ion::Battery::level() != Ion::Battery::Charge::EMPTY) { if (Ion::Battery::level() != Ion::Battery::Charge::EMPTY) {
return; return;
} }
// We don't use Ion::Power::suspend because we don't want to move the exam buffer into the internal // we don't use Ion::Power::suspend because we don't want to move the exam buffer into the internal
Ion::Device::Board::shutdownPeripherals(true); Ion::Device::Board::shutdownPeripherals(true);
bool plugged = Ion::USB::isPlugged(); bool plugged = Ion::USB::isPlugged();
while (true) { while (1) {
Ion::Device::Battery::initGPIO(); Ion::Device::Battery::initGPIO();
Ion::Device::USB::initGPIO(); Ion::Device::USB::initGPIO();
Ion::Device::LED::init(); Ion::Device::LED::init();
@@ -373,27 +224,27 @@ void __attribute__((noinline)) uf_abort() {
* (just in case 'start' was to be called from the external flash). */ * (just in case 'start' was to be called from the external flash). */
void __attribute__((noinline)) start() { void __attribute__((noinline)) start() {
/* This is where execution starts after reset. /* This is where execution starts after reset.
* Many things are not initialized yet so the code here has to pay attention. */ * Many things are not initialized yet so the code here has to pay attention. */
/* Copy data section to RAM /* Copy data section to RAM
* The data section is R/W but its initialization value matters. It's stored * The data section is R/W but its initialization value matters. It's stored
* in Flash, but linked as if it were in RAM. Now's our opportunity to copy * in Flash, but linked as if it were in RAM. Now's our opportunity to copy
* it. Note that until then the data section (e.g. global variables) contains * it. Note that until then the data section (e.g. global variables) contains
* garbage values and should not be used. */ * garbage values and should not be used. */
size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram); size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram);
memcpy(&_data_section_start_ram, &_data_section_start_flash, dataSectionLength); memcpy(&_data_section_start_ram, &_data_section_start_flash, dataSectionLength);
/* Zero-out the bss section in RAM /* Zero-out the bss section in RAM
* Until we do, any uninitialized global variable will be unusable. */ * Until we do, any uninitialized global variable will be unusable. */
size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram); size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram);
memset(&_bss_section_start_ram, 0, bssSectionLength); memset(&_bss_section_start_ram, 0, bssSectionLength);
/* Initialize the FPU as early as possible. /* Initialize the FPU as early as possible.
* For example, static C++ objects are very likely to manipulate float values */ * For example, static C++ objects are very likely to manipulate float values */
Ion::Device::Board::initFPU(); Ion::Device::Board::initFPU();
/* Call static C++ object constructors /* Call static C++ object constructors
* The C++ compiler creates an initialization function for each static object. * The C++ compiler creates an initialization function for each static object.
* The linker then stores the address of each of those functions consecutively * The linker then stores the address of each of those functions consecutively
* between _init_array_start and _init_array_end. So to initialize all C++ * between _init_array_start and _init_array_end. So to initialize all C++
@@ -405,26 +256,26 @@ void __attribute__((noinline)) start() {
(*c)(); (*c)();
} }
#else #else
/* In practice, static initialized objects are a terrible idea. Since the init /* In practice, static initialized objects are a terrible idea. Since the init
* order is not specified, most often than not this yields the dreaded static * order is not specified, most often than not this yields the dreaded static
* init order fiasco. How about bypassing the issue altogether? */ * init order fiasco. How about bypassing the issue altogether? */
if (&_init_array_start != &_init_array_end) { if (&_init_array_start != &_init_array_end) {
abort(); abort();
} }
#endif #endif
Ion::Device::Board::init(); Ion::Device::Board::init();
/* At this point, we initialized clocks and the external flash but no other /* At this point, we initialized clocks and the external flash but no other
* peripherals. */ * peripherals. */
jump_to_external_flash(); jump_to_external_flash();
abort(); abort();
} }
void __attribute__((interrupt, noinline)) isr_systick() { void __attribute__((interrupt, noinline)) isr_systick() {
auto t = Ion::Device::Timing::MillisElapsed; auto t = Ion::Device::Timing::MillisElapsed;
t++; t++;
Ion::Device::Timing::MillisElapsed = t; Ion::Device::Timing::MillisElapsed = t;
} }

View File

@@ -10,10 +10,13 @@
#include <ion/storage.h> #include <ion/storage.h>
#include <ion/timing.h> #include <ion/timing.h>
#include <string.h> #include <string.h>
namespace Ion { namespace Ion {
namespace Device { namespace Device {
namespace USB { namespace USB {
constexpr static uint8_t k_externalMagik[9] = {0x64, 0x6c, 0x31, 0x31, 0x23, 0x39, 0x38, 0x33, 0x35};
static inline uint32_t minUint32T(uint32_t x, uint32_t y) { return x < y ? x : y; } static inline uint32_t minUint32T(uint32_t x, uint32_t y) { return x < y ? x : y; }
void DFUInterface::StatusData::push(Channel *c) const { void DFUInterface::StatusData::push(Channel *c) const {
@@ -54,7 +57,6 @@ void DFUInterface::wholeDataReceivedCallback(SetupPacket *request, uint8_t *tran
if (request->wLength() > 0) { if (request->wLength() > 0) {
// The request is a "real" download. Compute the writing address. // The request is a "real" download. Compute the writing address.
m_writeAddress = (request->wValue() - 2) * Endpoint0::MaxTransferSize + m_addressPointer; m_writeAddress = (request->wValue() - 2) * Endpoint0::MaxTransferSize + m_addressPointer;
// Store the received data until we copy it on the flash. // Store the received data until we copy it on the flash.
memcpy(m_largeBuffer, transferBuffer, *transferBufferLength); memcpy(m_largeBuffer, transferBuffer, *transferBufferLength);
m_largeBufferLength = *transferBufferLength; m_largeBufferLength = *transferBufferLength;
@@ -67,9 +69,6 @@ void DFUInterface::wholeDataSentCallback(SetupPacket *request, uint8_t *transfer
if (request->bRequest() == (uint8_t)DFURequest::GetStatus) { if (request->bRequest() == (uint8_t)DFURequest::GetStatus) {
// Do any needed action after the GetStatus request. // Do any needed action after the GetStatus request.
if (m_state == State::dfuMANIFEST) { if (m_state == State::dfuMANIFEST) {
if (m_dfuLevel == 1 && m_isFirstExternalFlash && !m_isInternalLocked) {
return;
}
/* If we leave the DFU and reset immediately, dfu-util outputs an error: /* If we leave the DFU and reset immediately, dfu-util outputs an error:
* "File downloaded successfully * "File downloaded successfully
* dfu-util: Error during download get_status" * dfu-util: Error during download get_status"
@@ -81,7 +80,6 @@ void DFUInterface::wholeDataSentCallback(SetupPacket *request, uint8_t *transfer
// Leave DFU routine: Leave DFU, reset device, jump to application code // Leave DFU routine: Leave DFU, reset device, jump to application code
leaveDFUAndReset(); leaveDFUAndReset();
} else if (m_state == State::dfuDNBUSY) { } else if (m_state == State::dfuDNBUSY) {
m_state = State::dfuDNBUSY;
if (m_largeBufferLength != 0) { if (m_largeBufferLength != 0) {
// Here, copy the data from the transfer buffer to the flash memory // Here, copy the data from the transfer buffer to the flash memory
writeOnMemory(); writeOnMemory();
@@ -168,7 +166,10 @@ bool DFUInterface::processUploadRequest(SetupPacket *request, uint8_t *transferB
void DFUInterface::setAddressPointerCommand(SetupPacket *request, uint8_t *transferBuffer, uint16_t transferBufferLength) { void DFUInterface::setAddressPointerCommand(SetupPacket *request, uint8_t *transferBuffer, uint16_t transferBufferLength) {
assert(transferBufferLength == 5); assert(transferBufferLength == 5);
// Compute the new address but change it after the next getStatus request. // Compute the new address but change it after the next getStatus request.
m_potentialNewAddressPointer = transferBuffer[1] + (transferBuffer[2] << 8) + (transferBuffer[3] << 16) + (transferBuffer[4] << 24); m_potentialNewAddressPointer = transferBuffer[1]
+ (transferBuffer[2] << 8)
+ (transferBuffer[3] << 16)
+ (transferBuffer[4] << 24);
m_state = State::dfuDNLOADSYNC; m_state = State::dfuDNLOADSYNC;
} }
@@ -198,7 +199,10 @@ void DFUInterface::eraseCommand(uint8_t *transferBuffer, uint16_t transferBuffer
// Sector erase // Sector erase
assert(transferBufferLength == 5); assert(transferBufferLength == 5);
m_eraseAddress = transferBuffer[1] + (transferBuffer[2] << 8) + (transferBuffer[3] << 16) + (transferBuffer[4] << 24); uint32_t m_eraseAddress = transferBuffer[1]
+ (transferBuffer[2] << 8)
+ (transferBuffer[3] << 16)
+ (transferBuffer[4] << 24);
m_erasePage = Flash::SectorAtAddress(m_eraseAddress); m_erasePage = Flash::SectorAtAddress(m_eraseAddress);
if (m_erasePage < 0) { if (m_erasePage < 0) {
@@ -210,13 +214,24 @@ void DFUInterface::eraseCommand(uint8_t *transferBuffer, uint16_t transferBuffer
void DFUInterface::eraseMemoryIfNeeded() { void DFUInterface::eraseMemoryIfNeeded() {
if (m_erasePage < 0) { if (m_erasePage < 0) {
// There was no erase waiting.
return; return;
} }
willErase(); willErase();
if ((m_eraseAddress >= k_ExternalBorderAddress && m_eraseAddress < ExternalFlash::Config::EndAddress) || m_dfuUnlocked) {
int32_t order = Flash::SectorAtAddress(m_eraseAddress); #if 0 // We don't erase now the flash memory to avoid crash if writing is refused
Flash::EraseSector(order); if (m_erasePage == Flash::TotalNumberOfSectors()) {
Flash::MassErase();
} }
#endif
if ((m_eraseAddress >= k_externalAppsBorderAddress && m_eraseAddress < ExternalFlash::Config::EndAddress) || m_dfuUnlocked) {
Flash::EraseSector(m_erasePage);
}
/* Put an out of range value in m_erasePage to indicate that no erase is
* waiting. */
m_erasePage = -1;
m_state = State::dfuDNLOADIDLE; m_state = State::dfuDNLOADIDLE;
m_status = Status::OK; m_status = Status::OK;
m_erasePage = -1; m_erasePage = -1;
@@ -227,238 +242,67 @@ void DFUInterface::writeOnMemory() {
// Write on SRAM // Write on SRAM
// FIXME We should check that we are not overriding the current instructions. // FIXME We should check that we are not overriding the current instructions.
memcpy((void *)m_writeAddress, m_largeBuffer, m_largeBufferLength); memcpy((void *)m_writeAddress, m_largeBuffer, m_largeBufferLength);
reset_custom_vars(); // On reset les vars car la ram n'a pas de secteur à effacer resetProtectionVariables(); // We can reset the protection variables because update process is finsihed.
} else if (Flash::SectorAtAddress(m_writeAddress) >= 0) { } else if (Flash::SectorAtAddress(m_writeAddress) >= 0) {
if (m_dfuLevel == 2) { if (m_dfuLevel == 2) { // If no-update mode, we throw an error
m_largeBufferLength = 0; m_largeBufferLength = 0;
m_state = State::dfuERROR; m_state = State::dfuERROR;
m_status = Status::errWRITE; m_status = Status::errWRITE;
leaveDFUAndReset(false);
return; return;
} }
int current_memory_flashed; if (!(m_isTemporaryUnlocked || m_dfuUnlocked)) {
if (m_writeAddress >= InternalFlash::Config::StartAddress && m_writeAddress <= InternalFlash::Config::EndAddress) { if (m_writeAddress >= InternalFlash::Config::StartAddress && m_writeAddress <= InternalFlash::Config::EndAddress) {
if (m_isInternalLocked && !m_dfuUnlocked) // On vérifie si l'external a été flash // We check if the user is autorized to write on the internal flash
{ if (m_haveAlreadyFlashedExternal) {
m_largeBufferLength = 0; for (size_t i = 0; i < 4; i++) {
m_state = State::dfuERROR; if (k_internalMagik[i] != m_largeBuffer[k_internalMagikPointer + i]) {
m_status = Status::errTARGET; m_largeBufferLength = 0;
leaveDFUAndReset(false); // Numworks flash l'internal avant donc on exit pour afficher le message m_state = State::dfuERROR;
return; m_status = Status::errWRITE;
} // We don't leave DFU to avoid having only external flashed
current_memory_flashed = 0; return;
}
//on écrit dans la mémoire interne m_largeBuffer[k_internalMagikPointer + i] = 0; // We reset the buffer to its initial value
if (m_isFirstInternalFlash && !m_dfuUnlocked) {
m_temp_is_valid = true;
for (int i = 0; i < 4; i++) {
if (magik[i] != m_largeBuffer[magik_adrs + i]) {
m_temp_is_valid = false;
break;
} }
} }
if (!m_temp_is_valid) { else { // All people trying to write on the internal flash before external are considered as not authorized
m_largeBufferLength = 0; m_largeBufferLength = 0;
m_state = State::dfuERROR; m_state = State::dfuERROR;
m_status = Status::errVERIFY; m_status = Status::errTARGET;
//leaveDFUAndReset(); On ne leave plus sinon on fait crash la calc si il n'y a que la partie ext. leaveDFUAndReset(false);
return; return;
} else {
m_isFirstInternalFlash = false;
} }
} }
} else { else if (m_writeAddress < k_externalAppsBorderAddress) { // If we are not installing external apps
current_memory_flashed = 1;
// Nous écrivons la partie external os
if (m_writeAddress < k_ExternalBorderAddress && m_isFirstExternalFlash && !m_dfuUnlocked) // On vérifie si on installe des apps ext
{
// if (m_dfuLevel == 1 && m_isInternalLocked) {
// m_largeBufferLength = 0;
// m_state = State::dfuERROR;
// m_status = Status::errTARGET;
// return;
// }
if (m_dfuLevel == 0) { if (m_dfuLevel == 0) {
// Partie moche du code parce que je n'arrivais pas à compil avec 3 boucles for sous msys for (size_t i = 0; i < 9; i++) {
int adress_magik = magik_ext_adrs[0]; if (k_externalMagik[i] != m_largeBuffer[k_externalMagikPointer + i]) {
m_temp_is_valid = external_magik[0] == m_largeBuffer[adress_magik]; m_largeBufferLength = 0;
m_largeBuffer[adress_magik] = 0xff; m_state = State::dfuERROR;
m_status = Status::errWRITE;
if (!m_temp_is_valid) { leaveDFUAndReset(false);
m_largeBufferLength = 0; return;
leaveDFUAndReset(false); }
return; m_largeBuffer[k_externalMagikPointer + i] = 0; // We reset the buffer to its initial value
} }
m_isTemporaryUnlocked = true; // We can unlock the flash because signature is good
m_temp_is_valid = external_magik[1] == m_largeBuffer[adress_magik + 1]; }
m_largeBuffer[adress_magik + 1] = 0xff; else {
m_haveAlreadyFlashedExternal = true;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[2] == m_largeBuffer[adress_magik + 2];
m_largeBuffer[adress_magik + 2] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[3] == m_largeBuffer[adress_magik + 3];
m_largeBuffer[adress_magik + 3] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
adress_magik = magik_ext_adrs[1];
m_temp_is_valid = external_magik[5] == m_largeBuffer[adress_magik];
m_largeBuffer[adress_magik] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[6] == m_largeBuffer[adress_magik + 1];
m_largeBuffer[adress_magik + 1] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[7] == m_largeBuffer[adress_magik + 2];
m_largeBuffer[adress_magik + 2] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[8] == m_largeBuffer[adress_magik + 3];
m_largeBuffer[adress_magik + 3] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
adress_magik = magik_ext_adrs[2];
m_temp_is_valid = true;
m_temp_is_valid = external_magik[0] == m_largeBuffer[adress_magik];
m_largeBuffer[adress_magik] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[1] == m_largeBuffer[adress_magik + 1];
m_largeBuffer[adress_magik + 1] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[2] == m_largeBuffer[adress_magik + 2];
m_largeBuffer[adress_magik + 2] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[3] == m_largeBuffer[adress_magik + 3];
m_largeBuffer[adress_magik + 3] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[4] == m_largeBuffer[adress_magik + 4];
m_largeBuffer[adress_magik + 4] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[5] == m_largeBuffer[adress_magik + 5];
m_largeBuffer[adress_magik + 5] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[6] == m_largeBuffer[adress_magik + 6];
m_largeBuffer[adress_magik + 6] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[7] == m_largeBuffer[adress_magik + 7];
m_largeBuffer[adress_magik + 7] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
}
m_temp_is_valid = external_magik[8] == m_largeBuffer[adress_magik + 8];
m_largeBuffer[adress_magik + 8] = 0xff;
if (!m_temp_is_valid) {
m_largeBufferLength = 0;
leaveDFUAndReset(false);
return;
} else {
m_isFirstExternalFlash = false;
m_isInternalLocked = false;
}
} else {
m_isFirstExternalFlash = false;
m_isInternalLocked = false;
} }
} }
} }
if (m_last_memoryFlashed >= 0 && current_memory_flashed != m_last_memoryFlashed) {
m_last_memoryFlashed = -1;
}
m_erasePage = Flash::SectorAtAddress(m_writeAddress); int pageToErase = Flash::SectorAtAddress(m_writeAddress);
//On vérifie qu'on a pas déjà effacé le secteur et si ce n'est pas un secteur external déjà effacé //On vérifie qu'on a pas déjà effacé le secteur et si ce n'est pas un secteur external déjà effacé
if ((m_last_memoryFlashed < 0 || m_erasePage != m_lastPageErased) && m_writeAddress < k_ExternalBorderAddress && !m_dfuUnlocked) { if ((m_lastErasedPage == -1 || pageToErase != m_lastErasedPage) && m_writeAddress < k_externalAppsBorderAddress && !m_dfuUnlocked) {
Flash::EraseSector(m_erasePage); Flash::EraseSector(pageToErase);
m_last_memoryFlashed = current_memory_flashed; m_lastErasedPage = pageToErase;
} }
m_lastPageErased = m_erasePage;
m_erasePage = -1;
Ion::Timing::msleep(1);
Flash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress), m_largeBuffer, m_largeBufferLength); Flash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress), m_largeBuffer, m_largeBufferLength);
} else { } else {
// Invalid write address // Invalid write address
@@ -467,6 +311,7 @@ void DFUInterface::writeOnMemory() {
m_status = Status::errTARGET; m_status = Status::errTARGET;
return; return;
} }
// Reset the buffer length // Reset the buffer length
m_largeBufferLength = 0; m_largeBufferLength = 0;
// Change the interface state and status // Change the interface state and status
@@ -505,14 +350,11 @@ bool DFUInterface::dfuAbort(uint16_t *transferBufferLength) {
} }
void DFUInterface::leaveDFUAndReset(bool do_reset) { void DFUInterface::leaveDFUAndReset(bool do_reset) {
reset_custom_vars(); resetProtectionVariables();
m_isInternalLocked = true;
m_isFirstInternalFlash = true;
m_isFirstExternalFlash = true;
m_device->setResetOnDisconnect(do_reset); m_device->setResetOnDisconnect(do_reset);
m_device->detach(); m_device->detach();
} }
} // namespace USB }
} // namespace Device }
} // namespace Ion }

View File

@@ -148,10 +148,10 @@ private:
constexpr static uint32_t k_sramEndAddress = 0x20040000; constexpr static uint32_t k_sramEndAddress = 0x20040000;
constexpr static uint32_t k_externalAppsBorderAddress = 0x90200000; constexpr static uint32_t k_externalAppsBorderAddress = 0x90200000;
const static int k_internalMagikPointer = 0x1C4; constexpr static int k_internalMagikPointer = 0x1C4;
constexpr static int k_externalMagikPointer = 0x44F; constexpr static int k_externalMagikPointer = 0x44F;
constexpr static uint8_t k_internalMagik[4] = {0xF0, 0x0D, 0xC0, 0xDE}; constexpr static uint8_t k_internalMagik[4] = {0xF0, 0x0D, 0xC0, 0xDE};
constexpr static uint8_t k_externalMagik[9] = {0x64, 0x6c, 0x31, 0x31, 0x23, 0x39, 0x38, 0x33, 0x35}; constexpr static uint8_t k_externalMagik[4] = {0x32, 0x30, 0x30, 0x36};
// Download and upload // Download and upload
bool processDownloadRequest(uint16_t wLength, uint16_t *transferBufferLength); bool processDownloadRequest(uint16_t wLength, uint16_t *transferBufferLength);