diff options
Diffstat (limited to 'examples/stm32wb/src/bin/eddystone_beacon.rs')
| -rw-r--r-- | examples/stm32wb/src/bin/eddystone_beacon.rs | 120 |
1 files changed, 53 insertions, 67 deletions
diff --git a/examples/stm32wb/src/bin/eddystone_beacon.rs b/examples/stm32wb/src/bin/eddystone_beacon.rs index 3bd8b4a63..413b1ac8f 100644 --- a/examples/stm32wb/src/bin/eddystone_beacon.rs +++ b/examples/stm32wb/src/bin/eddystone_beacon.rs | |||
| @@ -8,15 +8,15 @@ use embassy_executor::Spawner; | |||
| 8 | use embassy_stm32::bind_interrupts; | 8 | use embassy_stm32::bind_interrupts; |
| 9 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; | 9 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; |
| 10 | use embassy_stm32::rcc::WPAN_DEFAULT; | 10 | use embassy_stm32::rcc::WPAN_DEFAULT; |
| 11 | use embassy_stm32_wpan::TlMbox; | ||
| 12 | use embassy_stm32_wpan::hci::BdAddr; | ||
| 11 | use embassy_stm32_wpan::hci::host::uart::UartHci; | 13 | use embassy_stm32_wpan::hci::host::uart::UartHci; |
| 12 | use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType}; | 14 | use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType}; |
| 13 | use embassy_stm32_wpan::hci::types::AdvertisingType; | 15 | use embassy_stm32_wpan::hci::types::AdvertisingType; |
| 14 | use embassy_stm32_wpan::hci::vendor::command::gap::{AdvertisingDataType, DiscoverableParameters, GapCommands, Role}; | 16 | use embassy_stm32_wpan::hci::vendor::command::gap::{AdvertisingDataType, DiscoverableParameters, GapCommands, Role}; |
| 15 | use embassy_stm32_wpan::hci::vendor::command::gatt::GattCommands; | 17 | use embassy_stm32_wpan::hci::vendor::command::gatt::GattCommands; |
| 16 | use embassy_stm32_wpan::hci::vendor::command::hal::{ConfigData, HalCommands, PowerLevel}; | 18 | use embassy_stm32_wpan::hci::vendor::command::hal::{ConfigData, HalCommands, PowerLevel}; |
| 17 | use embassy_stm32_wpan::hci::BdAddr; | ||
| 18 | use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp; | 19 | use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp; |
| 19 | use embassy_stm32_wpan::TlMbox; | ||
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | 21 | ||
| 22 | bind_interrupts!(struct Irqs{ | 22 | bind_interrupts!(struct Irqs{ |
| @@ -57,126 +57,112 @@ async fn main(_spawner: Spawner) { | |||
| 57 | info!("Hello World!"); | 57 | info!("Hello World!"); |
| 58 | 58 | ||
| 59 | let config = Config::default(); | 59 | let config = Config::default(); |
| 60 | let mut mbox = TlMbox::init(p.IPCC, Irqs, config); | 60 | let mbox = TlMbox::init(p.IPCC, Irqs, config).await; |
| 61 | 61 | let mut sys = mbox.sys_subsystem; | |
| 62 | let sys_event = mbox.sys_subsystem.read().await; | 62 | let mut ble = mbox.ble_subsystem; |
| 63 | info!("sys event: {}", sys_event.payload()); | ||
| 64 | 63 | ||
| 65 | let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; | 64 | let _ = sys.shci_c2_ble_init(Default::default()).await; |
| 66 | 65 | ||
| 67 | info!("resetting BLE..."); | 66 | info!("resetting BLE..."); |
| 68 | mbox.ble_subsystem.reset().await; | 67 | ble.reset().await; |
| 69 | let response = mbox.ble_subsystem.read().await.unwrap(); | 68 | let response = ble.read().await.unwrap(); |
| 70 | defmt::info!("{}", response); | 69 | defmt::info!("{}", response); |
| 71 | 70 | ||
| 72 | info!("config public address..."); | 71 | info!("config public address..."); |
| 73 | mbox.ble_subsystem | 72 | ble.write_config_data(&ConfigData::public_address(get_bd_addr()).build()) |
| 74 | .write_config_data(&ConfigData::public_address(get_bd_addr()).build()) | ||
| 75 | .await; | 73 | .await; |
| 76 | let response = mbox.ble_subsystem.read().await.unwrap(); | 74 | let response = ble.read().await.unwrap(); |
| 77 | defmt::info!("{}", response); | 75 | defmt::info!("{}", response); |
| 78 | 76 | ||
| 79 | info!("config random address..."); | 77 | info!("config random address..."); |
| 80 | mbox.ble_subsystem | 78 | ble.write_config_data(&ConfigData::random_address(get_random_addr()).build()) |
| 81 | .write_config_data(&ConfigData::random_address(get_random_addr()).build()) | ||
| 82 | .await; | 79 | .await; |
| 83 | let response = mbox.ble_subsystem.read().await.unwrap(); | 80 | let response = ble.read().await.unwrap(); |
| 84 | defmt::info!("{}", response); | 81 | defmt::info!("{}", response); |
| 85 | 82 | ||
| 86 | info!("config identity root..."); | 83 | info!("config identity root..."); |
| 87 | mbox.ble_subsystem | 84 | ble.write_config_data(&ConfigData::identity_root(&get_irk()).build()) |
| 88 | .write_config_data(&ConfigData::identity_root(&get_irk()).build()) | ||
| 89 | .await; | 85 | .await; |
| 90 | let response = mbox.ble_subsystem.read().await.unwrap(); | 86 | let response = ble.read().await.unwrap(); |
| 91 | defmt::info!("{}", response); | 87 | defmt::info!("{}", response); |
| 92 | 88 | ||
| 93 | info!("config encryption root..."); | 89 | info!("config encryption root..."); |
| 94 | mbox.ble_subsystem | 90 | ble.write_config_data(&ConfigData::encryption_root(&get_erk()).build()) |
| 95 | .write_config_data(&ConfigData::encryption_root(&get_erk()).build()) | ||
| 96 | .await; | 91 | .await; |
| 97 | let response = mbox.ble_subsystem.read().await.unwrap(); | 92 | let response = ble.read().await.unwrap(); |
| 98 | defmt::info!("{}", response); | 93 | defmt::info!("{}", response); |
| 99 | 94 | ||
| 100 | info!("config tx power level..."); | 95 | info!("config tx power level..."); |
| 101 | mbox.ble_subsystem.set_tx_power_level(PowerLevel::ZerodBm).await; | 96 | ble.set_tx_power_level(PowerLevel::ZerodBm).await; |
| 102 | let response = mbox.ble_subsystem.read().await.unwrap(); | 97 | let response = ble.read().await.unwrap(); |
| 103 | defmt::info!("{}", response); | 98 | defmt::info!("{}", response); |
| 104 | 99 | ||
| 105 | info!("GATT init..."); | 100 | info!("GATT init..."); |
| 106 | mbox.ble_subsystem.init_gatt().await; | 101 | ble.init_gatt().await; |
| 107 | let response = mbox.ble_subsystem.read().await.unwrap(); | 102 | let response = ble.read().await.unwrap(); |
| 108 | defmt::info!("{}", response); | 103 | defmt::info!("{}", response); |
| 109 | 104 | ||
| 110 | info!("GAP init..."); | 105 | info!("GAP init..."); |
| 111 | mbox.ble_subsystem | 106 | ble.init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH).await; |
| 112 | .init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH) | 107 | let response = ble.read().await.unwrap(); |
| 113 | .await; | ||
| 114 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 115 | defmt::info!("{}", response); | 108 | defmt::info!("{}", response); |
| 116 | 109 | ||
| 117 | // info!("set scan response..."); | 110 | // info!("set scan response..."); |
| 118 | // mbox.ble_subsystem.le_set_scan_response_data(&[]).await.unwrap(); | 111 | // ble.le_set_scan_response_data(&[]).await.unwrap(); |
| 119 | // let response = mbox.ble_subsystem.read().await.unwrap(); | 112 | // let response = ble.read().await.unwrap(); |
| 120 | // defmt::info!("{}", response); | 113 | // defmt::info!("{}", response); |
| 121 | 114 | ||
| 122 | info!("set discoverable..."); | 115 | info!("set discoverable..."); |
| 123 | mbox.ble_subsystem | 116 | ble.set_discoverable(&DiscoverableParameters { |
| 124 | .set_discoverable(&DiscoverableParameters { | 117 | advertising_type: AdvertisingType::NonConnectableUndirected, |
| 125 | advertising_type: AdvertisingType::NonConnectableUndirected, | 118 | advertising_interval: Some((Duration::from_millis(250), Duration::from_millis(250))), |
| 126 | advertising_interval: Some((Duration::from_millis(250), Duration::from_millis(250))), | 119 | address_type: OwnAddressType::Public, |
| 127 | address_type: OwnAddressType::Public, | 120 | filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan, |
| 128 | filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan, | 121 | local_name: None, |
| 129 | local_name: None, | 122 | advertising_data: &[], |
| 130 | advertising_data: &[], | 123 | conn_interval: (None, None), |
| 131 | conn_interval: (None, None), | 124 | }) |
| 132 | }) | 125 | .await |
| 133 | .await | 126 | .unwrap(); |
| 134 | .unwrap(); | 127 | |
| 135 | 128 | let response = ble.read().await; | |
| 136 | let response = mbox.ble_subsystem.read().await; | ||
| 137 | defmt::info!("{}", response); | 129 | defmt::info!("{}", response); |
| 138 | 130 | ||
| 139 | // remove some advertisement to decrease the packet size | 131 | // remove some advertisement to decrease the packet size |
| 140 | info!("delete tx power ad type..."); | 132 | info!("delete tx power ad type..."); |
| 141 | mbox.ble_subsystem | 133 | ble.delete_ad_type(AdvertisingDataType::TxPowerLevel).await; |
| 142 | .delete_ad_type(AdvertisingDataType::TxPowerLevel) | 134 | let response = ble.read().await.unwrap(); |
| 143 | .await; | ||
| 144 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 145 | defmt::info!("{}", response); | 135 | defmt::info!("{}", response); |
| 146 | 136 | ||
| 147 | info!("delete conn interval ad type..."); | 137 | info!("delete conn interval ad type..."); |
| 148 | mbox.ble_subsystem | 138 | ble.delete_ad_type(AdvertisingDataType::PeripheralConnectionInterval) |
| 149 | .delete_ad_type(AdvertisingDataType::PeripheralConnectionInterval) | ||
| 150 | .await; | 139 | .await; |
| 151 | let response = mbox.ble_subsystem.read().await.unwrap(); | 140 | let response = ble.read().await.unwrap(); |
| 152 | defmt::info!("{}", response); | 141 | defmt::info!("{}", response); |
| 153 | 142 | ||
| 154 | info!("update advertising data..."); | 143 | info!("update advertising data..."); |
| 155 | mbox.ble_subsystem | 144 | ble.update_advertising_data(&eddystone_advertising_data()) |
| 156 | .update_advertising_data(&eddystone_advertising_data()) | ||
| 157 | .await | 145 | .await |
| 158 | .unwrap(); | 146 | .unwrap(); |
| 159 | let response = mbox.ble_subsystem.read().await.unwrap(); | 147 | let response = ble.read().await.unwrap(); |
| 160 | defmt::info!("{}", response); | 148 | defmt::info!("{}", response); |
| 161 | 149 | ||
| 162 | info!("update advertising data type..."); | 150 | info!("update advertising data type..."); |
| 163 | mbox.ble_subsystem | 151 | ble.update_advertising_data(&[3, AdvertisingDataType::UuidCompleteList16 as u8, 0xaa, 0xfe]) |
| 164 | .update_advertising_data(&[3, AdvertisingDataType::UuidCompleteList16 as u8, 0xaa, 0xfe]) | ||
| 165 | .await | 152 | .await |
| 166 | .unwrap(); | 153 | .unwrap(); |
| 167 | let response = mbox.ble_subsystem.read().await.unwrap(); | 154 | let response = ble.read().await.unwrap(); |
| 168 | defmt::info!("{}", response); | 155 | defmt::info!("{}", response); |
| 169 | 156 | ||
| 170 | info!("update advertising data flags..."); | 157 | info!("update advertising data flags..."); |
| 171 | mbox.ble_subsystem | 158 | ble.update_advertising_data(&[ |
| 172 | .update_advertising_data(&[ | 159 | 2, |
| 173 | 2, | 160 | AdvertisingDataType::Flags as u8, |
| 174 | AdvertisingDataType::Flags as u8, | 161 | (0x02 | 0x04) as u8, // BLE general discoverable, without BR/EDR support |
| 175 | (0x02 | 0x04) as u8, // BLE general discoverable, without BR/EDR support | 162 | ]) |
| 176 | ]) | 163 | .await |
| 177 | .await | 164 | .unwrap(); |
| 178 | .unwrap(); | 165 | let response = ble.read().await.unwrap(); |
| 179 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 180 | defmt::info!("{}", response); | 166 | defmt::info!("{}", response); |
| 181 | 167 | ||
| 182 | cortex_m::asm::wfi(); | 168 | cortex_m::asm::wfi(); |
