├── .clang-format ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── Projects ├── Mynd │ ├── CMakeLists.txt │ ├── changelog.md │ ├── docs │ │ ├── charger.puml │ │ ├── power_on_button.puml │ │ ├── power_on_usb.puml │ │ └── soc.puml │ ├── external │ │ ├── teufel │ │ │ ├── .clang-format │ │ │ ├── drivers │ │ │ │ ├── .clang-format │ │ │ │ ├── FindTeufelDrivers.cmake │ │ │ │ ├── STM32_vEEPROM │ │ │ │ │ ├── eeprom.c │ │ │ │ │ ├── eeprom.h │ │ │ │ │ ├── eeprom_config_template.h │ │ │ │ │ ├── virtual_eeprom.c │ │ │ │ │ └── virtual_eeprom.h │ │ │ │ ├── aw9523b │ │ │ │ │ ├── aw9523b.c │ │ │ │ │ └── aw9523b.h │ │ │ │ ├── bq25713 │ │ │ │ │ ├── bq25713.c │ │ │ │ │ └── bq25713.h │ │ │ │ ├── driver_logger.h │ │ │ │ ├── input_handlers │ │ │ │ │ ├── button │ │ │ │ │ │ ├── button_handler.c │ │ │ │ │ │ └── button_handler.h │ │ │ │ │ ├── input_events.c │ │ │ │ │ └── input_events.h │ │ │ │ ├── tas5805m │ │ │ │ │ ├── tas5805m.c │ │ │ │ │ └── tas5805m.h │ │ │ │ ├── tas5825p │ │ │ │ │ ├── tas5825p.c │ │ │ │ │ └── tas5825p.h │ │ │ │ ├── tasxxxx_volume_table │ │ │ │ │ ├── tasxxxx_volume_table.c │ │ │ │ │ └── tasxxxx_volume_table.h │ │ │ │ └── tps25751 │ │ │ │ │ ├── tps25751.c │ │ │ │ │ └── tps25751.h │ │ │ └── libs │ │ │ │ ├── .clang-format │ │ │ │ ├── FindActionslink.cmake │ │ │ │ ├── FindIEngine.cmake │ │ │ │ ├── FindLogger.cmake │ │ │ │ ├── FindTeufelLibraries.cmake │ │ │ │ ├── GenericThread │ │ │ │ └── GenericThread++.h │ │ │ │ ├── IEngine │ │ │ │ ├── IndicationEngine.h │ │ │ │ ├── PatternSnippet.h │ │ │ │ ├── pattern │ │ │ │ │ ├── dblink │ │ │ │ │ │ └── dblink.h │ │ │ │ │ ├── fade │ │ │ │ │ │ └── fade.h │ │ │ │ │ └── generic │ │ │ │ │ │ └── generic.h │ │ │ │ └── tests │ │ │ │ │ └── indication_test.cpp │ │ │ │ ├── __README.md │ │ │ │ ├── actionslink │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── README.md │ │ │ │ ├── proto │ │ │ │ │ ├── common │ │ │ │ │ │ ├── app.proto │ │ │ │ │ │ ├── audio.proto │ │ │ │ │ │ ├── battery.proto │ │ │ │ │ │ ├── bluetooth.proto │ │ │ │ │ │ ├── common.proto │ │ │ │ │ │ ├── error.proto │ │ │ │ │ │ ├── kvstorage.proto │ │ │ │ │ │ ├── system.proto │ │ │ │ │ │ └── usb.proto │ │ │ │ │ └── eco │ │ │ │ │ │ ├── device.proto │ │ │ │ │ │ └── message.proto │ │ │ │ └── src │ │ │ │ │ ├── .clang-format │ │ │ │ │ ├── api │ │ │ │ │ ├── actionslink.c │ │ │ │ │ ├── actionslink.h │ │ │ │ │ └── actionslink_types.h │ │ │ │ │ ├── decoders │ │ │ │ │ ├── actionslink_decoders.c │ │ │ │ │ └── actionslink_decoders.h │ │ │ │ │ ├── encoders │ │ │ │ │ ├── actionslink_encoders.c │ │ │ │ │ └── actionslink_encoders.h │ │ │ │ │ ├── events │ │ │ │ │ ├── actionslink_events.c │ │ │ │ │ └── actionslink_events.h │ │ │ │ │ ├── log │ │ │ │ │ ├── actionslink_log.c │ │ │ │ │ └── actionslink_log.h │ │ │ │ │ ├── requests │ │ │ │ │ ├── actionslink_requests.c │ │ │ │ │ └── actionslink_requests.h │ │ │ │ │ ├── transport │ │ │ │ │ ├── actionslink_bt_ll.c │ │ │ │ │ ├── actionslink_bt_ll.h │ │ │ │ │ ├── actionslink_bt_ul.c │ │ │ │ │ └── actionslink_bt_ul.h │ │ │ │ │ ├── utils │ │ │ │ │ ├── actionslink_utils.c │ │ │ │ │ └── actionslink_utils.h │ │ │ │ │ └── version │ │ │ │ │ └── actionslink_version.h.in │ │ │ │ ├── app_assert │ │ │ │ ├── app_assert.c │ │ │ │ └── app_assert.h │ │ │ │ ├── core_utils │ │ │ │ ├── debouncer.h │ │ │ │ ├── ewma.h │ │ │ │ ├── hysteresis.h │ │ │ │ ├── mapper.h │ │ │ │ ├── misc.h │ │ │ │ ├── monitor.h │ │ │ │ ├── overload.h │ │ │ │ ├── quantizator.h │ │ │ │ ├── sync.h │ │ │ │ ├── tests │ │ │ │ │ └── test_hysteresis.cpp │ │ │ │ ├── uncopyable.h │ │ │ │ └── unmovable.h │ │ │ │ ├── greeting │ │ │ │ ├── greeting.c │ │ │ │ └── greeting.h │ │ │ │ ├── logger │ │ │ │ ├── README.md │ │ │ │ ├── configs │ │ │ │ │ ├── num1 │ │ │ │ │ │ └── logger_config.h │ │ │ │ │ ├── num2 │ │ │ │ │ │ └── logger_config.h │ │ │ │ │ └── off │ │ │ │ │ │ └── logger_config.h │ │ │ │ ├── formats │ │ │ │ │ ├── num1 │ │ │ │ │ │ └── logger_format.h │ │ │ │ │ ├── num2 │ │ │ │ │ │ └── logger_format.h │ │ │ │ │ └── num3 │ │ │ │ │ │ └── logger_format.h │ │ │ │ ├── implementations │ │ │ │ │ └── logger_weak_implementation.c │ │ │ │ ├── include │ │ │ │ │ ├── logger_defs.h │ │ │ │ │ ├── logger_impl.h │ │ │ │ │ └── logger_putchar.h │ │ │ │ ├── logger.c │ │ │ │ ├── logger.h │ │ │ │ ├── logger_syscalls.c │ │ │ │ └── outputs │ │ │ │ │ ├── logger_any.h │ │ │ │ │ └── logger_printf.h │ │ │ │ ├── power │ │ │ │ └── power.h │ │ │ │ ├── property │ │ │ │ └── property.h │ │ │ │ ├── syscalls │ │ │ │ └── syscalls.c │ │ │ │ └── tshell │ │ │ │ ├── tshell.c │ │ │ │ ├── tshell.h │ │ │ │ ├── tshell_args_parser.c │ │ │ │ ├── tshell_args_parser.h │ │ │ │ ├── tshell_printf.c │ │ │ │ └── tshell_printf.h │ │ └── thirdparty │ │ │ ├── .clang-format │ │ │ ├── FindFreeRTOS.cmake │ │ │ └── FindNanopb.cmake │ ├── mynd-bundle.json │ ├── mynd-complete.JLinkScript │ ├── mynd-factory-complete.JLinkScript │ ├── mynd-factory.JLinkScript │ ├── mynd-offset.JLinkScript │ ├── mynd.JLinkScript │ ├── src │ │ ├── CMakeLists.txt │ │ ├── FreeRTOSConfig.h │ │ ├── battery │ │ │ ├── CMakeLists.txt │ │ │ ├── battery.cpp │ │ │ ├── battery.h │ │ │ ├── battery_indicator │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── battery_indicator.cpp │ │ │ │ └── battery_indicator.h │ │ │ ├── charge_controller │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── charge_controller.cpp │ │ │ │ └── charge_controller.h │ │ │ ├── soc_estimator │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── soc_estimator.cpp │ │ │ │ └── soc_estimator.h │ │ │ └── temperature │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── temperature.cpp │ │ │ │ └── temperature.h │ │ ├── board │ │ │ ├── CMakeLists.txt │ │ │ ├── amps │ │ │ │ ├── .clang-format │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_amps.c │ │ │ │ ├── board_link_amps.h │ │ │ │ ├── eco_5805_config.h │ │ │ │ ├── eco_5805_eco_mode_config.h │ │ │ │ ├── eco_5805_patch_to_bypass_mode.h │ │ │ │ ├── eco_5805_treble_config.h │ │ │ │ ├── eco_5825_bass_config.h │ │ │ │ ├── eco_5825_config.h │ │ │ │ ├── eco_5825_eco_mode_config.h │ │ │ │ └── eco_5825_patch_to_bypass_mode.h │ │ │ ├── bluetooth │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_bluetooth.c │ │ │ │ └── board_link_bluetooth.h │ │ │ ├── board_link.h │ │ │ ├── boost_converter │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_boost_converter.c │ │ │ │ └── board_link_boost_converter.h │ │ │ ├── charger │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_charger.c │ │ │ │ └── board_link_charger.h │ │ │ ├── eeprom │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_eeprom.c │ │ │ │ └── board_link_eeprom.h │ │ │ ├── hw_revision │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_hw_revision.c │ │ │ │ └── board_link_hw_revision.h │ │ │ ├── io_expander │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_io_expander.c │ │ │ │ └── board_link_io_expander.h │ │ │ ├── moisture_detection │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_moisture_detection.c │ │ │ │ └── board_link_moisture_detection.h │ │ │ ├── plug_detection │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_plug_detection.c │ │ │ │ └── board_link_plug_detection.h │ │ │ ├── power_supply │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_power_supply.c │ │ │ │ └── board_link_power_supply.h │ │ │ ├── usb_pd_controller │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_usb_pd_controller.c │ │ │ │ └── board_link_usb_pd_controller.h │ │ │ └── usb_switch │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── board_link_usb_switch.c │ │ │ │ └── board_link_usb_switch.h │ │ ├── bsp │ │ │ ├── CMakeLists.txt │ │ │ ├── adc │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── bsp_adc.c │ │ │ │ └── bsp_adc.h │ │ │ ├── bluetooth_uart │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── bsp_bluetooth_uart.c │ │ │ │ └── bsp_bluetooth_uart.h │ │ │ ├── board.c │ │ │ ├── board.h │ │ │ ├── board_hw.h │ │ │ ├── board_msp.c │ │ │ ├── debug_uart │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── bsp_debug_uart.c │ │ │ │ └── bsp_debug_uart.h │ │ │ ├── shared_i2c │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── bsp_shared_i2c.c │ │ │ │ └── bsp_shared_i2c.h │ │ │ └── usb_pd_i2c │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── bsp_usb_pd_i2c.c │ │ │ │ └── bsp_usb_pd_i2c.h │ │ ├── config.h │ │ ├── factory │ │ │ ├── CMakeLists.txt │ │ │ ├── tests.cpp │ │ │ └── tests.h │ │ ├── leds │ │ │ ├── CMakeLists.txt │ │ │ ├── leds.cpp │ │ │ ├── leds.h │ │ │ └── pattern │ │ │ │ └── generic_rgb │ │ │ │ └── generic_rgb.h │ │ ├── main.cpp │ │ ├── persistent_storage │ │ │ ├── CMakeLists.txt │ │ │ ├── e_config.c │ │ │ ├── e_config.h │ │ │ ├── eeprom_config.h │ │ │ └── kvstorage.h │ │ ├── stm32f0xx_hal_conf.h │ │ ├── stm32f0xx_it.c │ │ ├── tasks │ │ │ ├── CMakeLists.txt │ │ │ ├── audio │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── task_audio.cpp │ │ │ │ └── task_audio.h │ │ │ ├── bluetooth │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── task_bluetooth.cpp │ │ │ │ └── task_bluetooth.h │ │ │ ├── system │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── task_system.cpp │ │ │ │ └── task_system.h │ │ │ └── task_priorities.h │ │ ├── tshell │ │ │ ├── CMakeLists.txt │ │ │ ├── tshell.c │ │ │ ├── tshell.h │ │ │ ├── tshell_args_parser.c │ │ │ ├── tshell_args_parser.h │ │ │ ├── tshell_printf.c │ │ │ └── tshell_printf.h │ │ └── ux │ │ │ ├── audio │ │ │ └── audio.h │ │ │ ├── bluetooth │ │ │ └── bluetooth.h │ │ │ ├── input │ │ │ └── input.h │ │ │ └── system │ │ │ └── system.h │ └── tests_power_states.txt └── MyndBootloader │ ├── CMakeLists.txt │ ├── board │ ├── io_expander │ │ ├── board_link_io_expander.c │ │ └── board_link_io_expander.h │ ├── power_supply │ │ ├── board_link_power_supply.c │ │ └── board_link_power_supply.h │ └── usb_switch │ │ ├── board_link_usb_switch.c │ │ └── board_link_usb_switch.h │ ├── bsp │ ├── board.c │ ├── board.h │ ├── board_hw.h │ ├── board_msp.c │ ├── debug_uart │ │ ├── bsp_debug_uart.c │ │ └── bsp_debug_uart.h │ └── shared_i2c │ │ ├── bsp_shared_i2c.c │ │ └── bsp_shared_i2c.h │ ├── changelog.md │ ├── dfu_mcu.c │ ├── dfu_mcu.h │ ├── external │ └── teufel │ │ ├── .clang-format │ │ ├── drivers │ │ ├── .clang-format │ │ ├── .gitignore │ │ ├── FindTeufelDrivers.cmake │ │ ├── aw9523b │ │ │ ├── aw9523b.c │ │ │ └── aw9523b.h │ │ └── driver_logger.h │ │ └── libs │ │ ├── .clang-format │ │ ├── .gitignore │ │ ├── FindLogger.cmake │ │ ├── FindTboot.cmake │ │ ├── FindTeufelLibraries.cmake │ │ ├── README.md │ │ ├── __FindActionslink.cmake │ │ ├── app_assert │ │ ├── app_assert.c │ │ └── app_assert.h │ │ ├── logger │ │ ├── README.md │ │ ├── configs │ │ │ ├── num1 │ │ │ │ └── logger_config.h │ │ │ ├── num2 │ │ │ │ └── logger_config.h │ │ │ └── off │ │ │ │ └── logger_config.h │ │ ├── formats │ │ │ ├── num1 │ │ │ │ └── logger_format.h │ │ │ ├── num2 │ │ │ │ └── logger_format.h │ │ │ └── num3 │ │ │ │ └── logger_format.h │ │ ├── implementations │ │ │ └── logger_weak_implementation.c │ │ ├── include │ │ │ ├── logger_defs.h │ │ │ ├── logger_impl.h │ │ │ └── logger_putchar.h │ │ ├── logger.c │ │ ├── logger.h │ │ ├── logger_syscalls.c │ │ └── outputs │ │ │ ├── logger_any.h │ │ │ └── logger_printf.h │ │ ├── syscalls │ │ └── syscalls.c │ │ └── t-boot │ │ ├── README.md │ │ ├── assets │ │ └── t-boot-batching.png │ │ ├── keys │ │ ├── t_boot_dev_private.pem │ │ └── t_boot_dev_public.pem │ │ ├── scripts │ │ └── prepare_update.py │ │ ├── src │ │ ├── bootloader │ │ │ ├── dfu │ │ │ │ ├── t_boot_dfu.c │ │ │ │ └── t_boot_dfu.h │ │ │ ├── encryption │ │ │ │ ├── t_boot_encryption.c │ │ │ │ └── t_boot_encryption.h │ │ │ └── ram_disk │ │ │ │ ├── t_boot_ram_disk.c │ │ │ │ └── t_boot_ram_disk.h │ │ ├── device_specific │ │ │ ├── agnostic │ │ │ │ └── crc │ │ │ │ │ ├── crc32.c │ │ │ │ │ ├── crc32.h │ │ │ │ │ ├── t_boot_crc.c │ │ │ │ │ └── t_boot_crc.h │ │ │ ├── mimxrt1010 │ │ │ │ └── crc │ │ │ │ │ ├── t_boot_crc.c │ │ │ │ │ └── t_boot_crc.h │ │ │ └── stm32f0 │ │ │ │ ├── crc │ │ │ │ ├── t_boot_crc.c │ │ │ │ └── t_boot_crc.h │ │ │ │ ├── t_boot_stm32_config_template.h │ │ │ │ └── usbd │ │ │ │ ├── usbd_conf.c │ │ │ │ ├── usbd_conf.h │ │ │ │ ├── usbd_desc.c │ │ │ │ ├── usbd_desc.h │ │ │ │ ├── usbd_storage.c │ │ │ │ └── usbd_storage.h │ │ ├── logger_config │ │ │ └── t_boot_logger.h │ │ └── t_boot_config_template.h │ │ └── tests │ │ ├── t_boot_config.h │ │ ├── test_generate_crc.c │ │ └── test_parse_dfu_packets.c │ ├── main.c │ ├── mynd-bootloader.JLinkScript │ ├── stm32f0xx_hal_conf.h │ ├── stm32f0xx_it.c │ ├── stm32f0xx_it.h │ ├── t_boot_config.h │ └── t_boot_stm32_config.h ├── README.md ├── drivers └── platform │ └── stm32 │ ├── i2c.c │ ├── i2c.h │ ├── i2c_freertos.c │ └── i2c_freertos.h ├── firmwares ├── bluetooth │ └── Teufel_MYND_20241016_v1.3.8.zip └── usb-pd │ └── 25751_no_bc1.2_3A_V2.5.zip ├── gitversion ├── gitversion.h.in └── version.h ├── requirements.txt ├── software_manifest.md ├── support ├── cmake │ ├── FindCMSIS.cmake │ ├── FindDRIVERS.cmake │ ├── FindHAL.cmake │ ├── FindUSBDevice.cmake │ ├── deploy.cmake │ ├── format.cmake │ ├── gitversion.cmake │ ├── stm32 │ │ ├── common.cmake │ │ ├── devices.cmake │ │ ├── f0.cmake │ │ ├── f1.cmake │ │ ├── f2.cmake │ │ ├── f3.cmake │ │ ├── f4.cmake │ │ ├── f7.cmake │ │ ├── g0.cmake │ │ ├── g4.cmake │ │ ├── h7.cmake │ │ ├── l0.cmake │ │ ├── l1.cmake │ │ ├── l4.cmake │ │ ├── l5.cmake │ │ ├── linker_ld.cmake │ │ ├── u5.cmake │ │ ├── utilities.cmake │ │ ├── wb.cmake │ │ └── wl.cmake │ ├── stm32_gcc.cmake │ ├── stm32_linker.cmake │ └── utils.cmake ├── docker-build │ ├── docker-config │ │ ├── Dockerfile │ │ └── Dockerfile-x86 │ ├── docker-run.sh │ ├── docker-unittest.sh │ └── readme.md ├── keys │ ├── teufel_dev_private.pem │ └── teufel_dev_public.pem ├── scripts │ └── prepare_update.py └── svd │ └── STM32F0x0.svd ├── teufel-pre-push └── teufel-prepare-commit-msg /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Ignore files in dl dir. Needs for dependencies. 35 | /dl/* 36 | !/dl/.gitkeep 37 | 38 | # build dirs 39 | /build 40 | /cmake-build-* 41 | 42 | # idea settings 43 | .idea 44 | 45 | # vscode settings 46 | .vscode 47 | 48 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sdk/STM32CubeF0"] 2 | path = sdk/STM32CubeF0 3 | url = https://github.com/STMicroelectronics/STM32CubeF0.git 4 | [submodule "Projects/Mynd/external/thirdparty/nanopb"] 5 | path = Projects/Mynd/external/thirdparty/nanopb 6 | url = https://github.com/nanopb/nanopb.git 7 | [submodule "Projects/Mynd/external/thirdparty/freertos-kernel"] 8 | path = Projects/Mynd/external/thirdparty/freertos-kernel 9 | url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Lautsprecher Teufel GmbH. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Projects/Mynd/docs/charger.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | 'https://plantuml.com/state-diagram 3 | 4 | scale 650 width 5 | hide empty description 6 | 7 | state Active { 8 | ' aliases to avoid unique names for Active and Inactive states 9 | state "BFC" as BfcActive 10 | state "Power Charging" as NonBfcActive 11 | 12 | BfcActive : charge current 2.45A, 13 | BfcActive : charge voltage 8.2V 14 | 15 | NonBfcActive : charge current 4.9A, 16 | NonBfcActive : charge voltage 8.4V 17 | 18 | BfcActive -right-> NonBfcActive : BFCModeDisabled 19 | NonBfcActive -left-> BfcActive : BFCModeEnabled 20 | } 21 | 22 | state Inactive { 23 | state "BFC" as BfcInactive 24 | state "Power Charging" as NonBfcInactive 25 | 26 | Inactive : charge current 0A 27 | 28 | ' BfcInactive : set charge current 2.45A, 29 | ' BfcInactive : set charge voltage 8.2V 30 | ' 31 | ' NonBfcInactive : set charge current 4.9A, 32 | ' NonBfcInactive : set charge voltage 8.4V 33 | 34 | BfcInactive -right-> NonBfcInactive : BFCModeDisabled 35 | NonBfcInactive -left-> BfcInactive : BFCModeEnabled 36 | } 37 | 38 | state "Trickle Charging" as Trickle_Charging { 39 | Trickle_Charging: charge current 0.5A 40 | } 41 | 42 | state "Not connected" as NotConnected { 43 | 44 | } 45 | 46 | Active --> Inactive : Battery current lower 500mA for 5sec\nand Battery >= 8.35V (8.15V for BFC) 47 | Trickle_Charging --> Active : Battery >= 6V 48 | Active --> Trickle_Charging : Battery < 6V 49 | Inactive --> Trickle_Charging : Battery < 6V 50 | BfcInactive --> BfcActive : Battery <=7.9V for 5sec 51 | NonBfcInactive --> NonBfcActive : Battery <= 8.1V for 5sec 52 | 53 | Active --> NotConnected : Disconnect charger 54 | Inactive --> NotConnected : Disconnect charger 55 | Trickle_Charging -> NotConnected : Disconnect charger 56 | NotConnected -> Trickle_Charging: Connect charger 57 | @enduml 58 | -------------------------------------------------------------------------------- /Projects/Mynd/docs/power_on_button.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | 'https://plantuml.com/sequence-diagram 3 | 4 | == Early(Pre-scheduler) Init == 5 | 6 | Baremetal -> Baremetal : Init (HAL, SystemClock) 7 | Baremetal -> Baremetal : Logger Init 8 | 9 | Baremetal -> Baremetal : Start Scheduler and Task System 10 | 11 | control System as System 12 | control Bluetooth as Bluetooth 13 | control Audio as Audio 14 | 15 | 16 | == System(Task) Init == 17 | 18 | Baremetal -> System ** : start 19 | 20 | autonumber 21 | 22 | System -> System : SetPowerState{Transition} 23 | activate System 24 | 25 | System -> System : Early configurations 26 | 27 | System -> Bluetooth ** : start 28 | System -> Audio ** : start 29 | 30 | System -> System : SetPowerState{Off} 31 | deactivate System 32 | 33 | 34 | == PreOn power state == 35 | 36 | System -> System : SetGlobalPowerState{Transition Off -> PreOn} 37 | activate System 38 | System -> Audio : SetPowerState{PreOn} 39 | Audio -> Battery: Init Battery 40 | 41 | Battery -> Battery : wait for PD controller 42 | Battery -> Battery : init/configure charger IC 43 | 44 | Audio --> System : Sync::notify(SetPowerState) 45 | 46 | deactivate System 47 | 48 | 49 | == On power state == 50 | 51 | System -> System : SetGlobalPowerState{Transition PreOn -> On} 52 | 53 | activate System 54 | 55 | System -> Bluetooth : SetPowerState{On} 56 | Bluetooth --> System : Sync::notify(SetPowerState) 57 | 58 | System -> Audio : SetPowerState{On} 59 | 60 | note right: I2S must be configured on the BT side 61 | Audio -> Audio : Init AMPs 62 | 63 | Audio --> System : Sync::notify(SetPowerState) 64 | 65 | System -> System : Play SI(PowerOn) 66 | 67 | System -> System : SetGlobalPowerState{On} 68 | deactivate System 69 | 70 | @enduml 71 | -------------------------------------------------------------------------------- /Projects/Mynd/docs/power_on_usb.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | 'https://plantuml.com/sequence-diagram 3 | 4 | == Early(Pre-scheduler) Init == 5 | 6 | Baremetal -> Baremetal : Init (HAL, SystemClock) 7 | Baremetal -> Baremetal : Logger Init 8 | 9 | Baremetal -> Baremetal : Start Scheduler and Task System 10 | 11 | control System as System 12 | control Bluetooth as Bluetooth 13 | control Audio as Audio 14 | 15 | 16 | == System(Task) Init == 17 | 18 | Baremetal -> System ** : start 19 | 20 | autonumber 21 | 22 | System -> System : SetPowerState{Transition} 23 | activate System 24 | 25 | System -> System : Early configurations 26 | 27 | System -> Bluetooth ** : start 28 | System -> Audio ** : start 29 | 30 | Audio -> Audio : expander_init() 31 | 32 | Audio -> Audio : reset_expander() 33 | 34 | System -> System : SetPowerState{Off} 35 | deactivate System 36 | 37 | 38 | @enduml 39 | -------------------------------------------------------------------------------- /Projects/Mynd/docs/soc.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | 'https://plantuml.com/state-diagram 3 | 4 | scale 350 width 5 | [*] --> FirstStartOrBatteryReset: Approximate CHG based on VBAT and charge curve of Battery,\n Set CAP according to charge curve of Battery 6 | FirstStartOrBatteryReset: Set CHG based on VBAT LUT 7 | FirstStartOrBatteryReset: Set CAP based on charge curve of bat 8 | 9 | FirstStartOrBatteryReset -right-> FirstFullChargeCompleted : FirstFullChargeCompleted 10 | FirstFullChargeCompleted: Set CHG to CAP 11 | 12 | FirstStartOrBatteryReset -left-> FirstFullDischargeCompleted : FirstFullDischargeCompleted 13 | 14 | FirstFullChargeCompleted --> NormalOperation : Fill discharge to Vmin (6.2V) / Set CAP to CAP - CHG,\n Set CHG to 0mAh 15 | 16 | FirstFullDischargeCompleted --> NormalOperation : Fill charge to Vmax (8.4V) / Set CAP to CHG 17 | 18 | NormalOperation -> NormalOperation : FullCharge / Set CAP to (CHG+CAP)/2; Set CHG to CAP 19 | 20 | NormalOperation -> NormalOperation : FullDischarge / Set CAP to CAP-CHG/2; Set CHG to 0mAh 21 | 22 | @enduml -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/drivers/STM32_vEEPROM/eeprom_config_template.h: -------------------------------------------------------------------------------- 1 | /* Define to prevent recursive inclusion -------------------------------------*/ 2 | #ifndef __EEPROM_CONFIG_H 3 | #define __EEPROM_CONFIG_H 4 | 5 | #define EEPROM_FLASH_PAGE0 ((uint32_t) ADDR_FLASH_PAGE_14) 6 | #define EEPROM_FLASH_PAGE1 ((uint32_t) ADDR_FLASH_PAGE_14) 7 | 8 | #define EEPROM_ELEMENTS 34 9 | 10 | #endif /* __EEPROM_CONFIG_H */ 11 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/drivers/STM32_vEEPROM/virtual_eeprom.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #if defined(__cplusplus) 5 | extern "C" 6 | { 7 | #endif 8 | 9 | int vEEPROM_Init(void); 10 | 11 | int vEEPROM_AddressWrite(uint16_t addr, uint16_t value); 12 | int vEEPROM_AddressWriteBuffer(uint16_t addr, const uint16_t *data, uint16_t size); 13 | 14 | int vEEPROM_AddressRead(uint16_t addr, uint16_t *value); 15 | int vEEPROM_AddressReadBuffer(uint16_t addr, uint16_t *target, uint16_t size); 16 | 17 | #if defined(__cplusplus) 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/drivers/tasxxxx_volume_table/tasxxxx_volume_table.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | const uint8_t * tasxxxx_volume_get_data_for_db(int8_t volume_db); 6 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/IEngine/pattern/generic/generic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "PatternSnippet.h" 7 | 8 | template 9 | class PatternGeneric final : public IndicationEngine::LedPattern 10 | { 11 | public: 12 | explicit PatternGeneric(const IndicationEngine::Pattern &pattern) 13 | : m_p(pattern) 14 | , m_id(IndicationEngine::Pattern::generatePatternId()) 15 | { 16 | } 17 | 18 | explicit PatternGeneric(const IndicationEngine::Pattern &pattern, uint32_t offset) 19 | : m_p(pattern) 20 | , m_id(IndicationEngine::Pattern::generatePatternId()) 21 | { 22 | } 23 | 24 | explicit PatternGeneric(const IndicationEngine::Pattern &pattern, uint8_t id) 25 | : m_p(pattern) 26 | , m_id(id) 27 | { 28 | } 29 | 30 | IndicationEngine::PatternResult step(std::array &leds) override 31 | { 32 | for (size_t i = 0; i < LED_NUMS; ++i) 33 | { 34 | if (LED_MASK & (1u << i)) 35 | leds[i] = m_p[m_pattern_index]; 36 | } 37 | 38 | m_pattern_index++; 39 | 40 | if (m_pattern_index >= m_p.steps()) 41 | { 42 | m_pattern_index = 0; 43 | return IndicationEngine::PatternResult::FINISHED; 44 | } 45 | 46 | return IndicationEngine::PatternResult::IN_PROGRESS; 47 | } 48 | 49 | void reset() override 50 | { 51 | m_pattern_index = 0; 52 | } 53 | 54 | [[nodiscard]] uint8_t getPatternId() const override 55 | { 56 | return m_id; 57 | }; 58 | 59 | private: 60 | const IndicationEngine::Pattern &m_p; 61 | uint16_t m_pattern_index = 0; 62 | uint8_t m_id = 0; 63 | }; 64 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/__README.md: -------------------------------------------------------------------------------- 1 | # Teufel libraries 2 | 3 | This repository contains a collection of libraries used in several Teufel projects. 4 | 5 | ## Add to an existing project 6 | 7 | You can add this repository as a submodule with the following command: 8 | 9 | ``` 10 | git submodule add ssh://git@sources.teufelhome.com/tf/teufel-libs.git 11 | ``` 12 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/README.md: -------------------------------------------------------------------------------- 1 | # Actions link library 2 | 3 | The Actionslink library manages the communication between the Actions module and your processor. 4 | 5 | More bla bla here. 6 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/proto/common/app.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ActionsLink.App; 3 | 4 | 5 | /** A generic packet to be sent to the device connected to the Actions chip. */ 6 | message Packet { 7 | /** The payload of the packet. */ 8 | bytes payload = 1; 9 | } 10 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/proto/common/battery.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ActionsLink.Battery; 3 | 4 | 5 | /** Enumeration of battery charger status. */ 6 | enum ChargerStatus { 7 | NotConnected = 0; 8 | Active = 1; 9 | Inactive = 2; 10 | Fault = 3; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/proto/common/common.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ActionsLink.Common; 3 | 4 | import "error.proto"; 5 | 6 | import "google/protobuf/descriptor.proto"; 7 | 8 | /* Field options for attaching a range to a numeric value. */ 9 | extend google.protobuf.FieldOptions { 10 | int32 minVal = 50001; 11 | int32 maxVal = 50002; 12 | int32 stepVal = 50003; 13 | } 14 | 15 | /** 16 | * Generic message used for commands (e.g. reset) or requests without "parameters" (e.g. get_status). 17 | */ 18 | message Command { } 19 | 20 | /** 21 | * Generic message used to communicate an operation's result. 22 | */ 23 | message Result { 24 | Error.Error status = 1; 25 | } 26 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/proto/common/error.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ActionsLink.Error; 3 | 4 | enum Code { 5 | Success = 0; 6 | OperationFailed = 1; 7 | OperationCanceled = 2; 8 | OperationNotSupported = 3; 9 | ResourceUnavailable = 4; 10 | } 11 | 12 | message Error { 13 | Code code = 1; 14 | string text = 2; 15 | } 16 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/proto/common/kvstorage.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ActionsLink.KVStorage; 3 | 4 | import "error.proto"; 5 | 6 | /** Define KV element. */ 7 | message Element { 8 | uint32 key = 1; 9 | uint32 value = 2; 10 | } 11 | 12 | /** Define KV write. */ 13 | message Write { 14 | Element el = 1; 15 | } 16 | 17 | /** Define KV read. */ 18 | message Read { 19 | uint32 key = 1; 20 | } 21 | 22 | /** Define KV read response. */ 23 | message ReadResponse { 24 | oneof Result { 25 | Element el = 1; 26 | Error.Error error = 2; 27 | } 28 | } -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/proto/common/system.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ActionsLink.System; 3 | 4 | import "common.proto"; 5 | 6 | /** 7 | * Message to transmit the firmware version of the device. 8 | */ 9 | message FirmwareVersion { 10 | /** Major version number. */ 11 | uint32 major = 1; 12 | 13 | /** Minor version number. */ 14 | uint32 minor = 2; 15 | 16 | /** Patch version number. */ 17 | uint32 patch = 3; 18 | 19 | /** Build version string (see git describe). */ 20 | string build = 4; 21 | } 22 | 23 | /** 24 | * Message to request/notify a power state change. 25 | */ 26 | message PowerState { 27 | /** The various application power modes that the Actions chip can be in. */ 28 | enum SystemPowerMode { 29 | /** The chip is powered off. */ 30 | OFF = 0; 31 | 32 | /** The application is running and functional. */ 33 | ON = 1; 34 | 35 | /** The chip is in standby mode. */ 36 | STANDBY = 2; 37 | 38 | /** The BT chip has requested a shutdown. */ 39 | SHUTDOWN_REQUEST = 3; 40 | 41 | // TODO: Adjust if necessary 42 | } 43 | 44 | /** System power mode. */ 45 | SystemPowerMode mode = 1; 46 | } 47 | 48 | message OffTimer { 49 | enum State { 50 | /** The off timer is disabled. */ 51 | DISABLED = 0; 52 | 53 | /** The off timer is enabled. */ 54 | ENABLED = 1; 55 | } 56 | 57 | /** The state of the off timer. */ 58 | State state = 1; 59 | 60 | /** The off timer in minutes. */ 61 | uint32 minutes = 2 [(Common.minVal) = 5, (Common.maxVal) = 240]; 62 | } 63 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/proto/common/usb.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ActionsLink.Usb; 3 | 4 | 5 | /** 6 | * This command is used to send a HID action to the device. 7 | */ 8 | message HidAction { 9 | enum Action { 10 | PLAY_PAUSE = 0; 11 | NEXT_TRACK = 1; 12 | PREVIOUS_TRACK = 2; 13 | } 14 | 15 | /** The action to perform. */ 16 | Action action = 1; 17 | } 18 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/proto/eco/device.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ActionsLink.Eco.Device; 3 | 4 | enum Color { 5 | BLACK = 0; 6 | WHITE = 1; 7 | BERRY = 2; 8 | MINT = 3; 9 | } 10 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/decoders/actionslink_decoders.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actionslink_types.h" 4 | #include "pb_decode.h" 5 | 6 | bool actionslink_decode_to_mcu_message(pb_istream_t *stream, const pb_field_t *field, void **arg); 7 | bool actionslink_decode_to_mcu_response_message(pb_istream_t *stream, const pb_field_t *field, void **arg); 8 | bool actionslink_decode_to_mcu_event_message(pb_istream_t *stream, const pb_field_t *field, void **arg); 9 | bool actionslink_decode_string(pb_istream_t *stream, const pb_field_t *field, void **arg); 10 | 11 | // Unused code that could be useful for future reference 12 | #if 0 13 | 14 | typedef struct 15 | { 16 | actionslink_bluetooth_device_status_t *p_list; 17 | uint8_t number_of_items; 18 | const uint8_t list_size; 19 | } actionslink_decoder_bluetooth_devices_t; 20 | 21 | bool actionslink_decode_bluetooth_single_bd_addr(pb_istream_t *stream, const pb_field_t *field, void **arg); 22 | bool actionslink_decode_confirm_message(pb_istream_t *stream, const pb_field_t *field, void **arg); 23 | bool actionslink_decode_connection_status_event(pb_istream_t *stream, const pb_field_t *field, void **arg); 24 | bool actionslink_decode_device_list_confirmation(pb_istream_t *stream, const pb_field_t *field, void **arg); 25 | #endif 26 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/encoders/actionslink_encoders.c: -------------------------------------------------------------------------------- 1 | #include "actionslink_encoders.h" 2 | #include "actionslink_log.h" 3 | 4 | // Check the following link for a very nice encoding/decoding example with nested repeated messages 5 | // https://github.com/BlockWorksCo/Playground/tree/c968e22cd923ee184fe9362905a4d58e9f69cb27/ProtobufTest 6 | 7 | // Unused code that could be useful for future reference 8 | #if 0 9 | static void log_encoder_error(const char *fn, const char *error) 10 | { 11 | log_error("encoder: %s failed [%s]", fn, error); 12 | } 13 | 14 | bool actionslink_encode_bluetooth_single_bd_addr(pb_ostream_t *stream, const pb_field_t *field, void *const *arg) 15 | { 16 | actionslink_bluetooth_address_t *p_bd_addr = *((actionslink_bluetooth_address_t **) arg); 17 | 18 | if (!pb_encode_tag_for_field(stream, field)) 19 | { 20 | log_encoder_error(__FUNCTION__, stream->errmsg); 21 | return false; 22 | } 23 | 24 | if (!pb_encode_string(stream, p_bd_addr->buffer, 6)) 25 | { 26 | log_encoder_error(__FUNCTION__, stream->errmsg); 27 | return false; 28 | } 29 | 30 | return true; 31 | } 32 | #endif 33 | 34 | bool actionslink_encode_string(pb_ostream_t* stream, const pb_field_t* field, void* const* arg) 35 | { 36 | const char* str = (const char*)(*arg); 37 | 38 | if (!pb_encode_tag_for_field(stream, field)) 39 | return false; 40 | 41 | return pb_encode_string(stream, (uint8_t*)str, strlen(str)); 42 | } 43 | 44 | bool actionslink_encode_bytes(pb_ostream_t* stream, const pb_field_t* field, void* const* arg) 45 | { 46 | actionslink_encode_bytes_t* data = (actionslink_encode_bytes_t*)(*arg); 47 | 48 | if (!pb_encode_tag_for_field(stream, field)) 49 | return false; 50 | 51 | return pb_encode_string(stream, data->p_buffer, data->size); 52 | } 53 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/encoders/actionslink_encoders.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actionslink_types.h" 4 | #include "pb_encode.h" 5 | 6 | // Unused code that could be useful for future reference 7 | #if 0 8 | bool actionslink_encode_bluetooth_single_bd_addr(pb_ostream_t *stream, const pb_field_t *field, void *const *arg); 9 | #endif 10 | 11 | typedef struct { 12 | uint8_t *p_buffer; 13 | size_t size; 14 | } actionslink_encode_bytes_t; 15 | 16 | bool actionslink_encode_string(pb_ostream_t* stream, const pb_field_t* field, void* const* arg); 17 | 18 | bool actionslink_encode_bytes(pb_ostream_t* stream, const pb_field_t* field, void* const* arg); 19 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/events/actionslink_events.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actionslink_types.h" 4 | #include "message.pb.h" 5 | 6 | void actionslink_events_init(const actionslink_event_handlers_t *p_event_handlers); 7 | 8 | bool actionslink_events_has_received_system_ready(void); 9 | 10 | void actionslink_event_handler(const ActionsLink_ToMcuEvent *p_event, const uint8_t *p_data, uint16_t data_length); 11 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/log/actionslink_log.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "actionslink_log.h" 4 | 5 | static actionslink_log_fn_t m_actionslink_log_fn; 6 | 7 | void actionslink_log_register(actionslink_log_fn_t log_fn) 8 | { 9 | m_actionslink_log_fn = log_fn; 10 | } 11 | 12 | void actionslink_log(actionslink_log_level_t lvl, const char *format, ...) 13 | { 14 | if (!m_actionslink_log_fn) 15 | return; 16 | 17 | va_list args; 18 | va_start(args, format); 19 | char buf[128]; 20 | vsnprintf(buf, sizeof(buf), format, args); 21 | va_end(args); 22 | 23 | m_actionslink_log_fn(lvl, buf); 24 | } 25 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/log/actionslink_log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actionslink_types.h" 4 | 5 | #define log_internal(level, ...) \ 6 | do \ 7 | { \ 8 | if (ACTIONSLINK_LOG_LEVEL >= level) \ 9 | { \ 10 | actionslink_log(level, __VA_ARGS__); \ 11 | } \ 12 | } while (0) 13 | 14 | #define log_error(...) log_internal(ACTIONSLINK_LOG_LEVEL_ERROR, __VA_ARGS__) 15 | #define log_warning(...) log_internal(ACTIONSLINK_LOG_LEVEL_WARN, __VA_ARGS__) 16 | #define log_info(...) log_internal(ACTIONSLINK_LOG_LEVEL_INFO, __VA_ARGS__) 17 | #define log_debug(...) log_internal(ACTIONSLINK_LOG_LEVEL_DEBUG, __VA_ARGS__) 18 | #define log_trace(...) log_internal(ACTIONSLINK_LOG_LEVEL_TRACE, __VA_ARGS__) 19 | 20 | /** 21 | * @brief Passes log messages to user-defined log function. 22 | * 23 | * @param[in] lvl log level 24 | * @param[in] args log format string 25 | * @param ... format arguments 26 | */ 27 | void actionslink_log(actionslink_log_level_t lvl, const char *args, ...); 28 | 29 | /** 30 | * @brief Registers a function to pass logs to. 31 | * 32 | * @param[in] log_fn log function 33 | */ 34 | void actionslink_log_register(actionslink_log_fn_t log_fn); 35 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/requests/actionslink_requests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actionslink_types.h" 4 | #include "message.pb.h" 5 | 6 | void actionslink_requests_init(const actionslink_request_handlers_t *p_request_handlers); 7 | 8 | void actionslink_request_handler(const ActionsLink_ToMcuRequest *p_request, const uint8_t *p_data, uint16_t data_length); 9 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/transport/actionslink_bt_ll.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actionslink_types.h" 4 | #include "message.pb.h" 5 | 6 | typedef enum { 7 | ACTIONSLINK_BT_LL_PACKET_TYPE_ACK = 0x00, 8 | ACTIONSLINK_BT_LL_PACKET_TYPE_PROTOBUF = 0x01, 9 | } actionslink_bt_ll_packet_type_t; 10 | 11 | typedef struct 12 | { 13 | actionslink_bt_ll_packet_type_t packet_type; 14 | uint8_t value; 15 | uint8_t transaction_id; 16 | const ActionsLink_FromMcu *p_payload; 17 | } actionslink_bt_ll_tx_packet_t; 18 | 19 | typedef struct 20 | { 21 | ActionsLink_ToMcu * p_message; // Decoded payload 22 | const uint8_t *p_raw_data; // Undecoded payload data 23 | uint16_t raw_data_length; // Length of the undecoded payload data 24 | } actionslink_bt_ll_rx_packet_payload_t; 25 | 26 | typedef struct 27 | { 28 | actionslink_bt_ll_packet_type_t packet_type; 29 | uint8_t value; 30 | uint8_t transaction_id; 31 | actionslink_bt_ll_rx_packet_payload_t payload; 32 | } actionslink_bt_ll_rx_packet_t; 33 | 34 | /** 35 | * @brief Initializes the low layer of the Actionslink transport. 36 | * 37 | * @param[in] p_config pointer to the configuration 38 | */ 39 | void actionslink_bt_ll_init(const actionslink_config_t *p_config); 40 | 41 | /** 42 | * @brief Resets the low layer of the Actionslink transport 43 | */ 44 | void actionslink_bt_ll_reset(void); 45 | 46 | /** 47 | * @brief Sends a packet to the Actions module. 48 | * @note This function reuses the buffer passed to it to build a frame around 49 | * the payload. If the buffer is not big enough to construct the frame, 50 | * this function will return error. 51 | * 52 | * @param[in] p_packet pointer to packet to send 53 | * @param[in] p_tx_buffer pointer to buffer to use for constructing the frame 54 | * @param[in] tx_buffer_size size of the TX buffer 55 | * 56 | * @return 0 if successful, -1 otherwise 57 | */ 58 | int actionslink_bt_ll_tx(const actionslink_bt_ll_tx_packet_t *p_packet); 59 | 60 | /** 61 | * @brief Receives bytes from the Actions module and processes them to extract a received payload. 62 | * 63 | * @param[out] p_packet pointer to where the pointer to the received packet will be written to 64 | * 65 | * @return 0 if no packets were received 66 | * 1 if a packet was received 67 | * -1 if a communication error occurred 68 | */ 69 | int actionslink_bt_ll_rx(actionslink_bt_ll_rx_packet_t *p_packet); 70 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/utils/actionslink_utils.c: -------------------------------------------------------------------------------- 1 | #include "actionslink_utils.h" 2 | 3 | static const actionslink_config_t *mp_config; 4 | 5 | void actionslink_utils_init(const actionslink_config_t *p_config) 6 | { 7 | mp_config = p_config; 8 | } 9 | 10 | uint32_t actionslink_utils_get_ms(void) 11 | { 12 | return mp_config->get_tick_ms_fn(); 13 | } 14 | 15 | uint32_t actionslink_utils_get_ms_since(uint32_t tick_ms) 16 | { 17 | uint32_t current_tick_ms = mp_config->get_tick_ms_fn(); 18 | 19 | // Handle tick overflow 20 | if (current_tick_ms < tick_ms) 21 | { 22 | // Account for the 0 by adding 1 23 | // -> if last tick is UINT32_MAX and current tick is 0, this function should return 1 24 | return (UINT32_MAX - tick_ms) + current_tick_ms + 1; 25 | } 26 | else 27 | { 28 | return current_tick_ms - tick_ms; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/utils/actionslink_utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actionslink_types.h" 4 | 5 | /** 6 | * @brief Initializes the actionslink utilities 7 | * 8 | * @param[in] p_config pointer to driver configuration 9 | */ 10 | void actionslink_utils_init(const actionslink_config_t *p_config); 11 | 12 | /** 13 | * @brief Gets the current system timestamp in milliseconds. 14 | * 15 | * @return system timestamp in milliseconds 16 | */ 17 | uint32_t actionslink_utils_get_ms(void); 18 | 19 | /** 20 | * @brief Gets the number of milliseconds elapsed since a given timestamp. 21 | * 22 | * @param[in] timestamp_ms timestamp in milliseconds 23 | * 24 | * @return number of milliseconds 25 | */ 26 | uint32_t actionslink_utils_get_ms_since(uint32_t timestamp_ms); 27 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/actionslink/src/version/actionslink_version.h.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define ACTIONSLINK_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 4 | #define ACTIONSLINK_VERSION_MINOR @PROJECT_VERSION_MINOR@ 5 | #define ACTIONSLINK_VERSION_PATCH @PROJECT_VERSION_PATCH@ 6 | #define ACTIONSLINK_VERSION_TWEAK @PROJECT_VERSION_TWEAK@ 7 | #define ACTIONSLINK_VERSION "@PROJECT_VERSION@" 8 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/app_assert/app_assert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "app_assert.h" 6 | 7 | void app_assertion_handler(const char *file, int line_number) 8 | { 9 | printf("Assertion failed in %s:%d\r\n", file, line_number); 10 | __disable_irq(); 11 | __BKPT(0); 12 | for (;;) 13 | { 14 | } 15 | } 16 | 17 | void __assert_func(const char *file, int line, const char *func, const char *failedExpr) 18 | { 19 | printf("Assertion failed in %s:%d\r\n", file, line); 20 | printf("%s in %s()\r\n", failedExpr, func); 21 | __disable_irq(); 22 | __BKPT(0); 23 | for (;;) 24 | { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/app_assert/app_assert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | 8 | void app_assertion_handler(const char * file, int line_number); 9 | 10 | #if defined(APP_ASSERT_NDEBUG) 11 | 12 | #define APP_ASSERT(...) 13 | 14 | #else 15 | 16 | #define APP_ASSERT(condition, ...) \ 17 | do { \ 18 | if ((condition) == 0) { \ 19 | app_assertion_handler(__FILE_NAME__, __LINE__); \ 20 | } \ 21 | } while (0) 22 | 23 | #endif // defined(APP_ASSERT_NDEBUG) 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/debouncer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | template 6 | class Debouncer 7 | { 8 | public: 9 | using get_systick_fn_t = uint32_t(); 10 | using get_ms_since_fn_t = uint32_t(uint32_t); 11 | 12 | Debouncer(T init_value, get_systick_fn_t *get_systick, get_ms_since_fn_t *get_ms_since) 13 | : m_value(init_value) 14 | , m_get_systick(get_systick) 15 | , m_get_ms_since(get_ms_since) 16 | { 17 | } 18 | 19 | T operator()(T value) 20 | { 21 | // WARNING! Only asymmetric timeouts are supported now! 22 | static_assert(TIMEOUT_OUT == UINT32_MAX, "Only asymmetric timeouts are supported now!"); 23 | 24 | if constexpr (TIMEOUT_OUT == UINT32_MAX) 25 | { 26 | if (m_value != value) 27 | { 28 | if (m_last_change_ts == 0) 29 | m_last_change_ts = m_get_systick(); 30 | else if (m_get_ms_since(m_last_change_ts) >= TIMEOUT_IN) 31 | { 32 | m_last_change_ts = 0; 33 | return value; 34 | } 35 | } 36 | return m_value; 37 | } 38 | } 39 | 40 | private: 41 | T m_value; 42 | uint32_t m_last_change_ts = 0u; 43 | get_systick_fn_t *m_get_systick; 44 | get_ms_since_fn_t *m_get_ms_since; 45 | }; -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/ewma.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /** 6 | * @brief Simple (and optimized) Exponential weighted moving average. 7 | * The implementation is optimized for for a MCU without FPU unit, and advanced multiplication/division support. 8 | * However, please keep in mind, that the function not flexible as the classic IIR implementation, because 9 | * the coefficient is power of 2, therefore the tuning might be not precise enough for a certain task. 10 | * @tparam K - alpha coefficient that represented as 1/(x^K) (smooth coefficient). 11 | * @tparam uint_t - Unsigned integer type used for the filter state and input/output values. 12 | */ 13 | template 14 | class EWMA 15 | { 16 | public: 17 | explicit EWMA(uint_t initial = uint_t(0)) 18 | : m_state(0u + (uint_t(initial) << K) - initial) 19 | { 20 | } 21 | 22 | // Update the filter with the given input and return the filtered output. 23 | uint_t operator()(uint_t input) 24 | { 25 | m_state = m_state + input - ((m_state + half) >> K); 26 | return m_state >> K; 27 | } 28 | 29 | // Get the current state of the filter. 30 | uint_t get() const 31 | { 32 | return m_state >> K; 33 | } 34 | 35 | static_assert(uint_t(0) < uint_t(-1), // Check that `uint_t` is an unsigned type 36 | "The `uint_t` type should be an unsigned integer, otherwise, " 37 | "the division using bit shifts is invalid."); 38 | 39 | // Fixed point representation of one half, used for rounding. 40 | constexpr static uint_t half = 1 << (K - 1); 41 | 42 | private: 43 | uint_t m_state; 44 | }; 45 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/hysteresis.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | /** 7 | * @brief Hysteresis function 8 | * @tparam ThresholdValue - Threshold value 9 | * @tparam RecoveryValue - Recovery value 10 | * @return - Lambda function, which returns a boolean value if the threshold/recovery values are crossed. 11 | * @note The function works when the threshold value is greater than the recovery value, and vice versa. 12 | */ 13 | template 14 | requires std::integral && std::integral 15 | constexpr auto hysteresis(const char *name) 16 | { 17 | return [](std::integral auto value) { 18 | static bool in_critical = false; 19 | 20 | static_assert(ThresholdValue != RecoveryValue, "Critical and recovery values must be different"); 21 | 22 | if constexpr(ThresholdValue > RecoveryValue) 23 | { 24 | in_critical = in_critical ? (value > RecoveryValue) : (value >= ThresholdValue); 25 | } 26 | else if constexpr(ThresholdValue < RecoveryValue) 27 | { 28 | in_critical = in_critical ? (value < RecoveryValue) : (value <= ThresholdValue); 29 | } 30 | 31 | return in_critical; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/mapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Teufel::Core 8 | { 9 | template 10 | static auto mapValue(Mapper &m, K k) -> std::optionalvalue)>> 11 | { 12 | auto res = std::find_if(std::begin(m), std::end(m), [&](const auto &e) { return e.key == k; }); 13 | if (res != std::end(m)) 14 | return res->value; 15 | return {}; 16 | } 17 | 18 | template 19 | static std::optional mapValueReverse(Mapper &m, K k) 20 | { 21 | auto res = std::find_if(std::begin(m), std::end(m), [&](const auto &e) { return e.value == k; }); 22 | if (res != std::end(m)) 23 | return std::optional(res->key); 24 | return {}; 25 | } 26 | } 27 | 28 | #define TS_KEY_VALUE_CONST_MAP(name, key_type, value_type, ...) \ 29 | typedef struct name##_ \ 30 | { \ 31 | key_type key{}; \ 32 | value_type value{}; \ 33 | } name##_t; \ 34 | static const name##_t name[] = { __VA_ARGS__ }; 35 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/misc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Teufel::Core 7 | { 8 | 9 | template struct is_one_of; 10 | 11 | template 12 | struct is_one_of> 13 | : std::bool_constant<(std::is_same_v || ...)> 14 | { }; 15 | 16 | template 17 | struct remove_cvref 18 | { 19 | typedef std::remove_cv_t> type; 20 | }; 21 | 22 | /** 23 | * @brief The function returns true if the type has been seen before. 24 | * @note It _tracks_ known/initialized types and _mark_ them, such that the next call with the same type 25 | * returns true, which means that this type already has been seen by the function. The list of the known types 26 | * defined in the SyncedTypesVariant template parameter, which *must* be a std::variant. 27 | * @note One of the possible use cases: to filter out the initial values from the SOM(SDK) during the bootup. 28 | * @tparam T - type of the target variable 29 | * @tparam SyncedTypesVariant - a std::variant of the list of _tracked_ types 30 | * @return true if the type has been seen before(known), false otherwise 31 | */ 32 | template 33 | bool isSynced(T) 34 | { 35 | using type = typename remove_cvref::type; 36 | 37 | if constexpr (is_one_of::value) 38 | { 39 | static bool is_synced = false; 40 | if (!is_synced) 41 | { 42 | is_synced = true; 43 | return false; 44 | } 45 | return true; 46 | } 47 | return false; 48 | } 49 | 50 | template 51 | bool isSynced(T) 52 | { 53 | static bool is_synced = false; 54 | if (!is_synced) 55 | { 56 | is_synced = true; 57 | return false; 58 | } 59 | return true; 60 | } 61 | 62 | /** 63 | * @brief The function calls the *lambda* only once. 64 | * @note Please, keep in mind that it accept only lambdas, which are invocable and have no arguments. 65 | * @tparam C - type of the lambda 66 | * @param c - lambda to be called 67 | */ 68 | template 69 | void callOnce(C&& c) 70 | { 71 | static_assert(std::is_class_v, "must be a lambda type"); 72 | static_assert(std::is_invocable_v, "must be a lambda type"); 73 | [[maybe_unused]] static bool is_called = (c(), true); 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/overload.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Teufel::Core 4 | { 5 | // Simplified version of what is proposed for a future C++ standard: 6 | // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0051r3.pdf 7 | // Each T has to be a type defining one or more operator() functions. 8 | 9 | template struct overload : Ts... { using Ts::operator()...; }; 10 | template overload(Ts...) -> overload; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/sync.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "FreeRTOS.h" 5 | #if defined(TEUFEL_LOGGER) 6 | #include "logger.h" 7 | #else 8 | #include "dbg_log.h" 9 | #endif 10 | 11 | struct SyncPrimitive 12 | { 13 | template 14 | static int await(const T &t, uint32_t timeout_ms, const char *msg) 15 | { 16 | /* FreeRTOS Stream and Message Buffers use the task notification at array index 0. 17 | * If you want to maintain the state of a task notification across a call to a Stream, 18 | * or Message Buffer API function then use a task notification at an array index greater than 0. 19 | * In order to avoid collisions, please consider to use indexes starting from 1. */ 20 | if (static_cast(t) == 0) 21 | log_warn("SyncPrimitive (%s) Task notification at array index 0!", __func__); 22 | 23 | uint32_t ulNotificationValue = 24 | ulTaskNotifyTakeIndexed(static_cast(t), pdTRUE, pdMS_TO_TICKS(timeout_ms)); 25 | if (ulNotificationValue == 1) 26 | { 27 | log_info("Task %s %s", getDesc(t), msg); 28 | return 0; 29 | } 30 | 31 | log_err("%s: task %s sync timeout", __func__, getDesc(t)); 32 | 33 | return 1; 34 | } 35 | 36 | template 37 | static int notify(const T &t) 38 | { 39 | static TaskHandle_t xTaskToNotifySystem = nullptr; 40 | 41 | if (!xTaskToNotifySystem) 42 | { 43 | xTaskToNotifySystem = xTaskGetHandle("System"); 44 | } 45 | 46 | if (xTaskToNotifySystem == nullptr) 47 | { 48 | log_err("Sys sync notify failed"); 49 | return -1; 50 | } 51 | 52 | /* FreeRTOS Stream and Message Buffers use the task notification at array index 0. 53 | * If you want to maintain the state of a task notification across a call to a Stream, 54 | * or Message Buffer API function then use a task notification at an array index greater than 0. 55 | * In order to avoid collisions, please consider to use indexes starting from 1. */ 56 | if (static_cast(t) == 0) 57 | log_warn("SyncPrimitive (%s) Task notification at array index 0!", __func__); 58 | 59 | xTaskNotifyGiveIndexed(xTaskToNotifySystem, static_cast(t)); 60 | 61 | return 0; 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/tests/test_hysteresis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "core_utils/hysteresis.h" 4 | 5 | TEST(HysteresisTest, ThresholdGreaterThanRecovery_InactiveToActive) 6 | { 7 | auto hyst = hysteresis<10, 5>("test"); 8 | ASSERT_FALSE(hyst(4)); 9 | ASSERT_FALSE(hyst(9)); // Still in critical state 10 | ASSERT_TRUE(hyst(10)); 11 | } 12 | 13 | TEST(HysteresisTest, ThresholdGreaterThanRecovery_ActiveToInactive) 14 | { 15 | auto hyst = hysteresis<10, 5>("test"); 16 | ASSERT_TRUE(hyst(10)); 17 | ASSERT_TRUE(hyst(6)); // Still in critical state 18 | ASSERT_FALSE(hyst(5)); 19 | } 20 | 21 | TEST(HysteresisTest, ThresholdLessThanRecovery_InactiveToActive) 22 | { 23 | auto hyst = hysteresis<5, 10>("test"); 24 | ASSERT_FALSE(hyst(11)); 25 | ASSERT_FALSE(hyst(6)); // Still in critical state 26 | ASSERT_TRUE(hyst(5)); 27 | } 28 | 29 | TEST(HysteresisTest, ThresholdLessThanRecovery_ActiveToInactive) 30 | { 31 | auto hyst = hysteresis<5, 10>("test"); 32 | ASSERT_TRUE(hyst(5)); 33 | ASSERT_TRUE(hyst(9)); // Still in critical state 34 | ASSERT_FALSE(hyst(10)); 35 | } 36 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/uncopyable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace Teufel::Core 4 | { 5 | class Uncopyable 6 | { 7 | public: 8 | Uncopyable() = default; 9 | 10 | Uncopyable(const Uncopyable&) = delete; 11 | Uncopyable& operator=(const Uncopyable&) = delete; 12 | 13 | Uncopyable(Uncopyable&&) = default; 14 | Uncopyable& operator=(Uncopyable&&) = default; 15 | }; 16 | 17 | static_assert(!std::is_copy_constructible::value, "Uncopyable must not be copy-constructible."); 18 | static_assert(!std::is_copy_assignable::value, "Uncopyable must not be copy-assignable."); 19 | static_assert(std::is_move_constructible::value, "Uncopyable should be move-constructible."); 20 | static_assert(std::is_move_assignable::value, "Uncopyable should be move-assignable."); 21 | } 22 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/core_utils/unmovable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace Teufel::Core 4 | { 5 | class Unmovable 6 | { 7 | public: 8 | Unmovable() = default; 9 | 10 | Unmovable(const Unmovable&) = default; 11 | Unmovable& operator=(const Unmovable&) = default; 12 | 13 | Unmovable(Unmovable&&) = delete; 14 | Unmovable& operator=(Unmovable&&) = delete; 15 | }; 16 | 17 | static_assert(std::is_copy_constructible::value, "Unmovable should be copy-constructible."); 18 | static_assert(std::is_copy_assignable::value, "Unmovable should be copy-assignable."); 19 | static_assert(!std::is_move_constructible::value, "Unmovable must not be move-constructible."); 20 | static_assert(!std::is_move_assignable::value, "Unmovable must not be move-assignable."); 21 | } 22 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/greeting/greeting.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__cplusplus) 4 | extern "C" { 5 | #endif /* __cplusplus */ 6 | 7 | void PrintFirmwareInfo(const char *name); 8 | 9 | #if defined(__cplusplus) 10 | } 11 | #endif /* __cplusplus */ 12 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/formats/num1/logger_format.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/logger_defs.h" 4 | 5 | // clang-format off 6 | 7 | // Set this to 1 to produce colored output 8 | #define LOGGER_USE_COLOR 1 9 | 10 | // Set this to 1 to apply the color to the entire log line, 11 | // otherwise only the log level will be colored 12 | #define LOGGER_USE_FULL_LINE_COLOR 0 13 | 14 | // Set this to 1 to prefix the output with a "[LEVEL]" string 15 | #define LOGGER_PRINT_LOG_LEVEL 1 16 | 17 | // Set this to 1 to timestamp the logs 18 | #define LOGGER_PRINT_TIMESTAMP 1 19 | 20 | // Set this to 1 to print the timestamp before the log level 21 | #define LOGGER_PRINT_TIMESTAMP_BEFORE_LOG_LEVEL 1 22 | 23 | // Set this to 1 to add the "module:line_number" to the logs 24 | // Note that if this option is enabled 25 | // LOG_MODULE_NAME must be defined in every file where the logger is used 26 | #define LOGGER_PRINT_LOG_LOCATION 1 27 | 28 | // Set this to terminate each log with a new line string 29 | #define LOGGER_PRINT_NEW_LINE 1 30 | 31 | // This defines the string to be appended to the logs 32 | // when the LOGGER_PRINT_NEW_LINE option is set to 1 33 | #define LOGGER_NEW_LINE_STRING "\r\n" 34 | 35 | // This defines the width of the log location string that is added to the logs 36 | // when the LOGGER_PRINT_LOG_LOCATION option is set to 1. 37 | // It is useful to align the actual contents of the logs to the right of the "log header" 38 | // Increase it if you have long module names or decrease it if your module names are short 39 | #define LOGGER_LOG_LOCATION_WIDTH 30 40 | 41 | // clang-format on 42 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/formats/num2/logger_format.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/logger_defs.h" 4 | 5 | // clang-format off 6 | 7 | // Set this to 1 to produce colored output 8 | #define LOGGER_USE_COLOR 1 9 | 10 | // Set this to 1 to apply the color to the entire log line, 11 | // otherwise only the log level will be colored 12 | #define LOGGER_USE_FULL_LINE_COLOR 1 13 | 14 | // Set this to 1 to prefix the output with a "[LEVEL]" string 15 | #define LOGGER_PRINT_LOG_LEVEL 1 16 | 17 | // Set this to 1 to timestamp the logs 18 | #define LOGGER_PRINT_TIMESTAMP 1 19 | 20 | // Set this to 1 to print the timestamp before the log level 21 | #define LOGGER_PRINT_TIMESTAMP_BEFORE_LOG_LEVEL 0 22 | 23 | // Set this to 1 to add the "module:line_number" to the logs 24 | // Note that if this option is enabled 25 | // LOG_MODULE_NAME must be defined in every file where the logger is used 26 | #define LOGGER_PRINT_LOG_LOCATION 1 27 | 28 | // Set this to terminate each log with a new line string 29 | #define LOGGER_PRINT_NEW_LINE 1 30 | 31 | // This defines the string to be appended to the logs 32 | // when the LOGGER_PRINT_NEW_LINE option is set to 1 33 | #define LOGGER_NEW_LINE_STRING "\r\n" 34 | 35 | // This defines the width of the log location string that is added to the logs 36 | // when the LOGGER_PRINT_LOG_LOCATION option is set to 1. 37 | // It is useful to align the actual contents of the logs to the right of the "log header" 38 | // Increase it if you have long module names or decrease it if your module names are short 39 | #define LOGGER_LOG_LOCATION_WIDTH 30 40 | 41 | // clang-format on 42 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/formats/num3/logger_format.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/logger_defs.h" 4 | 5 | // clang-format off 6 | 7 | // Set this to 1 to produce colored output 8 | #define LOGGER_USE_COLOR 1 9 | 10 | // Set this to 1 to apply the color to the entire log line, 11 | // otherwise only the log level will be colored 12 | #define LOGGER_USE_FULL_LINE_COLOR 0 13 | 14 | // Set this to 1 to prefix the output with a "[LEVEL]" string 15 | #define LOGGER_PRINT_LOG_LEVEL 1 16 | 17 | // Set this to 1 to timestamp the logs 18 | #define LOGGER_PRINT_TIMESTAMP 1 19 | 20 | // Set this to 1 to print the timestamp before the log level 21 | #define LOGGER_PRINT_TIMESTAMP_BEFORE_LOG_LEVEL 1 22 | 23 | // Set this to 1 to add the "module:line_number" to the logs 24 | // Note that if this option is enabled 25 | // LOG_MODULE_NAME must be defined in every file where the logger is used 26 | #define LOGGER_PRINT_LOG_LOCATION 1 27 | 28 | // Set this to terminate each log with a new line string 29 | #define LOGGER_PRINT_NEW_LINE 1 30 | 31 | // This defines the string to be appended to the logs 32 | // when the LOGGER_PRINT_NEW_LINE option is set to 1 33 | #define LOGGER_NEW_LINE_STRING "\r\n" 34 | 35 | // This defines the width of the log location string that is added to the logs 36 | // when the LOGGER_PRINT_LOG_LOCATION option is set to 1. 37 | // It is useful to align the actual contents of the logs to the right of the "log header" 38 | // Increase it if you have long module names or decrease it if your module names are short 39 | #define LOGGER_LOG_LOCATION_WIDTH 35 40 | 41 | // clang-format on 42 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/implementations/logger_weak_implementation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __attribute__((weak)) void logger_flush(void) {} 4 | 5 | __attribute__((weak)) uint32_t logger_get_timestamp() 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/include/logger_defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define LOG_COLOR_DEFAULT "\x1B[0m" 4 | #define LOG_COLOR_BLACK "\x1B[2;30m" 5 | #define LOG_COLOR_RED "\x1B[2;31m" 6 | #define LOG_COLOR_GREEN "\x1B[2;32m" 7 | #define LOG_COLOR_YELLOW "\x1B[2;33m" 8 | #define LOG_COLOR_BLUE "\x1B[2;34m" 9 | #define LOG_COLOR_MAGENTA "\x1B[2;35m" 10 | #define LOG_COLOR_CYAN "\x1B[2;36m" 11 | #define LOG_COLOR_WHITE "\x1B[2;37m" 12 | #define LOG_COLOR_BRIGHT_BLACK "\x1B[1;30m" 13 | #define LOG_COLOR_BRIGHT_RED "\x1B[1;31m" 14 | #define LOG_COLOR_BRIGHT_GREEN "\x1B[1;32m" 15 | #define LOG_COLOR_BRIGHT_YELLOW "\x1B[1;33m" 16 | #define LOG_COLOR_BRIGHT_BLUE "\x1B[1;34m" 17 | #define LOG_COLOR_BRIGHT_MAGENTA "\x1B[1;35m" 18 | #define LOG_COLOR_BRIGHT_CYAN "\x1B[1;36m" 19 | #define LOG_COLOR_BRIGHT_WHITE "\x1B[1;37m" 20 | #define LOG_COLOR_GREY "\x1B[1;90m" 21 | 22 | // --------------------------------------------------------------------------------- 23 | // Logger output configuration 24 | // --------------------------------------------------------------------------------- 25 | 26 | #define LOGGER_OUTPUT_RAW 0 // Logs using printf without any formatting 27 | #define LOGGER_OUTPUT_FORMATTED 1 // Generic output, which invokes printf call, with defined formatting 28 | 29 | typedef enum 30 | { 31 | LOG_LEVEL_OFF, 32 | LOG_LEVEL_FATAL, 33 | LOG_LEVEL_ERROR, 34 | LOG_LEVEL_WARNING, 35 | LOG_LEVEL_HIGHLIGHT, 36 | LOG_LEVEL_INFO, 37 | LOG_LEVEL_DEBUG, 38 | LOG_LEVEL_TRACE, 39 | } logger_log_level_t; 40 | 41 | typedef enum 42 | { 43 | LOG_OUTPUT_OPTION_NORMAL, 44 | LOG_OUTPUT_OPTION_RAW, 45 | } logger_log_output_option_t; 46 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/include/logger_impl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #if defined(__cplusplus) 5 | extern "C" 6 | { 7 | #endif 8 | 9 | /** 10 | * @brief Initializes the logger. 11 | */ 12 | #if defined(FreeRTOS) && defined(LOGGER_USE_EXTERNAL_THREAD) 13 | 14 | #include "FreeRTOS.h" 15 | #include "semphr.h" 16 | #include "stream_buffer.h" 17 | 18 | int logger_init(StreamBufferHandle_t sbuf); 19 | #else 20 | void logger_init(void); 21 | #endif 22 | 23 | /** 24 | * @brief Flushes the logger. 25 | */ 26 | void logger_flush(void); 27 | 28 | /** 29 | * @brief Gets a system timestamp. 30 | * @return timestamp 31 | */ 32 | uint32_t logger_get_timestamp(); 33 | 34 | #if defined(__cplusplus) 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/include/logger_putchar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __GNUC__ 4 | 5 | #define PUTCHAR(c) __io_putchar(c) 6 | #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) 7 | 8 | PUTCHAR_PROTOTYPE; 9 | 10 | #else 11 | 12 | #define PUTCHAR(c) fputc(c, __stdout) 13 | #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) 14 | 15 | PUTCHAR_PROTOTYPE; 16 | 17 | #endif // __GNUC__ 18 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/logger_syscalls.c: -------------------------------------------------------------------------------- 1 | #include "logger_config.h" 2 | #include // required for _write_r 3 | 4 | #if defined(SEGGER_RTT) 5 | #include "SEGGER_RTT.h" 6 | #else 7 | #include "logger_putchar.h" 8 | #endif 9 | 10 | // If necessary define the _reent struct 11 | // to match the one passed by the used standard library. 12 | struct _reent; 13 | 14 | _ssize_t _write(int file, const void *ptr, size_t len); 15 | _ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len); 16 | 17 | _ssize_t _write(int file, const void *ptr, size_t len) 18 | { 19 | (void) file; // Not used, avoid warning 20 | #if defined(SEGGER_RTT) 21 | SEGGER_RTT_Write(0, ptr, len); 22 | #else 23 | const char *p_data = (const char *) ptr; 24 | for (int i = 0; i < len; i++) 25 | { 26 | PUTCHAR(p_data[i]); 27 | } 28 | #endif 29 | return len; 30 | } 31 | 32 | _ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len) 33 | { 34 | (void) file; // Not used, avoid warning 35 | (void) r; // Not used, avoid warning 36 | #if defined(SEGGER_RTT) 37 | SEGGER_RTT_Write(0, ptr, len); 38 | #else 39 | const char *p_data = (const char *) ptr; 40 | for (int i = 0; i < len; i++) 41 | { 42 | PUTCHAR(p_data[i]); 43 | } 44 | #endif 45 | return len; 46 | } 47 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/logger/outputs/logger_printf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdio.h" 4 | 5 | #define log_internal_raw(level, ...) \ 6 | do \ 7 | { \ 8 | if (LOG_LEVEL >= level) \ 9 | { \ 10 | printf(__VA_ARGS__); \ 11 | } \ 12 | } while (0) 13 | 14 | #define log_internal(level, ...) \ 15 | do \ 16 | { \ 17 | if (LOG_LEVEL >= level) \ 18 | { \ 19 | printf(__VA_ARGS__); \ 20 | } \ 21 | } while (0) 22 | -------------------------------------------------------------------------------- /Projects/Mynd/external/teufel/libs/tshell/tshell_args_parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__cplusplus) 4 | extern "C" 5 | { 6 | #endif /* __cplusplus */ 7 | 8 | int tshell_parse_args_uint8(size_t argc, char** argv, uint8_t min, uint8_t max, uint8_t *result); 9 | int tshell_parse_args_int8(size_t argc, char** argv, int8_t min, int8_t max, int8_t *result); 10 | int tshell_parse_args_uint32(size_t argc, char** argv, uint32_t min, uint32_t max, uint32_t *result); 11 | int tshell_parse_args_int32(size_t argc, char** argv, int32_t min, int32_t max, int32_t *result); 12 | 13 | #if defined(__cplusplus) 14 | } 15 | #endif /* __cplusplus */ 16 | -------------------------------------------------------------------------------- /Projects/Mynd/external/thirdparty/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | -------------------------------------------------------------------------------- /Projects/Mynd/mynd-bundle.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_name": "MYND", 3 | "project_id": "oa2302", 4 | "artifactory_path": "de.teufel.mcu.firmware-releases/de/teufel/firmware/mynd", 5 | "components": [ 6 | { 7 | "name": "bootloader", 8 | "path": "bootloader", 9 | "filename": "mynd-bootloader-v2.1.0.hex", 10 | "version": "v2.1.0" 11 | }, 12 | { 13 | "name": "mcu", 14 | "path": "mcu", 15 | "filename": "mynd-v1.3.0.hex", 16 | "version": "v1.3.0" 17 | }, 18 | { 19 | "name": "mcu-complete", 20 | "path": "mcu", 21 | "filename": "mynd-complete-v1.3.0.hex", 22 | "version": "v1.3.0" 23 | }, 24 | { 25 | "name": "mcu-factory-complete", 26 | "path": "mcu", 27 | "filename": "mynd-factory-complete-v1.3.0.hex", 28 | "version": "v1.3.0" 29 | }, 30 | { 31 | "name": "update-firmware-mcu", 32 | "path": "mcu", 33 | "filename": "mynd-update-firmware-mcu-v1.3.0.bin", 34 | "version": "v1.3.0" 35 | }, 36 | { 37 | "name": "factory-update-firmware-mcu", 38 | "path": "mcu", 39 | "filename": "mynd-factory-update-firmware-mcu-v1.3.0.bin", 40 | "version": "v1.3.0" 41 | }, 42 | { 43 | "name": "bluetooth", 44 | "path": "bluetooth", 45 | "filename": "Teufel_MYND_20241016_v1.3.8.zip", 46 | "version": "v1.3.8" 47 | }, 48 | { 49 | "name": "pd-controller", 50 | "path": "pd_controller", 51 | "filename": "25751_no_bc1.2_3A_V2.5.zip", 52 | "version": "v2.5" 53 | } 54 | ] 55 | } -------------------------------------------------------------------------------- /Projects/Mynd/mynd-complete.JLinkScript: -------------------------------------------------------------------------------- 1 | Device STM32F072RB 2 | si SWD 3 | speed 4000 4 | h 5 | erase 6 | loadfile Projects/Mynd/mynd-complete.hex 7 | r 8 | q 9 | -------------------------------------------------------------------------------- /Projects/Mynd/mynd-factory-complete.JLinkScript: -------------------------------------------------------------------------------- 1 | Device STM32F072RB 2 | si SWD 3 | speed 4000 4 | h 5 | erase 6 | loadfile Projects/Mynd/mynd-factory-complete.hex 7 | r 8 | q 9 | -------------------------------------------------------------------------------- /Projects/Mynd/mynd-factory.JLinkScript: -------------------------------------------------------------------------------- 1 | Device STM32F072RB 2 | si SWD 3 | speed 4000 4 | h 5 | erase 6 | loadfile Projects/Mynd/mynd-factory.hex 7 | r 8 | q 9 | -------------------------------------------------------------------------------- /Projects/Mynd/mynd-offset.JLinkScript: -------------------------------------------------------------------------------- 1 | Device STM32F072RB 2 | si SWD 3 | speed 4000 4 | h 5 | #erase 6 | loadfile Projects/Mynd/mynd-offset.hex 7 | r 8 | q 9 | -------------------------------------------------------------------------------- /Projects/Mynd/mynd.JLinkScript: -------------------------------------------------------------------------------- 1 | Device STM32F072RB 2 | si SWD 3 | speed 4000 4 | h 5 | #erase 6 | loadfile Projects/Mynd/mynd.hex 7 | r 8 | q 9 | -------------------------------------------------------------------------------- /Projects/Mynd/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(battery) 2 | add_subdirectory(board) 3 | add_subdirectory(bsp) 4 | add_subdirectory(factory) 5 | add_subdirectory(leds) 6 | add_subdirectory(persistent_storage) 7 | add_subdirectory(tasks) 8 | add_subdirectory(tshell) 9 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | battery.h 3 | ) 4 | 5 | set(SOURCES 6 | battery.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | 15 | add_subdirectory(battery_indicator) 16 | add_subdirectory(charge_controller) 17 | add_subdirectory(soc_estimator) 18 | add_subdirectory(temperature) 19 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/battery.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "ux/system/system.h" 6 | 7 | namespace Teufel::Task::Battery 8 | { 9 | 10 | void init(); 11 | void poll(); 12 | Ux::System::ChargeType toggle_fast_charging(); 13 | Ux::System::ChargeType get_charge_type(); 14 | void set_charge_type(const Ux::System::ChargeType &type); 15 | void load_persistent_parameters(); 16 | void save_persistent_parameters(); 17 | void set_power_state(const Teufel::Ux::System::PowerState &state); 18 | void factory_reset(); 19 | 20 | #ifdef INCLUDE_PRODUCTION_TESTS 21 | // RAW battery data which are exposed only for prod testing purpose! 22 | int8_t get_battery_temperature(); 23 | uint16_t get_battery_voltage_mv(); 24 | #endif // INCLUDE_PRODUCTION_TESTS 25 | } 26 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/battery_indicator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | battery_indicator.h 3 | ) 4 | 5 | set(SOURCES 6 | battery_indicator.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/battery_indicator/battery_indicator.cpp: -------------------------------------------------------------------------------- 1 | #include "battery_indicator.h" 2 | 3 | void BatteryIndicator::update_battery_level(uint8_t level, uint32_t ts) 4 | { 5 | m_check_battery_level(level, ts); 6 | } 7 | 8 | void BatteryIndicator::update_charger_status(ChargerStatus status) 9 | { 10 | if (status == ChargerStatus::Active) 11 | { 12 | m_is_low10_indicated = false; 13 | m_is_low5_indicated = false; 14 | } 15 | m_charger_status = status; 16 | } 17 | 18 | void BatteryIndicator::update_power_state(const Teufel::Ux::System::PowerState &ps, uint32_t ts) 19 | { 20 | if (ps == Teufel::Ux::System::PowerState::On) 21 | { 22 | m_is_low10_indicated = false; 23 | m_is_low5_indicated = false; 24 | 25 | m_power_on_ts = ts; 26 | m_power_is_on = true; 27 | } 28 | else 29 | { 30 | m_power_is_on = false; 31 | } 32 | } 33 | 34 | void BatteryIndicator::m_check_battery_level(uint8_t level, uint32_t ts) 35 | { 36 | // This is the edge case where the battery level is 0 during power on! 37 | // According to the spec the unit has to be powered off if the battery level is 0 after power on. 38 | // All indication must be synchronized with the power state, and it's managed in power transition handlers. 39 | if (level == 0 && ts < 10000) 40 | { 41 | m_is_low5_indicated = true; 42 | m_is_low10_indicated = true; 43 | m_power_on_ts = UINT32_MAX; 44 | return; 45 | } 46 | 47 | if (!m_power_is_on) 48 | return; 49 | 50 | // Wait 5 seconds after power on to indicate low battery (to avoid sound icons overlapping) 51 | if (ts - m_power_on_ts < 5000) 52 | { 53 | log_debug("Battery level check skipped, waiting for power on indication to finish"); 54 | return; 55 | } 56 | 57 | if (m_charger_status == ChargerStatus::Active) 58 | return; 59 | 60 | if (level < 5 && !m_is_low5_indicated) 61 | { 62 | m_low5_action(); 63 | m_is_low5_indicated = true; 64 | m_is_low10_indicated = true; // Set low10Indicated to true to ignore the 10% indication 65 | } 66 | else if (level < 10 && !m_is_low10_indicated) 67 | { 68 | m_low10_action(); 69 | m_is_low10_indicated = true; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/battery_indicator/battery_indicator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "ux/system/system.h" 5 | 6 | using low_battery_indication_action_fn_t = void (*)(); 7 | 8 | class BatteryIndicator 9 | { 10 | using ChargerStatus = Teufel::Ux::System::ChargerStatus; 11 | 12 | public: 13 | BatteryIndicator() = delete; 14 | BatteryIndicator(low_battery_indication_action_fn_t low5_action, low_battery_indication_action_fn_t low10_action) 15 | : m_low5_action(low5_action) 16 | , m_low10_action(low10_action) 17 | { 18 | } 19 | 20 | void update_battery_level(uint8_t level, uint32_t ts); 21 | void update_charger_status(ChargerStatus status); 22 | 23 | void update_power_state(const Teufel::Ux::System::PowerState &ps, uint32_t ts); 24 | 25 | private: 26 | void m_check_battery_level(uint8_t level, uint32_t ts); 27 | 28 | bool m_is_low5_indicated = false; 29 | bool m_is_low10_indicated = false; 30 | ChargerStatus m_charger_status = ChargerStatus::NotConnected; 31 | low_battery_indication_action_fn_t m_low5_action; 32 | low_battery_indication_action_fn_t m_low10_action; 33 | 34 | uint32_t m_power_on_ts = UINT32_MAX; 35 | bool m_power_is_on = false; 36 | }; 37 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/charge_controller/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | charge_controller.h 3 | ) 4 | 5 | set(SOURCES 6 | charge_controller.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/soc_estimator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | soc_estimator.h 3 | ) 4 | 5 | set(SOURCES 6 | soc_estimator.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/temperature/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | temperature.h 3 | ) 4 | 5 | set(SOURCES 6 | temperature.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/battery/temperature/temperature.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | int8_t ntc_voltage_to_temperature(float ntc); 6 | bool is_battery_temperature_in_critical_for_charge(int8_t temperature); 7 | bool is_battery_temperature_in_critical_for_discharge(int8_t temperature); 8 | Teufel::Ux::System::BatteryCriticalTemperature battery_temperature_state(int8_t temperature); 9 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link.h 3 | ) 4 | 5 | target_sources(${projectTarget} PRIVATE ${API_HEADERS}) 6 | 7 | target_include_directories(${projectTarget} PUBLIC 8 | $ 9 | ) 10 | 11 | add_subdirectory(amps) 12 | add_subdirectory(bluetooth) 13 | add_subdirectory(boost_converter) 14 | add_subdirectory(charger) 15 | add_subdirectory(eeprom) 16 | add_subdirectory(hw_revision) 17 | add_subdirectory(io_expander) 18 | add_subdirectory(moisture_detection) 19 | add_subdirectory(plug_detection) 20 | add_subdirectory(power_supply) 21 | add_subdirectory(usb_pd_controller) 22 | add_subdirectory(usb_switch) 23 | 24 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/amps/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/amps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_amps.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_amps.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/amps/eco_5805_patch_to_bypass_mode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tas5805m.h" 3 | 4 | // From 2023-11-01 5 | 6 | const tas5805m_cfg_reg_t tas5805m_bypass_config_registers[] = { 7 | { 0x00, 0x00 }, 8 | { 0x7f, 0x00 }, 9 | { 0x00, 0x00 }, 10 | { 0x66, 0x87 }, 11 | }; 12 | 13 | #define TAS5805M_BYPASS_CONFIG_REGISTERS_SIZE (sizeof(tas5805m_bypass_config_registers) / sizeof(tas5805m_bypass_config_registers[0])) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/bluetooth/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_bluetooth.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_bluetooth.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/bluetooth/board_link_bluetooth.c: -------------------------------------------------------------------------------- 1 | #include "board_link_bluetooth.h" 2 | #include "board_hw.h" 3 | #define LOG_LEVEL LOG_LEVEL_ERROR 4 | #include "logger.h" 5 | 6 | static bool is_bluetooth_gpios_initialized = false; 7 | 8 | void board_link_bluetooth_init(void) 9 | { 10 | GPIO_InitTypeDef GPIO_InitStruct; 11 | 12 | // Configure BT Vreg control pin 13 | BT_CTRL_VREG_GPIO_CLK_ENABLE(); 14 | GPIO_InitStruct.Pin = BT_CTRL_VREG_GPIO_PIN; 15 | GPIO_InitStruct.Mode = BT_CTRL_VREG_GPIO_MODE; 16 | GPIO_InitStruct.Pull = BT_CTRL_VREG_GPIO_PULL; 17 | GPIO_InitStruct.Speed = BT_CTRL_VREG_GPIO_SPEED; 18 | HAL_GPIO_Init(BT_CTRL_VREG_GPIO_PORT, &GPIO_InitStruct); 19 | 20 | // Configure BT control 3V3 pin 21 | BT_CTRL_3V3_GPIO_CLK_ENABLE(); 22 | GPIO_InitStruct.Pin = BT_CTRL_3V3_GPIO_PIN; 23 | GPIO_InitStruct.Mode = BT_CTRL_3V3_GPIO_MODE; 24 | GPIO_InitStruct.Pull = BT_CTRL_3V3_GPIO_PULL; 25 | GPIO_InitStruct.Speed = BT_CTRL_3V3_GPIO_SPEED; 26 | HAL_GPIO_Init(BT_CTRL_3V3_GPIO_PORT, &GPIO_InitStruct); 27 | 28 | // Configure BT reset pin 29 | BT_RESET_GPIO_CLK_ENABLE(); 30 | GPIO_InitStruct.Pin = BT_RESET_GPIO_PIN; 31 | GPIO_InitStruct.Mode = BT_RESET_GPIO_MODE; 32 | GPIO_InitStruct.Pull = BT_RESET_GPIO_PULL; 33 | GPIO_InitStruct.Speed = BT_RESET_GPIO_SPEED; 34 | HAL_GPIO_Init(BT_RESET_GPIO_PORT, &GPIO_InitStruct); 35 | 36 | is_bluetooth_gpios_initialized = true; 37 | } 38 | 39 | void board_link_bluetooth_set_power(bool on) 40 | { 41 | HAL_GPIO_WritePin(BT_CTRL_VREG_GPIO_PORT, BT_CTRL_VREG_GPIO_PIN, (on) ? GPIO_PIN_SET : GPIO_PIN_RESET); 42 | HAL_GPIO_WritePin(BT_CTRL_3V3_GPIO_PORT, BT_CTRL_3V3_GPIO_PIN, (on) ? GPIO_PIN_SET : GPIO_PIN_RESET); 43 | log_info("Bluetooth powered %s", on ? "on" : "off"); 44 | } 45 | 46 | void board_link_bluetooth_reset(bool assert) 47 | { 48 | HAL_GPIO_WritePin(BT_RESET_GPIO_PORT, BT_RESET_GPIO_PIN, (assert) ? GPIO_PIN_SET : GPIO_PIN_RESET); 49 | log_info("Bluetooth reset %s", assert ? "asserted" : "deasserted"); 50 | } 51 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/bluetooth/board_link_bluetooth.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | /** 11 | * @brief Initializes GPIOs necessary to control the Bluetooth module. 12 | */ 13 | void board_link_bluetooth_init(void); 14 | 15 | /** 16 | * @brief Powers the Bluetooth module on/off. 17 | * 18 | * @param[in] on power option 19 | */ 20 | void board_link_bluetooth_set_power(bool on); 21 | 22 | /** 23 | * @brief Asserts/deasserts the reset line of the Bluetooth module. 24 | * 25 | * @param[in] assert assert option 26 | */ 27 | void board_link_bluetooth_reset(bool assert); 28 | 29 | #if defined(__cplusplus) 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/board_link.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "board_link_amps.h" 4 | #include "board_link_bluetooth.h" 5 | #include "board_link_boost_converter.h" 6 | #include "board_link_charger.h" 7 | #include "board_link_eeprom.h" 8 | #include "board_link_hw_revision.h" 9 | #include "board_link_io_expander.h" 10 | #include "board_link_moisture_detection.h" 11 | #include "board_link_plug_detection.h" 12 | #include "board_link_power_supply.h" 13 | #include "board_link_usb_pd_controller.h" 14 | #include "board_link_usb_switch.h" 15 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/boost_converter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_boost_converter.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_boost_converter.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/boost_converter/board_link_boost_converter.c: -------------------------------------------------------------------------------- 1 | #include "board_link_boost_converter.h" 2 | #include "board_hw.h" 3 | #define LOG_LEVEL LOG_LEVEL_ERROR 4 | #include "logger.h" 5 | 6 | void board_link_boost_converter_init(void) 7 | { 8 | GPIO_InitTypeDef GPIO_InitStruct; 9 | 10 | // Configure boost enable pin 11 | BOOST_ENABLE_GPIO_CLK_ENABLE(); 12 | board_link_boost_converter_enable(false); 13 | GPIO_InitStruct.Pin = BOOST_ENABLE_GPIO_PIN; 14 | GPIO_InitStruct.Mode = BOOST_ENABLE_GPIO_MODE; 15 | GPIO_InitStruct.Pull = BOOST_ENABLE_GPIO_PULL; 16 | GPIO_InitStruct.Speed = BOOST_ENABLE_GPIO_SPEED; 17 | HAL_GPIO_Init(BOOST_ENABLE_GPIO_PORT, &GPIO_InitStruct); 18 | } 19 | 20 | void board_link_boost_converter_enable(bool enable) 21 | { 22 | HAL_GPIO_WritePin(BOOST_ENABLE_GPIO_PORT, BOOST_ENABLE_GPIO_PIN, (enable) ? GPIO_PIN_SET : GPIO_PIN_RESET); 23 | log_info("Boost converter %s", enable ? "enabled" : "disabled"); 24 | } 25 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/boost_converter/board_link_boost_converter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | /** 11 | * @brief Initializes the hardware needed to interface the boost converter. 12 | */ 13 | void board_link_boost_converter_init(void); 14 | 15 | /** 16 | * @brief Enables/disables the boost converter. 17 | * 18 | * @param[in] enable enable option 19 | */ 20 | void board_link_boost_converter_enable(bool enable); 21 | 22 | #if defined(__cplusplus) 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/charger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_charger.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_charger.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/eeprom/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_eeprom.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_eeprom.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/eeprom/board_link_eeprom.c: -------------------------------------------------------------------------------- 1 | // Due to the flash size limit, only the WARNING level is available 2 | // for use in the complete firmware (including the bootloader). 3 | #if defined(BOOTLOADER) 4 | #define LOG_LEVEL LOG_LEVEL_ERROR 5 | #else 6 | #define LOG_LEVEL LOG_LEVEL_INFO 7 | #endif 8 | 9 | #include "board_link_eeprom.h" 10 | #include "board_link_usb_pd_controller.h" 11 | #include "board_hw.h" 12 | #include "logger.h" 13 | 14 | // size 32KB 15 | #define EEPROM_SIZE (32 * 1024) 16 | #define EEPROM_I2C_ADDRESS 0x50 17 | 18 | void board_link_eeprom_init(void) {} 19 | 20 | int board_link_eeprom_write(uint16_t address, const uint8_t *data, size_t size) 21 | { 22 | if (size == 0) 23 | { 24 | return 0; 25 | } 26 | 27 | if (data == NULL) 28 | { 29 | return -1; 30 | } 31 | 32 | #if 0 33 | // if (size > 8) 34 | // { 35 | // log_error("EEPROM write supports only 8 bytes at a time."); 36 | // return -1; 37 | // } 38 | 39 | if (address + size > EEPROM_SIZE) 40 | { 41 | return -1; 42 | } 43 | 44 | uint8_t address_lsb = address & 0xFF; 45 | uint8_t address_msb = (address >> 8) & 0xFF; 46 | 47 | uint8_t buf[17] = {0}; 48 | buf[0] = address_lsb; 49 | for (size_t i = 0; i < size; i++) 50 | { 51 | buf[i + 1] = data[i]; 52 | } 53 | 54 | return board_link_usb_pd_controller_i2c_write(EEPROM_I2C_ADDRESS, address_msb, buf, size + 1); 55 | #endif 56 | 57 | return board_link_usb_pd_controller_eeprom_write(address, data, size); 58 | } 59 | 60 | int board_link_eeprom_read(uint16_t address, uint8_t *data, size_t size) 61 | { 62 | if (size == 0) 63 | { 64 | return 0; 65 | } 66 | 67 | if (data == NULL) 68 | { 69 | return -1; 70 | } 71 | 72 | if (address + size > EEPROM_SIZE) 73 | { 74 | return -1; 75 | } 76 | 77 | // if (board_link_usb_pd_controller_i2c_write(EEPROM_I2C_ADDRESS, address_msb, &address_lsb, 1) < 0) 78 | // if (board_link_usb_pd_controller_i2c_write(EEPROM_I2C_ADDRESS, 0xff, &data[0], 2) < 0) 79 | // { 80 | // log_error("Failed to write EEPROM address"); 81 | // return -1; 82 | // } 83 | 84 | return board_link_usb_pd_controller_eeprom_read(address, data, size); 85 | } 86 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/eeprom/board_link_eeprom.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #if defined(__cplusplus) 7 | extern "C" 8 | { 9 | #endif 10 | 11 | /** 12 | * @brief Initializes the EEPROM. 13 | */ 14 | void board_link_eeprom_init(void); 15 | 16 | /** 17 | * @brief Reads data from the EEPROM. 18 | * 19 | * @param[in] address the address to read from 20 | * @param[out] data pointer to where the data should be written 21 | * @param[in] size the number of bytes to read 22 | * 23 | * @return 0 if successful, -1 otherwise 24 | */ 25 | int board_link_eeprom_read(uint16_t address, uint8_t *data, size_t size); 26 | 27 | /** 28 | * @brief Writes data to the EEPROM. 29 | * 30 | * @param[in] address the address to write to 31 | * @param[in] data pointer to the data to write 32 | * @param[in] size the number of bytes to write 33 | * 34 | * @return 0 if successful, -1 otherwise 35 | */ 36 | int board_link_eeprom_write(uint16_t address, const uint8_t *data, size_t size); 37 | 38 | #if defined(__cplusplus) 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/hw_revision/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_hw_revision.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_hw_revision.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/hw_revision/board_link_hw_revision.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | uint8_t read_hw_revision(void); 11 | uint8_t read_bt_hw_revision(void); 12 | uint8_t read_amp_hw_revision(void); 13 | 14 | #if defined(__cplusplus) 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/io_expander/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_io_expander.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_io_expander.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/moisture_detection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_moisture_detection.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_moisture_detection.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/moisture_detection/board_link_moisture_detection.c: -------------------------------------------------------------------------------- 1 | #include "board_link_moisture_detection.h" 2 | #include "board_hw.h" 3 | 4 | void board_link_moisture_detection_init(void) 5 | { 6 | GPIO_InitTypeDef GPIO_InitStruct; 7 | 8 | MOISTURE_DETECTION_GPIO_CLK_ENABLE(); 9 | 10 | GPIO_InitStruct.Pin = MOISTURE_DETECTION_GPIO_PIN; 11 | GPIO_InitStruct.Mode = MOISTURE_DETECTION_GPIO_MODE; 12 | GPIO_InitStruct.Pull = MOISTURE_DETECTION_GPIO_PULL; 13 | GPIO_InitStruct.Speed = MOISTURE_DETECTION_GPIO_SPEED; 14 | HAL_GPIO_Init(MOISTURE_DETECTION_GPIO_PORT, &GPIO_InitStruct); 15 | } 16 | 17 | bool board_link_moisture_detection_is_detected(void) 18 | { 19 | return HAL_GPIO_ReadPin(MOISTURE_DETECTION_GPIO_PORT, MOISTURE_DETECTION_GPIO_PIN) == GPIO_PIN_SET; 20 | } 21 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/moisture_detection/board_link_moisture_detection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | void board_link_moisture_detection_init(void); 11 | 12 | bool board_link_moisture_detection_is_detected(void); 13 | 14 | #if defined(__cplusplus) 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/plug_detection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_plug_detection.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_plug_detection.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/plug_detection/board_link_plug_detection.c: -------------------------------------------------------------------------------- 1 | #include "board_link_plug_detection.h" 2 | #include "board_hw.h" 3 | 4 | void board_link_plug_detection_init(void) 5 | { 6 | GPIO_InitTypeDef GPIO_InitStruct; 7 | 8 | // Configure power button pin 9 | PLUG_DETECTION_GPIO_CLK_ENABLE(); 10 | GPIO_InitStruct.Pin = PLUG_DETECTION_GPIO_PIN; 11 | GPIO_InitStruct.Mode = PLUG_DETECTION_GPIO_MODE; 12 | GPIO_InitStruct.Pull = PLUG_DETECTION_GPIO_PULL; 13 | GPIO_InitStruct.Speed = PLUG_DETECTION_GPIO_SPEED; 14 | HAL_GPIO_Init(PLUG_DETECTION_GPIO_PORT, &GPIO_InitStruct); 15 | } 16 | 17 | bool board_link_plug_detection_is_jack_connected(void) 18 | { 19 | return HAL_GPIO_ReadPin(PLUG_DETECTION_GPIO_PORT, PLUG_DETECTION_GPIO_PIN) == GPIO_PIN_RESET; 20 | } 21 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/plug_detection/board_link_plug_detection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | void board_link_plug_detection_init(void); 11 | 12 | bool board_link_plug_detection_is_jack_connected(void); 13 | 14 | #if defined(__cplusplus) 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/power_supply/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_power_supply.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_power_supply.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/power_supply/board_link_power_supply.c: -------------------------------------------------------------------------------- 1 | #include "board_link_power_supply.h" 2 | #include "board_hw.h" 3 | #include "logger.h" 4 | 5 | void board_link_power_supply_init(void) 6 | { 7 | GPIO_InitTypeDef GPIO_InitStruct; 8 | 9 | // Configure power button pin 10 | POWER_BUTTON_GPIO_CLK_ENABLE(); 11 | GPIO_InitStruct.Pin = POWER_BUTTON_GPIO_PIN; 12 | GPIO_InitStruct.Mode = POWER_BUTTON_GPIO_MODE; 13 | GPIO_InitStruct.Pull = POWER_BUTTON_GPIO_PULL; 14 | GPIO_InitStruct.Speed = POWER_BUTTON_GPIO_SPEED; 15 | HAL_GPIO_Init(POWER_BUTTON_GPIO_PORT, &GPIO_InitStruct); 16 | 17 | // Configure power hold pin 18 | POWER_HOLD_GPIO_CLK_ENABLE(); 19 | GPIO_InitStruct.Pin = POWER_HOLD_GPIO_PIN; 20 | GPIO_InitStruct.Mode = POWER_HOLD_GPIO_MODE; 21 | GPIO_InitStruct.Pull = POWER_HOLD_GPIO_PULL; 22 | GPIO_InitStruct.Speed = POWER_HOLD_GPIO_SPEED; 23 | HAL_GPIO_Init(POWER_HOLD_GPIO_PORT, &GPIO_InitStruct); 24 | 25 | // Configure AC OK pin 26 | AC_OK_GPIO_CLK_ENABLE(); 27 | GPIO_InitStruct.Pin = AC_OK_GPIO_PIN; 28 | GPIO_InitStruct.Mode = AC_OK_GPIO_MODE; 29 | GPIO_InitStruct.Pull = AC_OK_GPIO_PULL; 30 | GPIO_InitStruct.Speed = AC_OK_GPIO_SPEED; 31 | HAL_GPIO_Init(AC_OK_GPIO_PORT, &GPIO_InitStruct); 32 | } 33 | 34 | bool board_link_power_supply_is_ac_ok(void) 35 | { 36 | return HAL_GPIO_ReadPin(AC_OK_GPIO_PORT, AC_OK_GPIO_PIN) == GPIO_PIN_SET; 37 | } 38 | 39 | bool board_link_power_supply_button_is_pressed(void) 40 | { 41 | return HAL_GPIO_ReadPin(POWER_BUTTON_GPIO_PORT, POWER_BUTTON_GPIO_PIN) == GPIO_PIN_SET; 42 | } 43 | 44 | bool board_link_power_supply_is_held_on(void) 45 | { 46 | return HAL_GPIO_ReadPin(POWER_HOLD_GPIO_PORT, POWER_HOLD_GPIO_PIN) == GPIO_PIN_SET; 47 | } 48 | 49 | void board_link_power_supply_hold_on(bool hold) 50 | { 51 | HAL_GPIO_WritePin(POWER_HOLD_GPIO_PORT, POWER_HOLD_GPIO_PIN, (hold) ? GPIO_PIN_SET : GPIO_PIN_RESET); 52 | log_info("Power supply hold %s", hold ? "active" : "released"); 53 | } 54 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/power_supply/board_link_power_supply.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | void board_link_power_supply_init(void); 11 | 12 | bool board_link_power_supply_is_ac_ok(void); 13 | 14 | bool board_link_power_supply_button_is_pressed(void); 15 | 16 | bool board_link_power_supply_is_held_on(void); 17 | 18 | void board_link_power_supply_hold_on(bool hold); 19 | 20 | #if defined(__cplusplus) 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/usb_pd_controller/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_usb_pd_controller.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_usb_pd_controller.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/usb_switch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board_link_usb_switch.h 3 | ) 4 | 5 | set(SOURCES 6 | board_link_usb_switch.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/usb_switch/board_link_usb_switch.c: -------------------------------------------------------------------------------- 1 | #define LOG_LEVEL LOG_LEVEL_ERROR 2 | #include "board_link_usb_switch.h" 3 | #include "board_hw.h" 4 | #include "logger.h" 5 | 6 | void board_link_usb_switch_init(void) 7 | { 8 | GPIO_InitTypeDef GPIO_InitStruct; 9 | 10 | USB_SELECT0_GPIO_CLK_ENABLE(); 11 | USB_SELECT1_GPIO_CLK_ENABLE(); 12 | 13 | GPIO_InitStruct.Pin = USB_SELECT0_GPIO_PIN; 14 | GPIO_InitStruct.Mode = USB_SELECT0_GPIO_MODE; 15 | GPIO_InitStruct.Pull = USB_SELECT0_GPIO_PULL; 16 | GPIO_InitStruct.Speed = USB_SELECT0_GPIO_SPEED; 17 | HAL_GPIO_Init(USB_SELECT0_GPIO_PORT, &GPIO_InitStruct); 18 | 19 | GPIO_InitStruct.Pin = USB_SELECT1_GPIO_PIN; 20 | GPIO_InitStruct.Mode = USB_SELECT1_GPIO_MODE; 21 | GPIO_InitStruct.Pull = USB_SELECT1_GPIO_PULL; 22 | GPIO_InitStruct.Speed = USB_SELECT1_GPIO_SPEED; 23 | HAL_GPIO_Init(USB_SELECT1_GPIO_PORT, &GPIO_InitStruct); 24 | 25 | log_debug("USB switch initialized"); 26 | } 27 | 28 | void board_link_usb_switch_to_mcu(void) 29 | { 30 | HAL_GPIO_WritePin(USB_SELECT0_GPIO_PORT, USB_SELECT0_GPIO_PIN, GPIO_PIN_SET); 31 | HAL_GPIO_WritePin(USB_SELECT1_GPIO_PORT, USB_SELECT1_GPIO_PIN, GPIO_PIN_SET); 32 | log_info("USB switched to MCU"); 33 | } 34 | 35 | void board_link_usb_switch_to_bluetooth(void) 36 | { 37 | HAL_GPIO_WritePin(USB_SELECT0_GPIO_PORT, USB_SELECT0_GPIO_PIN, GPIO_PIN_RESET); 38 | HAL_GPIO_WritePin(USB_SELECT1_GPIO_PORT, USB_SELECT1_GPIO_PIN, GPIO_PIN_SET); 39 | log_info("USB switched to Bluetooth module"); 40 | } 41 | 42 | void board_link_usb_switch_to_usb_pd(void) 43 | { 44 | HAL_GPIO_WritePin(USB_SELECT0_GPIO_PORT, USB_SELECT0_GPIO_PIN, GPIO_PIN_RESET); 45 | HAL_GPIO_WritePin(USB_SELECT1_GPIO_PORT, USB_SELECT1_GPIO_PIN, GPIO_PIN_RESET); 46 | log_info("USB switched to Bluetooth module"); 47 | } 48 | 49 | void board_link_usb_switch_to_uart_debug(void) 50 | { 51 | HAL_GPIO_WritePin(USB_SELECT1_GPIO_PORT, USB_SELECT1_GPIO_PIN, GPIO_PIN_RESET); 52 | log_info("USB switched to UART debug"); 53 | } 54 | -------------------------------------------------------------------------------- /Projects/Mynd/src/board/usb_switch/board_link_usb_switch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__cplusplus) 4 | extern "C" 5 | { 6 | #endif 7 | 8 | /** 9 | * @brief Initializes the hardware needed to interface the USB switch. 10 | * @note The USB is switched to the MCU after initialization. 11 | */ 12 | void board_link_usb_switch_init(void); 13 | 14 | /** 15 | * @brief Switches USB to the MCU. 16 | */ 17 | void board_link_usb_switch_to_mcu(void); 18 | 19 | /** 20 | * @brief Switches USB to the Bluetooth module. 21 | */ 22 | void board_link_usb_switch_to_bluetooth(void); 23 | 24 | /** 25 | * @brief Switches USB to the USB PD controller IC. 26 | */ 27 | void board_link_usb_switch_to_usb_pd(void); 28 | 29 | /** 30 | * @brief Switches USB to the UART debug. 31 | */ 32 | void board_link_usb_switch_to_uart_debug(void); 33 | 34 | #if defined(__cplusplus) 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | board.h 3 | board_hw.h 4 | ) 5 | 6 | set(SOURCES 7 | board.c 8 | board_msp.c 9 | ) 10 | 11 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 12 | 13 | target_include_directories(${projectTarget} PUBLIC 14 | $ 15 | ) 16 | 17 | add_subdirectory(adc) 18 | add_subdirectory(bluetooth_uart) 19 | add_subdirectory(debug_uart) 20 | add_subdirectory(shared_i2c) 21 | add_subdirectory(usb_pd_i2c) 22 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/adc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | bsp_adc.h 3 | ) 4 | 5 | set(SOURCES 6 | bsp_adc.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/adc/bsp_adc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | typedef void (*bsp_adc_conversion_complete_callback_t)(void); 7 | 8 | #if defined(__cplusplus) 9 | extern "C" 10 | { 11 | #endif 12 | 13 | void bsp_bat_voltage_enable_init(void); 14 | void bsp_bat_voltage_enable(bool enable); 15 | void bsp_adc_init(void); 16 | void bsp_adc_deinit(void); 17 | void bsp_adc_start(uint32_t *buffer, uint32_t buffer_size, bsp_adc_conversion_complete_callback_t callback); 18 | void bsp_adc_stop(void); 19 | 20 | #if defined(__cplusplus) 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/bluetooth_uart/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | bsp_bluetooth_uart.h 3 | ) 4 | 5 | set(SOURCES 6 | bsp_bluetooth_uart.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/bluetooth_uart/bsp_bluetooth_uart.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #if defined(__cplusplus) 7 | extern "C" 8 | { 9 | #endif 10 | 11 | /** 12 | * @brief Initializes the UART hardware needed to interface with the Bluetooth module. 13 | */ 14 | void bsp_bluetooth_uart_init(void); 15 | 16 | void bsp_bluetooth_uart_msp_init(void); 17 | 18 | void bsp_bluetooth_uart_msp_deinit(void); 19 | 20 | void bsp_bluetooth_uart_clear_buffer(void); 21 | 22 | /** 23 | * @brief Sends data over UART. 24 | * @note This function returns immediately. The TX done callback provided 25 | * in `board_hal_bluetooth_uart_init()` will be called when the transfer completes. 26 | * 27 | * @param[in] p_data pointer to data to send 28 | * @param[in] length length of data to send 29 | * 30 | * @return 0 if successful, -1 otherwise 31 | */ 32 | int bsp_bluetooth_uart_tx(const uint8_t *p_data, size_t length); 33 | 34 | /** 35 | * @brief Reads data from the UART RX buffer. 36 | * 37 | * @details This function checks if the requested length has already been received and 38 | * returns it if that's the case. If the expected length is not in the buffer yet, 39 | * the function will return an error. 40 | * 41 | * @param[out] p_data pointer to where the read data will be written 42 | * @param[in] length number of bytes to read 43 | * 44 | * @return 0 if successful, -1 otherwise 45 | */ 46 | int bsp_bluetooth_uart_rx(uint8_t *p_data, size_t length); 47 | 48 | #if defined(__cplusplus) 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/board.c: -------------------------------------------------------------------------------- 1 | #include "board.h" 2 | #include "FreeRTOS.h" 3 | #include "task.h" 4 | #include "stm32f0xx_hal.h" 5 | 6 | extern I2C_HandleTypeDef I2C2_Handle; 7 | 8 | void board_init(void) 9 | { 10 | /* EXTI interrupt init*/ 11 | HAL_NVIC_SetPriority(EXTI2_3_IRQn, 3, 0); 12 | HAL_NVIC_EnableIRQ(EXTI2_3_IRQn); 13 | 14 | /* Enable all GPIO clocks */ 15 | __HAL_RCC_GPIOA_CLK_ENABLE(); 16 | __HAL_RCC_GPIOB_CLK_ENABLE(); 17 | __HAL_RCC_GPIOC_CLK_ENABLE(); 18 | __HAL_RCC_GPIOD_CLK_ENABLE(); 19 | __HAL_RCC_GPIOF_CLK_ENABLE(); 20 | } 21 | 22 | void HAL_MspInit(void) 23 | { 24 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 25 | __HAL_RCC_PWR_CLK_ENABLE(); 26 | } 27 | 28 | uint32_t get_systick(void) 29 | { 30 | if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) 31 | return 0; 32 | 33 | uint32_t IPSR_register; 34 | __asm volatile("MRS %0, ipsr" : "=r"(IPSR_register)); 35 | 36 | if (0U == IPSR_register) 37 | return xTaskGetTickCountFromISR(); 38 | 39 | return xTaskGetTickCount(); 40 | } 41 | 42 | uint32_t board_get_ms_since(uint32_t tick_ms) 43 | { 44 | uint32_t current_tick_ms = get_systick(); 45 | 46 | // Handle overflow 47 | if (current_tick_ms < tick_ms) 48 | { 49 | // Note: if last tick is UINT32_MAX and current tick is 0, this function should return 1 50 | return (UINT32_MAX - tick_ms) + current_tick_ms + 1; 51 | } 52 | else 53 | { 54 | return current_tick_ms - tick_ms; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/board.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | void board_init(void); 11 | uint32_t get_systick(void); 12 | uint32_t board_get_ms_since(uint32_t tick_ms); 13 | 14 | #if defined(__cplusplus) 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/board_msp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f0xx_hal.h" 3 | #include "board_hw.h" 4 | #include "bsp_bluetooth_uart.h" 5 | #include "bsp_debug_uart.h" 6 | #include "bsp_shared_i2c.h" 7 | #include "bsp_usb_pd_i2c.h" 8 | #include "external/teufel/libs/app_assert/app_assert.h" 9 | 10 | void HAL_UART_MspInit(UART_HandleTypeDef *huart) 11 | { 12 | if (huart->Instance == BLUETOOTH_UART) 13 | { 14 | bsp_bluetooth_uart_msp_init(); 15 | } 16 | else if (huart->Instance == DEBUG_UART) 17 | { 18 | bsp_debug_uart_msp_init(); 19 | } 20 | } 21 | 22 | void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) 23 | { 24 | if (huart->Instance == BLUETOOTH_UART) 25 | { 26 | bsp_bluetooth_uart_msp_deinit(); 27 | } 28 | else if (huart->Instance == DEBUG_UART) 29 | { 30 | } 31 | } 32 | 33 | void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) 34 | { 35 | if (hi2c->Instance == USB_PD_I2C) 36 | { 37 | bsp_usb_pd_i2c_msp_init(); 38 | } 39 | else if (hi2c->Instance == SHARED_I2C) 40 | { 41 | bsp_shared_i2c_msp_init(); 42 | } 43 | else 44 | { 45 | APP_ASSERT(false); 46 | } 47 | } 48 | 49 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c) 50 | { 51 | if (hi2c->Instance == USB_PD_I2C) 52 | { 53 | GPIO_InitTypeDef GPIO_InitStruct; 54 | 55 | USB_PD_I2C_FORCE_RESET(); 56 | USB_PD_I2C_RELEASE_RESET(); 57 | 58 | /* Configure I2C SDA&SCL GPIO as analog pin */ 59 | GPIO_InitStruct.Pin = USB_PD_I2C_SCL_GPIO_PIN; 60 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 61 | GPIO_InitStruct.Pull = GPIO_NOPULL; 62 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 63 | HAL_GPIO_Init(USB_PD_I2C_SCL_GPIO_PORT, &GPIO_InitStruct); 64 | 65 | GPIO_InitStruct.Pin = USB_PD_I2C_SDA_GPIO_PIN; 66 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 67 | GPIO_InitStruct.Pull = GPIO_NOPULL; 68 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 69 | HAL_GPIO_Init(USB_PD_I2C_SDA_GPIO_PORT, &GPIO_InitStruct); 70 | 71 | HAL_NVIC_DisableIRQ(USB_PD_I2C_IRQn); 72 | 73 | USB_PD_I2C_CLK_DISABLE(); 74 | } 75 | else if (hi2c->Instance == SHARED_I2C) 76 | { 77 | bsp_shared_i2c_msp_deinit(); 78 | } 79 | else 80 | { 81 | APP_ASSERT(false); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/debug_uart/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | bsp_debug_uart.h 3 | ) 4 | 5 | set(SOURCES 6 | bsp_debug_uart.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/debug_uart/bsp_debug_uart.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #if defined(__cplusplus) 7 | extern "C" 8 | { 9 | #endif 10 | 11 | /** 12 | * @brief Initializes the UART hardware needed to interface with the debug serial port. 13 | */ 14 | void bsp_debug_uart_init(void); 15 | 16 | void bsp_debug_uart_msp_init(void); 17 | 18 | /** 19 | * @brief Sends data over UART. 20 | * @note This function returns immediately. The TX done callback provided 21 | * in `board_hal_bluetooth_uart_init()` will be called when the transfer completes. 22 | * 23 | * @param[in] p_data pointer to data to send 24 | * @param[in] length length of data to send 25 | * 26 | * @return 0 if successful, -1 otherwise 27 | */ 28 | int bsp_debug_uart_tx(const uint8_t *p_data, size_t length); 29 | 30 | /** 31 | * @brief Reads data from the UART RX buffer. 32 | * 33 | * @details This function checks if the requested length has already been received and 34 | * returns it if that's the case. If the expected length is not in the buffer yet, 35 | * the function will return an error. 36 | * 37 | * @param[out] p_data pointer to where the read data will be written 38 | * @param[in] length number of bytes to read 39 | * 40 | * @return 0 if successful, -1 otherwise 41 | */ 42 | int bsp_debug_uart_rx(uint8_t *p_data, size_t length); 43 | 44 | #if defined(__cplusplus) 45 | } 46 | #endif 47 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/shared_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | bsp_shared_i2c.h 3 | ) 4 | 5 | set(SOURCES 6 | bsp_shared_i2c.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/shared_i2c/bsp_shared_i2c.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | /** 11 | * @brief Initializes the I2C hardware needed to interface with the shared I2C bus. 12 | */ 13 | void bsp_shared_i2c_init(void); 14 | 15 | void bsp_shared_i2c_deinit(void); 16 | 17 | void bsp_shared_i2c_msp_init(void); 18 | 19 | void bsp_shared_i2c_msp_deinit(void); 20 | 21 | /** 22 | * @brief Writes to the shared I2C bus. 23 | * 24 | * @param[in] i2c_address I2C device address 25 | * @param[in] register_address register address to write to 26 | * @param[in] p_buffer pointer to data to write 27 | * @param[in] length number of bytes to write 28 | * 29 | * @return 0 if successful, -1 otherwise 30 | */ 31 | int bsp_shared_i2c_write(uint8_t i2c_address, uint8_t register_address, const uint8_t *p_buffer, uint32_t length); 32 | 33 | /** 34 | * @brief Reads from the shared I2C bus. 35 | * 36 | * @param[in] i2c_address I2C device address 37 | * @param[in] register_address register address to read from 38 | * @param[out] p_buffer pointer to where the read data will be written to 39 | * @param[in] length number of bytes to read 40 | * 41 | * @return 0 if successful, -1 otherwise 42 | */ 43 | int bsp_shared_i2c_read(uint8_t i2c_address, uint8_t register_address, uint8_t *p_buffer, uint32_t length); 44 | 45 | #if defined(__cplusplus) 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/usb_pd_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | bsp_usb_pd_i2c.h 3 | ) 4 | 5 | set(SOURCES 6 | bsp_usb_pd_i2c.c 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/bsp/usb_pd_i2c/bsp_usb_pd_i2c.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | /** 11 | * @brief Initializes the I2C hardware needed to interface with the USB PD I2C bus. 12 | */ 13 | void bsp_usb_pd_i2c_init(void); 14 | 15 | void bsp_usb_pd_i2c_msp_init(void); 16 | 17 | /** 18 | * @brief Writes to the USB PD I2C bus. 19 | * 20 | * @param[in] i2c_address I2C device address 21 | * @param[in] register_address register address to write to 22 | * @param[in] p_buffer pointer to data to write 23 | * @param[in] length number of bytes to write 24 | * 25 | * @return 0 if successful, -1 otherwise 26 | */ 27 | int bsp_usb_pd_i2c_write(uint8_t i2c_address, uint8_t register_address, const uint8_t *p_buffer, uint32_t length); 28 | 29 | /** 30 | * @brief Reads from the USB PD I2C bus. 31 | * 32 | * @param[in] i2c_address I2C device address 33 | * @param[in] register_address register address to read from 34 | * @param[out] p_buffer pointer to where the read data will be written to 35 | * @param[in] length number of bytes to read 36 | * 37 | * @return 0 if successful, -1 otherwise 38 | */ 39 | int bsp_usb_pd_i2c_read(uint8_t i2c_address, uint8_t register_address, uint8_t *p_buffer, uint32_t length); 40 | 41 | #if defined(__cplusplus) 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /Projects/Mynd/src/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // clang-format off 4 | 5 | #define CONFIG_BRIGHTNESS_DEFAULT (50) 6 | #define CONFIG_BRIGHTNESS_DIMMED (10) 7 | 8 | #define CONFIG_DSP_BASS_MIN (-6) 9 | #define CONFIG_DSP_BASS_MAX (6) 10 | #define CONFIG_DSP_BASS_DEFAULT (0) 11 | 12 | #define CONFIG_DSP_TREBLE_MIN (-6) 13 | #define CONFIG_DSP_TREBLE_MAX (6) 14 | #define CONFIG_DSP_TREBLE_DEFAULT (0) 15 | 16 | #define CONFIG_BATTERY_LEVEL_FULL_MIN_THRESHOLD (80) 17 | #define CONFIG_BATTERY_LEVEL_HALF_MIN_THRESHOLD (34) 18 | #define CONFIG_BATTERY_LEVEL_LOW_MIN_THRESHOLD (11) 19 | 20 | #define CONFIG_STANDBY_TIMER_MINS_DEFAULT (10) 21 | 22 | #define CONFIG_MAX_AVRCP_VOLUME (127) 23 | #define CONFIG_DEFAULT_ABSOLUTE_AVRCP_VOLUME ((127 * 40) / 100) // 40% of 127 avrcp max 24 | 25 | #define CONFIG_IDLE_POWER_OFF_TIMEOUT_MS_FACTOR (60UL * 1000UL) 26 | #define CONFIG_MAX_IDLE_TIMEOUT_MINUTES (254) 27 | #define CONFIG_MIN_IDLE_TIMEOUT_MINUTES (0) 28 | 29 | #define CONFIG_CHARGE_OVER_TEMP_PROTECTION_DEGREE (45) 30 | #define CONFIG_CHARGE_OVER_TEMP_PROTECTION_RECOVERY_DEGREE (40) 31 | #define CONFIG_DISCHARGE_OVER_TEMP_PROTECTION_DEGREE (60) 32 | #define CONFIG_DISCHARGE_OVER_TEMP_PROTECTION_RECOVERY_DEGREE (50) 33 | #define CONFIG_CHARGE_UNDER_TEMP_PROTECTION_DEGREE (0) 34 | #define CONFIG_CHARGE_UNDER_TEMP_PROTECTION_RECOVERY_DEGREE (5) 35 | #define CONFIG_DISCHARGE_UNDER_TEMP_PROTECTION_DEGREE (-20) 36 | #define CONFIG_DISCHARGE_UNDER_TEMP_PROTECTION_RECOVERY_DEGREE (-10) 37 | 38 | #define CONFIG_POWER_BANK_LOW_BATTERY_THRESHOLD (20) 39 | #define CONFIG_POWER_BANK_LOW_BATTERY_RECOVERY_THRESHOLD (40) 40 | 41 | #define CONFIG_FAST_CHARGE_DEFAULT (false) 42 | 43 | // clang-format on 44 | -------------------------------------------------------------------------------- /Projects/Mynd/src/factory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | tests.h 3 | ) 4 | 5 | set(SOURCES 6 | tests.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/factory/tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | bool is_test_mode_activated(); 4 | bool is_led_test_activated(); 5 | bool is_key_test_activated(); 6 | void factory_test_key_process(); 7 | 8 | typedef void (*button_evt_handler_fn_t)(Teufel::Ux::InputState event); 9 | 10 | const std::optional get_handler_mapper(uint32_t button_state); 11 | void set_power_with_prompt(bool value); -------------------------------------------------------------------------------- /Projects/Mynd/src/leds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | leds.h 3 | ) 4 | 5 | set(SOURCES 6 | leds.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/leds/leds.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "ux/system/system.h" 6 | 7 | namespace Teufel::Task::Leds 8 | { 9 | 10 | enum class Led : uint8_t 11 | { 12 | Status, 13 | Source, 14 | }; 15 | 16 | enum class Color : uint8_t 17 | { 18 | Off, 19 | Red, 20 | Green, 21 | Blue, 22 | Yellow, 23 | Orange, 24 | Purple, 25 | Cyan, 26 | White 27 | }; 28 | 29 | enum class SourcePattern : uint8_t 30 | { 31 | Off, 32 | BluetoothDisconnected, 33 | BluetoothPairing, 34 | CsbMaster, 35 | CsbSlave, 36 | #ifdef INCLUDE_TWS_MODE 37 | TwsMasterPairing, 38 | #endif 39 | SlavePairing, 40 | OffFromBtDfu, 41 | OffFromBtSource, 42 | OffFromAuxSource, 43 | OffFromUsbSource, 44 | OffFromMstrChain, 45 | OffFromSlvChain, 46 | BluetoothConnected, 47 | AuxConnected, 48 | UsbConnected, 49 | PositiveFeedback, 50 | EcoModeOn, 51 | EcoModeOff, 52 | BtDfu, 53 | }; 54 | 55 | inline auto getDesc(const SourcePattern &value) 56 | { 57 | switch (value) 58 | { 59 | case SourcePattern::Off: 60 | return "Off"; 61 | case SourcePattern::BluetoothDisconnected: 62 | return "BluetoothDisconnected"; 63 | case SourcePattern::BluetoothPairing: 64 | return "BluetoothPairing"; 65 | case SourcePattern::CsbMaster: 66 | return "CsbMaster"; 67 | case SourcePattern::CsbSlave: 68 | return "CsbSlave"; 69 | default: 70 | return "Unknown"; 71 | } 72 | } 73 | 74 | void tick(); 75 | bool is_engine_running(Led led); 76 | void run_engines(); 77 | void set_solid_color(Led led, Color color); 78 | void set_source_pattern(SourcePattern pattern); 79 | void set_brightness(uint8_t brightness); 80 | 81 | void user_activity(); 82 | 83 | void indicate_battery_level(const Teufel::Ux::System::BatteryLevel &p); 84 | void indicate_factory_reset(const Ux::System::FactoryReset &p); 85 | void indicate_charge_type(const Ux::System::ChargeType &charge_type, const Ux::System::BatteryLevel &battery_level); 86 | void indicate_low_battery_level(const Ux::System::BatteryLowLevelState &p); 87 | void indicate_power_off(const Ux::System::BatteryLevel &battery_level); 88 | void indicate_temperature_warning(const Ux::System::BatteryCriticalTemperature &p); 89 | 90 | } 91 | -------------------------------------------------------------------------------- /Projects/Mynd/src/persistent_storage/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | e_config.h 3 | kvstorage.h 4 | eeprom_config.h 5 | ) 6 | 7 | set(SOURCES 8 | e_config.c 9 | ) 10 | 11 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 12 | 13 | target_include_directories(${projectTarget} PUBLIC 14 | $ 15 | ) 16 | -------------------------------------------------------------------------------- /Projects/Mynd/src/persistent_storage/e_config.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "e_config.h" 3 | #include "eeprom_config.h" 4 | 5 | uint16_t VirtAddVarTab[EEPROM_ELEMENTS] = { 6 | ADDR_SPEAKER_COLOR, 7 | ADDR_LED_BRIGHTNESS, 8 | ADDR_BASS_LEVEL, 9 | ADDR_TREBLE_LEVEL, 10 | ADDR_VOLUME_LEVEL, 11 | ADDR_ECO_MODE, 12 | ADDR_SOUND_ICONS_ACTIVE, 13 | ADDR_CHARGE_TYPE, 14 | 15 | ADDR_BATTERY_SOC_ALGO_STATE, 16 | ADDR_BATTERY_SOC_ACCUMULATED_CHARGE_MSB, 17 | ADDR_BATTERY_SOC_ACCUMULATED_CHARGE_LSB, 18 | ADDR_BATTERY_SOC_CAPACITY_MSB, 19 | ADDR_BATTERY_SOC_CAPACITY_LSB, 20 | }; 21 | -------------------------------------------------------------------------------- /Projects/Mynd/src/persistent_storage/e_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef enum 4 | { 5 | ADDR_SPEAKER_COLOR = 0x00, 6 | ADDR_LED_BRIGHTNESS = 0x01, 7 | ADDR_BASS_LEVEL = 0x02, 8 | ADDR_TREBLE_LEVEL = 0x03, 9 | ADDR_VOLUME_LEVEL = 0x04, 10 | ADDR_ECO_MODE = 0x05, 11 | ADDR_SOUND_ICONS_ACTIVE = 0x06, 12 | ADDR_CHARGE_TYPE = 0x07, 13 | 14 | ADDR_BATTERY_SOC_ALGO_STATE = 0x70, 15 | ADDR_BATTERY_SOC_ACCUMULATED_CHARGE_MSB = 0x71, 16 | ADDR_BATTERY_SOC_ACCUMULATED_CHARGE_LSB = 0x72, 17 | ADDR_BATTERY_SOC_CAPACITY_MSB = 0x73, 18 | ADDR_BATTERY_SOC_CAPACITY_LSB = 0x74, 19 | } virtAddress_t; 20 | -------------------------------------------------------------------------------- /Projects/Mynd/src/persistent_storage/eeprom_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define EEPROM_FLASH_PAGE0 ((uint32_t) ADDR_FLASH_PAGE_62) 4 | #define EEPROM_FLASH_PAGE1 ((uint32_t) ADDR_FLASH_PAGE_63) 5 | 6 | #define EEPROM_ELEMENTS 13 7 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tasks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | task_priorities.h 3 | ) 4 | 5 | target_sources(${projectTarget} PRIVATE ${API_HEADERS}) 6 | 7 | target_include_directories(${projectTarget} PUBLIC 8 | $ 9 | ) 10 | 11 | add_subdirectory(audio) 12 | add_subdirectory(bluetooth) 13 | add_subdirectory(system) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tasks/audio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | task_audio.h 3 | ) 4 | 5 | set(SOURCES 6 | task_audio.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tasks/audio/task_audio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "ux/audio/audio.h" 7 | #include "ux/bluetooth/bluetooth.h" 8 | #include "ux/system/system.h" 9 | 10 | namespace Teufel::Task::Audio 11 | { 12 | 13 | // clang-format off 14 | struct IoExpanderInterrupt {}; 15 | 16 | using AudioMessage = std::variant< 17 | Teufel::Ux::System::SetPowerState, 18 | Teufel::Ux::System::LedBrightness, 19 | Teufel::Ux::Audio::UpdateVolume, 20 | Teufel::Ux::Bluetooth::Status, 21 | IoExpanderInterrupt, 22 | Teufel::Ux::System::FactoryReset, 23 | Teufel::Ux::System::HardReset, 24 | Teufel::Ux::Audio::SoundIconsActive, 25 | Teufel::Ux::Audio::EcoMode, 26 | Teufel::Ux::Audio::BassLevel, 27 | Teufel::Ux::Audio::TrebleLevel, 28 | Teufel::Ux::System::BatteryCriticalTemperature, 29 | Teufel::Ux::System::ChargeType, 30 | Teufel::Ux::System::BatteryLowLevelState 31 | >; 32 | // clang-format on 33 | 34 | int start(); 35 | 36 | int postMessage(Teufel::Ux::System::Task source_task, AudioMessage msg); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tasks/bluetooth/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | task_bluetooth.h 3 | ) 4 | 5 | set(SOURCES 6 | task_bluetooth.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tasks/bluetooth/task_bluetooth.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "ux/audio/audio.h" 7 | #include "ux/bluetooth/bluetooth.h" 8 | #include "ux/system/system.h" 9 | 10 | namespace Teufel::Task::Bluetooth 11 | { 12 | 13 | // clang-format off 14 | struct ActionsReady{}; 15 | 16 | using BluetoothMessage = std::variant< 17 | Teufel::Ux::System::SetPowerState, 18 | Teufel::Ux::System::BatteryLevel, 19 | Teufel::Ux::System::ChargerStatus, 20 | Teufel::Ux::System::ChargeType, 21 | Teufel::Ux::System::Color, 22 | ActionsReady, 23 | Teufel::Ux::Bluetooth::BtWakeUp, 24 | Teufel::Ux::Bluetooth::StartPairing, 25 | #ifdef INCLUDE_TWS_MODE 26 | Teufel::Ux::Bluetooth::TwsPairing, 27 | #endif // INCLUDE_TWS_MODE 28 | Teufel::Ux::Bluetooth::MultichainPairing, 29 | Teufel::Ux::Bluetooth::VolumeChange, 30 | Teufel::Ux::Bluetooth::StopPairingAndMultichain, 31 | Teufel::Ux::Bluetooth::ClearDeviceList, 32 | Teufel::Ux::Bluetooth::PlayPause, 33 | Teufel::Ux::Bluetooth::NextTrack, 34 | Teufel::Ux::Bluetooth::PreviousTrack, 35 | Teufel::Ux::Bluetooth::NotifyAuxConnectionChange, 36 | Teufel::Ux::Bluetooth::NotifyUsbConnectionChange, 37 | Teufel::Ux::Bluetooth::EnterDfuMode, 38 | Teufel::Ux::System::FactoryReset, 39 | Teufel::Ux::Audio::RequestSoundIcon, 40 | Teufel::Ux::Audio::StopPlayingSoundIcon, 41 | Teufel::Ux::Audio::EcoMode 42 | #ifdef INCLUDE_PRODUCTION_TESTS 43 | , 44 | Teufel::Ux::Bluetooth::FWVersionProdTest, 45 | Teufel::Ux::Bluetooth::DeviceNameProdTest, 46 | Teufel::Ux::Bluetooth::BtMacAddressProdTest, 47 | Teufel::Ux::Bluetooth::BleMacAddressProdTest, 48 | Teufel::Ux::Bluetooth::BtRssiProdTest, 49 | Teufel::Ux::Bluetooth::SetVolumeProdTest, 50 | Teufel::Ux::Bluetooth::AudioBypassProdTest 51 | #endif // INCLUDE_PRODUCTION_TESTS 52 | >; 53 | // clang-format on 54 | 55 | int start(); 56 | 57 | int postMessage(Teufel::Ux::System::Task source_task, BluetoothMessage msg); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tasks/system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | task_system.h 3 | ) 4 | 5 | set(SOURCES 6 | task_system.cpp 7 | ) 8 | 9 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 10 | 11 | target_include_directories(${projectTarget} PUBLIC 12 | $ 13 | ) 14 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tasks/system/task_system.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "ux/system/system.h" 7 | #include "ux/audio/audio.h" 8 | #include "ux/bluetooth/bluetooth.h" 9 | #include "ux/input/input.h" 10 | 11 | #include "task_audio.h" 12 | 13 | namespace Teufel::Task::System 14 | { 15 | 16 | // clang-format off 17 | using SystemMessage = std::variant< 18 | Teufel::Ux::System::SetPowerState, 19 | Teufel::Ux::System::UserActivity, 20 | Teufel::Ux::System::OffTimer, 21 | Teufel::Ux::System::OffTimerEnabled, 22 | Teufel::Ux::System::FactoryResetRequest 23 | >; 24 | // clang-format on 25 | 26 | Teufel::Ux::System::PowerState getState(); 27 | 28 | int start(); 29 | int postMessage(Teufel::Ux::System::Task source_task, SystemMessage msg); 30 | } 31 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tasks/task_priorities.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "FreeRTOS.h" 4 | #include "task.h" 5 | 6 | #define TASK_AUDIO_PRIORITY (tskIDLE_PRIORITY + 1) 7 | #define TASK_BLUETOOTH_PRIORITY (tskIDLE_PRIORITY + 2) 8 | #define TASK_SYSTEM_PRIORITY (tskIDLE_PRIORITY + 1) 9 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tshell/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(API_HEADERS 2 | tshell.h 3 | tshell_args_parser.h 4 | tshell_printf.h 5 | ) 6 | 7 | set(SOURCES 8 | tshell.c 9 | tshell_args_parser.c 10 | tshell_printf.c 11 | ) 12 | 13 | target_sources(${projectTarget} PRIVATE ${API_HEADERS} ${SOURCES}) 14 | 15 | target_include_directories(${projectTarget} PUBLIC 16 | $ 17 | ) 18 | -------------------------------------------------------------------------------- /Projects/Mynd/src/tshell/tshell_args_parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__cplusplus) 4 | extern "C" 5 | { 6 | #endif /* __cplusplus */ 7 | 8 | int tshell_parse_args_uint8(size_t argc, char **argv, uint8_t min, uint8_t max, uint8_t *result); 9 | int tshell_parse_args_int8(size_t argc, char **argv, int8_t min, int8_t max, int8_t *result); 10 | int tshell_parse_args_uint32(size_t argc, char **argv, uint32_t min, uint32_t max, uint32_t *result); 11 | int tshell_parse_args_int32(size_t argc, char **argv, int32_t min, int32_t max, int32_t *result); 12 | 13 | #if defined(__cplusplus) 14 | } 15 | #endif /* __cplusplus */ 16 | -------------------------------------------------------------------------------- /Projects/Mynd/src/ux/audio/audio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "actionslink.h" 5 | 6 | namespace Teufel::Ux::Audio 7 | { 8 | // clang-format off 9 | struct EcoMode { bool value; }; 10 | struct UpdateVolume { uint8_t value; }; 11 | struct VolumeLevel { uint8_t value; }; 12 | struct RequestSoundIcon { 13 | actionslink_sound_icon_t sound_icon; 14 | actionslink_sound_icon_playback_mode_t playback_mode = ACTIONSLINK_SOUND_ICON_PLAYBACK_MODE_PLAY_IMMEDIATELY; 15 | bool loop_forever = false; 16 | }; 17 | struct StopPlayingSoundIcon { actionslink_sound_icon_t sound_icon; }; 18 | struct SoundIconsActive { bool value; }; 19 | struct BassLevel { int8_t value; }; 20 | struct TrebleLevel { int8_t value; }; 21 | 22 | // clang-format on 23 | 24 | // Public API 25 | EcoMode getProperty(EcoMode *); 26 | VolumeLevel getProperty(VolumeLevel *); 27 | SoundIconsActive getProperty(SoundIconsActive *); 28 | BassLevel getProperty(BassLevel *); 29 | TrebleLevel getProperty(TrebleLevel *); 30 | } 31 | -------------------------------------------------------------------------------- /Projects/Mynd/tests_power_states.txt: -------------------------------------------------------------------------------- 1 | 1. 2 | 3 | 4 | 3. Turn on DUT while it's in Off mode and charger is inactive 5 | Preconditions: 6 | - USB-C cable is connected to the DUT 7 | - DUT is in Off mode after standby 8 | 9 | 10 | 11 | 2. Turn on DUT with USB-C cable (DUT fully charged) 12 | - DUT is in Off mode, USB-C cable is not connected 13 | - Plug USB-C cable into DUT 14 | - DUT PC < 0.5W (Voltage 5V) 15 | - LED is off 16 | 17 | - Turn on with power button 18 | ... doesn't matter actually what is the state of charger here 19 | 20 | wait for standby timer: 21 | - PC !!!!!! wrong!!!! 22 | 23 | 24 | 25 | 3. Standby timer while DUT is fully charged 26 | - DUT is fully charged and in active state 27 | - Wait for stadnby timer 28 | - DUT goes to standby: 29 | - LED is off 30 | - PC < 0.5W 31 | 32 | 4. Standby timer while DUT charging 33 | 4.1 DUT goes to standby: 34 | - LED keeps running 35 | - DUT is in Off power state 36 | 37 | When battery full: 38 | - LED goes off 39 | - PC < 0.5W 40 | 41 | Turning on with power button, and wait for standby timer: 42 | (This part duplicates the previous one, but it's good to check it as well) 43 | - LED should be off 44 | - PC < 0.5W 45 | 46 | 47 | 5. Standby timer while DUT is not charging 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/board/io_expander/board_link_io_expander.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #if defined(__cplusplus) 7 | extern "C" 8 | { 9 | #endif 10 | 11 | /** 12 | * @brief Interrupt handler for interrupts signalled with the INT line of the 13 | * IO expander. 14 | */ 15 | typedef void (*board_link_io_expander_interrupt_handler_t)(void); 16 | 17 | /** 18 | * @brief Initializes the IO expander. 19 | */ 20 | void board_link_io_expander_init(void); 21 | 22 | /** 23 | * @brief Asserts/deasserts the reset line of the IO expander. 24 | * 25 | * @param[in] assert true to assert, false to deassert 26 | */ 27 | void board_link_io_expander_reset(bool assert); 28 | 29 | /** 30 | * @brief Sets up the IO expander for normal operation. 31 | * 32 | * @return 0 if successful, -1 otherwise 33 | */ 34 | int board_link_io_expander_setup_for_normal_operation(void); 35 | 36 | /** 37 | * @brief Sets the PWM of all channels of the status LED. 38 | * 39 | * @param[in] r pwm value for the R channel 40 | * @param[in] g pwm value for the G channel 41 | * @param[in] b pwm value for the B channel 42 | * 43 | * @return 0 if successful, -1 otherwise 44 | */ 45 | int board_link_io_expander_set_status_led(uint8_t r, uint8_t g, uint8_t b); 46 | 47 | /** 48 | * @brief Sets the PWM of all channels of the source LED. 49 | * 50 | * @param[in] r pwm value for the R channel 51 | * @param[in] g pwm value for the G channel 52 | * @param[in] b pwm value for the B channel 53 | * 54 | * @return 0 if successful, -1 otherwise 55 | */ 56 | int board_link_io_expander_set_source_led(uint8_t r, uint8_t g, uint8_t b); 57 | 58 | #if defined(__cplusplus) 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/board/power_supply/board_link_power_supply.c: -------------------------------------------------------------------------------- 1 | #include "board_link_power_supply.h" 2 | #include "board_hw.h" 3 | #include "logger.h" 4 | 5 | void board_link_power_supply_init(void) 6 | { 7 | GPIO_InitTypeDef GPIO_InitStruct; 8 | 9 | // Configure power button pin 10 | POWER_BUTTON_GPIO_CLK_ENABLE(); 11 | GPIO_InitStruct.Pin = POWER_BUTTON_GPIO_PIN; 12 | GPIO_InitStruct.Mode = POWER_BUTTON_GPIO_MODE; 13 | GPIO_InitStruct.Pull = POWER_BUTTON_GPIO_PULL; 14 | GPIO_InitStruct.Speed = POWER_BUTTON_GPIO_SPEED; 15 | HAL_GPIO_Init(POWER_BUTTON_GPIO_PORT, &GPIO_InitStruct); 16 | 17 | // Configure power hold pin 18 | POWER_HOLD_GPIO_CLK_ENABLE(); 19 | board_link_power_supply_hold_on(true); 20 | GPIO_InitStruct.Pin = POWER_HOLD_GPIO_PIN; 21 | GPIO_InitStruct.Mode = POWER_HOLD_GPIO_MODE; 22 | GPIO_InitStruct.Pull = POWER_HOLD_GPIO_PULL; 23 | GPIO_InitStruct.Speed = POWER_HOLD_GPIO_SPEED; 24 | HAL_GPIO_Init(POWER_HOLD_GPIO_PORT, &GPIO_InitStruct); 25 | } 26 | 27 | bool board_link_power_supply_button_is_pressed(void) 28 | { 29 | return HAL_GPIO_ReadPin(POWER_BUTTON_GPIO_PORT, POWER_BUTTON_GPIO_PIN) == GPIO_PIN_SET; 30 | } 31 | 32 | void board_link_power_supply_hold_on(bool hold) 33 | { 34 | HAL_GPIO_WritePin(POWER_HOLD_GPIO_PORT, POWER_HOLD_GPIO_PIN, (hold) ? GPIO_PIN_SET : GPIO_PIN_RESET); 35 | log_info("Power supply hold %s", hold ? "active" : "released"); 36 | } 37 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/board/power_supply/board_link_power_supply.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | void board_link_power_supply_init(void); 11 | 12 | bool board_link_power_supply_button_is_pressed(void); 13 | 14 | void board_link_power_supply_hold_on(bool hold); 15 | 16 | #if defined(__cplusplus) 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/board/usb_switch/board_link_usb_switch.c: -------------------------------------------------------------------------------- 1 | #define LOG_LEVEL LOG_LEVEL_INFO 2 | #include "board_link_usb_switch.h" 3 | #include "board_hw.h" 4 | #include "logger.h" 5 | 6 | void board_link_usb_switch_init(void) 7 | { 8 | GPIO_InitTypeDef GPIO_InitStruct; 9 | 10 | USB_SELECT0_GPIO_CLK_ENABLE(); 11 | USB_SELECT1_GPIO_CLK_ENABLE(); 12 | 13 | GPIO_InitStruct.Pin = USB_SELECT0_GPIO_PIN; 14 | GPIO_InitStruct.Mode = USB_SELECT0_GPIO_MODE; 15 | GPIO_InitStruct.Pull = USB_SELECT0_GPIO_PULL; 16 | GPIO_InitStruct.Speed = USB_SELECT0_GPIO_SPEED; 17 | HAL_GPIO_Init(USB_SELECT0_GPIO_PORT, &GPIO_InitStruct); 18 | 19 | GPIO_InitStruct.Pin = USB_SELECT1_GPIO_PIN; 20 | GPIO_InitStruct.Mode = USB_SELECT1_GPIO_MODE; 21 | GPIO_InitStruct.Pull = USB_SELECT1_GPIO_PULL; 22 | GPIO_InitStruct.Speed = USB_SELECT1_GPIO_SPEED; 23 | HAL_GPIO_Init(USB_SELECT1_GPIO_PORT, &GPIO_InitStruct); 24 | 25 | log_debug("USB switch initialized"); 26 | } 27 | 28 | void board_link_usb_switch_to_mcu(void) 29 | { 30 | HAL_GPIO_WritePin(USB_SELECT0_GPIO_PORT, USB_SELECT0_GPIO_PIN, GPIO_PIN_SET); 31 | HAL_GPIO_WritePin(USB_SELECT1_GPIO_PORT, USB_SELECT1_GPIO_PIN, GPIO_PIN_SET); 32 | log_info("USB switched to MCU"); 33 | } 34 | 35 | void board_link_usb_switch_to_bluetooth(void) 36 | { 37 | HAL_GPIO_WritePin(USB_SELECT0_GPIO_PORT, USB_SELECT0_GPIO_PIN, GPIO_PIN_RESET); 38 | HAL_GPIO_WritePin(USB_SELECT1_GPIO_PORT, USB_SELECT1_GPIO_PIN, GPIO_PIN_SET); 39 | log_info("USB switched to Bluetooth module"); 40 | } 41 | 42 | void board_link_usb_switch_to_usb_pd(void) 43 | { 44 | HAL_GPIO_WritePin(USB_SELECT0_GPIO_PORT, USB_SELECT0_GPIO_PIN, GPIO_PIN_RESET); 45 | HAL_GPIO_WritePin(USB_SELECT1_GPIO_PORT, USB_SELECT1_GPIO_PIN, GPIO_PIN_RESET); 46 | log_info("USB switched to Bluetooth module"); 47 | } 48 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/board/usb_switch/board_link_usb_switch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__cplusplus) 4 | extern "C" 5 | { 6 | #endif 7 | 8 | /** 9 | * @brief Initializes the hardware needed to interface the USB switch. 10 | * @note The USB is switched to the MCU after initialization. 11 | */ 12 | void board_link_usb_switch_init(void); 13 | 14 | /** 15 | * @brief Switches USB to the MCU. 16 | */ 17 | void board_link_usb_switch_to_mcu(void); 18 | 19 | /** 20 | * @brief Switches USB to the Bluetooth module. 21 | */ 22 | void board_link_usb_switch_to_bluetooth(void); 23 | 24 | /** 25 | * @brief Switches USB to the USB PD controller IC. 26 | */ 27 | void board_link_usb_switch_to_usb_pd(void); 28 | 29 | #if defined(__cplusplus) 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/bsp/board.c: -------------------------------------------------------------------------------- 1 | #include "board.h" 2 | #include "stm32f0xx_hal.h" 3 | 4 | extern I2C_HandleTypeDef I2C2_Handle; 5 | 6 | void board_init(void) 7 | { 8 | /* Enable all GPIO clocks */ 9 | __HAL_RCC_GPIOA_CLK_ENABLE(); 10 | __HAL_RCC_GPIOB_CLK_ENABLE(); 11 | __HAL_RCC_GPIOC_CLK_ENABLE(); 12 | __HAL_RCC_GPIOD_CLK_ENABLE(); 13 | __HAL_RCC_GPIOF_CLK_ENABLE(); 14 | } 15 | 16 | void HAL_MspInit(void) 17 | { 18 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 19 | __HAL_RCC_PWR_CLK_ENABLE(); 20 | } 21 | 22 | uint32_t get_systick(void) 23 | { 24 | return HAL_GetTick(); 25 | } 26 | 27 | uint32_t board_get_ms_since(uint32_t tick_ms) 28 | { 29 | uint32_t current_tick_ms = get_systick(); 30 | 31 | // Handle overflow 32 | if (current_tick_ms < tick_ms) 33 | { 34 | // Note: if last tick is UINT32_MAX and current tick is 0, this function should return 1 35 | return (UINT32_MAX - tick_ms) + current_tick_ms + 1; 36 | } 37 | else 38 | { 39 | return current_tick_ms - tick_ms; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/bsp/board.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "stm32f0xx_hal.h" 6 | 7 | #if defined(__cplusplus) 8 | extern "C" 9 | { 10 | #endif 11 | 12 | void board_init(void); 13 | uint32_t get_systick(void); 14 | uint32_t board_get_ms_since(uint32_t tick_ms); 15 | 16 | #if defined(__cplusplus) 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/bsp/debug_uart/bsp_debug_uart.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "bsp_debug_uart.h" 3 | #include "board_hw.h" 4 | #include "stm32f0xx_hal.h" 5 | #include "stm32f0xx_ll_usart.h" 6 | #include "logger.h" 7 | 8 | UART_HandleTypeDef UART2_Handle; 9 | 10 | void bsp_debug_uart_init(void) 11 | { 12 | UART2_Handle.Instance = DEBUG_UART; 13 | UART2_Handle.Init.BaudRate = DEBUG_UART_BAUDRATE; 14 | UART2_Handle.Init.WordLength = UART_WORDLENGTH_8B; 15 | UART2_Handle.Init.StopBits = UART_STOPBITS_1; 16 | UART2_Handle.Init.Parity = UART_PARITY_NONE; 17 | UART2_Handle.Init.Mode = UART_MODE_TX_RX; 18 | UART2_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; 19 | UART2_Handle.Init.OverSampling = UART_OVERSAMPLING_16; 20 | UART2_Handle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 21 | UART2_Handle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 22 | 23 | HAL_UART_Init(&UART2_Handle); 24 | } 25 | 26 | void bsp_debug_uart_msp_init(void) 27 | { 28 | GPIO_InitTypeDef GPIO_InitStruct; 29 | 30 | /* Gpio clock enable */ 31 | DEBUG_UART_TX_GPIO_CLK_ENABLE(); 32 | DEBUG_UART_RX_GPIO_CLK_ENABLE(); 33 | 34 | /* USART RX/TX GPIO Configuration */ 35 | GPIO_InitStruct.Pin = DEBUG_UART_TX_GPIO_PIN; 36 | GPIO_InitStruct.Mode = DEBUG_UART_TX_GPIO_MODE; 37 | GPIO_InitStruct.Pull = DEBUG_UART_TX_GPIO_PULL; 38 | GPIO_InitStruct.Speed = DEBUG_UART_TX_GPIO_SPEED; 39 | GPIO_InitStruct.Alternate = DEBUG_UART_TX_GPIO_AF; 40 | HAL_GPIO_Init(DEBUG_UART_TX_GPIO_PORT, &GPIO_InitStruct); 41 | 42 | GPIO_InitStruct.Pin = DEBUG_UART_RX_GPIO_PIN; 43 | GPIO_InitStruct.Mode = DEBUG_UART_RX_GPIO_MODE; 44 | GPIO_InitStruct.Pull = DEBUG_UART_RX_GPIO_PULL; 45 | GPIO_InitStruct.Speed = DEBUG_UART_RX_GPIO_SPEED; 46 | GPIO_InitStruct.Alternate = DEBUG_UART_RX_GPIO_AF; 47 | HAL_GPIO_Init(DEBUG_UART_RX_GPIO_PORT, &GPIO_InitStruct); 48 | 49 | HAL_NVIC_SetPriority(DEBUG_UART_IRQn, 1, 0); 50 | HAL_NVIC_EnableIRQ(DEBUG_UART_IRQn); 51 | 52 | DEBUG_UART_CLK_ENABLE(); 53 | } 54 | 55 | int bsp_debug_uart_tx(const uint8_t *p_data, size_t length) 56 | { 57 | HAL_UART_Transmit(&UART2_Handle, (uint8_t *) p_data, length, HAL_MAX_DELAY); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/bsp/debug_uart/bsp_debug_uart.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #if defined(__cplusplus) 7 | extern "C" 8 | { 9 | #endif 10 | 11 | /** 12 | * @brief Initializes the UART hardware needed to interface with the debug serial port. 13 | */ 14 | void bsp_debug_uart_init(void); 15 | 16 | void bsp_debug_uart_msp_init(void); 17 | 18 | /** 19 | * @brief Sends data over UART. 20 | * @note This function returns immediately. The TX done callback provided 21 | * in `board_hal_bluetooth_uart_init()` will be called when the transfer completes. 22 | * 23 | * @param[in] p_data pointer to data to send 24 | * @param[in] length length of data to send 25 | * 26 | * @return 0 if successful, -1 otherwise 27 | */ 28 | int bsp_debug_uart_tx(const uint8_t *p_data, size_t length); 29 | 30 | /** 31 | * @brief Reads data from the UART RX buffer. 32 | * 33 | * @details This function checks if the requested length has already been received and 34 | * returns it if that's the case. If the expected length is not in the buffer yet, 35 | * the function will return an error. 36 | * 37 | * @param[out] p_data pointer to where the read data will be written 38 | * @param[in] length number of bytes to read 39 | * 40 | * @return 0 if successful, -1 otherwise 41 | */ 42 | int bsp_debug_uart_rx(uint8_t *p_data, size_t length); 43 | 44 | #if defined(__cplusplus) 45 | } 46 | #endif 47 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/bsp/shared_i2c/bsp_shared_i2c.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | /** 11 | * @brief Initializes the I2C hardware needed to interface with the shared I2C bus. 12 | */ 13 | void bsp_shared_i2c_init(void); 14 | 15 | void bsp_shared_i2c_deinit(void); 16 | 17 | void bsp_shared_i2c_msp_init(void); 18 | 19 | void bsp_shared_i2c_msp_deinit(void); 20 | 21 | /** 22 | * @brief Writes to the shared I2C bus. 23 | * 24 | * @param[in] i2c_address I2C device address 25 | * @param[in] register_address register address to write to 26 | * @param[in] p_buffer pointer to data to write 27 | * @param[in] length number of bytes to write 28 | * 29 | * @return 0 if successful, -1 otherwise 30 | */ 31 | int bsp_shared_i2c_write(uint8_t i2c_address, uint8_t register_address, const uint8_t *p_buffer, uint32_t length); 32 | 33 | /** 34 | * @brief Reads from the shared I2C bus. 35 | * 36 | * @param[in] i2c_address I2C device address 37 | * @param[in] register_address register address to read from 38 | * @param[out] p_buffer pointer to where the read data will be written to 39 | * @param[in] length number of bytes to read 40 | * 41 | * @return 0 if successful, -1 otherwise 42 | */ 43 | int bsp_shared_i2c_read(uint8_t i2c_address, uint8_t register_address, uint8_t *p_buffer, uint32_t length); 44 | 45 | #if defined(__cplusplus) 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/changelog.md: -------------------------------------------------------------------------------- 1 | # MYND bootloader changelog 2 | 3 | ## [Unreleased] 4 | 5 | ## [2.1.0] - 2024-07-24 6 | ### Changed 7 | - Virtual EEPROM flash size 8 | 9 | ### Added 10 | - Write magic number on UPDATE_STATE_COMPLETE event to signal application to power on after a successful update 11 | 12 | ## [2.0.0] - 2024-06-14 13 | ### Changed 14 | - Flash memory layout 15 | 16 | ## [1.0.0] - 2024-05-15 17 | ### Changed 18 | - Product name (MYND) 19 | - USB pid to the value 0x003F 20 | - Flash memory layout 21 | 22 | ## [0.2.0] - 2024-03-06 23 | ### Added 24 | - Support for HW with extra USB multiplexer for USB PD controller IC 25 | 26 | ## [0.1.0] - 2024-02-20 27 | ### Added 28 | - MCU FW update capability via USB 29 | - System reset when power button is pressed (only if update is not in progress) 30 | - Simple LED indications 31 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/dfu_mcu.c: -------------------------------------------------------------------------------- 1 | #include "stm32f0xx_hal.h" 2 | #include "bsp/board_hw.h" 3 | #include "logger.h" 4 | #include "dfu_mcu.h" 5 | #include 6 | 7 | static struct 8 | { 9 | bool flash_was_erased; 10 | } s_dfu_mcu; 11 | 12 | int dfu_mcu_init(void) 13 | { 14 | log_dbg("%s", __func__); 15 | s_dfu_mcu.flash_was_erased = false; 16 | return 0; 17 | } 18 | 19 | int dfu_mcu_prepare(uint32_t fw_size, uint32_t crc32) 20 | { 21 | // Arguments are irrelevant, we are erasing the entire application area 22 | (void) fw_size; 23 | (void) crc32; 24 | 25 | log_dbg("%s", __func__); 26 | 27 | FLASH_EraseInitTypeDef EraseInitStruct; 28 | uint32_t PageError; 29 | EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; 30 | EraseInitStruct.PageAddress = APPLICATION_FLASH_ADDRESS; 31 | 32 | // TODO: Adjust this to not erase the pages reserved for persisted settings storage 33 | EraseInitStruct.NbPages = APPLICATION_FLASH_SIZE / FLASH_PAGE_SIZE; 34 | 35 | log_info("Erasing application area from 0x%08x pages %d", EraseInitStruct.PageAddress, EraseInitStruct.NbPages); 36 | 37 | HAL_FLASH_Unlock(); 38 | if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK) 39 | { 40 | log_err("Error erasing flash"); 41 | return -1; 42 | } 43 | 44 | log_info("Flash erased"); 45 | HAL_FLASH_Lock(); 46 | 47 | s_dfu_mcu.flash_was_erased = true; 48 | return 0; 49 | } 50 | 51 | int dfu_mcu_write(const uint8_t *buf, uint32_t len, uint32_t offset) 52 | { 53 | if (!s_dfu_mcu.flash_was_erased) 54 | { 55 | // Erase flash before writing 56 | dfu_mcu_prepare(0, 0); 57 | } 58 | 59 | uint32_t *data = ((uint32_t *) buf); 60 | uint32_t addr = APPLICATION_FLASH_ADDRESS + offset; 61 | 62 | log_trace("Write %d bytes @ 0x%08X (offset: 0x%x)", len, addr, offset); 63 | 64 | HAL_FLASH_Unlock(); 65 | for (uint32_t i = 0; i < len; i += 4, addr += 4, data++) 66 | { 67 | if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, addr, *data) != HAL_OK) 68 | { 69 | log_err("Error writing to flash(addr: 0x%08x)", addr); 70 | 71 | HAL_FLASH_Lock(); 72 | return -1; 73 | } 74 | if (*(uint32_t *) (addr) != *data) 75 | { 76 | log_err("Error verifying flash(addr: 0x%08x)", addr); 77 | } 78 | } 79 | HAL_FLASH_Lock(); 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/dfu_mcu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | int dfu_mcu_init(void); 6 | int dfu_mcu_prepare(uint32_t fw_size, uint32_t crc32); 7 | int dfu_mcu_write(const uint8_t *data, uint32_t len, uint32_t offset); 8 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/drivers/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | .idea 55 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | .idea 55 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/README.md: -------------------------------------------------------------------------------- 1 | # Teufel libraries 2 | 3 | This repository contains a collection of libraries used in several Teufel projects. 4 | 5 | ## Add to an existing project 6 | 7 | You can add this repository as a submodule with the following command: 8 | 9 | ``` 10 | git submodule add ssh://git@sources.teufelhome.com/tf/teufel-libs.git 11 | ``` 12 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/app_assert/app_assert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "app_assert.h" 6 | 7 | void app_assertion_handler(const char *file, int line_number) 8 | { 9 | printf("Assertion failed in %s:%d\r\n", file, line_number); 10 | __disable_irq(); 11 | __BKPT(0); 12 | for (;;) 13 | { 14 | } 15 | } 16 | 17 | void __assert_func(const char *file, int line, const char *func, const char *failedExpr) 18 | { 19 | printf("Assertion failed in %s:%d\r\n", file, line); 20 | printf("%s in %s()\r\n", failedExpr, func); 21 | __disable_irq(); 22 | __BKPT(0); 23 | for (;;) 24 | { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/app_assert/app_assert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | 8 | void app_assertion_handler(const char * file, int line_number); 9 | 10 | #if defined(APP_ASSERT_NDEBUG) 11 | 12 | #define APP_ASSERT(...) 13 | 14 | #else 15 | 16 | #define APP_ASSERT(condition, ...) \ 17 | do { \ 18 | if ((condition) == 0) { \ 19 | app_assertion_handler(__FILE_NAME__, __LINE__); \ 20 | } \ 21 | } while (0) 22 | 23 | #endif // defined(APP_ASSERT_NDEBUG) 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/formats/num1/logger_format.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/logger_defs.h" 4 | 5 | // clang-format off 6 | 7 | // Set this to 1 to produce colored output 8 | #define LOGGER_USE_COLOR 1 9 | 10 | // Set this to 1 to apply the color to the entire log line, 11 | // otherwise only the log level will be colored 12 | #define LOGGER_USE_FULL_LINE_COLOR 0 13 | 14 | // Set this to 1 to prefix the output with a "[LEVEL]" string 15 | #define LOGGER_PRINT_LOG_LEVEL 1 16 | 17 | // Set this to 1 to timestamp the logs 18 | #define LOGGER_PRINT_TIMESTAMP 1 19 | 20 | // Set this to 1 to print the timestamp before the log level 21 | #define LOGGER_PRINT_TIMESTAMP_BEFORE_LOG_LEVEL 1 22 | 23 | // Set this to 1 to add the "module:line_number" to the logs 24 | // Note that if this option is enabled 25 | // LOG_MODULE_NAME must be defined in every file where the logger is used 26 | #define LOGGER_PRINT_LOG_LOCATION 1 27 | 28 | // Set this to terminate each log with a new line string 29 | #define LOGGER_PRINT_NEW_LINE 1 30 | 31 | // This defines the string to be appended to the logs 32 | // when the LOGGER_PRINT_NEW_LINE option is set to 1 33 | #define LOGGER_NEW_LINE_STRING "\r\n" 34 | 35 | // This defines the width of the log location string that is added to the logs 36 | // when the LOGGER_PRINT_LOG_LOCATION option is set to 1. 37 | // It is useful to align the actual contents of the logs to the right of the "log header" 38 | // Increase it if you have long module names or decrease it if your module names are short 39 | #define LOGGER_LOG_LOCATION_WIDTH 30 40 | 41 | // clang-format on 42 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/formats/num2/logger_format.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/logger_defs.h" 4 | 5 | // clang-format off 6 | 7 | // Set this to 1 to produce colored output 8 | #define LOGGER_USE_COLOR 1 9 | 10 | // Set this to 1 to apply the color to the entire log line, 11 | // otherwise only the log level will be colored 12 | #define LOGGER_USE_FULL_LINE_COLOR 1 13 | 14 | // Set this to 1 to prefix the output with a "[LEVEL]" string 15 | #define LOGGER_PRINT_LOG_LEVEL 1 16 | 17 | // Set this to 1 to timestamp the logs 18 | #define LOGGER_PRINT_TIMESTAMP 1 19 | 20 | // Set this to 1 to print the timestamp before the log level 21 | #define LOGGER_PRINT_TIMESTAMP_BEFORE_LOG_LEVEL 0 22 | 23 | // Set this to 1 to add the "module:line_number" to the logs 24 | // Note that if this option is enabled 25 | // LOG_MODULE_NAME must be defined in every file where the logger is used 26 | #define LOGGER_PRINT_LOG_LOCATION 1 27 | 28 | // Set this to terminate each log with a new line string 29 | #define LOGGER_PRINT_NEW_LINE 1 30 | 31 | // This defines the string to be appended to the logs 32 | // when the LOGGER_PRINT_NEW_LINE option is set to 1 33 | #define LOGGER_NEW_LINE_STRING "\r\n" 34 | 35 | // This defines the width of the log location string that is added to the logs 36 | // when the LOGGER_PRINT_LOG_LOCATION option is set to 1. 37 | // It is useful to align the actual contents of the logs to the right of the "log header" 38 | // Increase it if you have long module names or decrease it if your module names are short 39 | #define LOGGER_LOG_LOCATION_WIDTH 30 40 | 41 | // clang-format on 42 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/formats/num3/logger_format.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/logger_defs.h" 4 | 5 | // clang-format off 6 | 7 | // Set this to 1 to produce colored output 8 | #define LOGGER_USE_COLOR 1 9 | 10 | // Set this to 1 to apply the color to the entire log line, 11 | // otherwise only the log level will be colored 12 | #define LOGGER_USE_FULL_LINE_COLOR 0 13 | 14 | // Set this to 1 to prefix the output with a "[LEVEL]" string 15 | #define LOGGER_PRINT_LOG_LEVEL 1 16 | 17 | // Set this to 1 to timestamp the logs 18 | #define LOGGER_PRINT_TIMESTAMP 1 19 | 20 | // Set this to 1 to print the timestamp before the log level 21 | #define LOGGER_PRINT_TIMESTAMP_BEFORE_LOG_LEVEL 1 22 | 23 | // Set this to 1 to add the "module:line_number" to the logs 24 | // Note that if this option is enabled 25 | // LOG_MODULE_NAME must be defined in every file where the logger is used 26 | #define LOGGER_PRINT_LOG_LOCATION 1 27 | 28 | // Set this to terminate each log with a new line string 29 | #define LOGGER_PRINT_NEW_LINE 1 30 | 31 | // This defines the string to be appended to the logs 32 | // when the LOGGER_PRINT_NEW_LINE option is set to 1 33 | #define LOGGER_NEW_LINE_STRING "\r\n" 34 | 35 | // This defines the width of the log location string that is added to the logs 36 | // when the LOGGER_PRINT_LOG_LOCATION option is set to 1. 37 | // It is useful to align the actual contents of the logs to the right of the "log header" 38 | // Increase it if you have long module names or decrease it if your module names are short 39 | #define LOGGER_LOG_LOCATION_WIDTH 35 40 | 41 | // clang-format on 42 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/implementations/logger_weak_implementation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __attribute__((weak)) void logger_flush(void) {} 4 | 5 | __attribute__((weak)) uint32_t logger_get_timestamp() 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/include/logger_defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define LOG_COLOR_DEFAULT "\x1B[0m" 4 | #define LOG_COLOR_BLACK "\x1B[2;30m" 5 | #define LOG_COLOR_RED "\x1B[2;31m" 6 | #define LOG_COLOR_GREEN "\x1B[2;32m" 7 | #define LOG_COLOR_YELLOW "\x1B[2;33m" 8 | #define LOG_COLOR_BLUE "\x1B[2;34m" 9 | #define LOG_COLOR_MAGENTA "\x1B[2;35m" 10 | #define LOG_COLOR_CYAN "\x1B[2;36m" 11 | #define LOG_COLOR_WHITE "\x1B[2;37m" 12 | #define LOG_COLOR_BRIGHT_BLACK "\x1B[1;30m" 13 | #define LOG_COLOR_BRIGHT_RED "\x1B[1;31m" 14 | #define LOG_COLOR_BRIGHT_GREEN "\x1B[1;32m" 15 | #define LOG_COLOR_BRIGHT_YELLOW "\x1B[1;33m" 16 | #define LOG_COLOR_BRIGHT_BLUE "\x1B[1;34m" 17 | #define LOG_COLOR_BRIGHT_MAGENTA "\x1B[1;35m" 18 | #define LOG_COLOR_BRIGHT_CYAN "\x1B[1;36m" 19 | #define LOG_COLOR_BRIGHT_WHITE "\x1B[1;37m" 20 | #define LOG_COLOR_GREY "\x1B[1;90m" 21 | 22 | // --------------------------------------------------------------------------------- 23 | // Logger output configuration 24 | // --------------------------------------------------------------------------------- 25 | 26 | #define LOGGER_OUTPUT_RAW 0 // Logs using printf without any formatting 27 | #define LOGGER_OUTPUT_FORMATTED 1 // Generic output, which invokes printf call, with defined formatting 28 | 29 | typedef enum 30 | { 31 | LOG_LEVEL_OFF, 32 | LOG_LEVEL_FATAL, 33 | LOG_LEVEL_ERROR, 34 | LOG_LEVEL_WARNING, 35 | LOG_LEVEL_HIGHLIGHT, 36 | LOG_LEVEL_INFO, 37 | LOG_LEVEL_DEBUG, 38 | LOG_LEVEL_TRACE, 39 | } logger_log_level_t; 40 | 41 | typedef enum 42 | { 43 | LOG_OUTPUT_OPTION_NORMAL, 44 | LOG_OUTPUT_OPTION_RAW, 45 | } logger_log_output_option_t; 46 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/include/logger_impl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #if defined(__cplusplus) 5 | extern "C" 6 | { 7 | #endif 8 | 9 | /** 10 | * @brief Initializes the logger. 11 | */ 12 | #if defined(FreeRTOS) && defined(LOGGER_USE_EXTERNAL_THREAD) 13 | 14 | #include "FreeRTOS.h" 15 | #include "semphr.h" 16 | #include "stream_buffer.h" 17 | 18 | int logger_init(StreamBufferHandle_t sbuf); 19 | #else 20 | void logger_init(void); 21 | #endif 22 | 23 | /** 24 | * @brief Flushes the logger. 25 | */ 26 | void logger_flush(void); 27 | 28 | /** 29 | * @brief Gets a system timestamp. 30 | * @return timestamp 31 | */ 32 | uint32_t logger_get_timestamp(); 33 | 34 | #if defined(__cplusplus) 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/include/logger_putchar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __GNUC__ 4 | 5 | #define PUTCHAR(c) __io_putchar(c) 6 | #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) 7 | 8 | PUTCHAR_PROTOTYPE; 9 | 10 | #else 11 | 12 | #define PUTCHAR(c) fputc(c, __stdout) 13 | #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) 14 | 15 | PUTCHAR_PROTOTYPE; 16 | 17 | #endif // __GNUC__ 18 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/logger_syscalls.c: -------------------------------------------------------------------------------- 1 | #include "logger_config.h" 2 | #include // required for _write_r 3 | 4 | #if defined(SEGGER_RTT) 5 | #include "SEGGER_RTT.h" 6 | #else 7 | #include "logger_putchar.h" 8 | #endif 9 | 10 | // If necessary define the _reent struct 11 | // to match the one passed by the used standard library. 12 | struct _reent; 13 | 14 | _ssize_t _write(int file, const void *ptr, size_t len); 15 | _ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len); 16 | 17 | _ssize_t _write(int file, const void *ptr, size_t len) 18 | { 19 | (void) file; // Not used, avoid warning 20 | #if defined(SEGGER_RTT) 21 | SEGGER_RTT_Write(0, ptr, len); 22 | #else 23 | const char *p_data = (const char *) ptr; 24 | for (int i = 0; i < len; i++) 25 | { 26 | PUTCHAR(p_data[i]); 27 | } 28 | #endif 29 | return len; 30 | } 31 | 32 | _ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len) 33 | { 34 | (void) file; // Not used, avoid warning 35 | (void) r; // Not used, avoid warning 36 | #if defined(SEGGER_RTT) 37 | SEGGER_RTT_Write(0, ptr, len); 38 | #else 39 | const char *p_data = (const char *) ptr; 40 | for (int i = 0; i < len; i++) 41 | { 42 | PUTCHAR(p_data[i]); 43 | } 44 | #endif 45 | return len; 46 | } 47 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/logger/outputs/logger_printf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdio.h" 4 | 5 | #define log_internal_raw(level, ...) \ 6 | do \ 7 | { \ 8 | if (LOG_LEVEL >= level) \ 9 | { \ 10 | printf(__VA_ARGS__); \ 11 | } \ 12 | } while (0) 13 | 14 | #define log_internal(level, ...) \ 15 | do \ 16 | { \ 17 | if (LOG_LEVEL >= level) \ 18 | { \ 19 | printf(__VA_ARGS__); \ 20 | } \ 21 | } while (0) 22 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/assets/t-boot-batching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teufelaudio/mynd-firmware/f4d027a5dcf73e2665dcbac9cab82b0614da98ae/Projects/MyndBootloader/external/teufel/libs/t-boot/assets/t-boot-batching.png -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/keys/t_boot_dev_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQDb3emgu9JyHq2K0FcqMKbzb88qxCJpxdOdYWRHYL1F/tbKh5YD 3 | bi7aQpOdCZA0SsgR7/al+6SzGr0D8T1vFwh0EbJK5cIGebHjpyMst6VZSpJlKkX0 4 | Dv6IwrvzZHzbg/CTcZeDmwKDkU74n/2O/n8qTD+NbDRPcZsO2jlBpJcBYQIDAQAB 5 | AoGAO2Cj7p+qxt0YGwwG7kLzY30HotITRSOC8dbSgSBUHWokUc/qKIUCLDmcqeVi 6 | R20GuSloIA1kvmXzM/RblfvPcSEJNpaxoQoeEmbe+lXFKux4HTDB2CAxvheRuL5x 7 | 3Nb6evzqHPkmG/XW6F2nOMuFeCjyKXmKZzpI3LGEsRVFdJECQQDxF4U69PNzI2yP 8 | ie5kTALVrDy6pknfAUoWUL2qP29ML+z0Lacflpp0rKezsy+oMH1qRpK7qIIfY2oF 9 | DyiJ/uuVAkEA6XZmfqsAMnBfVBivASge7yna1okEBfzHH45AeM9gM06z5HRKn1Wt 10 | fdlgwMnaOlDDRGGxdlRziFc4JNsk81SrnQJAf+qO0d0tXiWpb+8rASQjTON5xT59 11 | a0jv2i80sqO9lZrICjY+uc/aW5VP1VR5MK+pmz2elNqvT6AbnFuSksUikQJBAKsl 12 | rUW2vlI7pubToZfLfcH+gPs9PsHU6XTsp77o57E1RRN5XSspeCIGNbOfRmfxxPRg 13 | WeRRTNDqf7IlJRVtQNECQFKOZSSATZStooUqinfuLn5Vv4sq/topp+dLG6SfLBI7 14 | PxtM8SnOxmpPtIS9BWEGYl7p/ia2uzf3NBe5LLGhk7Y= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/keys/t_boot_dev_public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDb3emgu9JyHq2K0FcqMKbzb88q 3 | xCJpxdOdYWRHYL1F/tbKh5YDbi7aQpOdCZA0SsgR7/al+6SzGr0D8T1vFwh0EbJK 4 | 5cIGebHjpyMst6VZSpJlKkX0Dv6IwrvzZHzbg/CTcZeDmwKDkU74n/2O/n8qTD+N 5 | bDRPcZsO2jlBpJcBYQIDAQAB 6 | -----END PUBLIC KEY----- 7 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/bootloader/encryption/t_boot_encryption.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "t_boot_encryption.h" 3 | 4 | __attribute__((always_inline)) static inline bool is_alpha_upper(char c) 5 | { 6 | return ((c >= 0x41) && (c <= 0x5a)); 7 | } 8 | 9 | __attribute__((always_inline)) static inline bool is_alpha_lower(char c) 10 | { 11 | return ((c >= 0x61) && (c <= 0x7a)); 12 | } 13 | 14 | void t_boot_encryption_decode(const uint8_t *p_input, size_t input_length, const uint8_t *p_key, size_t key_length, uint8_t *p_output) 15 | { 16 | int8_t shifts[key_length]; 17 | int8_t sign = -1; // Decrypting, shifts will be negative. 18 | 19 | for (size_t i = 0; i < key_length; i++) 20 | { 21 | char charcase = is_alpha_upper(p_key[i]) ? 'A' : 'a'; 22 | shifts[i] = (p_key[i] - charcase) * sign; 23 | } 24 | 25 | for (size_t i = 0, j = 0; i < input_length; i++) 26 | { 27 | // Skip non-alphabetical characters 28 | if ((!is_alpha_upper(p_input[i])) && (!(is_alpha_lower(p_input[i])))) 29 | { 30 | p_output[i] = p_input[i]; 31 | continue; 32 | } 33 | 34 | uint8_t charcase = is_alpha_upper(p_input[i]) ? 'A' : 'a'; 35 | 36 | // Wrapping conversion algorithm 37 | // TODO: Guard against p_output buffer overflow 38 | p_output[i] = ((p_input[i] + shifts[j] - charcase + 26) % 26) + charcase; 39 | 40 | j = (j + 1) % key_length; 41 | } 42 | } 43 | 44 | void t_boot_encryption_decode_in_place(uint8_t *p_input, size_t input_length, const uint8_t *p_key, size_t key_length) 45 | { 46 | int8_t shifts[key_length]; 47 | int8_t sign = -1; // Decrypting, shifts will be negative. 48 | 49 | for (size_t i = 0; i < key_length; i++) 50 | { 51 | char charcase = is_alpha_upper(p_key[i]) ? 'A' : 'a'; 52 | 53 | shifts[i] = (p_key[i] - charcase) * sign; 54 | } 55 | 56 | for (size_t i = 0, j = 0; i < input_length; i++) 57 | { 58 | if ((!is_alpha_upper(p_input[i])) && (!(is_alpha_lower(p_input[i])))) 59 | { 60 | continue; 61 | } 62 | 63 | uint8_t charcase = is_alpha_upper(p_input[i]) ? 'A' : 'a'; 64 | 65 | // Wrapping conversion algorithm 66 | p_input[i] = (((uint8_t)(p_input[i] + shifts[j] - charcase + 26)) % 26) + charcase; 67 | 68 | j = (j + 1) % key_length; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/bootloader/encryption/t_boot_encryption.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | /** 7 | * @brief Decodes classic Vigenere's cipher with fixed length alphabetic key to an output buffer. 8 | * 9 | * @param[in] p_input pointer to input buffer 10 | * @param[in] input_length length of input buffer 11 | * @param[in] p_key pointer to encryption key 12 | * @param[in] key_length length of encryption key 13 | * @param[out] p_output pointer to output buffer 14 | */ 15 | void t_boot_encryption_decode(const uint8_t *p_input, size_t input_length, const uint8_t *p_key, size_t key_length, uint8_t *p_output); 16 | 17 | /** 18 | * @brief Decodes classic Vigenere's cipher in-place with fixed length alphabetic key. 19 | * 20 | * @param[inout] p_input pointer to input buffer 21 | * @param[in] input_length length of input buffer 22 | * @param[in] p_key pointer to encryption key 23 | * @param[in] key_length length of encryption key 24 | */ 25 | void t_boot_encryption_decode_in_place(uint8_t *p_input, size_t input_length, const uint8_t *p_key, size_t key_length); 26 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/bootloader/ram_disk/t_boot_ram_disk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "t_boot_config.h" 5 | 6 | /** 7 | * @brief Creates a file in dynamic area with a given name and extension. 8 | * @note Name and extension must be given in capital letters. 9 | * For example: VERSION.TXT 10 | * 11 | * @param[in] name file name (up to 8 characters) 12 | * @param[in] extension file extension (up to 3 characters) 13 | * @param[in] p_data pointer to data to write in the file 14 | * @param[in] length data length 15 | * 16 | * @return 0 if successful, -1 otherwise 17 | */ 18 | int t_boot_ram_disk_add_file(const char *name, const char *extension, const uint8_t *p_data, uint32_t length); 19 | 20 | int t_boot_ram_disk_read_block(uint8_t *p_buffer, uint32_t block_address, uint16_t block_length); 21 | int t_boot_ram_disk_write_block(uint8_t *p_buffer, uint32_t block_address, uint16_t block_length); 22 | void t_boot_ram_disk_get_capacity(uint32_t *p_number_of_blocks, uint16_t *p_block_size); 23 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/agnostic/crc/crc32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LXP32 License 3 | * Copyright © 2016–2022 by Alex I. Kuznetsov 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | * documentation files (the “Software”), to deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | * permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 10 | * Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 11 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 12 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 13 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 14 | * THE SOFTWARE. 15 | */ 16 | 17 | #include "crc32.h" 18 | 19 | uint32_t crc32(const char *s, size_t n) 20 | { 21 | uint32_t crc = UINT32_MAX; 22 | 23 | for (size_t i = 0; i < n; i++) 24 | { 25 | char ch = s[i]; 26 | for (size_t j = 0; j < 8; j++) 27 | { 28 | uint32_t b = (ch ^ crc) & 1; 29 | crc >>= 1; 30 | if (b) 31 | crc = crc ^ 0xEDB88320; 32 | ch >>= 1; 33 | } 34 | } 35 | 36 | return ~crc; 37 | } -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/agnostic/crc/crc32.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | uint32_t crc32(const char *s, size_t n); 5 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/agnostic/crc/t_boot_crc.c: -------------------------------------------------------------------------------- 1 | #include "crc32.h" 2 | #include 3 | #include "t_boot_crc.h" 4 | 5 | void t_boot_crc_init(void) {} 6 | 7 | void t_boot_crc_deinit(void) {} 8 | 9 | uint32_t t_boot_crc_compute(const uint32_t *p_buffer, uint32_t length) 10 | { 11 | if (p_buffer == NULL || length == 0) 12 | { 13 | return 0; 14 | } 15 | 16 | return crc32(p_buffer, length); 17 | } -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/agnostic/crc/t_boot_crc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" { 7 | #endif 8 | 9 | /** 10 | * @brief Initializes the CRC module used by t-boot. 11 | */ 12 | void t_boot_crc_init(void); 13 | 14 | /** 15 | * @brief Deinitializes the CRC module used by t-boot. 16 | */ 17 | void t_boot_crc_deinit(void); 18 | 19 | /** 20 | * @brief Computes the CRC of a given buffer. 21 | * 22 | * @param[in] p_buffer pointer to buffer 23 | * @param[in] length buffer length 24 | * 25 | * @return CRC32 26 | */ 27 | uint32_t t_boot_crc_compute(const uint32_t *p_buffer, uint32_t length); 28 | 29 | #if defined(__cplusplus) 30 | } 31 | #endif -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/mimxrt1010/crc/t_boot_crc.c: -------------------------------------------------------------------------------- 1 | #include "t_boot_crc.h" 2 | #include "fsl_adapter_crc.h" 3 | 4 | static hal_crc_config_t crc_config = { 5 | .crcRefIn = KHAL_CrcRefInput, 6 | .crcRefOut = KHAL_CrcOutputNoRef, 7 | .crcByteOrder = KHAL_CrcLSByteFirst, 8 | .crcSeed = 0xFFFFFFFF, 9 | .crcPoly = KHAL_CrcPolynomial_CRC_32, 10 | .crcXorOut = 0xFFFFFFFF, 11 | .complementChecksum = 0, 12 | .crcSize = 4, 13 | .crcStartByte = 0, 14 | }; 15 | 16 | void t_boot_crc_init(void) 17 | { 18 | crc_config.crcSeed = 0xFFFFFFFF; 19 | } 20 | 21 | void t_boot_crc_deinit(void) 22 | { 23 | 24 | } 25 | 26 | uint32_t t_boot_crc_compute(const uint32_t *p_buffer, uint32_t length) 27 | { 28 | uint32_t res; 29 | res = HAL_CrcCompute(&crc_config, (uint8_t *)p_buffer, length); 30 | crc_config.crcSeed = res; 31 | return res; 32 | } 33 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/mimxrt1010/crc/t_boot_crc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" { 7 | #endif 8 | 9 | /** 10 | * @brief Initializes the CRC module used by t-boot. 11 | */ 12 | void t_boot_crc_init(void); 13 | 14 | /** 15 | * @brief Deinitializes the CRC module used by t-boot. 16 | */ 17 | void t_boot_crc_deinit(void); 18 | 19 | /** 20 | * @brief Computes the CRC of a given buffer. 21 | * 22 | * @param[in] p_buffer pointer to buffer 23 | * @param[in] length buffer length 24 | * 25 | * @return CRC32 26 | */ 27 | uint32_t t_boot_crc_compute(const uint32_t *p_buffer, uint32_t length); 28 | 29 | #if defined(__cplusplus) 30 | } 31 | #endif -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/stm32f0/crc/t_boot_crc.c: -------------------------------------------------------------------------------- 1 | #include "stm32f0xx_hal.h" 2 | #include "t_boot_crc.h" 3 | 4 | /* CRC handler declaration */ 5 | CRC_HandleTypeDef CrcHandle; 6 | 7 | void t_boot_crc_init(void) 8 | { 9 | /*##-1- Configure the CRC peripheral #######################################*/ 10 | CrcHandle.Instance = CRC; 11 | 12 | #if defined(CRC_POL_POL) 13 | /* The default polynomial is used */ 14 | CrcHandle.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; 15 | #endif 16 | 17 | /* The default init value is used */ 18 | CrcHandle.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; 19 | 20 | /* The input data are inverted */ 21 | CrcHandle.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_BYTE; 22 | 23 | /* The output data are not inverted */ 24 | CrcHandle.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_ENABLE; 25 | 26 | /* The input data are 8 bits lenght */ 27 | CrcHandle.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; 28 | 29 | /* CRC Peripheral clock enable */ 30 | __HAL_RCC_CRC_CLK_ENABLE(); 31 | 32 | HAL_CRC_Init(&CrcHandle); 33 | } 34 | 35 | void t_boot_crc_deinit(void) 36 | { 37 | HAL_CRC_DeInit(&CrcHandle); 38 | 39 | /* CRC Peripheral clock disable */ 40 | __HAL_RCC_CRC_CLK_DISABLE(); 41 | } 42 | 43 | uint32_t t_boot_crc_compute(const uint32_t *p_buffer, uint32_t length) 44 | { 45 | return HAL_CRC_Calculate(&CrcHandle, (uint32_t *)p_buffer, length) ^ 0xffffffff; 46 | } 47 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/stm32f0/crc/t_boot_crc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__cplusplus) 6 | extern "C" { 7 | #endif 8 | 9 | /** 10 | * @brief Initializes the CRC module used by t-boot. 11 | */ 12 | void t_boot_crc_init(void); 13 | 14 | /** 15 | * @brief Deinitializes the CRC module used by t-boot. 16 | */ 17 | void t_boot_crc_deinit(void); 18 | 19 | /** 20 | * @brief Computes the CRC of a given buffer. 21 | * 22 | * @param[in] p_buffer pointer to buffer 23 | * @param[in] length buffer length 24 | * 25 | * @return CRC32 26 | */ 27 | uint32_t t_boot_crc_compute(const uint32_t *p_buffer, uint32_t length); 28 | 29 | #if defined(__cplusplus) 30 | } 31 | #endif -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/stm32f0/t_boot_stm32_config_template.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define USBD_PID 0x0016 4 | 5 | #define USBD_PRODUCT_FS_STRING "Teufel Dev" 6 | 7 | // clang-format off 8 | #define STORAGE_INQUIRYDATA_CONFIG \ 9 | /* 36 */ \ 10 | /* LUN 0 */ \ 11 | 0x00, 0x80, 0x02, 0x02, (STANDARD_INQUIRY_DATA_LEN - 5), \ 12 | 0x00, 0x00, 0x00, 'T', 'e', \ 13 | 'u', 'f', 'e', 'l', ' ', \ 14 | ' ', /* Manufacturer: 8 bytes */ \ 15 | 'C', 'B', ' ', 'O', 'n', \ 16 | 'e', ' ', ' ', /* Product : 16 Bytes */ \ 17 | ' ', ' ', ' ', ' ', ' ', \ 18 | ' ', ' ', ' ', '1', '.', \ 19 | '0', '0', /* Version : 4 Bytes */ 20 | // clang-format on 21 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/stm32f0/usbd/usbd_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_CONF_H 2 | #define __USBD_CONF_H 3 | 4 | #include "stm32f0xx_hal.h" 5 | #include 6 | #include 7 | #include 8 | 9 | // clang-format off 10 | /* Common Config */ 11 | #define USBD_MAX_NUM_INTERFACES 1 12 | #define USBD_MAX_NUM_CONFIGURATION 1 13 | #define USBD_MAX_STR_DESC_SIZ 0x100 14 | #define USBD_SUPPORT_USER_STRING 0 15 | #define USBD_SELF_POWERED 1 16 | #define USBD_DEBUG_LEVEL 0 17 | 18 | /* MSC Class Config */ 19 | #define MSC_MEDIA_PACKET 512 20 | // clang-format on 21 | 22 | /* For footprint reasons and since only one allocation is handled in the MSC class 23 | driver, the malloc/free is changed into a static allocation method */ 24 | 25 | void *USBD_static_malloc(uint32_t size); 26 | void USBD_static_free(void *p); 27 | 28 | // clang-format off 29 | #define MAX_STATIC_ALLOC_SIZE 200 /*MSC Class Driver Structure size*/ 30 | 31 | #define USBD_malloc (uint32_t *)USBD_static_malloc 32 | #define USBD_free USBD_static_free 33 | #define USBD_memset /* Not used */ 34 | #define USBD_memcpy /* Not used */ 35 | 36 | 37 | /* DEBUG macros */ 38 | #if (USBD_DEBUG_LEVEL > 0) 39 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 40 | printf("\n"); 41 | #else 42 | #define USBD_UsrLog(...) 43 | #endif 44 | 45 | #if (USBD_DEBUG_LEVEL > 1) 46 | 47 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 48 | printf(__VA_ARGS__);\ 49 | printf("\n"); 50 | #else 51 | #define USBD_ErrLog(...) 52 | #endif 53 | 54 | #if (USBD_DEBUG_LEVEL > 2) 55 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 56 | printf(__VA_ARGS__);\ 57 | printf("\n"); 58 | #else 59 | #define USBD_DbgLog(...) 60 | #endif 61 | // clang-format on 62 | 63 | #endif /* __USBD_CONF_H */ 64 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/stm32f0/usbd/usbd_desc.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_DESC_H 2 | #define __USBD_DESC_H 3 | 4 | #include "usbd_def.h" 5 | 6 | #define DEVICE_ID1 (0x1FFFF7AC) 7 | #define DEVICE_ID2 (0x1FFFF7B0) 8 | #define DEVICE_ID3 (0x1FFFF7B4) 9 | 10 | #define USB_SIZ_STRING_SERIAL 0x1A 11 | 12 | extern USBD_DescriptorsTypeDef MSC_Desc; 13 | 14 | #endif /* __USBD_DESC_H */ 15 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/device_specific/stm32f0/usbd/usbd_storage.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_STORAGE_H__ 2 | #define __USBD_STORAGE_H__ 3 | 4 | #include "usbd_msc.h" 5 | 6 | extern USBD_StorageTypeDef USBD_DISK_fops; 7 | 8 | #endif /* __USBD_STORAGE_H__ */ 9 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/logger_config/t_boot_logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "logger.h" 4 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/src/t_boot_config_template.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Product type: Little endian ASCII '\0\0AD' representation 4 | #define T_BOOT_DFU_PRODUCT_TYPE_U32 (0x44410000) 5 | 6 | // Product ID: Little endian ASCII '2101' representation 7 | #define T_BOOT_DFU_PRODUCT_ID_U32 (0x31303132) 8 | 9 | // Skips signature verification if set 10 | #define T_BOOT_DFU_SKIP_SIGNATURE 1 11 | 12 | // Size of the FS localed in RAM 13 | #define T_BOOT_RAM_DISK_SIZE (4 * 1024) 14 | 15 | // Log level of the t-boot library 16 | #define T_BOOT_LOG_LEVEL LOG_LEVEL_INFO 17 | 18 | // Encryption key 19 | #define T_BOOT_ENCRYPTION_KEY "TEUFELDEV" 20 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/tests/t_boot_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Product type: Little endian ASCII '\0\0AA' representation 4 | #define T_BOOT_DFU_PRODUCT_TYPE_U32 (0x41410000) 5 | #define T_BOOT_DFU_PRODUCT_ID_U32 (0x31303132) 6 | 7 | // Disable sha1 signature verification 8 | #define T_BOOT_DFU_SKIP_SIGNATURE 1 9 | 10 | // Size of the FS localed in RAM 11 | #define T_BOOT_RAM_DISK_SIZE (4 * 1024) 12 | 13 | // Log level of the t-boot library 14 | #define T_BOOT_LOG_LEVEL LOG_LEVEL_DEBUG 15 | 16 | // Encryption key 17 | #define T_BOOT_ENCRYPTION_KEY "TEUFELDEV" 18 | 19 | // Non-sequential mode 20 | #define T_BOOT_DFU_NON_SEQUENTIAL_MODE 1 -------------------------------------------------------------------------------- /Projects/MyndBootloader/external/teufel/libs/t-boot/tests/test_generate_crc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "t_boot_dfu.h" 4 | #include "unity.h" 5 | #include "unity_fixture.h" 6 | 7 | TEST_GROUP(TbootCrc); 8 | 9 | TEST_SETUP(TbootCrc) 10 | { 11 | t_boot_crc_init(); 12 | } 13 | 14 | TEST_TEAR_DOWN(TbootCrc) 15 | { 16 | t_boot_crc_deinit(); 17 | } 18 | 19 | TEST(TbootCrc, test_buffer1_crc) 20 | { 21 | uint8_t buffer[4] = {0xAB, 0xAB, 0xAB, 0xAB}; 22 | uint32_t res = t_boot_crc_compute((uint32_t *) &buffer, sizeof(buffer)); 23 | 24 | TEST_ASSERT_EQUAL(res, 0x62F4ECDB); 25 | } 26 | 27 | TEST(TbootCrc, test_buffer2_crc) 28 | { 29 | uint8_t buffer[7] = {0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB}; 30 | uint32_t res = t_boot_crc_compute((uint32_t *) &buffer, sizeof(buffer)); 31 | 32 | TEST_ASSERT_EQUAL(res, 0xEF5C2487); 33 | } 34 | 35 | TEST(TbootCrc, test_empty_crc) 36 | { 37 | uint32_t res = t_boot_crc_compute(NULL, 0); 38 | 39 | TEST_ASSERT_EQUAL(res, 0); 40 | } 41 | 42 | TEST_GROUP_RUNNER(TbootCrc) 43 | { 44 | RUN_TEST_CASE(TbootCrc, test_buffer1_crc); 45 | 46 | RUN_TEST_CASE(TbootCrc, test_buffer2_crc); 47 | 48 | RUN_TEST_CASE(TbootCrc, test_empty_crc); 49 | } -------------------------------------------------------------------------------- /Projects/MyndBootloader/mynd-bootloader.JLinkScript: -------------------------------------------------------------------------------- 1 | Device STM32F072RB 2 | si SWD 3 | speed 4000 4 | h 5 | #erase 6 | loadfile Projects/MyndBootloader/mynd-bootloader.hex 7 | r 8 | q 9 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/stm32f0xx_it.c: -------------------------------------------------------------------------------- 1 | #include "stm32f0xx_hal.h" 2 | #include "stm32f0xx.h" 3 | #include "stm32f0xx_it.h" 4 | 5 | extern PCD_HandleTypeDef hpcd; 6 | extern I2C_HandleTypeDef I2C2_Handle; 7 | 8 | /** 9 | * @brief This function handles NMI exception. 10 | * @param None 11 | * @retval None 12 | */ 13 | void NMI_Handler(void) {} 14 | 15 | /** 16 | * @brief This function handles Hard Fault exception. 17 | * @param None 18 | * @retval None 19 | */ 20 | void HardFault_Handler(void) 21 | { 22 | __BKPT(0); 23 | /* Go to infinite loop when Hard Fault exception occurs */ 24 | while (1) 25 | { 26 | } 27 | } 28 | 29 | /** 30 | * @brief This function handles SVCall exception. 31 | * @param None 32 | * @retval None 33 | */ 34 | void SVC_Handler(void) {} 35 | 36 | /** 37 | * @brief This function handles PendSVC exception. 38 | * @param None 39 | * @retval None 40 | */ 41 | void PendSV_Handler(void) {} 42 | 43 | /** 44 | * @brief This function handles SysTick Handler. 45 | * @param None 46 | * @retval None 47 | */ 48 | void SysTick_Handler(void) 49 | { 50 | HAL_IncTick(); 51 | } 52 | 53 | /** 54 | * @brief This function handles USB Handler. 55 | * @param None 56 | * @retval None 57 | */ 58 | void USB_IRQHandler(void) 59 | { 60 | HAL_PCD_IRQHandler(&hpcd); 61 | } 62 | 63 | void DMA1_Channel4_5_6_7_IRQHandler(void) 64 | { 65 | // HAL_DMA_IRQHandler(I2C2_Handle.hdmarx); 66 | HAL_DMA_IRQHandler(I2C2_Handle.hdmatx); 67 | } 68 | 69 | /** 70 | * @brief This function handles I2C event and error interrupt request. 71 | * @param None 72 | * @retval None 73 | * @Note This function is redefined in "main.h" and related to I2C data transmission 74 | */ 75 | void I2C2_IRQHandler(void) 76 | { 77 | HAL_I2C_EV_IRQHandler(&I2C2_Handle); 78 | HAL_I2C_ER_IRQHandler(&I2C2_Handle); 79 | } 80 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/stm32f0xx_it.h: -------------------------------------------------------------------------------- 1 | #ifndef __STM32F0xx_IT_H 2 | #define __STM32F0xx_IT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | void NMI_Handler(void); 10 | void HardFault_Handler(void); 11 | void SVC_Handler(void); 12 | void PendSV_Handler(void); 13 | void SysTick_Handler(void); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif /* __STM32F0xx_IT_H */ 20 | -------------------------------------------------------------------------------- /Projects/MyndBootloader/t_boot_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // clang-format off 4 | // Product type: Little endian ASCII '\0\0OA' representation 5 | #define T_BOOT_DFU_PRODUCT_TYPE_U32 (0x414F0000) 6 | // Produce ID: Little endian ASCII '2302' representation 7 | #define T_BOOT_DFU_PRODUCT_ID_U32 (0x32303332) 8 | 9 | #define T_BOOT_DFU_SKIP_SIGNATURE 1 10 | 11 | #define T_BOOT_RAM_DISK_SIZE (4 * 1024) 12 | 13 | #define T_BOOT_LOG_LEVEL LOG_LEVEL_INFO 14 | 15 | #define T_BOOT_ENCRYPTION_KEY "TEUFELDEV" 16 | 17 | #define T_BOOT_DFU_NON_SEQUENTIAL_MODE 1 18 | // clang-format on -------------------------------------------------------------------------------- /Projects/MyndBootloader/t_boot_stm32_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define USBD_PID 0x003F 4 | 5 | #define USBD_PRODUCT_FS_STRING "Teufel MYND" 6 | 7 | // clang-format off 8 | #define STORAGE_INQUIRYDATA_CONFIG \ 9 | /* 36 */ \ 10 | /* LUN 0 */ \ 11 | 0x00, 0x80, 0x02, 0x02, (STANDARD_INQUIRY_DATA_LEN - 5), \ 12 | 0x00, 0x00, 0x00, 'T', 'e', \ 13 | 'u', 'f', 'e', 'l', ' ', \ 14 | ' ', /* Manufacturer: 8 bytes */ \ 15 | 'M', 'Y', 'N', 'D', ' ', \ 16 | ' ', ' ', ' ', /* Product : 16 Bytes */ \ 17 | ' ', ' ', ' ', ' ', ' ', \ 18 | ' ', ' ', ' ', '1', '.', \ 19 | '0', '0', /* Version : 4 Bytes */ 20 | // clang-format on 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clone 2 | ```shell 3 | git clone --recurse-submodules git@github.com:teufelaudio/mynd-firmware.git 4 | ``` 5 | # Build 6 | ```shell 7 | mkdir build && cd build 8 | cmake -DPROJECT=Mynd -DTOOLCHAIN_PREFIX= -DCMAKE_BUILD_TYPE=Release .. 9 | make mynd-update-firmware-mcu 10 | ``` 11 | # Project structure 12 | - `drivers` - Basic stm I/O drivers 13 | - `firmwares` - Third-party firmwares (Bluetooth, USB-PD controller) 14 | - `gitversion` - Version string generator 15 | - `Projects` 16 | - `Mynd` - Source code for MCU firmware 17 | - `MyndBootloader` - Source code for bootloader 18 | - `sdk` - Board support package 19 | - `support` 20 | - `cmake` - Cmake helpers for stm32 components and other libraries 21 | - `docker-build` - Configuration for docker build 22 | - `keys` - Keys to sign firmware update file (Only for tests! They are not used.) 23 | - `scripts` - Helper scripts for build and CI/CD 24 | - `svd` - Hardware description file - internal registers outline 25 | -------------------------------------------------------------------------------- /drivers/platform/stm32/i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLATFORM_I2C_H__ 2 | #define __PLATFORM_I2C_H__ 3 | 4 | #include 5 | 6 | #ifdef STM32F0 7 | #include "stm32f0xx.h" 8 | #include "stm32f0xx_hal.h" 9 | #elif STM32F1 10 | #include "stm32f1xx.h" 11 | #include "stm32f1xx_hal.h" 12 | #elif STM32F3 13 | #include "stm32f3xx.h" 14 | #include "stm32f3xx_hal.h" 15 | #elif STM32F4 16 | #include "stm32f4xx.h" 17 | #include "stm32f4xx_hal.h" 18 | #endif 19 | 20 | #include "board.h" 21 | 22 | typedef enum 23 | { 24 | I2C_OK = 0, 25 | I2C_BUSY, 26 | I2C_ERROR_NACK, 27 | I2C_ERROR_TIMEOUT, 28 | I2C_ERROR_HAL, 29 | I2C_STATUS_UNDEFINED, 30 | } I2C_Status_t; 31 | 32 | void I2C_Init(I2C_HandleTypeDef *hi2c); 33 | void I2C_Deinit(I2C_HandleTypeDef *hi2c); 34 | 35 | uint32_t I2C_Read_Reg8(I2C_HandleTypeDef *hi2c, uint8_t Addr, uint8_t Reg, uint8_t *pData, uint8_t len); 36 | uint32_t I2C_Write_Reg8(I2C_HandleTypeDef *hi2c, uint8_t Addr, uint8_t Reg, uint8_t *pData, uint8_t len); 37 | 38 | uint32_t I2C_Write_Reg16(I2C_HandleTypeDef *hi2c, uint8_t Addr, uint16_t memAddr, uint8_t *pData, uint16_t len); 39 | 40 | uint32_t I2C_Write_Data(I2C_HandleTypeDef *hi2c, uint8_t Addr, uint8_t *pData, uint16_t len); 41 | uint32_t I2C_Read_Data(I2C_HandleTypeDef *hi2c, uint8_t Addr, uint8_t *pData, uint16_t len); 42 | 43 | uint32_t I2C_Write_Reg16_DMA(I2C_HandleTypeDef *hi2c, uint8_t Addr, uint16_t memAddr, uint8_t *pData, uint16_t len); 44 | 45 | uint32_t I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint8_t Addr, uint32_t trials, uint32_t timeout); 46 | 47 | #endif /* __PLATFORM_I2C_H__ */ 48 | -------------------------------------------------------------------------------- /drivers/platform/stm32/i2c_freertos.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stm32f0xx_hal.h" 4 | 5 | typedef struct i2c_rtos_handler i2c_rtos_handler_t; 6 | 7 | i2c_rtos_handler_t *i2c_rtos_init(I2C_HandleTypeDef *hi2c); 8 | int i2c_rtos_write_data(i2c_rtos_handler_t *i2c_h, uint8_t i2c_address, uint16_t reg_address, uint16_t reg_address_size, 9 | uint8_t *p_buffer, size_t length); 10 | int i2c_rtos_read_data(i2c_rtos_handler_t *i2c_h, uint8_t i2c_address, uint16_t reg_address, uint16_t reg_address_size, 11 | uint8_t *p_buffer, size_t length); 12 | -------------------------------------------------------------------------------- /firmwares/bluetooth/Teufel_MYND_20241016_v1.3.8.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teufelaudio/mynd-firmware/f4d027a5dcf73e2665dcbac9cab82b0614da98ae/firmwares/bluetooth/Teufel_MYND_20241016_v1.3.8.zip -------------------------------------------------------------------------------- /firmwares/usb-pd/25751_no_bc1.2_3A_V2.5.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teufelaudio/mynd-firmware/f4d027a5dcf73e2665dcbac9cab82b0614da98ae/firmwares/usb-pd/25751_no_bc1.2_3A_V2.5.zip -------------------------------------------------------------------------------- /gitversion/gitversion.h.in: -------------------------------------------------------------------------------- 1 | #ifndef __GITVERSION_H__ 2 | #define __GITVERSION_H__ 3 | // clang-format off 4 | #define VERSION_MAJOR ${VERSION_MAJOR} 5 | #define VERSION_MINOR ${VERSION_MINOR} 6 | #define VERSION_PATCH ${VERSION_PATCH} 7 | #define VERSION_BUILD ${VERSION_BUILD} 8 | // clang-format on 9 | #endif //__GITVERSION_H__ 10 | -------------------------------------------------------------------------------- /gitversion/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gitversion.h" 4 | 5 | #define STRINGIFY(s) #s 6 | #define TO_STRING(s) STRINGIFY(s) 7 | 8 | #define VERSION_FIRMWARE_STRING TO_STRING(VERSION_MAJOR) "." TO_STRING(VERSION_MINOR) "." TO_STRING(VERSION_PATCH) 9 | #define VERSION_BUILD_STRING TO_STRING(VERSION_BUILD) 10 | 11 | #if VERSION_MAJOR > 100 12 | #define VERSION_FIRMWARE_STRING_SHORT TO_STRING(VERSION_MAJOR) 13 | #else 14 | #define VERSION_FIRMWARE_STRING_SHORT TO_STRING(VERSION_MAJOR) "." TO_STRING(VERSION_MINOR) 15 | #endif // VERSION_MAJOR > 100 16 | 17 | #define FW_VERSION_DO_EXPAND(VAL) VAL##1 18 | #define FW_VERSION_EXPAND(VAL) FW_VERSION_DO_EXPAND(VAL) 19 | 20 | inline __attribute__((used)) void __mcu_firmware_version() 21 | { 22 | #if !defined(VERSION_BUILD) || (FW_VERSION_EXPAND(VERSION_BUILD) == 1) 23 | static const char __srcvers[] __attribute__((used)) = "FW_VERSION:" VERSION_FIRMWARE_STRING; 24 | #else 25 | static const char __srcvers[] __attribute__((used)) = 26 | "FW_VERSION:" VERSION_FIRMWARE_STRING "-" VERSION_BUILD_STRING; 27 | #endif 28 | } 29 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | protobuf 2 | grpcio-tools 3 | python3-protobuf 4 | google 5 | crcmod 6 | intelhex 7 | json 8 | shutil 9 | wget -------------------------------------------------------------------------------- /software_manifest.md: -------------------------------------------------------------------------------- 1 | | Name | Version | License Type | License Link | Note | 2 | |-------------------|---------------------|--------------------|------------------------------------------------------------------------|------| 3 | | newlib-nano (gcc) | v4.3.0 | | https://github.com/32bitmicro/newlib-nano-2/blob/master/COPYING.NEWLIB | | 4 | | STM32CubeF0 | v1.11.2 | | | | 5 | | -- CMSIS | | Apache License 2.0 | file://sdk/STM32CubeF0/Drivers/CMSIS/LICENSE.txt | | 6 | | -- CMSIS Devices | | Apache License 2.0 | file://sdk/STM32CubeF0/Drivers/CMSIS/LICENSE.txt | | 7 | | -- ST HAL | | BSD 3-Clause | file://sdk/STM32CubeF0/Drivers/STM32F0xx_HAL_Driver/License.md | | 8 | | stm-cmake | v2.1.0 | MIT License | https://github.com/ObKo/stm32-cmake/blob/master/LICENSE | | 9 | | FreeRTOS | V10.4.3-LTS-Patch-3 | MIT License | file://Projects/Mynd/external/thirdparty/freertos-kernel/LICENSE.md | | 10 | | Nanopb | v0.4.5 | Zlib License | file://Projects/Mynd/external/thirdparty/nanopb/LICENSE.txt | | 11 | 12 | -------------------------------------------------------------------------------- /support/cmake/deploy.cmake: -------------------------------------------------------------------------------- 1 | function(add_deploy_jlink TARGET) 2 | add_custom_target(${TARGET}-deploy-jlink DEPENDS ${TARGET}.hex 3 | COMMAND JLinkExe -NoGui 1 -CommanderScript ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.JLinkScript 4 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 5 | COMMENT "Deploy firmware via JLink." 6 | VERBATIM 7 | ) 8 | endfunction() 9 | -------------------------------------------------------------------------------- /support/cmake/format.cmake: -------------------------------------------------------------------------------- 1 | macro(installGitHooks) 2 | set(gitHooks "${CMAKE_SOURCE_DIR}/.git/hooks") 3 | 4 | if(EXISTS ${gitHooks}) # git client-side hooks are not available on CI 5 | # additionally check for (and automatically install) the git hooks we want 6 | set(gitPrepareCommitMsgHook "${CMAKE_SOURCE_DIR}/.git/hooks/prepare-commit-msg") 7 | if(NOT EXISTS ${gitPrepareCommitMsgHook}) 8 | message("* Installing git-hook teufel-prepare-commit-msg") 9 | file(CREATE_LINK ../../teufel-prepare-commit-msg ${gitPrepareCommitMsgHook} SYMBOLIC) 10 | endif() 11 | set(gitPrePushHook "${CMAKE_SOURCE_DIR}/.git/hooks/pre-push") 12 | file(REMOVE ${gitPrePushHook}) 13 | if(NOT EXISTS ${gitPrePushHook}) 14 | message("* Installing git-hook teufel-pre-push") 15 | file(CREATE_LINK ../../teufel-pre-push ${gitPrePushHook} SYMBOLIC) 16 | endif() 17 | endif() 18 | endmacro() 19 | -------------------------------------------------------------------------------- /support/cmake/stm32/f0.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_F0_TYPES 2 | F030x6 F030x8 F031x6 F038xx F042x6 F048xx F051x8 F058xx 3 | F070x6 F070xB F071xB F072xB F078xx F091xC F098xx F030xC 4 | ) 5 | set(STM32_F0_TYPE_MATCH 6 | "F030.[46]" "F030.8" "F031.[46]" "F038.." "F042.[46]" "F048.." "F051.[468]" "F058.." 7 | "F070.6" "F070.B" "F071.[8B]" "F072.[8B]" "F078.." "F091.[BC]" "F098.." "F030.C" 8 | ) 9 | set(STM32_F0_RAM_SIZES 10 | 4K 8K 4K 4K 6K 6K 8K 8K 11 | 6K 16K 16K 16K 16K 32K 32K 32K 12 | ) 13 | set(STM32_F0_CCRAM_SIZES 14 | 0K 0K 0K 0K 0K 0K 0K 0K 15 | 0K 0K 0K 0K 0K 0K 0K 0K 16 | ) 17 | 18 | stm32_util_create_family_targets(F0) 19 | 20 | target_compile_options(STM32::F0 INTERFACE 21 | -mcpu=cortex-m0 22 | ) 23 | target_link_options(STM32::F0 INTERFACE 24 | -mcpu=cortex-m0 25 | ) 26 | -------------------------------------------------------------------------------- /support/cmake/stm32/f2.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_F2_TYPES 2 | F205xx F215xx F207xx F217xx 3 | ) 4 | set(STM32_F2_TYPE_MATCH 5 | "F205.." "F215.." "F207.." "F217.." 6 | ) 7 | set(STM32_F2_RAM_SIZES 8 | 0K 128K 128K 128K 9 | ) 10 | set(STM32_F2_CCRAM_SIZES 11 | 0K 0K 0K 0K 12 | ) 13 | 14 | stm32_util_create_family_targets(F2) 15 | 16 | target_compile_options(STM32::F2 INTERFACE 17 | -mcpu=cortex-m3 18 | ) 19 | target_link_options(STM32::F2 INTERFACE 20 | -mcpu=cortex-m3 21 | ) 22 | 23 | function(stm32f2_get_memory_info DEVICE TYPE FLASH_SIZE RAM_SIZE) 24 | string(REGEX REPLACE "F2[0-9][0-9].([468BCDEFGHI])" "\\1" SIZE_CODE ${DEVICE}) 25 | 26 | if(TYPE STREQUAL "F205xx") 27 | if(SIZE_CODE STREQUAL "B") 28 | set(RAM "64K") 29 | elseif(SIZE_CODE STREQUAL "C") 30 | set(RAM "96K") 31 | else() 32 | set(RAM "128K") 33 | endif() 34 | endif() 35 | 36 | if(RAM) 37 | set(${RAM_SIZE} ${RAM} PARENT_SCOPE) 38 | endif() 39 | endfunction() 40 | -------------------------------------------------------------------------------- /support/cmake/stm32/f3.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_F3_TYPES 2 | F301x8 F302x8 F302xC F302xE F303x8 F303xC 3 | F303xE F318xx F328xx F334x8 F358xx F373xC 4 | F378xx F398xx 5 | ) 6 | set(STM32_F3_TYPE_MATCH 7 | "301.[68]" "302.[68]" "302.[BC]" "302.[ED]" "303.[68]" "303.[BC]" 8 | "303.[ED]" "318.." "328.." "334.[468]" "358.." "373.[8BC]" 9 | "378.." "398.." 10 | ) 11 | set(STM32_F3_RAM_SIZES 12 | 16K 16K 0K 64K 16K 0K 13 | 80K 16K 16K 16K 48K 0K 14 | 32K 80K 15 | ) 16 | set(STM32_F3_CCRAM_SIZES 17 | 0K 0K 0K 0K 0K 0K 18 | 0K 0K 0K 0K 0K 0K 19 | 0K 0K 20 | ) 21 | 22 | stm32_util_create_family_targets(F3) 23 | 24 | target_compile_options(STM32::F3 INTERFACE 25 | -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard 26 | ) 27 | target_link_options(STM32::F3 INTERFACE 28 | -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard 29 | ) 30 | 31 | function(stm32f3_get_memory_info DEVICE TYPE FLASH_SIZE RAM_SIZE) 32 | string(REGEX REPLACE "F3[0-9][0-9].([468BCDEFGHI])" "\\1" SIZE_CODE ${DEVICE}) 33 | 34 | if(TYPE STREQUAL "F302xC") 35 | if(SIZE_CODE STREQUAL "C") 36 | set(RAM "40K") 37 | else() 38 | set(RAM "32K") 39 | endif() 40 | elseif(TYPE STREQUAL "F303xC") 41 | if(SIZE_CODE STREQUAL "C") 42 | set(RAM "48K") 43 | else() 44 | set(RAM "40K") 45 | endif() 46 | elseif(TYPE STREQUAL "F373xC") 47 | if(SIZE_CODE STREQUAL "B") 48 | set(RAM "24K") 49 | elseif(SIZE_CODE STREQUAL "C") 50 | set(RAM "32K") 51 | else() 52 | set(RAM "16K") 53 | endif() 54 | endif() 55 | 56 | if(RAM) 57 | set(${RAM_SIZE} ${RAM} PARENT_SCOPE) 58 | endif() 59 | endfunction() 60 | -------------------------------------------------------------------------------- /support/cmake/stm32/f4.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_F4_TYPES 2 | F401xC F401xE F405xx F407xx F410Cx F410Rx F410Tx F411xE 3 | F412Cx F412Rx F412Vx F412Zx F413xx F415xx F417xx F423xx 4 | F427xx F429xx F437xx F439xx F446xx F469xx F479xx 5 | ) 6 | set(STM32_F4_TYPE_MATCH 7 | "F401.[CB]" "F401.[ED]" "F405.." "F407.." "F410C." "F410R." "F410T." "F411.[CE]" 8 | "F412C." "F412R." "F412V." "F412Z." "F413.." "F415.." "F417.." "F423.." 9 | "F427.." "F429.." "F437.." "F439.." "F446.." "F469.." "F479.." 10 | ) 11 | set(STM32_F4_RAM_SIZES 12 | 64K 96K 128K 128K 32K 32K 32K 128K 13 | 256K 256K 256K 256K 256K 128K 128K 320K 14 | 192K 192K 192K 192K 128K 320K 320K 15 | ) 16 | set(STM32_F4_CCRAM_SIZES 17 | 0K 0K 64K 64K 0K 0K 0K 0K 18 | 0K 0K 0K 0K 64K 64K 64K 0K 19 | 64K 64K 64K 64K 0K 64K 64K 20 | ) 21 | 22 | stm32_util_create_family_targets(F4) 23 | 24 | target_compile_options(STM32::F4 INTERFACE 25 | -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard 26 | ) 27 | target_link_options(STM32::F4 INTERFACE 28 | -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard 29 | ) 30 | -------------------------------------------------------------------------------- /support/cmake/stm32/f7.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_F7_TYPES 2 | F756xx F746xx F745xx F765xx F767xx F769xx F777xx F779xx 3 | F722xx F723xx F732xx F733xx F730xx F750xx 4 | ) 5 | set(STM32_F7_TYPE_MATCH 6 | "F756.." "F746.." "F745.." "F765.." "F767.." "F769.." "F777.." "F77[89].." 7 | "F722.." "F723.." "F732.." "F733.." "F730.." "F750.." 8 | ) 9 | set(STM32_F7_RAM_SIZES 10 | 320K 320K 320K 512K 512K 512K 512K 512K 11 | 256K 256K 256K 256K 256K 320K 12 | ) 13 | set(STM32_F7_CCRAM_SIZES 14 | 0K 0K 0K 0K 0K 0K 0K 0K 15 | 0K 0K 0K 0K 0K 0K 16 | ) 17 | 18 | stm32_util_create_family_targets(F7) 19 | 20 | target_compile_options(STM32::F7 INTERFACE 21 | -mcpu=cortex-m7 -mfpu=fpv5-sp-d16 -mfloat-abi=hard 22 | ) 23 | target_link_options(STM32::F7 INTERFACE 24 | -mcpu=cortex-m7 -mfpu=fpv5-sp-d16 -mfloat-abi=hard 25 | ) 26 | -------------------------------------------------------------------------------- /support/cmake/stm32/g0.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_G0_TYPES 2 | G030xx G031xx G041xx G070xx G071xx G081xx 3 | ) 4 | set(STM32_G0_TYPE_MATCH 5 | "G030.." "G031.." "G041.." "G070.." "G071.." "G081.." 6 | ) 7 | set(STM32_G0_RAM_SIZES 8 | 8K 8K 8K 36K 36K 36K 9 | ) 10 | set(STM32_G0_CCRAM_SIZES 11 | 0K 0K 0K 0K 0K 0K 12 | ) 13 | 14 | stm32_util_create_family_targets(G0) 15 | 16 | target_compile_options(STM32::G0 INTERFACE 17 | -mcpu=cortex-m0plus 18 | ) 19 | target_link_options(STM32::G0 INTERFACE 20 | -mcpu=cortex-m0plus 21 | ) 22 | -------------------------------------------------------------------------------- /support/cmake/stm32/g4.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_G4_TYPES 2 | G431xx G441xx G471xx G473xx G483xx G474xx G484xx 3 | ) 4 | set(STM32_G4_TYPE_MATCH 5 | "G431.." "G441.." "G471.." "G473.." "G483.." "G474.." "G484.." 6 | ) 7 | set(STM32_G4_RAM_SIZES 8 | 32K 32K 128K 128K 128K 128K 128K 9 | ) 10 | set(STM32_G4_CCRAM_SIZES 11 | 10K 10K 32K 32K 32K 32K 32K 12 | ) 13 | 14 | stm32_util_create_family_targets(G4) 15 | 16 | target_compile_options(STM32::G4 INTERFACE 17 | -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard 18 | ) 19 | target_link_options(STM32::G4 INTERFACE 20 | -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard 21 | ) 22 | -------------------------------------------------------------------------------- /support/cmake/stm32/l0.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_L0_TYPES 2 | L010x4 L010x6 L010x8 L010xB L011xx L021xx L031xx L041xx 3 | L051xx L052xx L053xx L061xx L062xx L063xx L071xx L072xx 4 | L073xx L081xx L082xx L083xx 5 | ) 6 | set(STM32_L0_TYPE_MATCH 7 | "L010.4" "L010.6" "L010.8" "L010.B" "L011.." "L021.." "L031.." "L041.." 8 | "L051.." "L052.." "L053.." "L061.." "L062.." "L063.." "L071.." "L072.." 9 | "L073.." "L081.." "L082.." "L083.." 10 | ) 11 | set(STM32_L0_RAM_SIZES 12 | 2K 8K 8K 20K 2K 2K 8K 8K 13 | 8K 8K 8K 8K 8K 8K 20K 20K 14 | 20K 20K 20K 20K 15 | ) 16 | set(STM32_L0_CCRAM_SIZES 17 | 0K 0K 0K 0K 0K 0K 0K 0K 18 | 0K 0K 0K 0K 0K 0K 0K 0K 19 | 0K 0K 0K 0K 20 | ) 21 | 22 | stm32_util_create_family_targets(L0) 23 | 24 | target_compile_options(STM32::L0 INTERFACE 25 | -mcpu=cortex-m0plus 26 | ) 27 | target_link_options(STM32::L0 INTERFACE 28 | -mcpu=cortex-m0plus 29 | ) 30 | -------------------------------------------------------------------------------- /support/cmake/stm32/l4.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_L4_TYPES 2 | L412xx L422xx L431xx L432xx L433xx L442xx 3 | L443xx L451xx L452xx L462xx L471xx L475xx 4 | L476xx L485xx L486xx L496xx L4A6xx L4P5xx 5 | L4Q5xx L4R5xx L4R7xx L4R9xx L4S5xx L4S7xx 6 | L4S9xx 7 | ) 8 | set(STM32_L4_TYPE_MATCH 9 | "L412.." "L422.." "L431.." "L432.." "L433.." "L442.." 10 | "L443.." "L451.." "L452.." "L462.." "L471.." "L475.." 11 | "L476.." "L485.." "L486.." "L496.." "L4A6.." "L4P5.." 12 | "L4Q5.." "L4R5.." "L4R7.." "L4R9.." "L4S5.." "L4S7.." 13 | "L4S9.." 14 | ) 15 | 16 | set(STM32_L4_RAM_SIZES 17 | 40K 40K 64K 64K 64K 64K 18 | 64K 160K 160K 160K 128K 128K 19 | 128K 128K 128K 320K 320K 320K 20 | 320K 640K 640K 640K 640K 640K 21 | 640K 22 | ) 23 | set(STM32_L4_CCRAM_SIZES 24 | 8K 8K 16K 16K 16K 16K 25 | 16K 32K 32K 32K 32K 32K 26 | 32K 32K 32K 64K 64K 64K 27 | 64K 64K 64K 64K 64K 64K 28 | 64K 29 | ) 30 | 31 | stm32_util_create_family_targets(L4) 32 | 33 | target_compile_options(STM32::L4 INTERFACE 34 | -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard 35 | ) 36 | target_link_options(STM32::L4 INTERFACE 37 | -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard 38 | ) 39 | -------------------------------------------------------------------------------- /support/cmake/stm32/l5.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_L5_TYPES 2 | L552xx L562xx 3 | ) 4 | set(STM32_L5_TYPE_MATCH 5 | "L552.." "L562.." 6 | ) 7 | 8 | set(STM32_L5_RAM_SIZES 9 | 256K 256K 10 | ) 11 | set(STM32_L5_CCRAM_SIZES 12 | 0K 0K 13 | ) 14 | 15 | stm32_util_create_family_targets(L5) 16 | 17 | target_compile_options(STM32::L5 INTERFACE 18 | -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard 19 | ) 20 | target_link_options(STM32::L5 INTERFACE 21 | -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard 22 | ) 23 | -------------------------------------------------------------------------------- /support/cmake/stm32/u5.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_U5_TYPES 2 | U575xx U585xx 3 | ) 4 | set(STM32_U5_TYPE_MATCH 5 | "U575.." "U585.." 6 | ) 7 | 8 | set(STM32_U5_RAM_SIZES 9 | 768K 768K 10 | ) 11 | 12 | stm32_util_create_family_targets(U5) 13 | 14 | target_compile_options(STM32::U5 INTERFACE 15 | -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard 16 | ) 17 | target_link_options(STM32::U5 INTERFACE 18 | -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard 19 | ) 20 | -------------------------------------------------------------------------------- /support/cmake/stm32/wb.cmake: -------------------------------------------------------------------------------- 1 | set(STM32_WB_TYPES 2 | WB55xx WB55xx WB35xx WB15xx WB50xx WB30xx WB10xx WB5Mxx 3 | ) 4 | set(STM32_WB_TYPE_MATCH 5 | "WB55.C" "WB55.[EGY]" "WB35.." "WB15.." "WB50.." "WB30.." "WB10.." "WB5M.." 6 | ) 7 | 8 | # this is not full RAM of the chip but only the part allocated to M4 core (SRAM1 in datasheet) 9 | set(STM32_WB_RAM_SIZES 10 | 64K 192K 32K 12K 64K 32K 12K 192K 11 | ) 12 | 13 | # WB series need special area for SRAM2 shared with core M0PLUS 14 | set(STM32_WB_RAM_SHARE_SIZES 15 | 10K 10K 10K 10K 10K 10K 10K 10K 16 | ) 17 | 18 | set(STM32_WB_CCRAM_SIZES 19 | 0K 0K 0K 0K 0K 0K 0K 0K 20 | ) 21 | 22 | stm32_util_create_family_targets(WB M4) 23 | 24 | target_compile_options(STM32::WB::M4 INTERFACE 25 | -mcpu=cortex-m4 -mfpu=fpv5-sp-d16 -mfloat-abi=hard 26 | ) 27 | target_link_options(STM32::WB::M4 INTERFACE 28 | -mcpu=cortex-m4 -mfpu=fpv5-sp-d16 -mfloat-abi=hard 29 | ) 30 | 31 | function(stm32wb_get_memory_info DEVICE TYPE CORE RAM RAM_ORIGIN TWO_FLASH_BANKS) 32 | set(${TWO_FLASH_BANKS} TRUE PARENT_SCOPE) 33 | list(FIND STM32_WB_TYPES ${TYPE} TYPE_INDEX) 34 | list(GET STM32_WB_RAM_SIZES ${TYPE_INDEX} RAM_VALUE) 35 | set(${RAM} "${RAM_VALUE}-4" PARENT_SCOPE) 36 | set(${RAM_ORIGIN} 0x20000004 PARENT_SCOPE) 37 | endfunction() 38 | 39 | -------------------------------------------------------------------------------- /support/cmake/stm32_gcc.cmake: -------------------------------------------------------------------------------- 1 | get_filename_component(STM32_CMAKE_DIR ${CMAKE_CURRENT_LIST_FILE} DIRECTORY) 2 | list(APPEND CMAKE_MODULE_PATH ${STM32_CMAKE_DIR}) 3 | 4 | include(stm32/common) 5 | -------------------------------------------------------------------------------- /support/docker-build/docker-config/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM frolvlad/alpine-glibc:glibc-2.28 2 | 3 | RUN apk --update --no-cache upgrade && \ 4 | apk --update --no-cache add make cmake python2 python3 py-pip protobuf git git-lfs ninja openssl && \ 5 | apk --update --no-cache add --virtual build-dependencies w3m wget curl ca-certificates && \ 6 | wget --no-check-certificate -O /tmp/gcc-arm-none-eabi.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.bz2 && \ 7 | tar xf /tmp/gcc-arm-none-eabi.tar.bz2 --strip-components=1 -C /usr/local && \ 8 | rm -rf /tmp/gcc-arm-none-eabi.tar.bz2 && \ 9 | rm -rf /usr/local/share/doc && \ 10 | curl -fL https://releases.jfrog.io/artifactory/jfrog-cli/v2-jf/2.49.1/scripts/install-cli.sh | sh && \ 11 | apk del build-dependencies 12 | RUN pip3 install --no-cache-dir --upgrade pip && \ 13 | pip3 install --no-cache-dir protobuf && \ 14 | pip3 install --no-cache-dir crcmod && \ 15 | pip3 install --no-cache-dir intelhex 16 | -------------------------------------------------------------------------------- /support/docker-build/docker-config/Dockerfile-x86: -------------------------------------------------------------------------------- 1 | FROM gcc:13.2 2 | 3 | RUN apt-get update && apt-get -y install cmake ninja-build python3-pip protobuf-compiler python3-protobuf python3-crcmod && \ 4 | wget --no-check-certificate -O /tmp/gcc-arm-none-eabi.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.bz2 && \ 5 | mkdir /usr/local/gcc-arm-none-eabi && \ 6 | tar xf /tmp/gcc-arm-none-eabi.tar.bz2 --strip-components=1 -C /usr/local/gcc-arm-none-eabi && \ 7 | rm -rf /tmp/gcc-arm-none-eabi.tar.bz2 && \ 8 | ln -s /usr/bin/gcc-12 /usr/bin/gcc && \ 9 | ln -s /usr/bin/g++-12 /usr/bin/g++ 10 | #RUN pip3 install --no-cache-dir --upgrade pip && \ 11 | # pip3 install --no-cache-dir protobuf && \ 12 | # pip3 install --no-cache-dir crcmod 13 | -------------------------------------------------------------------------------- /support/docker-build/docker-run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #script must be run complete to clean up and fetch logs (don't use -e) 3 | set -x 4 | 5 | # this script must be executed from inside this directory to honor docker-config 6 | # trace of the parameters passed from the buildagent: 7 | ## cd ../.. 8 | ## mapvolume=$(pwd) 9 | ## pathCheckout=%teamcity.build.checkoutDir% 10 | ## cd ${pathCheckout}/support/docker-build 11 | ## ./docker-run.sh projectname ${pathCheckout} ${mapvolume} 12 | ## 13 | ## 14 | 15 | sourceDirectory=$2 16 | shareDirectory=$3 17 | 18 | #stop and rm old container if any 19 | docker container stop build-mcufirmware 20 | docker container rm build-mcufirmware 21 | 22 | docker build -t build-mcufirmware docker-config 23 | 24 | #we need to share more than the checkout directory but also the git mirror has to be mapped to the same directory of the host 25 | #i.e. /home/buildagent/work/mcufirmware and /home/buildagent/system/git have common /home/buildagent 26 | # we are using the deprecated --volume share because some buildagents do not have docker updated 27 | 28 | docker run -d -it --name build-mcufirmware --volume ${shareDirectory}:${shareDirectory}:rw build-mcufirmware 29 | docker ps -a 30 | 31 | echo "creating buildscript that will run in docker container" 32 | 33 | echo "#!/bin/sh" > build.sh 34 | echo "cd ${sourceDirectory}/build" >> build.sh 35 | # git descibe has an issue because of the repo owns by another user, therefore 36 | # it fails in cmake scripts. In order to prevent it, we _mark_ the repo as safe. :) 37 | echo "git config --global --add safe.directory \"$sourceDirectory\"" >> build.sh 38 | echo "cmake -DTOOLCHAIN_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release -G Ninja .." >> build.sh 39 | echo "ninja $1" >> build.sh 40 | 41 | chmod +x build.sh 42 | 43 | #fresh build 44 | docker exec -i build-mcufirmware rm -rf ${shareDirectory}/build 45 | mkdir -p ${sourceDirectory}/build 46 | 47 | cp build.sh ${sourceDirectory}/build 48 | 49 | docker exec -i build-mcufirmware ${sourceDirectory}/build/build.sh 50 | errcode=$? 51 | #save code for later, retrieve stuff and gracefully close 52 | 53 | docker logs build-mcufirmware 54 | 55 | # remove all (the image will not be destroyed, only the container layer) 56 | docker container stop build-mcufirmware 57 | docker container rm build-mcufirmware 58 | 59 | if [ ${errcode} -ne 0 ]; then 60 | echo "docker reports error: " ${errcode} 61 | exit ${errcode} 62 | fi 63 | 64 | -------------------------------------------------------------------------------- /support/docker-build/docker-unittest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | 4 | # this script must be executed from inside this directory to honor docker-config 5 | # trace of the parameters passed from the buildagent: 6 | ## cd ../.. 7 | ## mapvolume=$(pwd) 8 | ## pathCheckout=%teamcity.build.checkoutDir% 9 | ## cd ${pathCheckout}/support/docker-build 10 | ## ./docker-unittest.sh ${pathCheckout} ${mapvolume} 11 | ## 12 | ## 13 | 14 | sourceDirectory=$1 15 | shareDirectory=$2 16 | 17 | #stop and rm old container if any 18 | docker container stop build-mcufirmware 19 | docker container rm build-mcufirmware 20 | 21 | docker build -t build-mcufirmware docker-config 22 | 23 | #we need to share more than the checkout directory but also the git mirror has to be mapped to the same directory of the host 24 | #i.e. /home/buildagent/work/mcufirmware and /home/buildagent/system/git have common /home/buildagent 25 | # we are using the deprecated --volume share because some buildagents do not have docker updated 26 | 27 | docker run -d -it --name build-mcufirmware --volume ${shareDirectory}:${shareDirectory}:rw build-mcufirmware 28 | docker ps -a 29 | 30 | echo "creating buildscript that will run in docker container" 31 | 32 | echo "#!/bin/sh" > build.sh 33 | echo "cd ${sourceDirectory}/build" >> build.sh 34 | echo "cmake -DTOOLCHAIN_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release .." >> build.sh 35 | argc=$# 36 | argv=("$@") 37 | 38 | for (( j=2; j> build.sh 40 | done 41 | 42 | chmod +x build.sh 43 | 44 | #fresh build 45 | rm -rf ${sourceDirectory}/build 46 | mkdir ${sourceDirectory}/build 47 | cp build.sh ${sourceDirectory}/build 48 | 49 | docker exec build-mcufirmware ${sourceDirectory}/build/build.sh 50 | 51 | docker logs build-mcufirmware 52 | 53 | # remove all (the image will not be destroyed, only the container layer) 54 | docker container stop build-mcufirmware 55 | docker container rm build-mcufirmware 56 | -------------------------------------------------------------------------------- /support/docker-build/readme.md: -------------------------------------------------------------------------------- 1 | # Docker hints 2 | 3 | 4 | ## Mac OSx 5 | Install docker with brew 6 | ``` 7 | brew install docker-machine 8 | docker-machine create --driver virtualbox default 9 | docker-machine restart 10 | eval $(docker-machine env) 11 | ``` 12 | 13 | running in terminal start 14 | ``` 15 | docker-machine start 16 | eval $(docker-machine env) 17 | ``` 18 | -------------------------------------------------------------------------------- /support/keys/teufel_dev_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQDb3emgu9JyHq2K0FcqMKbzb88qxCJpxdOdYWRHYL1F/tbKh5YD 3 | bi7aQpOdCZA0SsgR7/al+6SzGr0D8T1vFwh0EbJK5cIGebHjpyMst6VZSpJlKkX0 4 | Dv6IwrvzZHzbg/CTcZeDmwKDkU74n/2O/n8qTD+NbDRPcZsO2jlBpJcBYQIDAQAB 5 | AoGAO2Cj7p+qxt0YGwwG7kLzY30HotITRSOC8dbSgSBUHWokUc/qKIUCLDmcqeVi 6 | R20GuSloIA1kvmXzM/RblfvPcSEJNpaxoQoeEmbe+lXFKux4HTDB2CAxvheRuL5x 7 | 3Nb6evzqHPkmG/XW6F2nOMuFeCjyKXmKZzpI3LGEsRVFdJECQQDxF4U69PNzI2yP 8 | ie5kTALVrDy6pknfAUoWUL2qP29ML+z0Lacflpp0rKezsy+oMH1qRpK7qIIfY2oF 9 | DyiJ/uuVAkEA6XZmfqsAMnBfVBivASge7yna1okEBfzHH45AeM9gM06z5HRKn1Wt 10 | fdlgwMnaOlDDRGGxdlRziFc4JNsk81SrnQJAf+qO0d0tXiWpb+8rASQjTON5xT59 11 | a0jv2i80sqO9lZrICjY+uc/aW5VP1VR5MK+pmz2elNqvT6AbnFuSksUikQJBAKsl 12 | rUW2vlI7pubToZfLfcH+gPs9PsHU6XTsp77o57E1RRN5XSspeCIGNbOfRmfxxPRg 13 | WeRRTNDqf7IlJRVtQNECQFKOZSSATZStooUqinfuLn5Vv4sq/topp+dLG6SfLBI7 14 | PxtM8SnOxmpPtIS9BWEGYl7p/ia2uzf3NBe5LLGhk7Y= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /support/keys/teufel_dev_public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDb3emgu9JyHq2K0FcqMKbzb88q 3 | xCJpxdOdYWRHYL1F/tbKh5YDbi7aQpOdCZA0SsgR7/al+6SzGr0D8T1vFwh0EbJK 4 | 5cIGebHjpyMst6VZSpJlKkX0Dv6IwrvzZHzbg/CTcZeDmwKDkU74n/2O/n8qTD+N 5 | bDRPcZsO2jlBpJcBYQIDAQAB 6 | -----END PUBLIC KEY----- 7 | --------------------------------------------------------------------------------