Skip to content

Commit

Permalink
fix: examples building
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Nov 18, 2023
1 parent 9938f62 commit 5a52918
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 37 deletions.
23 changes: 22 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
license = "MIT/Apache-2.0"

[features]
default = ["ble"]
default = []
embassy = ["dep:embassy-time"]
ble = []

Expand Down Expand Up @@ -74,6 +74,27 @@ required-features = ["embassy"]
name = "embassy-ble-broadcaster"
required-features = ["embassy", "ble"]

[[example]]
name = "embassy-ble-scanner"
required-features = ["embassy", "ble"]

[[example]]
name = "ble-peripheral-simple"
required-features = ["embassy", "ble"]

[[example]]
name = "ble-peripheral"
required-features = ["embassy", "ble"]

# [[example]]
# name = "embassy-ble-sensor"
# required-features = ["embassy", "ble"]
#
# [[example]]
# name = "embassy-ble-sync-adv"
# required-features = ["embassy", "ble"]


[profile.release]
# panic = "unwind"
panic = "abort"
Expand Down
22 changes: 12 additions & 10 deletions examples/ble-peripheral-simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ async fn read_rssi(conn_handle: u16) {
unsafe {
let r = GAPRole_ReadRssiCmd(conn_handle);
if r.is_err() {
println!("!! GAPRole_ReadRssiCmd error: {:?}", r);
// normally it's already disconnected, quit
// println!("!! GAPRole_ReadRssiCmd error: {:?}", r);
return;
}
}
Expand Down Expand Up @@ -346,29 +347,29 @@ async fn peripheral(spawner: Spawner, task_id: u8, mut subscriber: ble::EventSub
unsafe extern "C" fn on_rssi_read(conn_handle: u16, rssi: i8) {
println!("RSSI -{} dB Conn {:x}", -rssi, conn_handle);
}
unsafe extern "C" fn on_param_update(connHandle: u16, connInterval: u16, connSlaveLatency: u16, connTimeout: u16) {
unsafe extern "C" fn on_param_update(conn_handle: u16, interval: u16, slave_latency: u16, timeout: u16) {
println!(
"on_param_update Conn handle: {} inverval: {} timeout: {}",
connHandle, connInterval, connTimeout
conn_handle, interval, timeout
);
}

unsafe {
static bond_mgr_cb: gapBondCBs_t = gapBondCBs_t {
static BOND_MGR_CB: gapBondCBs_t = gapBondCBs_t {
passcodeCB: None,
pairStateCB: None,
oobCB: None,
};

// peripheralStateNotificationCB

static app_cb: gapRolesCBs_t = gapRolesCBs_t {
static APP_CB: gapRolesCBs_t = gapRolesCBs_t {
pfnStateChange: Some(on_state_change),
pfnRssiRead: Some(on_rssi_read),
pfnParamUpdate: Some(on_param_update),
};
// Start the Device
GAPRole_PeripheralStartDevice(task_id, &bond_mgr_cb, &app_cb);
GAPRole_PeripheralStartDevice(task_id, &BOND_MGR_CB, &APP_CB);
}

loop {
Expand Down Expand Up @@ -470,13 +471,15 @@ async fn main(spawner: Spawner) -> ! {
println!("System Clocks: {}", hal::sysctl::clocks().hclk);
println!("ChipID: 0x{:02x}", hal::signature::get_chip_id());
println!("RTC datetime: {}", rtc.now());
println!("MemFree: {}K", hal::stack_free() / 1024);

spawner.spawn(blink(p.PA8.degrade())).unwrap();

// BLE part
println!("BLE Lib Version: {}", ble::lib_version());

let (task_id, sub) = hal::ble::init(Default::default()).unwrap();
let mut ble_config = ble::Config::default();
let (task_id, sub) = hal::ble::init(ble_config).unwrap();
println!("BLE task id: {}", task_id);

unsafe {
Expand All @@ -498,12 +501,11 @@ async fn main(spawner: Spawner) -> ! {
#[highcode]
#[embassy_executor::task]
async fn tmos_mainloop() {
let mut ticker = Ticker::every(Duration::from_micros(300));
loop {
Timer::after(Duration::from_micros(300)).await;
ticker.next().await;
unsafe {
hal::interrupt::SysTick::pend();
TMOS_SystemProcess();
hal::interrupt::SysTick::unpend();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/embassy-ble-broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ch32v_rt::highcode;
use ch58x_hal as hal;
use ch58x_hal::ble::gap::*;
use embassy_executor::Spawner;
use embassy_time::{Delay, Duration, Instant, Timer};
use hal::ble::ffi::*;
Expand Down
1 change: 1 addition & 0 deletions examples/embassy-ble-scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use embassy_executor::Spawner;
use embassy_sync::channel::Channel;
use embassy_time::{Delay, Duration, Instant, Timer};
use hal::ble::ffi::*;
use hal::ble::gap::*;
use hal::ble::{get_raw_temperature, MacAddress};
use hal::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pin, Pull};
use hal::interrupt::Interrupt;
Expand Down
2 changes: 1 addition & 1 deletion examples/uart-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use ch32v_rt::highcode;
use ch58x_hal as hal;
use embedded_hal_1::delay::DelayUs;

use hal::gpio::{Level, Output, OutputDrive};
use hal::peripherals;
use hal::rtc::Rtc;
Expand Down
10 changes: 5 additions & 5 deletions src/ble/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ pub const GAP_PHY_VAL_LE_2M: u16 = 2;
pub const GAP_PHY_VAL_LE_CODED: u16 = 3;

// GAP_ADVERTISEMENT_TYPE_DEFINES GAP Scan PHY VAL TYPE(GAP_PHY_BIT_TYPE)
pub const GAP_PHY_BIT_LE_1M: u32 = 1;
pub const GAP_PHY_BIT_LE_2M: u32 = 2;
pub const GAP_PHY_BIT_LE_CODED: u32 = 4;
pub const GAP_PHY_BIT_ALL: u32 = 7;
pub const GAP_PHY_BIT_LE_CODED_S2: u32 = 8;
pub const GAP_PHY_BIT_LE_1M: u16 = 1;
pub const GAP_PHY_BIT_LE_2M: u16 = 2;
pub const GAP_PHY_BIT_LE_CODED: u16 = 4;
pub const GAP_PHY_BIT_ALL: u16 = 7;
pub const GAP_PHY_BIT_LE_CODED_S2: u16 = 8;

// PHY_OPTIONS preferred coding when transmitting on the LE Coded PHY
pub const GAP_PHY_OPTIONS_NOPRE: u32 = 0;
Expand Down
21 changes: 3 additions & 18 deletions src/ble/gatt_uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,53 +47,38 @@ pub const LE_GATT_SEC_LEVELS_UUID: u16 = 0x2BF5; // LE GATT Security Levels

// UUID defined
extern "C" {
// [u8; 2]

// GATT Services
/// 1800
pub static gapServiceUUID: [u8; 0usize];

/// 1801
pub static gattServiceUUID: [u8; 0usize];

// GATT Attribute Types
pub static primaryServiceUUID: [u8; 0usize];

pub static secondaryServiceUUID: [u8; 0usize];

pub static includeUUID: [u8; 0usize];

pub static characterUUID: [u8; 0usize];

// GATT Characteristic Descriptors
pub static charExtPropsUUID: [u8; 0usize];

pub static charUserDescUUID: [u8; 0usize];

pub static clientCharCfgUUID: [u8; 0usize];

pub static servCharCfgUUID: [u8; 0usize];

pub static charFormatUUID: [u8; 0usize];

pub static charAggFormatUUID: [u8; 0usize];

pub static validRangeUUID: [u8; 0usize];

pub static extReportRefUUID: [u8; 0usize];

pub static reportRefUUID: [u8; 0usize];

// GATT Characteristic Types
pub static deviceNameUUID: [u8; 0usize];

pub static appearanceUUID: [u8; 0usize];

pub static periPrivacyFlagUUID: [u8; 0usize];

pub static reconnectAddrUUID: [u8; 0usize];

pub static periConnParamUUID: [u8; 0usize];

pub static serviceChangedUUID: [u8; 0usize];

pub static centAddrResUUID: [u8; 0usize];
}

Expand Down
4 changes: 2 additions & 2 deletions src/ble/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Config {

impl Default for Config {
fn default() -> Self {
let mac_addr = MacAddress::from_raw([0x11, 0x22, 0x33, 0x44, 0x55, 0x66]);
let mac_addr = MacAddress::from_msb([0x11, 0x22, 0x33, 0x44, 0x55, 0x66]);
Config { mac_addr }
}
}
Expand All @@ -87,7 +87,7 @@ unsafe extern "C" fn hal_tmos_task(task_id: u8, events: u16) -> u16 {
if !msg.is_null() {
let event = TmosEvent(msg as _);
CHANNEL.publish_immediate(event);

// Dealloc in Drop
// let _ = tmos_msg_deallocate(msg);
}
return events ^ SYS_EVENT_MSG;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod dma;
pub mod gpio;
pub mod i2c;
// pub mod lcd;
#[cfg(feature = "ble")]
pub mod ble;
pub mod rtc;
pub mod signature;
Expand Down

0 comments on commit 5a52918

Please sign in to comment.