forked from BitBoxSwiss/bitbox02-firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,587 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright 2019 Shift Cryptosecurity AG | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "bitboxbase_background.h" | ||
#include "bitboxbase_screensaver.h" | ||
#include "bitboxbase_status.h" | ||
#include "screen.h" | ||
#include <hardfault.h> | ||
#include <leds.h> | ||
#include <rust/bitbox02_rust.h> | ||
#include <string.h> | ||
#include <ui/component.h> | ||
#include <ui/components/image.h> | ||
#include <ui/components/label.h> | ||
#include <ui/components/ui_images.h> | ||
#include <ui/event.h> | ||
#include <ui/oled/oled.h> | ||
#include <ui/screen_stack.h> | ||
#include <ui/ui_util.h> | ||
|
||
static void _render(component_t* component); | ||
static void _on_event(const event_t* event, component_t* component); | ||
|
||
static component_functions_t _component_functions = { | ||
.cleanup = ui_util_component_cleanup, | ||
.render = _render, | ||
.on_event = _on_event, | ||
}; | ||
|
||
void _render(component_t* component) | ||
{ | ||
component_t* label = component->sub_components.sub_components[1]; | ||
char buf[100]; | ||
bitboxbase_state_get_description(buf, sizeof(buf)); | ||
switch (bitboxbase_state_get()) { | ||
case BBBNotAlive: | ||
leds_turn_big_led(0, LED_COLOR_RED); | ||
label_update(label, "Error, please restart"); | ||
break; | ||
case BBBWaiting: | ||
leds_turn_big_led(0, LED_COLOR_GREEN); | ||
label_update(label, "System starting..."); | ||
break; | ||
case BBBIdle: | ||
if (bitboxbase_config_led_mode_get() < OnWarning) { | ||
leds_turn_big_led(0, LED_COLOR_GREEN); | ||
} else { | ||
leds_turn_big_led(0, LED_COLOR_NONE); | ||
} | ||
label_update(label, buf); | ||
break; | ||
case BBBWorking: | ||
leds_turn_big_led(0, LED_COLOR_BLUE); | ||
label_update(label, buf); | ||
break; | ||
case BBBWarning: | ||
if (bitboxbase_config_led_mode_get() < OnError) { | ||
leds_turn_big_led(0, LED_COLOR_YELLOW); | ||
} else { | ||
leds_turn_big_led(0, LED_COLOR_NONE); | ||
} | ||
label_update(label, buf); | ||
break; | ||
case BBBError: | ||
leds_turn_big_led(0, LED_COLOR_RED); | ||
label_update(label, buf); | ||
break; | ||
default: | ||
Abort("Internal error"); | ||
break; | ||
} | ||
ui_util_component_render_subcomponents(component); | ||
} | ||
|
||
void _on_event(const event_t* event, component_t* component) | ||
{ | ||
(void)component; | ||
bitboxbase_screensaver_reset(); | ||
oled_init(); | ||
if (event->id == EVENT_BUTTON_SHORT_TAP) { | ||
bitboxbase_status(); | ||
} | ||
} | ||
|
||
static component_t* _create(void) | ||
{ | ||
component_t* show_logo = malloc(sizeof(component_t)); | ||
if (!show_logo) { | ||
Abort("Error: malloc show_logo"); | ||
} | ||
memset(show_logo, 0, sizeof(component_t)); | ||
show_logo->f = &_component_functions; | ||
show_logo->dimension.width = 128; | ||
show_logo->dimension.height = 64; | ||
component_t* bb2_logo = image_create( | ||
IMAGE_BB2_LOGO, | ||
sizeof(IMAGE_BB2_LOGO), | ||
IMAGE_BB2_LOGO_W, | ||
IMAGE_BB2_LOGO_H, | ||
CENTER, | ||
show_logo); | ||
component_t* loading_label = label_create("Booting...", NULL, RIGHT_BOTTOM, show_logo); | ||
ui_util_add_sub_component(show_logo, bb2_logo); | ||
ui_util_add_sub_component(show_logo, loading_label); | ||
return show_logo; | ||
} | ||
|
||
void bitboxbase_background(void) | ||
{ | ||
leds_turn_big_led(0, LED_COLOR_NONE); | ||
leds_turn_big_led(1, LED_COLOR_NONE); | ||
component_t* b = _create(); | ||
ui_screen_stack_push(b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2019 Shift Cryptosecurity AG | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
void bitboxbase_background(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2019 Shift Cryptosecurity AG | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "bitboxbase_screensaver.h" | ||
#include <hal_timer.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
// The periodicity to increment the timeout counter | ||
#define INTERVAL_MS 1000 | ||
// Number of periods we wait until we raise an alarm. | ||
#define TIMEOUT 120 | ||
|
||
extern struct timer_descriptor TIMER_0; | ||
|
||
static volatile uint32_t timeout_counter; | ||
|
||
static void _timer_task_cb(const struct timer_task* const timer_task) | ||
{ | ||
(void)timer_task; | ||
timeout_counter++; | ||
} | ||
|
||
static void _timer_config(void) | ||
{ | ||
static struct timer_task Timer_task; | ||
Timer_task.interval = INTERVAL_MS; | ||
Timer_task.cb = _timer_task_cb; | ||
Timer_task.mode = TIMER_TASK_REPEAT; | ||
|
||
timer_stop(&TIMER_0); | ||
timer_add_task(&TIMER_0, &Timer_task); | ||
timer_start(&TIMER_0); | ||
} | ||
|
||
// Initialize screensaver | ||
void bitboxbase_screensaver_init(void) | ||
{ | ||
bitboxbase_screensaver_reset(); | ||
_timer_config(); | ||
} | ||
|
||
// Checks the timer | ||
bool bitboxbase_screensaver_check(void) | ||
{ | ||
if (timeout_counter > TIMEOUT) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// Resets the screensaver | ||
void bitboxbase_screensaver_reset(void) | ||
{ | ||
timeout_counter = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2019 Shift Cryptosecurity AG | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef _BITBOXBASE_SCREENSAVER_H | ||
#define _BITBOXBASE_SCREENSAVER_H | ||
|
||
#include <stdbool.h> | ||
|
||
/** | ||
* @file | ||
* | ||
* bitboxbase screensaver is a timer that keeps track of whether to turn off the display or not. | ||
*/ | ||
|
||
/** | ||
* Initialize counter | ||
*/ | ||
void bitboxbase_screensaver_init(void); | ||
|
||
/** | ||
* Check if screensaver should be enabled | ||
*/ | ||
bool bitboxbase_screensaver_check(void); | ||
|
||
/** | ||
* Reset counter | ||
*/ | ||
void bitboxbase_screensaver_reset(void); | ||
|
||
#endif |
Oops, something went wrong.