-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d3206b
commit a74c10c
Showing
24 changed files
with
332 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 1.0.* | ||
|
||
## Breaking Changes | ||
|
||
- [Adapter] `c::send_command/2` -> `c::cast/2` | ||
- [HCI] remove `t::command/0` in favor of `binary()` | ||
- [HCI] `command/2` now prepends its return with a `<<1>>` | ||
- [Transport] remove `t::command/0` in favor of `binary()` | ||
- [Transport] `send_command/2` -> `cast/2` (the backing `handle_call`s were | ||
upadted as well) | ||
- [UART] `send_command/2` -> `cast/2` (the backing `handle_call`s were upadted | ||
as well) | ||
- [UART] `cast/2` no longer prepends its `bin`s with a `<<1>>` | ||
|
||
## Enhancements | ||
|
||
- [Changelog] now Harald has one | ||
- [HCI] `opcode/2` no longer guards `ogf` and `ocf` values because vendor | ||
specific commands may fall outside of those bounds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
defmodule Harald.Chip.TI.BTS do | ||
@moduledoc """ | ||
Parsing functionality for BTS files. | ||
Reference: http://www.ti.com/tool/WL18XX-BT-SP | ||
""" | ||
|
||
require Logger | ||
|
||
@action_send_command 1 | ||
|
||
@action_wait_event 2 | ||
|
||
@action_serial 3 | ||
|
||
@action_delay 4 | ||
|
||
@action_run_script 5 | ||
|
||
@action_remarks 6 | ||
|
||
@doc """ | ||
Parses the BTS file at `path`. | ||
Only send and delay actions are returned. | ||
""" | ||
def parse(path) do | ||
<< | ||
_magic::binary-size(4), | ||
_version::little-size(32), | ||
_future::size(192), | ||
actions::binary | ||
>> = File.read!(path) | ||
|
||
reduce_actions(actions) | ||
end | ||
|
||
defp reduce_actions(bin, actions \\ []) | ||
|
||
defp reduce_actions(<<>>, actions), do: Enum.reverse(actions) | ||
|
||
defp reduce_actions( | ||
<< | ||
@action_send_command::little-size(16), | ||
size::little-size(16), | ||
data::binary-size(size), | ||
rest::binary | ||
>>, | ||
actions | ||
) do | ||
debug(:send, data) | ||
reduce_actions(rest, [data | actions]) | ||
end | ||
|
||
defp reduce_actions( | ||
<< | ||
@action_wait_event::little-size(16), | ||
size::little-size(16), | ||
data::binary-size(size), | ||
rest::binary | ||
>>, | ||
actions | ||
) do | ||
debug(:wait, data) | ||
reduce_actions(rest, actions) | ||
end | ||
|
||
defp reduce_actions( | ||
<< | ||
@action_serial::little-size(16), | ||
size::little-size(16), | ||
data::binary-size(size), | ||
rest::binary | ||
>>, | ||
actions | ||
) do | ||
debug(:serial, data) | ||
reduce_actions(rest, actions) | ||
end | ||
|
||
defp reduce_actions( | ||
<< | ||
@action_delay::little-size(16), | ||
size::little-size(16), | ||
data::binary-size(size), | ||
rest::binary | ||
>>, | ||
actions | ||
) do | ||
debug(:delay, data) | ||
reduce_actions(rest, [data | actions]) | ||
end | ||
|
||
defp reduce_actions( | ||
<< | ||
@action_run_script::little-size(16), | ||
size::little-size(16), | ||
data::binary-size(size), | ||
rest::binary | ||
>>, | ||
actions | ||
) do | ||
debug(:run_script, data) | ||
reduce_actions(rest, actions) | ||
end | ||
|
||
defp reduce_actions( | ||
<< | ||
@action_remarks::little-size(16), | ||
size::little-size(16), | ||
data::binary-size(size), | ||
rest::binary | ||
>>, | ||
actions | ||
) do | ||
debug(:remarks, data) | ||
reduce_actions(rest, actions) | ||
end | ||
|
||
defp debug(:remarks, bin) do | ||
:ok = Logger.debug("remarks " <> String.replace(bin, <<0>>, <<>>)) | ||
end | ||
|
||
defp debug(label, bin) do | ||
:ok = Logger.debug(String.pad_trailing("#{label}", 10, " ") <> inspect(bin)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule Harald.Chip.TI.WiLink8 do | ||
@moduledoc """ | ||
Setup functionality for the TI WiLink 8. | ||
""" | ||
|
||
alias Harald.Chip.TI.BTS | ||
require Logger | ||
|
||
def setup(_namespace, args) do | ||
bts_path = Keyword.fetch!(args, :bts_path) | ||
gpio_bt_en = Keyword.fetch!(args, :gpio_bt_en) | ||
{:ok, pin_ref} = Circuits.GPIO.open(gpio_bt_en, :output) | ||
Circuits.GPIO.write(pin_ref, 0) | ||
Process.sleep(5) | ||
Circuits.GPIO.write(pin_ref, 1) | ||
Process.sleep(200) | ||
|
||
hci_commands = | ||
bts_path | ||
|> BTS.parse() | ||
|> Enum.filter(fn <<1, opcode::size(16), _::binary>> -> | ||
<<x::little-size(16)>> = <<opcode::size(16)>> | ||
|
||
case x do | ||
65334 -> false | ||
64780 -> false | ||
_ -> true | ||
end | ||
end) | ||
|
||
{:ok, hci_commands} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.