Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: rust
rust: nightly-2019-03-22
rust: nightly-2019-05-01
os:
- linux
- osx
Expand Down
181 changes: 125 additions & 56 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ version = "0.0.2"
[dependencies]
bare-metal = { version = "0.2.4", features = ["const-fn"] }
bit_field = "0.9.0"
cortex-m = "0.5.8"
cortex-m = "0.5.10"
cortex-m-rt = "0.6.5"
cortex-m-semihosting = "0.3.1"
nb = "0.1.1"
vcell = "0.1.0"

[patch.crates-io.cortex-m]
# for SCB::system_reset2
git = "https://github.com/hdhoang/cortex-m"
branch = "static-system_reset2"
num-derive = "0.2.5"

[dependencies.rtfm]
package = "cortex-m-rtfm"
Expand All @@ -48,6 +44,15 @@ optional = true
version = "0.5.1"
optional = true

[dependencies.num-traits]
version = "0.2.8"
default-features = false

[patch.crates-io.cortex-m]
# for SCB::system_reset2
git = "https://github.com/hdhoang/cortex-m"
branch = "static-system_reset2"

[features]
default = ["panic-abort"]
use_semihosting = ["panic-semihosting"]
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2019-03-22
nightly-2019-05-01
50 changes: 26 additions & 24 deletions src/bluetooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::serial::{DmaUsart, Serial, Transfer};

use core::marker::Unsize;
use nb;
use num_traits::FromPrimitive;

