mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-24 05:12:02 +00:00
RUST exposure
This commit is contained in:
parent
426acb8c16
commit
8a431cc4e3
@ -45,6 +45,7 @@ rgb_led = []
|
|||||||
backlight = []
|
backlight = []
|
||||||
usb = []
|
usb = []
|
||||||
optiga = []
|
optiga = []
|
||||||
|
ble = []
|
||||||
translations = ["crypto"]
|
translations = ["crypto"]
|
||||||
test = [
|
test = [
|
||||||
"backlight",
|
"backlight",
|
||||||
|
@ -445,6 +445,11 @@ fn generate_trezorhal_bindings() {
|
|||||||
.no_copy("buffer_jpeg_work_t")
|
.no_copy("buffer_jpeg_work_t")
|
||||||
.no_copy("buffer_blurring_t")
|
.no_copy("buffer_blurring_t")
|
||||||
.no_copy("buffer_blurring_totals_t")
|
.no_copy("buffer_blurring_totals_t")
|
||||||
|
// ble
|
||||||
|
.allowlist_function("ble_get_state")
|
||||||
|
.allowlist_function("ble_issue_command")
|
||||||
|
.allowlist_type("ble_command_t")
|
||||||
|
.allowlist_type("ble_state_t")
|
||||||
//usb
|
//usb
|
||||||
.allowlist_function("usb_configured")
|
.allowlist_function("usb_configured")
|
||||||
// touch
|
// touch
|
||||||
|
@ -120,6 +120,7 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR_bitcoin__unverified_external_inputs;
|
MP_QSTR_bitcoin__unverified_external_inputs;
|
||||||
MP_QSTR_bitcoin__valid_signature;
|
MP_QSTR_bitcoin__valid_signature;
|
||||||
MP_QSTR_bitcoin__voting_rights;
|
MP_QSTR_bitcoin__voting_rights;
|
||||||
|
MP_QSTR_ble_event;
|
||||||
MP_QSTR_bootscreen;
|
MP_QSTR_bootscreen;
|
||||||
MP_QSTR_br_code;
|
MP_QSTR_br_code;
|
||||||
MP_QSTR_br_name;
|
MP_QSTR_br_name;
|
||||||
|
31
core/embed/rust/src/trezorhal/ble.rs
Normal file
31
core/embed/rust/src/trezorhal/ble.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
use super::ffi;
|
||||||
|
|
||||||
|
pub fn connected() -> bool {
|
||||||
|
unsafe {
|
||||||
|
let mut state = ffi::ble_state_t {
|
||||||
|
connected: false,
|
||||||
|
peer_count: 0,
|
||||||
|
};
|
||||||
|
ffi::ble_get_state(&mut state as _);
|
||||||
|
|
||||||
|
state.connected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pairing_mode() {
|
||||||
|
unsafe {
|
||||||
|
ffi::ble_issue_command(ffi::ble_command_t_BLE_PAIRING_MODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn allow_pairing() {
|
||||||
|
unsafe {
|
||||||
|
ffi::ble_issue_command(ffi::ble_command_t_BLE_ALLOW_PAIRING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reject_pairing() {
|
||||||
|
unsafe {
|
||||||
|
ffi::ble_issue_command(ffi::ble_command_t_BLE_REJECT_PAIRING);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
pub mod bip39;
|
pub mod bip39;
|
||||||
|
#[cfg(feature = "ble")]
|
||||||
|
pub mod ble;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
pub mod fatal_error;
|
pub mod fatal_error;
|
||||||
|
@ -12,6 +12,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "ble")]
|
||||||
|
use crate::ui::event::BLEEvent;
|
||||||
#[cfg(feature = "button")]
|
#[cfg(feature = "button")]
|
||||||
use crate::ui::event::ButtonEvent;
|
use crate::ui::event::ButtonEvent;
|
||||||
use crate::ui::event::USBEvent;
|
use crate::ui::event::USBEvent;
|
||||||
@ -364,6 +366,8 @@ pub enum Event {
|
|||||||
Button(ButtonEvent),
|
Button(ButtonEvent),
|
||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
Touch(TouchEvent),
|
Touch(TouchEvent),
|
||||||
|
#[cfg(feature = "ble")]
|
||||||
|
BLE(BLEEvent),
|
||||||
USB(USBEvent),
|
USB(USBEvent),
|
||||||
/// Previously requested timer was triggered. This invalidates the timer
|
/// Previously requested timer was triggered. This invalidates the timer
|
||||||
/// token (another timer has to be requested).
|
/// token (another timer has to be requested).
|
||||||
|
21
core/embed/rust/src/ui/event/ble.rs
Normal file
21
core/embed/rust/src/ui/event/ble.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
use crate::error::Error;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))]
|
||||||
|
pub enum BLEEvent {
|
||||||
|
Connected,
|
||||||
|
Disconnected,
|
||||||
|
PairingRequest(&'static [u8]),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BLEEvent {
|
||||||
|
pub fn new(event: u32, data: &'static [u8]) -> Result<Self, Error> {
|
||||||
|
let result = match event {
|
||||||
|
1 => Self::Connected,
|
||||||
|
2 => Self::Disconnected,
|
||||||
|
3 => Self::PairingRequest(data),
|
||||||
|
_ => return Err(Error::OutOfRange),
|
||||||
|
};
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,11 @@ pub mod button;
|
|||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
pub mod touch;
|
pub mod touch;
|
||||||
|
|
||||||
|
#[cfg(feature = "ble")]
|
||||||
|
mod ble;
|
||||||
|
|
||||||
|
#[cfg(feature = "ble")]
|
||||||
|
pub use ble::BLEEvent;
|
||||||
#[cfg(feature = "button")]
|
#[cfg(feature = "button")]
|
||||||
pub use button::{ButtonEvent, PhysicalButton};
|
pub use button::{ButtonEvent, PhysicalButton};
|
||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
|
@ -5,6 +5,8 @@ use core::{
|
|||||||
};
|
};
|
||||||
use num_traits::{FromPrimitive, ToPrimitive};
|
use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
|
|
||||||
|
#[cfg(feature = "ble")]
|
||||||
|
use crate::ui::event::BLEEvent;
|
||||||
#[cfg(feature = "button")]
|
#[cfg(feature = "button")]
|
||||||
use crate::ui::event::ButtonEvent;
|
use crate::ui::event::ButtonEvent;
|
||||||
#[cfg(feature = "new_rendering")]
|
#[cfg(feature = "new_rendering")]
|
||||||
@ -15,7 +17,7 @@ use crate::{
|
|||||||
error::Error,
|
error::Error,
|
||||||
maybe_trace::MaybeTrace,
|
maybe_trace::MaybeTrace,
|
||||||
micropython::{
|
micropython::{
|
||||||
buffer::StrBuffer,
|
buffer::{get_buffer, StrBuffer},
|
||||||
gc::{self, Gc, GcBox},
|
gc::{self, Gc, GcBox},
|
||||||
macros::{obj_dict, obj_fn_1, obj_fn_2, obj_fn_3, obj_fn_var, obj_map, obj_type},
|
macros::{obj_dict, obj_fn_1, obj_fn_2, obj_fn_3, obj_fn_var, obj_map, obj_type},
|
||||||
map::Map,
|
map::Map,
|
||||||
@ -335,6 +337,7 @@ impl LayoutObj {
|
|||||||
Qstr::MP_QSTR_button_event => obj_fn_var!(3, 3, ui_layout_button_event).as_obj(),
|
Qstr::MP_QSTR_button_event => obj_fn_var!(3, 3, ui_layout_button_event).as_obj(),
|
||||||
Qstr::MP_QSTR_progress_event => obj_fn_var!(3, 3, ui_layout_progress_event).as_obj(),
|
Qstr::MP_QSTR_progress_event => obj_fn_var!(3, 3, ui_layout_progress_event).as_obj(),
|
||||||
Qstr::MP_QSTR_usb_event => obj_fn_var!(2, 2, ui_layout_usb_event).as_obj(),
|
Qstr::MP_QSTR_usb_event => obj_fn_var!(2, 2, ui_layout_usb_event).as_obj(),
|
||||||
|
Qstr::MP_QSTR_ble_event=> obj_fn_var!(3, 3, ui_layout_ble_event).as_obj(),
|
||||||
Qstr::MP_QSTR_timer => obj_fn_2!(ui_layout_timer).as_obj(),
|
Qstr::MP_QSTR_timer => obj_fn_2!(ui_layout_timer).as_obj(),
|
||||||
Qstr::MP_QSTR_paint => obj_fn_1!(ui_layout_paint).as_obj(),
|
Qstr::MP_QSTR_paint => obj_fn_1!(ui_layout_paint).as_obj(),
|
||||||
Qstr::MP_QSTR_request_complete_repaint => obj_fn_1!(ui_layout_request_complete_repaint).as_obj(),
|
Qstr::MP_QSTR_request_complete_repaint => obj_fn_1!(ui_layout_request_complete_repaint).as_obj(),
|
||||||
@ -469,6 +472,31 @@ extern "C" fn ui_layout_button_event(_n_args: usize, _args: *const Obj) -> Obj {
|
|||||||
Obj::const_none()
|
Obj::const_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ble")]
|
||||||
|
extern "C" fn ui_layout_ble_event(n_args: usize, args: *const Obj) -> Obj {
|
||||||
|
let block = |args: &[Obj], _kwargs: &Map| {
|
||||||
|
if args.len() != 3 {
|
||||||
|
return Err(Error::TypeError);
|
||||||
|
}
|
||||||
|
let this: Gc<LayoutObj> = args[0].try_into()?;
|
||||||
|
let data: Obj = args[2].try_into()?;
|
||||||
|
|
||||||
|
let data = unsafe { get_buffer(data) };
|
||||||
|
|
||||||
|
let data = unwrap!(data);
|
||||||
|
|
||||||
|
let event = BLEEvent::new(args[1].try_into()?, data)?;
|
||||||
|
let msg = this.inner_mut().obj_event(Event::BLE(event))?;
|
||||||
|
Ok(msg)
|
||||||
|
};
|
||||||
|
unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "ble"))]
|
||||||
|
extern "C" fn ui_layout_ble_event(_n_args: usize, _args: *const Obj) -> Obj {
|
||||||
|
Obj::const_none()
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" fn ui_layout_progress_event(n_args: usize, args: *const Obj) -> Obj {
|
extern "C" fn ui_layout_progress_event(n_args: usize, args: *const Obj) -> Obj {
|
||||||
let block = |args: &[Obj], _kwargs: &Map| {
|
let block = |args: &[Obj], _kwargs: &Map| {
|
||||||
if args.len() != 3 {
|
if args.len() != 3 {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <trezor_model.h>
|
#include <trezor_model.h>
|
||||||
|
|
||||||
|
#include "ble.h"
|
||||||
#include "buffers.h"
|
#include "buffers.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user