Skip to content

Commit

Permalink
Merge pull request #63 from OpenVoiceOS/feat/hardware_detection
Browse files Browse the repository at this point in the history
[RFE] Mark 2 support
  • Loading branch information
goldyfruit authored Mar 29, 2024
2 parents 95d5adb + d8e6a40 commit 49e9eb5
Show file tree
Hide file tree
Showing 33 changed files with 660 additions and 59 deletions.
11 changes: 11 additions & 0 deletions ansible/roles/ovos_hardware_mark2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ovos_hardware_mark2

Setup the VocalFusionDriver kernel module for SJ201 Raspberry Pi HAT running on the Mark II device.

## License

Apache 2

## Author Information

Gaëtan Trellu - @goldyfruit
4 changes: 4 additions & 0 deletions ansible/roles/ovos_hardware_mark2/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
ovos_hardware_mark2_eeprom_release: latest
ovos_hardware_mark2_vocalfusion_repo_url: https://github.com/BohdanBuinich/VocalFusionDriver
ovos_hardware_mark2_vocalfusion_branch: next_gen
155 changes: 155 additions & 0 deletions ansible/roles/ovos_hardware_mark2/files/50-alsa-config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
alsa_monitor.enabled = true

alsa_monitor.properties = {
-- Create a JACK device. This is not enabled by default because
-- it requires that the PipeWire JACK replacement libraries are
-- not used by the session manager, in order to be able to
-- connect to the real JACK server.
--["alsa.jack-device"] = false,

-- Reserve devices via org.freedesktop.ReserveDevice1 on D-Bus
-- Disable if you are running a system-wide instance, which
-- doesn't have access to the D-Bus user session
["alsa.reserve"] = true,
--["alsa.reserve.priority"] = -20,
--["alsa.reserve.application-name"] = "WirePlumber",

-- Enables MIDI functionality
["alsa.midi"] = true,

-- Enables monitoring of alsa MIDI devices
["alsa.midi.monitoring"] = true,

-- MIDI bridge node properties
["alsa.midi.node-properties"] = {
-- Name set for the node with ALSA MIDI ports
["node.name"] = "Midi-Bridge",
-- Removes longname/number from MIDI port names
--["api.alsa.disable-longname"] = true,
},

-- These properties override node defaults when running in a virtual machine.
-- The rules below still override those.
["vm.node.defaults"] = {
["api.alsa.period-size"] = 256,
["api.alsa.headroom"] = 8192,
},
}

alsa_monitor.rules = {
-- An array of matches/actions to evaluate.
--
-- If you want to disable some devices or nodes, you can apply properties per device as the following example.
-- The name can be found by running pw-cli ls Device, or pw-cli dump Device
--{
-- matches = {
-- {
-- { "device.name", "matches", "name_of_some_disabled_card" },
-- },
-- },
-- apply_properties = {
-- ["device.disabled"] = true,
-- },
--}
{
-- Rules for matching a device or node. It is an array of
-- properties that all need to match the regexp. If any of the
-- matches work, the actions are executed for the object.
matches = {
{
-- This matches all cards.
{ "device.name", "matches", "alsa_card.*" },
},
},
-- Apply properties on the matched object.
apply_properties = {
-- Use ALSA-Card-Profile devices. They use UCM or the profile
-- configuration to configure the device and mixer settings.
--["api.alsa.use-acp"] = true,

-- Use UCM instead of profile when available. Can be
-- disabled to skip trying to use the UCM profile.
["api.alsa.use-ucm"] = true,

-- Don't use the hardware mixer for volume control. It
-- will only use software volume. The mixer is still used
-- to mute unused paths based on the selected port.
--["api.alsa.soft-mixer"] = false,

-- Ignore decibel settings of the driver. Can be used to
-- work around buggy drivers that report wrong values.
--["api.alsa.ignore-dB"] = false,

-- The profile set to use for the device. Usually this is
-- "default.conf" but can be changed with a udev rule or here.
--["device.profile-set"] = "profileset-name",

-- The default active profile. Is by default set to "Off".
--["device.profile"] = "default profile name",

-- Automatically select the best profile. This is the
-- highest priority available profile. This is disabled
-- here and instead implemented in the session manager
-- where it can save and load previous preferences.
["api.acp.auto-profile"] = false,

-- Automatically switch to the highest priority available port.
-- This is disabled here and implemented in the session manager instead.
["api.acp.auto-port"] = false,

-- Other properties can be set here.
--["device.nick"] = "My Device",
},
},
{
matches = {
{
-- Matches all sources.
{ "node.name", "matches", "alsa_input.*" },
},
{
-- Matches all sinks.
{ "node.name", "matches", "alsa_output.*" },
},
},
apply_properties = {
--["node.nick"] = "My Node",
--["node.description"] = "My Node Description",
--["priority.driver"] = 100,
--["priority.session"] = 100,
--["node.pause-on-idle"] = false,
--["monitor.channel-volumes"] = false
--["resample.quality"] = 4,
--["resample.disable"] = false,
--["channelmix.normalize"] = false,
--["channelmix.mix-lfe"] = false,
--["channelmix.upmix"] = true,
--["channelmix.upmix-method"] = "psd", -- "none" or "simple"
--["channelmix.lfe-cutoff"] = 150,
--["channelmix.fc-cutoff"] = 12000,
--["channelmix.rear-delay"] = 12.0,
--["channelmix.stereo-widen"] = 0.0,
--["channelmix.hilbert-taps"] = 0,
--["channelmix.disable"] = false,
--["dither.noise"] = 0,
--["dither.method"] = "none", -- "rectangular", "triangular" or "shaped5"
["audio.channels"] = 2,
["audio.format"] = "S32LE",
["audio.rate"] = 48000,
--["audio.allowed-rates"] = "32000,96000",
["audio.position"] = "FL,FR",
--["api.alsa.period-size"] = 1024,
--["api.alsa.period-num"] = 2,
--["api.alsa.headroom"] = 0,
--["api.alsa.start-delay"] = 0,
--["api.alsa.disable-mmap"] = false,
--["api.alsa.disable-batch"] = false,
--["api.alsa.use-chmap"] = false,
--["api.alsa.multirate"] = true,
--["latency.internal.rate"] = 0
--["latency.internal.ns"] = 0
--["clock.name"] = "api.alsa.0"
["session.suspend-timeout-seconds"] = 0, -- 0 disables suspend
},
},
}
13 changes: 13 additions & 0 deletions ansible/roles/ovos_hardware_mark2/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Reload Systemd User
become: true
become_user: "{{ ovos_installer_user }}"
ansible.builtin.systemd_service:
daemon_reload: true
scope: user

