From 181b166aa3376ce18267cde1e8a6cf685246224e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 10:25:34 -0400 Subject: [PATCH 01/13] [mark1] Add initial support --- ansible/roles/ovos_hardware_mark1/README.md | 11 +++++ .../ovos_hardware_mark1/defaults/main.yml | 1 + .../ovos_hardware_mark1/files/initialize.sh | 21 ++++++++ .../ovos_hardware_mark1/handlers/main.yml | 11 +++++ .../roles/ovos_hardware_mark1/meta/main.yml | 28 +++++++++++ .../ovos_hardware_mark1/tasks/config.yml | 35 +++++++++++++ .../roles/ovos_hardware_mark1/tasks/main.yml | 9 ++++ .../ovos_hardware_mark1/tasks/prepare.yml | 14 ++++++ .../ovos_hardware_mark1/tasks/service.yml | 21 ++++++++ .../templates/mark1.service.j2 | 15 ++++++ .../roles/ovos_hardware_mark1/vars/main.yml | 2 + .../ovos_hardware_mark2/tasks/vocalfusion.yml | 4 +- ansible/site.yml | 9 ++++ tui/detection.sh | 3 ++ utils/common.sh | 49 ++++++++++++++++++- utils/constants.sh | 4 ++ 16 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 ansible/roles/ovos_hardware_mark1/README.md create mode 100644 ansible/roles/ovos_hardware_mark1/defaults/main.yml create mode 100644 ansible/roles/ovos_hardware_mark1/files/initialize.sh create mode 100644 ansible/roles/ovos_hardware_mark1/handlers/main.yml create mode 100644 ansible/roles/ovos_hardware_mark1/meta/main.yml create mode 100644 ansible/roles/ovos_hardware_mark1/tasks/config.yml create mode 100644 ansible/roles/ovos_hardware_mark1/tasks/main.yml create mode 100644 ansible/roles/ovos_hardware_mark1/tasks/prepare.yml create mode 100644 ansible/roles/ovos_hardware_mark1/tasks/service.yml create mode 100644 ansible/roles/ovos_hardware_mark1/templates/mark1.service.j2 create mode 100644 ansible/roles/ovos_hardware_mark1/vars/main.yml diff --git a/ansible/roles/ovos_hardware_mark1/README.md b/ansible/roles/ovos_hardware_mark1/README.md new file mode 100644 index 00000000..f31c6a89 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/README.md @@ -0,0 +1,11 @@ +# ovos_hardware_mark1 + +Setup the atmega328p Arduino chip running on the Mark 1 device. + +## License + +Apache 2 + +## Author Information + +Gaëtan Trellu - @goldyfruit diff --git a/ansible/roles/ovos_hardware_mark1/defaults/main.yml b/ansible/roles/ovos_hardware_mark1/defaults/main.yml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/ansible/roles/ovos_hardware_mark1/files/initialize.sh b/ansible/roles/ovos_hardware_mark1/files/initialize.sh new file mode 100644 index 00000000..09681716 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/files/initialize.sh @@ -0,0 +1,21 @@ +#!/bin/env bash +# +# This script initialiaze the atmega328p chip from the Mark 1 +# device. +# Once initialized the eyes color will be changed to yellow and +# the mouth text will display "booting". + +# Variables +eyes_color="16760576" +mouth_text="booting" +tty_device=/dev/ttyAMA0 + +# Initialiaze the firmware and wait two seconds +avrdude -p atmega328p -c linuxgpio -U signature:r:-:i -F +sleep 2 + +# Set eyes color +echo "eyes.color=$eyes_color" > "$tty_device" + +# Set mouth text +echo "mouth.text=$mouth_text" > "$tty_device" diff --git a/ansible/roles/ovos_hardware_mark1/handlers/main.yml b/ansible/roles/ovos_hardware_mark1/handlers/main.yml new file mode 100644 index 00000000..b2624374 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/handlers/main.yml @@ -0,0 +1,11 @@ +--- +- name: Reload Systemd User + become: true + become_user: "{{ ovos_installer_user }}" + ansible.builtin.systemd_service: + daemon_reload: true + scope: user + +- name: Set Reboot + ansible.builtin.set_fact: + ovos_installer_reboot: true diff --git a/ansible/roles/ovos_hardware_mark1/meta/main.yml b/ansible/roles/ovos_hardware_mark1/meta/main.yml new file mode 100644 index 00000000..97188474 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/meta/main.yml @@ -0,0 +1,28 @@ +--- +galaxy_info: + author: Gaëtan trellu (@goldyfruit) + description: Open Voice OS installer Mark 1 + 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 + - mark1 + - atmega328p + +dependencies: [] diff --git a/ansible/roles/ovos_hardware_mark1/tasks/config.yml b/ansible/roles/ovos_hardware_mark1/tasks/config.yml new file mode 100644 index 00000000..c9faa4d5 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/tasks/config.yml @@ -0,0 +1,35 @@ +--- +- name: Check for /boot/firmware directory + ansible.builtin.stat: + path: /boot/firmware + register: _boot_config_status + +- name: Set _boot_directory fact + ansible.builtin.set_fact: + _boot_directory: "{{ '/boot/firmware' if _boot_config_status.stat.exists | bool else '/boot' }}" + +- name: Manage TTY and soundcard overlays + ansible.builtin.lineinfile: + path: /boot/firmware/config.txt + regexp: "^{{ item }}" + line: "{{ item }}" + notify: Set Reboot + loop: + - dtoverlay=miniuart-bt + - dtoverlay=proto-codec + +- name: Disable onboard audio interface + ansible.builtin.lineinfile: + path: "{{ _boot_directory }}/config.txt" + regexp: "^{{ item.key }}=" + line: "{{ item.key }}={{ item.value }}" + notify: Set Reboot + loop: + - { key: "dtparam=audio", value: "off" } + +- name: Redirect console to tty1 only + ansible.builtin.replace: + path: "{{ _boot_directory }}/cmdline.txt" + regexp: '\bconsole=serial0,115200\b\s?' + replace: "" + notify: Set Reboot diff --git a/ansible/roles/ovos_hardware_mark1/tasks/main.yml b/ansible/roles/ovos_hardware_mark1/tasks/main.yml new file mode 100644 index 00000000..956017f4 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: Include prepare.yml + ansible.builtin.import_tasks: prepare.yml + +- name: Include config.yml + ansible.builtin.import_tasks: config.yml + +- name: Include service.yml + ansible.builtin.import_tasks: service.yml diff --git a/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml b/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml new file mode 100644 index 00000000..fb1c68fe --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml @@ -0,0 +1,14 @@ +--- +- name: Add {{ ovos_installer_user }} to dialout group + ansible.builtin.user: + name: "{{ ovos_installer_user }}" + groups: dialout + append: true + +- name: Create /opt/mark1 directory + ansible.builtin.file: + path: /opt/mark1 + state: directory + owner: "{{ ovos_installer_user }}" + group: "{{ ovos_installer_user }}" + mode: "0755" diff --git a/ansible/roles/ovos_hardware_mark1/tasks/service.yml b/ansible/roles/ovos_hardware_mark1/tasks/service.yml new file mode 100644 index 00000000..23574a74 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/tasks/service.yml @@ -0,0 +1,21 @@ +--- +- name: Copy mark1 systemd unit file + ansible.builtin.template: + src: mark1.service.j2 + dest: "{{ ovos_installer_user_home }}/.config/systemd/user/mark1.service" + owner: "{{ ovos_installer_user }}" + group: "{{ ovos_installer_user }}" + mode: "0644" + notify: Reload Systemd User + +- name: Flush handlers service + ansible.builtin.meta: flush_handlers + +- name: Enable mark1 systemd unit + become: true + become_user: "{{ ovos_installer_user }}" + ansible.builtin.systemd_service: + name: mark1.service + enabled: true + force: true + scope: user diff --git a/ansible/roles/ovos_hardware_mark1/templates/mark1.service.j2 b/ansible/roles/ovos_hardware_mark1/templates/mark1.service.j2 new file mode 100644 index 00000000..d5d9c440 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/templates/mark1.service.j2 @@ -0,0 +1,15 @@ +[Unit] +Documentation=https://github.com/MycroftAI/enclosure-mark1 +Description=Mycroft Mark 1's atmega328p initialization +After=network-online.target +ConditionPathExists=/dev/ttyAMA0 + +[Service] +Type=oneshot +ExecStart=/opt/mark1/initialize.sh +Restart=on-failure +RestartSec=5s +RemainAfterExit=yes + +[Install] +WantedBy=default.target diff --git a/ansible/roles/ovos_hardware_mark1/vars/main.yml b/ansible/roles/ovos_hardware_mark1/vars/main.yml new file mode 100644 index 00000000..b3de7dd3 --- /dev/null +++ b/ansible/roles/ovos_hardware_mark1/vars/main.yml @@ -0,0 +1,2 @@ +--- +_ovos_hardware_mark1_avrdude_binary: /usr/local/bin/avrdude diff --git a/ansible/roles/ovos_hardware_mark2/tasks/vocalfusion.yml b/ansible/roles/ovos_hardware_mark2/tasks/vocalfusion.yml index 3e78ce6d..ae2be32d 100644 --- a/ansible/roles/ovos_hardware_mark2/tasks/vocalfusion.yml +++ b/ansible/roles/ovos_hardware_mark2/tasks/vocalfusion.yml @@ -111,7 +111,7 @@ force: true scope: user -- name: Delete /usr/src/vocalfusion once compiled +- name: Delete {{ _ovos_hardware_mark2_vocalfusion_src_path }} once compiled ansible.builtin.file: - path: /usr/src/vocalfusion + path: "{{ _ovos_hardware_mark2_vocalfusion_src_path }}" state: absent diff --git a/ansible/site.yml b/ansible/site.yml index e8e7a5bf..507d8b0c 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -19,6 +19,14 @@ - always roles: + - role: ovos_hardware_mark1 + when: + - ansible_distribution == "Debian" + - ansible_distribution_major_version is version('11', '>=') + - "'Raspberry Pi 4' in ovos_installer_raspberrypi or 'Raspberry Pi 5' in ovos_installer_raspberrypi" + - "'atmega328p' in ovos_installer_i2c_devices" + - ansible_architecture == "aarch64" + - role: ovos_hardware_mark2 when: - ansible_distribution == "Debian" @@ -26,6 +34,7 @@ - "'Raspberry Pi 4' in ovos_installer_raspberrypi or 'Raspberry Pi 5' in ovos_installer_raspberrypi" - "'tas5806' in ovos_installer_i2c_devices" - ansible_architecture == "aarch64" + - role: ovos_installer tasks: diff --git a/tui/detection.sh b/tui/detection.sh index 357ab11f..a29bd823 100644 --- a/tui/detection.sh +++ b/tui/detection.sh @@ -7,6 +7,9 @@ for device in "${DETECTED_DEVICES[@]}"; do tas5806) HARDWARE_DETECTED="Mycroft Mark II" ;; + atmega328p) + HARDWARE_DETECTED="Mycroft Mark 1" + ;; esac done export HARDWARE_DETECTED diff --git a/utils/common.sh b/utils/common.sh index 99823edc..38f47f17 100644 --- a/utils/common.sh +++ b/utils/common.sh @@ -380,9 +380,56 @@ function i2c_scan() { for device in "${!SUPPORTED_DEVICES[@]}"; do address="${SUPPORTED_DEVICES[$device]}" if i2c_get "$address"; then - DETECTED_DEVICES+=("$device") + if [ "$device" == "reserved" ]; then + detect_mark1_device + else + DETECTED_DEVICES+=("$device") + fi fi done echo -e "[$done_format]" fi } + +# Downloads avrdude binary with libgpiod support from +# https://artifacts.smartgic.io. Once downloaded, a custom avrduderc will +# be created with the Mark 1 required pinout. This binary will only be +# downloaded when I2C UU reserved address and Raspberry Pi board are detected. +function setup_avrdude() { + if [ -f "$AVRDUDE_BINARY_PATH" ]; then + rm "$AVRDUDE_BINARY_PATH" + fi + + curl -s -f -L "$AVRDUDE_URL" -o "$AVRDUDE_BINARY_PATH" &>>"$LOG_FILE" + chmod 0755 "$AVRDUDE_BINARY_PATH" &>>"$LOG_FILE" + + cat <"$RUN_AS_HOME/.avrduderc" + # Mark 1 pinout + programmer + id = "linuxgpio"; + desc = "Use the Linux sysfs interface to bitbang GPIO lines"; + type = "linuxgpio"; + connection_type = linuxgpio; + prog_modes = PM_ISP; + reset = 22; + sck = 27; + sdo = 24; + sdi = 17; + ; +EOF + chown "$RUN_AS:$RUN_AS" "$RUN_AS_HOME/.avrduderc" +} + +# This function retrieves the atmega328p signature when present. If the +# signature matches a specific value then it means that a Mark 1 device +# is detected. +# This function is only triggered when a I2C reserved device is detected. +function detect_mark1_device() { + setup_avrdude + atmega328p="$(avrdude -p atmega328p -c linuxgpio -U signature:r:-:i -F 2>>"$LOG_FILE" | head -1)" + if [ "$atmega328p" == "$ATMEGA328P_SIGNATURE" ] ; then + DETECTED_DEVICES+=("atmega328p") + return 0 + fi + return 1 +} diff --git a/utils/constants.sh b/utils/constants.sh index ecf0e634..3a20b246 100644 --- a/utils/constants.sh +++ b/utils/constants.sh @@ -1,5 +1,8 @@ #!/bin/env bash +export ATMEGA328P_SIGNATURE=":030000001E950F3B" +export AVRDUDE_BINARY_PATH=/usr/local/bin/avrdude +export AVRDUDE_URL="https://artifacts.smartgic.io/avrdude-aarch64" declare -a DETECTED_DEVICES export DETECTED_DEVICES export DT_FILE=/sys/firmware/devicetree/base/model @@ -45,6 +48,7 @@ export SCENARIO_NAME="scenario.yaml" export SCENARIO_PATH="" declare -rA SUPPORTED_DEVICES=( ["tas5806"]="2f" #https://www.ti.com/product/TAS5806MD + ["reserved"]="UU" ) export SUPPORTED_DEVICES export TUI_WINDOW_HEIGHT="35" From 97fb0fb34e8a747d8a27e9dc73ce6ef140d9d5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 10:27:33 -0400 Subject: [PATCH 02/13] [mark1] Add PHAL plugin --- .../templates/virtualenv/core-requirements.txt.j2 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ansible/roles/ovos_installer/templates/virtualenv/core-requirements.txt.j2 b/ansible/roles/ovos_installer/templates/virtualenv/core-requirements.txt.j2 index 5872ad18..92a6b211 100644 --- a/ansible/roles/ovos_installer/templates/virtualenv/core-requirements.txt.j2 +++ b/ansible/roles/ovos_installer/templates/virtualenv/core-requirements.txt.j2 @@ -38,6 +38,9 @@ git+https://github.com/OpenVoiceOS/ovos-ocp-youtube-plugin.git {% if 'tas5806' in ovos_installer_i2c_devices %} git+https://github.com/OpenVoiceOS/ovos-PHAL-plugin-hotkeys.git {% endif %} +{% if 'atmega328p' in ovos_installer_i2c_devices %} +git+https://github.com/OpenVoiceOS/ovos-PHAL-plugin-mk1.git +{% endif %} git+https://github.com/OpenVoiceOS/ovos-stt-plugin-chromium.git git+https://github.com/OpenVoiceOS/ovos-tts-plugin-polly.git git+https://github.com/OpenVoiceOS/ovos-utterance-corrections-plugin.git From 2651c9257d8a4885f26a029763a3822082bd756e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 11:00:29 -0400 Subject: [PATCH 03/13] [mark1] Don't restrict only to RPi 4/5 --- ansible/site.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/ansible/site.yml b/ansible/site.yml index 507d8b0c..78712e95 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -23,7 +23,6 @@ when: - ansible_distribution == "Debian" - ansible_distribution_major_version is version('11', '>=') - - "'Raspberry Pi 4' in ovos_installer_raspberrypi or 'Raspberry Pi 5' in ovos_installer_raspberrypi" - "'atmega328p' in ovos_installer_i2c_devices" - ansible_architecture == "aarch64" From 87e4f45322beca5e738960502112781de03bf852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 11:02:50 -0400 Subject: [PATCH 04/13] [mark1] Check for specific I2C address for Mark 1 --- utils/common.sh | 9 +++++---- utils/constants.sh | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/utils/common.sh b/utils/common.sh index 38f47f17..9ead6355 100644 --- a/utils/common.sh +++ b/utils/common.sh @@ -356,7 +356,7 @@ function ver() { # This function takes an argument like "2f", this will be converted # to "0x2f". function i2c_get() { - if i2cdetect -y -a "$I2C_BUS" "0x$1" "0x$1" 2>>"$LOG_FILE" | grep -q "$1"; then + if i2cdetect -y -a "$I2C_BUS" "0x$1" "0x$1" 2>>"$LOG_FILE" | grep -Eq "$1|UU"; then return 0 fi return 1 @@ -380,7 +380,7 @@ function i2c_scan() { for device in "${!SUPPORTED_DEVICES[@]}"; do address="${SUPPORTED_DEVICES[$device]}" if i2c_get "$address"; then - if [ "$device" == "reserved" ]; then + if [ "$device" == "atmega328p" ]; then detect_mark1_device else DETECTED_DEVICES+=("$device") @@ -394,7 +394,8 @@ function i2c_scan() { # Downloads avrdude binary with libgpiod support from # https://artifacts.smartgic.io. Once downloaded, a custom avrduderc will # be created with the Mark 1 required pinout. This binary will only be -# downloaded when I2C UU reserved address and Raspberry Pi board are detected. +# downloaded when I2C 1a address (UU reserved address) and Raspberry Pi +# board are detected. function setup_avrdude() { if [ -f "$AVRDUDE_BINARY_PATH" ]; then rm "$AVRDUDE_BINARY_PATH" @@ -426,7 +427,7 @@ EOF # This function is only triggered when a I2C reserved device is detected. function detect_mark1_device() { setup_avrdude - atmega328p="$(avrdude -p atmega328p -c linuxgpio -U signature:r:-:i -F 2>>"$LOG_FILE" | head -1)" + atmega328p="$(avrdude -C +"$RUN_AS_HOME"/.avrduderc -p atmega328p -c linuxgpio -U signature:r:-:i -F 2>>"$LOG_FILE" | head -1)" if [ "$atmega328p" == "$ATMEGA328P_SIGNATURE" ] ; then DETECTED_DEVICES+=("atmega328p") return 0 diff --git a/utils/constants.sh b/utils/constants.sh index 3a20b246..bc45af08 100644 --- a/utils/constants.sh +++ b/utils/constants.sh @@ -48,7 +48,7 @@ export SCENARIO_NAME="scenario.yaml" export SCENARIO_PATH="" declare -rA SUPPORTED_DEVICES=( ["tas5806"]="2f" #https://www.ti.com/product/TAS5806MD - ["reserved"]="UU" + ["atmega328p"]="1a" #Displayed as UU ) export SUPPORTED_DEVICES export TUI_WINDOW_HEIGHT="35" From 7d4740a410c228666e9e90cf7dbed6366cf3c073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 11:08:38 -0400 Subject: [PATCH 05/13] [mark1] Add PHAL plugin to satellite --- .../templates/virtualenv/satellite-requirements.txt.j2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ansible/roles/ovos_installer/templates/virtualenv/satellite-requirements.txt.j2 b/ansible/roles/ovos_installer/templates/virtualenv/satellite-requirements.txt.j2 index 7f26d1ff..d1635ba5 100644 --- a/ansible/roles/ovos_installer/templates/virtualenv/satellite-requirements.txt.j2 +++ b/ansible/roles/ovos_installer/templates/virtualenv/satellite-requirements.txt.j2 @@ -24,6 +24,12 @@ poorman-handshake # No PyPi release git+https://github.com/JarbasHiveMind/HiveMind-voice-sat.git git+https://github.com/JarbasHiveMind/hivemind_websocket_client.git +{% if 'tas5806' in ovos_installer_i2c_devices %} +git+https://github.com/OpenVoiceOS/ovos-PHAL-plugin-hotkeys.git +{% endif %} +{% if 'atmega328p' in ovos_installer_i2c_devices %} +git+https://github.com/OpenVoiceOS/ovos-PHAL-plugin-mk1.git +{% endif %} git+https://github.com/OpenVoiceOS/ovos-stt-plugin-chromium.git git+https://github.com/OpenVoiceOS/ovos-tts-plugin-polly.git {% if ovos_installer_cpu_is_capable | bool %} From 594af08038a09d93e47ee781d0d85ca61b980da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 11:19:40 -0400 Subject: [PATCH 06/13] [mark1] Add missing initialize.sh file --- ansible/roles/ovos_hardware_mark1/tasks/prepare.yml | 12 ++++++++++-- ansible/roles/ovos_hardware_mark1/vars/main.yml | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml b/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml index fb1c68fe..0d129f75 100644 --- a/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml +++ b/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml @@ -5,10 +5,18 @@ groups: dialout append: true -- name: Create /opt/mark1 directory +- name: Create {{ _ovos_hardware_mark1_workind_directory }} directory ansible.builtin.file: - path: /opt/mark1 + path: "{{ _ovos_hardware_mark1_workind_directory }}" state: directory owner: "{{ ovos_installer_user }}" group: "{{ ovos_installer_user }}" mode: "0755" + +- name: Configure initialize.sh to {{ _ovos_hardware_mark1_workind_directory }} + ansible.builtin.copy: + src: initialize.sh + dest: "{{ _ovos_hardware_mark1_workind_directory }}/initialize.sh" + owner: "{{ ovos_installer_user }}" + group: "{{ ovos_installer_user }}" + mode: "0755" diff --git a/ansible/roles/ovos_hardware_mark1/vars/main.yml b/ansible/roles/ovos_hardware_mark1/vars/main.yml index b3de7dd3..0c37219c 100644 --- a/ansible/roles/ovos_hardware_mark1/vars/main.yml +++ b/ansible/roles/ovos_hardware_mark1/vars/main.yml @@ -1,2 +1,3 @@ --- _ovos_hardware_mark1_avrdude_binary: /usr/local/bin/avrdude +_ovos_hardware_mark1_workind_directory: /opt/mark1 From 5e7c159283902e6d015719d93bbfd1e3a5aad7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 11:42:12 -0400 Subject: [PATCH 07/13] [mark1] Make sure .config/systemd/user exists --- ansible/roles/ovos_hardware_mark1/tasks/prepare.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml b/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml index 0d129f75..58f6a2f3 100644 --- a/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml +++ b/ansible/roles/ovos_hardware_mark1/tasks/prepare.yml @@ -5,13 +5,16 @@ groups: dialout append: true -- name: Create {{ _ovos_hardware_mark1_workind_directory }} directory +- name: Create directories ansible.builtin.file: - path: "{{ _ovos_hardware_mark1_workind_directory }}" + path: "{{ item }}" state: directory owner: "{{ ovos_installer_user }}" group: "{{ ovos_installer_user }}" mode: "0755" + loop: + - "{{ ovos_installer_user_home }}/.config/systemd/user" + - "{{ _ovos_hardware_mark1_workind_directory }}" - name: Configure initialize.sh to {{ _ovos_hardware_mark1_workind_directory }} ansible.builtin.copy: From 92b168ca4f4b583d743836e5352366d21c247c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 11:53:27 -0400 Subject: [PATCH 08/13] [mark1] Disable containers method when Raspberry Pi 3 detected --- ansible/roles/ovos_hardware_mark1/tasks/config.yml | 2 +- tui/methods.sh | 2 +- utils/constants.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ansible/roles/ovos_hardware_mark1/tasks/config.yml b/ansible/roles/ovos_hardware_mark1/tasks/config.yml index c9faa4d5..6804fa1c 100644 --- a/ansible/roles/ovos_hardware_mark1/tasks/config.yml +++ b/ansible/roles/ovos_hardware_mark1/tasks/config.yml @@ -18,7 +18,7 @@ - dtoverlay=miniuart-bt - dtoverlay=proto-codec -- name: Disable onboard audio interface +- name: Disable snd_bcm2835 audio interface ansible.builtin.lineinfile: path: "{{ _boot_directory }}/config.txt" regexp: "^{{ item.key }}=" diff --git a/tui/methods.sh b/tui/methods.sh index 56e772ca..2d53ab68 100644 --- a/tui/methods.sh +++ b/tui/methods.sh @@ -10,7 +10,7 @@ available_methods=(containers virtualenv) # When 32-bit CPU is detected, the only method available # will be Python virtualenv as there are no 32-bit container # images available. -if [[ "$ARCH" != @(x86_64|aarch64) ]]; then +if [[ "$ARCH" != @(x86_64|aarch64) ]] && [[ "$RASPBERRYPI_MODEL" == *"Raspberry Pi 3"* ]]; then active_method="virtualenv" available_methods=(virtualenv) fi diff --git a/utils/constants.sh b/utils/constants.sh index bc45af08..c9fa6a00 100644 --- a/utils/constants.sh +++ b/utils/constants.sh @@ -48,7 +48,7 @@ export SCENARIO_NAME="scenario.yaml" export SCENARIO_PATH="" declare -rA SUPPORTED_DEVICES=( ["tas5806"]="2f" #https://www.ti.com/product/TAS5806MD - ["atmega328p"]="1a" #Displayed as UU + ["atmega328p"]="1a" #https://www.microchip.com/en-us/product/atmega328p ) export SUPPORTED_DEVICES export TUI_WINDOW_HEIGHT="35" From fd624ffbdd9b35bf039a6d9ccdb89456c20c2228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 11:55:33 -0400 Subject: [PATCH 09/13] [mark1] Update comment --- tui/methods.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tui/methods.sh b/tui/methods.sh index 2d53ab68..80a46a2f 100644 --- a/tui/methods.sh +++ b/tui/methods.sh @@ -9,7 +9,8 @@ available_methods=(containers virtualenv) # When 32-bit CPU is detected, the only method available # will be Python virtualenv as there are no 32-bit container -# images available. +# images available. Same for Raspberry Pi 3 as containers +# might be too heavy for this board. if [[ "$ARCH" != @(x86_64|aarch64) ]] && [[ "$RASPBERRYPI_MODEL" == *"Raspberry Pi 3"* ]]; then active_method="virtualenv" available_methods=(virtualenv) From 178cc55567e5937b128de95725beeec8d0069e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 12:32:03 -0400 Subject: [PATCH 10/13] [mark1] Configure sndrpiproto ALSA card --- .../roles/ovos_hardware_mark1/files/initialize.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ansible/roles/ovos_hardware_mark1/files/initialize.sh b/ansible/roles/ovos_hardware_mark1/files/initialize.sh index 09681716..4da4e6e2 100644 --- a/ansible/roles/ovos_hardware_mark1/files/initialize.sh +++ b/ansible/roles/ovos_hardware_mark1/files/initialize.sh @@ -9,6 +9,7 @@ eyes_color="16760576" mouth_text="booting" tty_device=/dev/ttyAMA0 +alsa_card="sndrpiproto" # Initialiaze the firmware and wait two seconds avrdude -p atmega328p -c linuxgpio -U signature:r:-:i -F @@ -19,3 +20,14 @@ echo "eyes.color=$eyes_color" > "$tty_device" # Set mouth text echo "mouth.text=$mouth_text" > "$tty_device" + +# Set default values to sndrpiproto ALSA card +if grep "$alsa_card" /proc/asound/cards -q; then + amixer -c "$alsa_card" cset numid=1 100,100 + amixer -c "$alsa_card" cset numid=2 on + amixer -c "$alsa_card" cset numid=6 on + amixer -c "$alsa_card" cset numid=10 on + amixer -c "$alsa_card" cset numid=14 1 + amixer -c "$alsa_card" cset numid=13 on + amixer -c "$alsa_card" cset numid=9 on +fi From 3abd2fd4d646ec76c9f95cbf63b7e83f027875bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 12:33:18 -0400 Subject: [PATCH 11/13] [mark1] Update comment --- ansible/roles/ovos_hardware_mark1/files/initialize.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ansible/roles/ovos_hardware_mark1/files/initialize.sh b/ansible/roles/ovos_hardware_mark1/files/initialize.sh index 4da4e6e2..690f6108 100644 --- a/ansible/roles/ovos_hardware_mark1/files/initialize.sh +++ b/ansible/roles/ovos_hardware_mark1/files/initialize.sh @@ -1,9 +1,10 @@ #!/bin/env bash # -# This script initialiaze the atmega328p chip from the Mark 1 -# device. +# This script initialiaze the atmega328p chip from the Mark 1 device. # Once initialized the eyes color will be changed to yellow and # the mouth text will display "booting". +# As final action, if the sndrpiproto soundcard is detected then +# it will be configured. # Variables eyes_color="16760576" From cc1cdc1aef896c6a9519bdbdd2faa343a73b0457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 12:39:01 -0400 Subject: [PATCH 12/13] [mark1] Don't override volume set by user --- ansible/roles/ovos_hardware_mark1/files/initialize.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ansible/roles/ovos_hardware_mark1/files/initialize.sh b/ansible/roles/ovos_hardware_mark1/files/initialize.sh index 690f6108..991fa964 100644 --- a/ansible/roles/ovos_hardware_mark1/files/initialize.sh +++ b/ansible/roles/ovos_hardware_mark1/files/initialize.sh @@ -11,6 +11,7 @@ eyes_color="16760576" mouth_text="booting" tty_device=/dev/ttyAMA0 alsa_card="sndrpiproto" +alsa_configured=/opt/mark1/alsa.configured # Initialiaze the firmware and wait two seconds avrdude -p atmega328p -c linuxgpio -U signature:r:-:i -F @@ -24,7 +25,11 @@ echo "mouth.text=$mouth_text" > "$tty_device" # Set default values to sndrpiproto ALSA card if grep "$alsa_card" /proc/asound/cards -q; then - amixer -c "$alsa_card" cset numid=1 100,100 + # Set volume mixer only once + if [ ! -f "$alsa_configured" ]; then + amixer -c "$alsa_card" cset numid=1 100,100 + touch "$alsa_configured" + fi amixer -c "$alsa_card" cset numid=2 on amixer -c "$alsa_card" cset numid=6 on amixer -c "$alsa_card" cset numid=10 on From 0f4ca36de7daf9a71e46be39ff90558d3f54b4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 2 May 2024 21:44:56 -0400 Subject: [PATCH 13/13] [mark1] Add global avrdude.conf --- utils/common.sh | 5 +++-- utils/constants.sh | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/utils/common.sh b/utils/common.sh index 9ead6355..4c33ee24 100644 --- a/utils/common.sh +++ b/utils/common.sh @@ -401,7 +401,7 @@ function setup_avrdude() { rm "$AVRDUDE_BINARY_PATH" fi - curl -s -f -L "$AVRDUDE_URL" -o "$AVRDUDE_BINARY_PATH" &>>"$LOG_FILE" + curl -s -f -L "$AVRDUDE_BINARY_URL" -o "$AVRDUDE_BINARY_PATH" &>>"$LOG_FILE" chmod 0755 "$AVRDUDE_BINARY_PATH" &>>"$LOG_FILE" cat <"$RUN_AS_HOME/.avrduderc" @@ -418,7 +418,8 @@ function setup_avrdude() { sdi = 17; ; EOF - chown "$RUN_AS:$RUN_AS" "$RUN_AS_HOME/.avrduderc" + chown "$RUN_AS:$RUN_AS" "$RUN_AS_HOME/.avrduderc" &>>"$LOG_FILE" + curl -s -f -L "$AVRDUDE_CONFIG_URL" -o "$AVRDUDE_CONFIG_PATH" &>>"$LOG_FILE" } # This function retrieves the atmega328p signature when present. If the diff --git a/utils/constants.sh b/utils/constants.sh index c9fa6a00..2fc5a219 100644 --- a/utils/constants.sh +++ b/utils/constants.sh @@ -2,7 +2,9 @@ export ATMEGA328P_SIGNATURE=":030000001E950F3B" export AVRDUDE_BINARY_PATH=/usr/local/bin/avrdude -export AVRDUDE_URL="https://artifacts.smartgic.io/avrdude-aarch64" +export AVRDUDE_BINARY_URL="https://artifacts.smartgic.io/avrdude/avrdude-aarch64" +export AVRDUDE_CONFIG_PATH=/usr/local/etc/avrdude.conf +export AVRDUDE_CONFIG_URL="https://artifacts.smartgic.io/avrdude/avrdude.conf" declare -a DETECTED_DEVICES export DETECTED_DEVICES export DT_FILE=/sys/firmware/devicetree/base/model