#[derive(Copy, Clone, PartialEq)]
pub enum BluetoothMode {
Expand Down Expand Up @@ -119,8 +120,8 @@ where
) {
match message.msg_type {
MsgType::System => {
match SystemOp::from(message.operation) {
SystemOp::GetId => {
match SystemOp::from_u8(message.operation) {
Some(SystemOp::GetId) => {
const DEVICE_TYPE_KEYBOARD: u8 = 1;
const DEVICE_MODEL_ANNE_PRO: u8 = 2;
//const DEVICE_ID = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
Expand Down Expand Up @@ -151,12 +152,12 @@ where
.send(MsgType::System, SystemOp::AckGetId as u8, &data2)
.log_error();
}
SystemOp::IsSyncCode => {
Some(SystemOp::IsSyncCode) => {
self.serial
.send(MsgType::System, SystemOp::AckIsSyncCode as u8, &[1])
.log_error();
}
SystemOp::SetSyncCode => {
Some(SystemOp::SetSyncCode) => {
self.serial
.send(MsgType::System, SystemOp::AckIsSyncCode as u8, &[])
.log_error();
Expand All @@ -168,38 +169,38 @@ where
}
}
MsgType::Ble => {
match BleOp::from(message.operation) {
BleOp::AckWakeup => {
match BleOp::from_u8(message.operation) {
Some(BleOp::AckWakeup) => {
// nothing to do here, this message only only lets us know
// that we can now safely send
}
BleOp::AckOn => {
Some(BleOp::AckOn) => {
// data = [0]
// TODO: always getting a [0] too much?
//crate::heprintln!("bt ack on: {:?}", message.data).ok();
}
BleOp::AckOff => {
Some(BleOp::AckOff) => {
// data = [0]
//crate::heprintln!("bt ack off: {:?}", message.data).ok();
}
BleOp::AckLegacyMode => {
Some(BleOp::AckLegacyMode) => {
// data = [0]
//crate::heprintln!("bt ack legacy mode: {:?}", message.data).ok();
}
BleOp::AckDeleteHost => {
Some(BleOp::AckDeleteHost) => {
// data = [0]
//crate::heprintln!("bt ack delete host: {:?}", message.data).ok();
}
BleOp::Pair => {
Some(BleOp::Pair) => {
crate::heprintln!("bt pair").ok();
keyboard.disable_bluetooth_mode();
led.bluetooth_pin_mode().log_error();
}
BleOp::Disconnect => {
Some(BleOp::Disconnect) => {
// check this? sent after off, 14
crate::heprintln!("bt disconnect").ok();
}
BleOp::AckHostListQuery => {
Some(BleOp::AckHostListQuery) => {
if message.data.len() == 3 {
self.saved_hosts = message.data[0];
self.connected_host = message.data[1];
Expand All @@ -219,11 +220,11 @@ where
}
}
}
MsgType::Led => match LedOp::from(message.operation) {
LedOp::ThemeMode => {
MsgType::Led => match LedOp::from_u8(message.operation) {
Some(LedOp::ThemeMode) => {
led.set_theme(message.data[0]).log_error();
}
LedOp::GetUserStaticTheme => {
Some(LedOp::GetUserStaticTheme) => {
crate::heprintln!("TODO: Theme Sync").ok();
// [data_length, num_blocks, block_i]
//let data = [2 + 4, 1, 0, 1, 2, 3, 4];
Expand All @@ -235,17 +236,17 @@ where
crate::heprintln!("msg: Led {} {:?}", message.operation, message.data).ok();
}
},
MsgType::Keyboard => match KeyboardOp::from(message.operation) {
KeyboardOp::UpUserLayout => {
MsgType::Keyboard => match KeyboardOp::from_u8(message.operation) {
Some(KeyboardOp::UpUserLayout) => {
crate::heprintln!("TODO: Keyboard Sync").ok();
}
_ => {
crate::heprintln!("msg: Keyboard {} {:?}", message.operation, message.data)
.ok();
}
},
MsgType::Macro => match MacroOp::from(message.operation) {
MacroOp::SyncMacro => {
MsgType::Macro => match MacroOp::from_u8(message.operation) {
Some(MacroOp::SyncMacro) => {
crate::heprintln!("TODO: Macro Sync").ok();
}
_ => {
Expand Down Expand Up @@ -278,15 +279,16 @@ where
{
let buffer: &mut [u8] = buffer;
let message = Message {
msg_type: MsgType::from(buffer[0]),
msg_type: MsgType::from_u8(buffer[0]).expect("bad MsgType"),
operation: buffer[2],
data: &buffer[3..3 + buffer[1] as usize - 1],
};
self.handle_message(&message, led, keyboard);

if let (MsgType::Ble, BleOp::AckWakeup) =
(message.msg_type, message.operation.into())
{
if let (MsgType::Ble, BleOp::AckWakeup) = (
message.msg_type,
BleOp::from_u8(message.operation).expect("bad BleOp"),
) {
// Wakeup acknowledged, send data
self.serial.usart.ack_wakeup();
self.serial.send_buffer_pos = 0;
Expand Down
11 changes: 6 additions & 5 deletions src/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use embedded_hal::digital::OutputPin;
use hal::gpio::gpioc::PC15;
use hal::gpio::{Input, Output};
use nb;
use num_traits::FromPrimitive;
use stm32l1::stm32l151::SYST;

pub enum LedMode {
Expand Down Expand Up @@ -214,16 +215,16 @@ where
pub fn handle_message(&mut self, message: &Message<'_>) {
match message.msg_type {
MsgType::Led => {
match LedOp::from(message.operation) {
LedOp::AckThemeMode => {
match LedOp::from_u8(message.operation) {
Some(LedOp::AckThemeMode) => {
// data: [theme id]
//crate::heprintln!("Led AckThemeMode {:?}", message.data).ok();
}
LedOp::AckConfigCmd => {
Some(LedOp::AckConfigCmd) => {
// data: [theme id, brightness, animation speed]
//crate::heprintln!("Led AckConfigCmd {:?}", message.data).ok();
}
LedOp::AckSetIndividualKeys => {
Some(LedOp::AckSetIndividualKeys) => {
// data: [202]
}
_ => {
Expand Down Expand Up @@ -264,7 +265,7 @@ where
{
let buffer: &mut [u8] = buffer;
let message = Message {
msg_type: MsgType::from(buffer[0]),
msg_type: MsgType::from_u8(buffer[0]).expect("bad MsgType"),
operation: buffer[2],
data: &buffer[3..3 + buffer[1] as usize - 1],
};
Expand Down
Loading