aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32-wpan/src/wb55/lhci.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32-wpan/src/wb55/lhci.rs')
-rw-r--r--embassy-stm32-wpan/src/wb55/lhci.rs112
1 files changed, 112 insertions, 0 deletions
diff --git a/embassy-stm32-wpan/src/wb55/lhci.rs b/embassy-stm32-wpan/src/wb55/lhci.rs
new file mode 100644
index 000000000..59c8bfb5d
--- /dev/null
+++ b/embassy-stm32-wpan/src/wb55/lhci.rs
@@ -0,0 +1,112 @@
1use core::ptr;
2
3use crate::cmd::CmdPacket;
4use crate::consts::{TL_EVT_HEADER_SIZE, TlPacketType};
5use crate::evt::{CcEvt, EvtPacket, EvtSerial};
6use crate::tables::{DeviceInfoTable, RssInfoTable, SafeBootInfoTable, TL_DEVICE_INFO_TABLE, WirelessFwInfoTable};
7
8const TL_BLEEVT_CC_OPCODE: u8 = 0x0e;
9const LHCI_OPCODE_C1_DEVICE_INF: u16 = 0xfd62;
10
11const PACKAGE_DATA_PTR: *const u8 = 0x1FFF_7500 as _;
12const UID64_PTR: *const u32 = 0x1FFF_7580 as _;
13
14#[derive(Debug, Copy, Clone)]
15#[repr(C, packed)]
16pub struct LhciC1DeviceInformationCcrp {
17 pub status: u8,
18 pub rev_id: u16,
19 pub dev_code_id: u16,
20 pub package_type: u8,
21 pub device_type_id: u8,
22 pub st_company_id: u32,
23 pub uid64: u32,
24
25 pub uid96_0: u32,
26 pub uid96_1: u32,
27 pub uid96_2: u32,
28
29 pub safe_boot_info_table: SafeBootInfoTable,
30 pub rss_info_table: RssInfoTable,
31 pub wireless_fw_info_table: WirelessFwInfoTable,
32
33 pub app_fw_inf: u32,
34}
35
36impl Default for LhciC1DeviceInformationCcrp {
37 fn default() -> Self {
38 let DeviceInfoTable {
39 safe_boot_info_table,
40 rss_info_table,
41 wireless_fw_info_table,
42 } = unsafe { ptr::read_volatile(TL_DEVICE_INFO_TABLE.as_ptr()) };
43
44 let device_id = stm32_device_signature::device_id();
45 let uid96_0 = (device_id[3] as u32) << 24
46 | (device_id[2] as u32) << 16
47 | (device_id[1] as u32) << 8
48 | device_id[0] as u32;
49 let uid96_1 = (device_id[7] as u32) << 24
50 | (device_id[6] as u32) << 16
51 | (device_id[5] as u32) << 8
52 | device_id[4] as u32;
53 let uid96_2 = (device_id[11] as u32) << 24
54 | (device_id[10] as u32) << 16
55 | (device_id[9] as u32) << 8
56 | device_id[8] as u32;
57
58 let package_type = unsafe { *PACKAGE_DATA_PTR };
59 let uid64 = unsafe { *UID64_PTR };
60 let st_company_id = unsafe { *UID64_PTR.offset(1) } >> 8 & 0x00FF_FFFF;
61 let device_type_id = (unsafe { *UID64_PTR.offset(1) } & 0x000000FF) as u8;
62
63 LhciC1DeviceInformationCcrp {
64 status: 0,
65 rev_id: 0,
66 dev_code_id: 0,
67 package_type,
68 device_type_id,
69 st_company_id,
70 uid64,
71 uid96_0,
72 uid96_1,
73 uid96_2,
74 safe_boot_info_table,
75 rss_info_table,
76 wireless_fw_info_table,
77 app_fw_inf: (1 << 8), // 0.0.1
78 }
79 }
80}
81
82impl LhciC1DeviceInformationCcrp {
83 pub fn new() -> Self {
84 Self::default()
85 }
86
87 pub fn write(&self, cmd_packet: &mut CmdPacket) {
88 let self_size = core::mem::size_of::<LhciC1DeviceInformationCcrp>();
89
90 unsafe {
91 let cmd_packet_ptr: *mut CmdPacket = cmd_packet;
92 let evet_packet_ptr: *mut EvtPacket = cmd_packet_ptr.cast();
93
94 let evt_serial: *mut EvtSerial = &mut (*evet_packet_ptr).evt_serial;
95 let evt_payload = (*evt_serial).evt.payload.as_mut_ptr();
96 let evt_cc: *mut CcEvt = evt_payload.cast();
97 let evt_cc_payload_buf = (*evt_cc).payload.as_mut_ptr();
98
99 (*evt_serial).kind = TlPacketType::LocRsp as u8;
100 (*evt_serial).evt.evt_code = TL_BLEEVT_CC_OPCODE;
101 (*evt_serial).evt.payload_len = TL_EVT_HEADER_SIZE as u8 + self_size as u8;
102
103 (*evt_cc).cmd_code = LHCI_OPCODE_C1_DEVICE_INF;
104 (*evt_cc).num_cmd = 1;
105
106 let self_ptr: *const LhciC1DeviceInformationCcrp = self;
107 let self_buf = self_ptr.cast();
108
109 ptr::copy(self_buf, evt_cc_payload_buf, self_size);
110 }
111 }
112}