- name: Run Depmod
ansible.builtin.command:
cmd: |
depmod -a {{ _ovos_hardware_mark2_kernel_target }}
changed_when: false
27 changes: 27 additions & 0 deletions ansible/roles/ovos_hardware_mark2/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
galaxy_info:
author: Gaëtan trellu (@goldyfruit)
description: Open Voice OS installer Mark II
company: Smart'Gic
standalone: true

issue_tracker_url: https://github.com/openvoiceos/ovos-installer/issues

license: Apache-2.0

min_ansible_version: "2.12"

platforms:
- name: Debian
versions:
- bookworm
- bullseye

galaxy_tags:
- openvoiceos
- ovos
- hivemind
- voiceassistant
- mark2

dependencies: []
80 changes: 80 additions & 0 deletions ansible/roles/ovos_hardware_mark2/tasks/firmware.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
# This block is only meaningful until kernel 6.6.22 becomes
# the default Raspberry Pi stock kernel.
# The current stock kernel version is 6.6.20 which does not work
# with the VocalFusionDriver.
# rpi-firmware commit f17defccf231912cfe96c9d3a779b4e2d006abd6 (6.6.22)
- name: Block kernel upgrade
when: ansible_kernel is version("6.6.22", "<")
block:
- name: Kernel headers packages requirement
ansible.builtin.apt:
name:
- bc
- bison
- flex
- libssl-dev
install_recommends: false
update_cache: true

- name: Update kernel and firmware
ansible.builtin.shell:
cmd: |
set -o pipefail
echo y | rpi-update f17defccf231912cfe96c9d3a779b4e2d006abd6
executable: /bin/bash
environment:
SKIP_BACKUP: "1"
UPDATE_SELF: "1"
register: _firmware_status
changed_when: no

- name: Retrieve rpi-source Python script
ansible.builtin.get_url:
url: "{{ _ovos_hardware_mark2_rpi_source_url }}"
dest: /usr/local/bin/rpi-source
owner: root
group: root
mode: "0755"

- name: Build kernel headers
ansible.builtin.shell:
cmd: |
set -o pipefail
rpi-source -q --tag-update
echo -e -n "\r" | sudo rpi-source -d /usr/src/ --delete
ln -sf /usr/src/linux {{ _ovos_hardware_mark2_lib_modules_path }}/build
executable: /bin/bash
changed_when: no

- name: Set ovos_installer_reboot fact (firmware)
vars:
_firmware_reboot: "{{ _firmware_status.stdout | regex_search('reboot') }}"
ansible.builtin.set_fact:
ovos_installer_reboot: true
when: _firmware_status is defined and _firmware_reboot | length > 0

- name: Install kernel headers
ansible.builtin.apt:
name: raspberrypi-kernel-headers
install_recommends: false
update_cache: true

- name: Set EEPROM release
ansible.builtin.lineinfile:
path: /etc/default/rpi-eeprom-update
regexp: "^FIRMWARE_RELEASE_STATUS="
line: 'FIRMWARE_RELEASE_STATUS="{{ ovos_hardware_mark2_eeprom_release }}"'

- name: Update EEPROM
ansible.builtin.command:
cmd: rpi-eeprom-update -a
register: _eeprom_status
changed_when: no

- name: Set ovos_installer_reboot fact (EEPROM)
vars:
_eeprom_reboot: "{{ _eeprom_status.stdout | regex_search('reboot') }}"
ansible.builtin.set_fact:
ovos_installer_reboot: true
when: _eeprom_status is defined and _eeprom_reboot | length > 0
12 changes: 12 additions & 0 deletions ansible/roles/ovos_hardware_mark2/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Include prepare.yml
ansible.builtin.import_tasks: prepare.yml

- name: Include firmware.yml
ansible.builtin.import_tasks: firmware.yml

- name: Include vocalfusion.yml
ansible.builtin.import_tasks: vocalfusion.yml

- name: Include wireplumber.yml
ansible.builtin.import_tasks: wireplumber.yml
12 changes: 12 additions & 0 deletions ansible/roles/ovos_hardware_mark2/tasks/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Create directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ ovos_installer_user }}"
group: "{{ ovos_installer_user }}"
mode: "0755"
loop:
- /opt/sj201
- "{{ ovos_installer_user_home }}/.config/systemd/user"
- "{{ ovos_installer_user_home }}/.config/wireplumber/main.lua.d"
Loading

0 comments on commit 49e9eb5

Please sign in to comment.