├── lib_ws2812 ├── .gitignore ├── ws2812.lisp ├── ws2812 │ └── Makefile ├── Makefile └── README.md ├── lib_midi ├── midi.lisp ├── .gitignore ├── axelf_base.mid ├── axelf_melody.mid ├── midi │ ├── Makefile │ ├── README.md │ └── midi-parser.h ├── Makefile ├── midi_test.lisp └── README.md ├── float ├── .gitignore ├── float │ ├── konami.h │ ├── Makefile │ ├── conf │ │ ├── confparser.h │ │ ├── conf_general.h │ │ ├── buffer.h │ │ ├── datatypes.h │ │ └── buffer.c │ ├── footpad_sensor.h │ ├── led.h │ ├── .project │ ├── konami.c │ └── footpad_sensor.c ├── float.lisp ├── Makefile └── README.md ├── lib_interpolation ├── .gitignore ├── interpolation.lisp ├── interpolation │ ├── Makefile │ └── .project ├── Makefile └── README.md ├── lib_files ├── fonts │ ├── font_16_26.bin │ └── font_16_26_aa.bin ├── other │ ├── axelf_base.mid │ └── axelf_melody.mid ├── images │ ├── img_test_160_80.jpg │ ├── img_test_320_240.jpg │ └── img_test_480_320.jpg ├── Makefile ├── files.lisp └── README.md ├── c_libs ├── stdperiph_stm32f4 │ ├── CMSIS │ │ ├── ST │ │ │ ├── stm32f405xx.h │ │ │ ├── stm32f407xx.h │ │ │ └── system_stm32f4xx.h │ │ └── include │ │ │ ├── arm_const_structs.h │ │ │ └── arm_common_tables.h │ └── inc │ │ ├── stm32f4xx_conf.h │ │ ├── stm32f4xx_wwdg.h │ │ ├── stm32f4_gpio_af.h │ │ └── stm32f4xx_iwdg.h ├── examples │ ├── extension │ │ ├── Makefile │ │ └── code.c │ ├── speed_test │ │ ├── Makefile │ │ ├── code.c │ │ └── README.md │ ├── ssd1306 │ │ ├── Makefile │ │ └── code.c │ ├── thread │ │ ├── Makefile │ │ └── code.c │ ├── custom_data_comm │ │ ├── Makefile │ │ ├── buffer.h │ │ ├── qml.qml │ │ ├── code.c │ │ └── buffer.c │ ├── ws2812 │ │ └── Makefile │ └── config │ │ ├── Makefile │ │ ├── conf │ │ ├── confxml.h │ │ ├── confparser.h │ │ ├── conf_general.h │ │ ├── buffer.h │ │ ├── datatypes.h │ │ └── buffer.c │ │ ├── datatypes.h │ │ └── code.c ├── conv.py ├── link.ld ├── utils │ ├── rb.h │ └── rb.c ├── rules.mk └── st_types.h ├── lib_disp_ui ├── disp_ui.lisp ├── Makefile ├── tests │ ├── test_text_c.lisp │ ├── test_text_l.lisp │ ├── test_button.lisp │ └── test_text_c_aa.lisp ├── symbols.lisp ├── gauges.lisp ├── button.lisp ├── README.md └── text.lisp ├── .gitignore ├── tnt ├── tnt │ ├── Makefile │ └── conf │ │ ├── confxml.h │ │ ├── confparser.h │ │ ├── conf_general.h │ │ ├── buffer.h │ │ ├── datatypes.h │ │ └── buffer.c ├── tnt.lisp ├── Makefile └── README.md ├── lib_pn532 ├── Makefile ├── examples │ └── mifare_read.lisp ├── pn532.lisp └── README.md ├── logui ├── Makefile └── README.md ├── lib_nau7802 ├── Makefile └── examples │ └── measure_torque.lisp ├── lib_code_server ├── Makefile ├── README.md └── code_server.lisp ├── balance ├── Makefile ├── README.md ├── balance │ ├── Makefile │ ├── conf │ │ ├── confparser.h │ │ ├── conf_general.h │ │ ├── buffer.h │ │ ├── datatypes.h │ │ └── buffer.c │ ├── .project │ └── datatypes.h └── balance.lisp ├── Makefile ├── res_all.qrc └── README.md /lib_ws2812/.gitignore: -------------------------------------------------------------------------------- 1 | ws2812/ws2812.lisp 2 | -------------------------------------------------------------------------------- /lib_midi/midi.lisp: -------------------------------------------------------------------------------- 1 | (import "midi/midi.bin" 'midi) 2 | -------------------------------------------------------------------------------- /lib_midi/.gitignore: -------------------------------------------------------------------------------- 1 | interpolation/interpolation.lisp 2 | -------------------------------------------------------------------------------- /float/.gitignore: -------------------------------------------------------------------------------- 1 | float/float.lisp 2 | README-pkg.md 3 | ui.qml 4 | -------------------------------------------------------------------------------- /lib_interpolation/.gitignore: -------------------------------------------------------------------------------- 1 | interpolation/interpolation.lisp 2 | -------------------------------------------------------------------------------- /lib_ws2812/ws2812.lisp: -------------------------------------------------------------------------------- 1 | (import "ws2812/ws2812.bin" 'ws2812) 2 | 3 | -------------------------------------------------------------------------------- /lib_interpolation/interpolation.lisp: -------------------------------------------------------------------------------- 1 | (import "interpolation/interpolation.bin" 'interpolation) 2 | -------------------------------------------------------------------------------- /lib_midi/axelf_base.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_midi/axelf_base.mid -------------------------------------------------------------------------------- /lib_midi/axelf_melody.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_midi/axelf_melody.mid -------------------------------------------------------------------------------- /lib_files/fonts/font_16_26.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_files/fonts/font_16_26.bin -------------------------------------------------------------------------------- /lib_files/other/axelf_base.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_files/other/axelf_base.mid -------------------------------------------------------------------------------- /lib_files/fonts/font_16_26_aa.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_files/fonts/font_16_26_aa.bin -------------------------------------------------------------------------------- /lib_files/other/axelf_melody.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_files/other/axelf_melody.mid -------------------------------------------------------------------------------- /lib_files/images/img_test_160_80.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_files/images/img_test_160_80.jpg -------------------------------------------------------------------------------- /lib_files/images/img_test_320_240.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_files/images/img_test_320_240.jpg -------------------------------------------------------------------------------- /lib_files/images/img_test_480_320.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/lib_files/images/img_test_480_320.jpg -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/CMSIS/ST/stm32f405xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/c_libs/stdperiph_stm32f4/CMSIS/ST/stm32f405xx.h -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/CMSIS/ST/stm32f407xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukash/vesc_pkg/HEAD/c_libs/stdperiph_stm32f4/CMSIS/ST/stm32f407xx.h -------------------------------------------------------------------------------- /lib_disp_ui/disp_ui.lisp: -------------------------------------------------------------------------------- 1 | (import "text.lisp" 'disp-text) 2 | (import "button.lisp" 'disp-button) 3 | (import "gauges.lisp" 'disp-gauges) 4 | 5 | -------------------------------------------------------------------------------- /c_libs/examples/extension/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = example 2 | 3 | SOURCES = code.c 4 | 5 | VESC_C_LIB_PATH=../../ 6 | include $(VESC_C_LIB_PATH)rules.mk 7 | 8 | -------------------------------------------------------------------------------- /c_libs/examples/speed_test/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = example 2 | 3 | SOURCES = code.c 4 | 5 | VESC_C_LIB_PATH=../../ 6 | include $(VESC_C_LIB_PATH)rules.mk 7 | 8 | -------------------------------------------------------------------------------- /c_libs/examples/ssd1306/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = ssdacc 2 | 3 | SOURCES = code.c 4 | 5 | VESC_C_LIB_PATH=../../ 6 | include $(VESC_C_LIB_PATH)/rules.mk 7 | 8 | -------------------------------------------------------------------------------- /c_libs/examples/thread/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = example 2 | 3 | SOURCES = code.c 4 | 5 | VESC_C_LIB_PATH=../../ 6 | include $(VESC_C_LIB_PATH)rules.mk 7 | 8 | -------------------------------------------------------------------------------- /lib_midi/midi/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = midi 2 | 3 | SOURCES = code.c midi-parser.c 4 | 5 | VESC_C_LIB_PATH=../../c_libs/ 6 | include $(VESC_C_LIB_PATH)rules.mk 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.list 2 | *.vescpkg 3 | confxml.c 4 | confxml.h 5 | 6 | *.elf 7 | *.o 8 | *.obj 9 | *.so 10 | *.rcc 11 | *.cproject 12 | *.project 13 | *.settings 14 | -------------------------------------------------------------------------------- /c_libs/examples/custom_data_comm/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = example 2 | 3 | SOURCES = code.c buffer.c 4 | 5 | VESC_C_LIB_PATH=../../ 6 | include $(VESC_C_LIB_PATH)rules.mk 7 | 8 | -------------------------------------------------------------------------------- /c_libs/examples/ws2812/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = ws2812 2 | 3 | SOURCES = code.c 4 | 5 | USE_STLIB = yes 6 | VESC_C_LIB_PATH=../../ 7 | include $(VESC_C_LIB_PATH)rules.mk 8 | 9 | -------------------------------------------------------------------------------- /lib_interpolation/interpolation/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = interpolation 2 | 3 | SOURCES = code.c 4 | 5 | VESC_C_LIB_PATH=../../c_libs/ 6 | include $(VESC_C_LIB_PATH)rules.mk 7 | 8 | -------------------------------------------------------------------------------- /lib_ws2812/ws2812/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = ws2812 2 | 3 | SOURCES = code.c 4 | 5 | USE_STLIB = yes 6 | VESC_C_LIB_PATH=../../c_libs/ 7 | include $(VESC_C_LIB_PATH)rules.mk 8 | 9 | -------------------------------------------------------------------------------- /tnt/tnt/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = tnt 2 | 3 | SOURCES = tnt.c conf/buffer.c conf/confparser.c conf/confxml.c 4 | 5 | VESC_C_LIB_PATH=../../c_libs/ 6 | include $(VESC_C_LIB_PATH)rules.mk 7 | 8 | -------------------------------------------------------------------------------- /c_libs/examples/config/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = config 2 | 3 | SOURCES = code.c conf/buffer.c conf/confparser.c conf/confxml.c 4 | 5 | VESC_C_LIB_PATH=../../ 6 | include $(VESC_C_LIB_PATH)rules.mk 7 | 8 | -------------------------------------------------------------------------------- /lib_files/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: files.vescpkg 4 | 5 | files.vescpkg: 6 | $(VESC_TOOL) --buildPkg "files.vescpkg:files.lisp::0:README.md:Files" 7 | 8 | clean: 9 | rm -f files.vescpkg 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /lib_pn532/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: pn532.vescpkg 4 | 5 | pn532.vescpkg: 6 | $(VESC_TOOL) --buildPkg "pn532.vescpkg:pn532.lisp::0:README.md:PN532" 7 | 8 | clean: 9 | rm -f pn532.vescpkg 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /logui/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: logui.vescpkg 4 | 5 | logui.vescpkg: 6 | $(VESC_TOOL) --buildPkg "logui.vescpkg:logger.lisp:ui.qml:0:README.md:LogUI" 7 | 8 | clean: 9 | rm -f logui.vescpkg 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /lib_disp_ui/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: disp_ui.vescpkg 4 | 5 | disp_ui.vescpkg: 6 | $(VESC_TOOL) --buildPkg "disp_ui.vescpkg:disp_ui.lisp::0:README.md:DispUI" 7 | 8 | clean: 9 | rm -f disp_ui.vescpkg 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /lib_nau7802/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: nau7802.vescpkg 4 | 5 | nau7802.vescpkg: 6 | $(VESC_TOOL) --buildPkg "nau7802.vescpkg:nau7802.lisp::0:README.md:NAU7802 Driver" 7 | 8 | clean: 9 | rm -f nau7802.vescpkg 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /lib_code_server/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: code_server.vescpkg 4 | 5 | code_server.vescpkg: 6 | $(VESC_TOOL) --buildPkg "code_server.vescpkg:code_server.lisp::0:README.md:Code Server" 7 | 8 | clean: 9 | rm -f code_server.vescpkg 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /lib_midi/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: midi.vescpkg 4 | 5 | midi.vescpkg: midi 6 | $(VESC_TOOL) --buildPkg "midi.vescpkg:midi.lisp::0:README.md:midi" 7 | 8 | midi: 9 | $(MAKE) -C $@ 10 | 11 | clean: 12 | rm -f midi.vescpkg 13 | $(MAKE) -C midi clean 14 | 15 | .PHONY: all clean midi 16 | -------------------------------------------------------------------------------- /lib_ws2812/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: ws2812.vescpkg 4 | 5 | ws2812.vescpkg: ws2812 6 | $(VESC_TOOL) --buildPkg "ws2812.vescpkg:ws2812.lisp::0:README.md:WS2812 Driver" 7 | 8 | ws2812: 9 | $(MAKE) -C $@ 10 | 11 | clean: 12 | rm -rf ws2812.vescpkg 13 | $(MAKE) -C ws2812 clean 14 | 15 | .PHONY: all clean ws2812 16 | -------------------------------------------------------------------------------- /balance/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: balance.vescpkg 4 | 5 | balance.vescpkg: balance 6 | $(VESC_TOOL) --buildPkg "balance.vescpkg:balance.lisp:ui.qml:0:README.md:Balance" 7 | 8 | balance: 9 | $(MAKE) -C $@ 10 | 11 | clean: 12 | rm -f balance.vescpkg 13 | $(MAKE) -C balance clean 14 | 15 | .PHONY: all clean balance 16 | -------------------------------------------------------------------------------- /lib_disp_ui/tests/test_text_c.lisp: -------------------------------------------------------------------------------- 1 | (import "pkg::font_16_26@://vesc_packages/lib_files/files.vescpkg" 'font) 2 | (import "../text.lisp" 'disp-text) 3 | 4 | (read-eval-program disp-text) 5 | 6 | (hw-init) 7 | 8 | (def img (img-buffer 'indexed2 200 200)) 9 | (txt-block-c img 1 100 100 font '("First Line" "Line 2")) 10 | 11 | (disp-render img 0 0 '(0 0xFF0000)) 12 | -------------------------------------------------------------------------------- /lib_disp_ui/tests/test_text_l.lisp: -------------------------------------------------------------------------------- 1 | (import "pkg::font_16_26@://vesc_packages/lib_files/files.vescpkg" 'font) 2 | (import "../text.lisp" 'disp-text) 3 | 4 | (read-eval-program disp-text) 5 | 6 | (hw-init) 7 | 8 | (def img (img-buffer 'indexed2 200 200)) 9 | (txt-block-l img 1 20 20 font '("First Line" "Line 2")) 10 | 11 | (disp-render img 0 0 '(0 0xFF0000)) 12 | -------------------------------------------------------------------------------- /tnt/tnt/conf/confxml.h: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by VESC Tool 2 | 3 | #ifndef CONFXML_H_ 4 | #define CONFXML_H_ 5 | 6 | #include "datatypes.h" 7 | #include 8 | #include 9 | 10 | // Constants 11 | #define DATA_TNT_CONFIG__SIZE 16231 12 | 13 | // Variables 14 | extern uint8_t data_tnt_config_[]; 15 | 16 | // CONFXML_H_ 17 | #endif 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PKGS = balance float tnt lib_files lib_interpolation lib_nau7802 lib_pn532 2 | PKGS += lib_ws2812 logui lib_code_server lib_midi lib_disp_ui 3 | 4 | all: vesc_pkg_all.rcc 5 | 6 | vesc_pkg_all.rcc: $(PKGS) 7 | rcc -binary res_all.qrc -o vesc_pkg_all.rcc 8 | 9 | clean: $(PKGS) 10 | 11 | $(PKGS): 12 | $(MAKE) -C $@ $(MAKECMDGOALS) 13 | 14 | .PHONY: all clean $(PKGS) 15 | -------------------------------------------------------------------------------- /c_libs/examples/config/conf/confxml.h: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by VESC Tool 2 | 3 | #ifndef CONFXML_H_ 4 | #define CONFXML_H_ 5 | 6 | #include "datatypes.h" 7 | #include 8 | #include 9 | 10 | // Constants 11 | #define DATA_BALANCE_CONFIG__SIZE 6723 12 | 13 | // Variables 14 | extern uint8_t data_balance_config_[]; 15 | 16 | // CONFXML_H_ 17 | #endif 18 | -------------------------------------------------------------------------------- /lib_interpolation/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: interpolation.vescpkg 4 | 5 | interpolation.vescpkg: interpolation 6 | $(VESC_TOOL) --buildPkg "interpolation.vescpkg:interpolation.lisp::0:README.md:Interpolation" 7 | 8 | interpolation: 9 | $(MAKE) -C $@ 10 | 11 | clean: 12 | rm -f interpolation.vescpkg 13 | $(MAKE) -C interpolation clean 14 | 15 | .PHONY: all clean interpolation 16 | -------------------------------------------------------------------------------- /lib_files/files.lisp: -------------------------------------------------------------------------------- 1 | (import "fonts/font_16_26.bin" 'font_16_26) 2 | (import "fonts/font_16_26_aa.bin" 'font_16_26_aa) 3 | 4 | (import "images/img_test_160_80.jpg" 'jpg_test_160_80) 5 | (import "images/img_test_320_240.jpg" 'jpg_test_320_240) 6 | (import "images/img_test_480_320.jpg" 'jpg_test_480_320) 7 | 8 | (import "other/axelf_base.mid" 'midi_axelf_base) 9 | (import "other/axelf_melody.mid" 'midi_axelf_melody) 10 | 11 | -------------------------------------------------------------------------------- /float/float/konami.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "footpad_sensor.h" 4 | 5 | typedef struct { 6 | float time; 7 | uint8_t state; 8 | const FootpadSensorState *sequence; 9 | uint8_t sequence_size; 10 | } Konami; 11 | 12 | void konami_init(Konami *konami, const FootpadSensorState *sequence, uint8_t sequence_size); 13 | 14 | bool konami_check(Konami *konami, const FootpadSensor *fs, const float_config *config, float current_time); 15 | -------------------------------------------------------------------------------- /balance/README.md: -------------------------------------------------------------------------------- 1 | # BALANCE v0.0.3 2 | 3 | Balance package. This is a first attempt based on the balance app just to get started. It compiles and loads, but is completely untested. All settings are there and there is also a QML-file that can be extended. 4 | 5 | Most things should be similar to the regular balance app, except some of the time measurements as they are mostly based on seconds now. If there are problems when testing I would check the time measurements first. 6 | -------------------------------------------------------------------------------- /balance/balance/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | TARGET = balance 4 | 5 | SOURCES = balance.c conf/buffer.c conf/confparser.c conf/confxml.c 6 | 7 | ADD_TO_CLEAN = conf/confxml.h conf/confxml.c 8 | 9 | VESC_C_LIB_PATH=../../c_libs/ 10 | include $(VESC_C_LIB_PATH)rules.mk 11 | 12 | balance.c: conf/confparser.h conf/confxml.h 13 | 14 | conf/confparser.h conf/confxml.h conf/confxml.c &: conf/settings.xml 15 | $(VESC_TOOL) --xmlConfToCode conf/settings.xml 16 | -------------------------------------------------------------------------------- /lib_disp_ui/symbols.lisp: -------------------------------------------------------------------------------- 1 | @const-start 2 | 3 | ; Power Symbol 4 | (defun sym-pwr (img col cx cy rad fill) { 5 | (setq fill (m-trunc fill 0.0 1.0)) 6 | (var attr (list 'thickness (* rad 0.2))) 7 | (var attr2 (list 'thickness (* rad 0.1))) 8 | (img-arc img cx (+ cy (* rad 0.2)) (* rad 0.8) (+ -50 (* fill 260)) -130 col attr '(rounded)) 9 | (img-line img cx cy cx (- cy (* 0.5 rad)) col attr2 '(rounded)) 10 | }) 11 | 12 | @const-end 13 | -------------------------------------------------------------------------------- /balance/balance.lisp: -------------------------------------------------------------------------------- 1 | (import "balance/balance.bin" 'balancelib) 2 | 3 | (load-native-lib balancelib) 4 | 5 | ; Set to 1 to monitor some debug variables using the extension ext-euc-dbg 6 | (define debug 1) 7 | 8 | (if (= debug 1) 9 | (loopwhile t 10 | (progn 11 | (define setpoint (ext-balance-dbg 2)) 12 | (define tt-filtered-current (ext-balance-dbg 3)) 13 | (define integral (ext-balance-dbg 14)) 14 | (sleep 0.1) 15 | ))) 16 | -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/inc/stm32f4xx_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __STM32F4xx_CONF_H 2 | #define __STM32F4xx_CONF_H 3 | 4 | #define USE_RTOS 0 5 | 6 | #include "misc.h" 7 | #include "stm32f4_gpio_af.h" 8 | #include "stm32f4xx_dma.h" 9 | #include "stm32f4xx_adc.h" 10 | #include "stm32f4xx_exti.h" 11 | #include "stm32f4xx_flash.h" 12 | #include "stm32f4xx_rcc.h" 13 | #include "stm32f4xx_syscfg.h" 14 | #include "stm32f4xx_tim.h" 15 | #include "stm32f4xx_wwdg.h" 16 | #include "stm32f4xx_iwdg.h" 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /lib_disp_ui/tests/test_button.lisp: -------------------------------------------------------------------------------- 1 | (import "pkg::font_16_26@://vesc_packages/lib_files/files.vescpkg" 'font) 2 | (import "../text.lisp" 'disp-text) 3 | (import "../button.lisp" 'disp-button) 4 | 5 | (read-eval-program disp-text) 6 | (read-eval-program disp-button) 7 | 8 | (hw-init) 9 | 10 | (def img (img-buffer 'indexed4 200 200)) 11 | 12 | (btn-simple img 2 1 20 20 100 50 font "Test") 13 | (btn-simple img 2 1 20 90 120 70 font '("Line 1" "Line 2")) 14 | 15 | (disp-render img 0 0 '(0 0xFF0000 0x003400)) 16 | -------------------------------------------------------------------------------- /float/float/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | TARGET = float 4 | 5 | SOURCES = float.c footpad_sensor.c konami.c led.c conf/buffer.c conf/confparser.c conf/confxml.c 6 | 7 | ADD_TO_CLEAN = conf/confxml.h conf/confxml.c 8 | 9 | USE_STLIB = yes 10 | VESC_C_LIB_PATH = ../../c_libs/ 11 | include $(VESC_C_LIB_PATH)rules.mk 12 | 13 | float.c: led.h conf/confparser.h conf/confxml.h 14 | 15 | conf/confparser.h conf/confxml.h conf/confxml.c &: conf/settings.xml 16 | $(VESC_TOOL) --xmlConfToCode conf/settings.xml 17 | -------------------------------------------------------------------------------- /lib_disp_ui/tests/test_text_c_aa.lisp: -------------------------------------------------------------------------------- 1 | (import "pkg::font_16_26@://vesc_packages/lib_files/files.vescpkg" 'font) 2 | (import "pkg::font_16_26_aa@://vesc_packages/lib_files/files.vescpkg" 'font_aa) 3 | 4 | (import "../text.lisp" 'disp-text) 5 | 6 | (read-eval-program disp-text) 7 | 8 | (hw-init) 9 | 10 | (def img (img-buffer 'indexed4 200 200)) 11 | (txt-block-c img 3 100 40 font '("Antialiasing" "Disabled")) 12 | (txt-block-c img '(0 1 2 3) 100 100 font_aa '("Antialiasing" "Enabled")) 13 | 14 | (disp-render img 0 0 '(0 0x550000 0xAA0000 0xFF0000)) 15 | -------------------------------------------------------------------------------- /tnt/tnt/conf/confparser.h: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by VESC Tool 2 | 3 | #ifndef CONFPARSER_H_ 4 | #define CONFPARSER_H_ 5 | 6 | #include "datatypes.h" 7 | #include 8 | #include 9 | 10 | // Constants 11 | #define TNT_CONFIG_SIGNATURE 462520272 12 | 13 | // Functions 14 | int32_t confparser_serialize_tnt_config(uint8_t *buffer, const tnt_config *conf); 15 | bool confparser_deserialize_tnt_config(const uint8_t *buffer, tnt_config *conf); 16 | void confparser_set_defaults_tnt_config(tnt_config *conf); 17 | 18 | // CONFPARSER_H_ 19 | #endif 20 | -------------------------------------------------------------------------------- /float/float/conf/confparser.h: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by VESC Tool 2 | 3 | #ifndef CONFPARSER_H_ 4 | #define CONFPARSER_H_ 5 | 6 | #include "datatypes.h" 7 | #include 8 | #include 9 | 10 | // Constants 11 | #define FLOAT_CONFIG_SIGNATURE 3424349568 12 | 13 | // Functions 14 | int32_t confparser_serialize_float_config(uint8_t *buffer, const float_config *conf); 15 | bool confparser_deserialize_float_config(const uint8_t *buffer, float_config *conf); 16 | void confparser_set_defaults_float_config(float_config *conf); 17 | 18 | // CONFPARSER_H_ 19 | #endif 20 | -------------------------------------------------------------------------------- /float/float/footpad_sensor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "conf/datatypes.h" 4 | 5 | typedef enum { 6 | FS_NONE = 0, 7 | FS_LEFT = 1, 8 | FS_RIGHT = 2, 9 | FS_BOTH = 3 10 | } FootpadSensorState; 11 | 12 | typedef struct { 13 | float adc1, adc2; 14 | FootpadSensorState state; 15 | } FootpadSensor; 16 | 17 | FootpadSensorState footpad_sensor_state_evaluate(const FootpadSensor *fs, const float_config *config, bool handpress); 18 | 19 | void footpad_sensor_update(FootpadSensor *fs, const float_config *config); 20 | 21 | int footpad_sensor_state_to_switch_compat(FootpadSensorState v); 22 | -------------------------------------------------------------------------------- /lib_disp_ui/gauges.lisp: -------------------------------------------------------------------------------- 1 | @const-start 2 | 3 | (defun m-trunc (v min max) 4 | (cond 5 | ((< v min) min) 6 | ((> v max) max) 7 | (t v) 8 | )) 9 | 10 | ; Round Gauge 11 | (defun gauge-simple (img col-bg col-bar col-txt cx cy rad val font txt) { 12 | (setq val (m-trunc val 0.0 1.0)) 13 | (var attr (list 'thickness (* rad 0.2))) 14 | (img-arc img cx cy rad 120 60 col-bg attr '(rounded)) 15 | (img-arc img cx cy rad 120 (+ 120 (* val 300.0)) col-bar attr '(rounded)) 16 | (txt-block-c img col-txt cx cy font txt) 17 | }) 18 | 19 | @const-end 20 | -------------------------------------------------------------------------------- /balance/balance/conf/confparser.h: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by VESC Tool 2 | 3 | #ifndef CONFPARSER_H_ 4 | #define CONFPARSER_H_ 5 | 6 | #include "datatypes.h" 7 | #include 8 | #include 9 | 10 | // Constants 11 | #define BALANCE_CONFIG_SIGNATURE 4098546538 12 | 13 | // Functions 14 | int32_t confparser_serialize_balance_config(uint8_t *buffer, const balance_config *conf); 15 | bool confparser_deserialize_balance_config(const uint8_t *buffer, balance_config *conf); 16 | void confparser_set_defaults_balance_config(balance_config *conf); 17 | 18 | // CONFPARSER_H_ 19 | #endif 20 | -------------------------------------------------------------------------------- /c_libs/examples/config/conf/confparser.h: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by VESC Tool 2 | 3 | #ifndef CONFPARSER_H_ 4 | #define CONFPARSER_H_ 5 | 6 | #include "datatypes.h" 7 | #include 8 | #include 9 | 10 | // Constants 11 | #define BALANCE_CONFIG_SIGNATURE 32903057 12 | 13 | // Functions 14 | int32_t confparser_serialize_balance_config(uint8_t *buffer, const balance_config *conf); 15 | bool confparser_deserialize_balance_config(const uint8_t *buffer, balance_config *conf); 16 | void confparser_set_defaults_balance_config(balance_config *conf); 17 | 18 | // CONFPARSER_H_ 19 | #endif 20 | -------------------------------------------------------------------------------- /tnt/tnt.lisp: -------------------------------------------------------------------------------- 1 | (import "tnt/tnt.bin" 'tntlib) 2 | 3 | (load-native-lib tntlib) 4 | 5 | ; Switch Balance App to UART App 6 | (if (= (conf-get 'app-to-use) 9) (conf-set 'app-to-use 3)) 7 | 8 | ; Set firmware version: 9 | (apply ext-set-fw-version (sysinfo 'fw-ver)) 10 | 11 | ; Set to 1 to monitor some debug variables using the extension ext-euc-dbg 12 | (define debug 1) 13 | 14 | (if (= debug 1) 15 | (loopwhile t 16 | (progn 17 | (define setpoint (ext-tnt-dbg 2)) 18 | (define tt-filtered-current (ext-tnt-dbg 3)) 19 | (define integral (ext-tnt-dbg 14)) 20 | (sleep 0.1) 21 | ))) 22 | -------------------------------------------------------------------------------- /float/float.lisp: -------------------------------------------------------------------------------- 1 | (import "float/float.bin" 'floatlib) 2 | 3 | (load-native-lib floatlib) 4 | 5 | ; Switch Balance App to UART App 6 | (if (= (conf-get 'app-to-use) 9) (conf-set 'app-to-use 3)) 7 | 8 | ; Set firmware version: 9 | (apply ext-set-fw-version (sysinfo 'fw-ver)) 10 | 11 | ; Set to 1 to monitor some debug variables using the extension ext-euc-dbg 12 | (define debug 1) 13 | 14 | (if (= debug 1) 15 | (loopwhile t 16 | (progn 17 | (apply ext-set-batt-level (get-batt)) 18 | (define setpoint (ext-float-dbg 2)) 19 | (define tt-filtered-current (ext-float-dbg 3)) 20 | (define integral (ext-float-dbg 14)) 21 | (sleep 0.1) 22 | ))) 23 | -------------------------------------------------------------------------------- /res_all.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | balance/balance.vescpkg 5 | float/float.vescpkg 6 | logui/logui.vescpkg 7 | tnt/tnt.vescpkg 8 | lib_ws2812/ws2812.vescpkg 9 | lib_nau7802/nau7802.vescpkg 10 | lib_interpolation/interpolation.vescpkg 11 | lib_files/files.vescpkg 12 | lib_pn532/pn532.vescpkg 13 | lib_code_server/code_server.vescpkg 14 | lib_midi/midi.vescpkg 15 | lib_disp_ui/disp_ui.vescpkg 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /c_libs/conv.py: -------------------------------------------------------------------------------- 1 | import sys,getopt,binascii 2 | 3 | filename = "" 4 | name = "test" 5 | 6 | opts,args = getopt.getopt(sys.argv[1:],'f:n:') 7 | for o,a in opts: 8 | if o == '-f': 9 | filename = a 10 | if o == '-n': 11 | name = a 12 | 13 | with open(filename, "rb") as f: 14 | hexdata = f.read().hex() 15 | tokens = [hexdata[i:i+2] for i in range(0, len(hexdata), 2)] 16 | res = "(def " + name + " [\n" 17 | cnt = 0 18 | for c in tokens: 19 | res += "0x" + c 20 | cnt = cnt + 1 21 | if cnt == 20: 22 | cnt = 0 23 | res += "\n" 24 | else: 25 | res += " " 26 | 27 | if res[-1] == '\n': 28 | res += "])\n" 29 | else: 30 | res += "\n])\n" 31 | print(res) 32 | 33 | -------------------------------------------------------------------------------- /tnt/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: clean tnt.vescpkg 4 | 5 | tnt.vescpkg: tnt README-pkg.md ui.qml 6 | $(VESC_TOOL) --buildPkg "tnt.vescpkg:tnt.lisp:ui.qml:0:README-pkg.md:Trick and Trail" 7 | 8 | tnt: 9 | $(MAKE) -C $@ 10 | 11 | VERSION=`grep APPCONF_TNT_VERSION tnt/conf/settings.xml -A10 | grep valDouble | tr -dc '[.[:digit:]]'` 12 | 13 | README-pkg.md: README.md 14 | cp README.md README-pkg.md 15 | echo "- Version: ${VERSION}" >> README-pkg.md 16 | echo "- Build Date: `date --rfc-3339=seconds`" >> README-pkg.md 17 | echo "- Git Commit: #`git rev-parse --short HEAD`" >> README-pkg.md 18 | 19 | ui.qml: ui.qml.in 20 | cat ui.qml.in | sed "s/{{VERSION}}/${VERSION}/g" > ui.qml 21 | 22 | clean: 23 | rm -f tnt.vescpkg README-pkg.md ui.qml 24 | $(MAKE) -C tnt clean 25 | 26 | .PHONY: all clean tnt 27 | -------------------------------------------------------------------------------- /lib_disp_ui/button.lisp: -------------------------------------------------------------------------------- 1 | @const-start 2 | 3 | (defun m-trunc (v min max) 4 | (cond 5 | ((< v min) min) 6 | ((> v max) max) 7 | (t v) 8 | )) 9 | 10 | ; Button 11 | (defun btn-simple (img col-bg col-txt ofs-x ofs-y w h font txt) { 12 | (img-rectangle img ofs-x ofs-y w h col-bg '(rounded 10) '(filled)) 13 | (txt-block-c img col-txt (+ ofs-x (* w 0.5 )) (+ ofs-y (* h 0.5 )) font txt) 14 | }) 15 | 16 | ; Button with bar 17 | (defun btn-bar (img col-bg col-txt val ofs-x ofs-y w h font txt) { 18 | (setq val (m-trunc val 0.0 1.0)) 19 | (var w1 (m-trunc (* w (- 1.0 val)) 20 100)) 20 | (img-rectangle img ofs-x ofs-y w1 h col-bg '(rounded 10) '(filled)) 21 | (txt-block-c img col-txt (+ ofs-x (* w 0.5 )) (+ ofs-y (* h 0.5 )) font txt) 22 | }) 23 | 24 | @const-end 25 | -------------------------------------------------------------------------------- /float/Makefile: -------------------------------------------------------------------------------- 1 | VESC_TOOL ?= vesc_tool 2 | 3 | all: clean float.vescpkg 4 | 5 | float.vescpkg: float README-pkg.md ui.qml 6 | $(VESC_TOOL) --buildPkg "float.vescpkg:float.lisp:ui.qml:0:README-pkg.md:Float" 7 | 8 | float: 9 | $(MAKE) -C $@ 10 | 11 | VERSION=`grep APPCONF_FLOAT_VERSION float/conf/settings.xml -A10 | grep valDouble | tr -dc '[.[:digit:]]'` 12 | 13 | README-pkg.md: README.md 14 | cp README.md README-pkg.md 15 | echo "- Version: ${VERSION}" >> README-pkg.md 16 | echo "- Build Date: `date --rfc-3339=seconds`" >> README-pkg.md 17 | echo "- Git Commit: #`git rev-parse --short HEAD`" >> README-pkg.md 18 | 19 | ui.qml: ui.qml.in 20 | cat ui.qml.in | sed "s/{{VERSION}}/${VERSION}/g" > ui.qml 21 | 22 | clean: 23 | rm -f float.vescpkg README-pkg.md ui.qml 24 | $(MAKE) -C float clean 25 | 26 | .PHONY: all clean float 27 | -------------------------------------------------------------------------------- /lib_files/README.md: -------------------------------------------------------------------------------- 1 | # Files 2 | 3 | This library contains various files that can be used in packages for convenience, such as fonts and images. 4 | 5 | ```clj 6 | ; Fonts 7 | (import "pkg::font_16_26@://vesc_packages/lib_files/files.vescpkg" 'font_16_26) 8 | 9 | ; Anti-aliased fonts 10 | (import "pkg::font_16_26_aa@://vesc_packages/lib_files/files.vescpkg" 'font_16_26_aa) 11 | 12 | ; Images 13 | (import "pkg::jpg_test_160_80@://vesc_packages/lib_files/files.vescpkg" 'jpg_test_160_80) 14 | (import "pkg::jpg_test_320_240@://vesc_packages/lib_files/files.vescpkg" 'jpg_test_320_240) 15 | (import "pkg::jpg_test_480_320@://vesc_packages/lib_files/files.vescpkg" 'jpg_test_480_320) 16 | 17 | ; Midi Files 18 | (import "pkg::midi_axelf_base@://vesc_packages/lib_files/files.vescpkg" 'midi_axelf_base) 19 | (import "pkg::midi_axelf_melody@://vesc_packages/lib_files/files.vescpkg" 'midi_axelf_melody) 20 | ``` -------------------------------------------------------------------------------- /float/float/led.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOATLED_H_ 2 | #define FLOATLED_H_ 3 | 4 | #include "conf/datatypes.h" 5 | 6 | typedef enum { 7 | LED_Type_None, 8 | LED_Type_RGB, 9 | LED_Type_RGBW, 10 | LED_Type_External_Module, 11 | } LEDType; 12 | 13 | typedef struct { 14 | float led_last_updated; 15 | uint8_t led_previous_brightness; 16 | bool led_latching_direction; 17 | uint8_t led_type; 18 | uint8_t led_status_count; 19 | uint8_t led_forward_count; 20 | uint8_t led_rear_count; 21 | int ledbuf_len; 22 | int bitbuf_len; 23 | uint16_t* bitbuffer; 24 | uint32_t* RGBdata; 25 | } LEDData; 26 | 27 | void led_init(LEDData* led_data, float_config* float_conf); 28 | void led_update(LEDData* led_data, float_config* float_conf, float current_time, float erpm, float abs_duty_cycle, int switch_state, int float_state); 29 | void led_stop(LEDData* led_data); 30 | 31 | #endif /* FLOATLED_H_ */ 32 | -------------------------------------------------------------------------------- /c_libs/link.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | MEM : org = 0, len = 64k 4 | } 5 | 6 | SECTIONS 7 | { 8 | . = 0; 9 | _text = .; 10 | 11 | .program_ptr : ALIGN(4) 12 | { 13 | . = ALIGN(4); 14 | *(.program_ptr) 15 | } > MEM 16 | 17 | .init_fun : ALIGN(4) 18 | { 19 | . = ALIGN(4); 20 | *(.init_fun) 21 | } > MEM 22 | 23 | .data : ALIGN(4) 24 | { 25 | . = ALIGN(4); 26 | *(.data) 27 | } > MEM 28 | 29 | .bss : ALIGN(4) 30 | { 31 | . = ALIGN(4); 32 | *(.bss) 33 | } > MEM 34 | 35 | .got : ALIGN(4) 36 | { 37 | . = ALIGN(4); 38 | *(.got*) 39 | . = ALIGN(4); 40 | } > MEM 41 | 42 | .text : ALIGN(16) SUBALIGN(16) 43 | { 44 | *(.text) 45 | *(.rodata) 46 | *(.rodata.*) 47 | } > MEM 48 | } 49 | 50 | -------------------------------------------------------------------------------- /float/float/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | euc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /balance/balance/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | euc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /lib_interpolation/interpolation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | interpolation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /tnt/tnt/conf/conf_general.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CONF_GENERAL_H_ 21 | #define CONF_GENERAL_H_ 22 | 23 | #include "conf_default.h" 24 | 25 | // CONF_GENERAL_H_ 26 | #endif 27 | -------------------------------------------------------------------------------- /float/float/conf/conf_general.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CONF_GENERAL_H_ 21 | #define CONF_GENERAL_H_ 22 | 23 | #include "conf_default.h" 24 | 25 | // CONF_GENERAL_H_ 26 | #endif 27 | -------------------------------------------------------------------------------- /balance/balance/conf/conf_general.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CONF_GENERAL_H_ 21 | #define CONF_GENERAL_H_ 22 | 23 | #include "conf_default.h" 24 | 25 | // CONF_GENERAL_H_ 26 | #endif 27 | -------------------------------------------------------------------------------- /c_libs/examples/config/conf/conf_general.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CONF_GENERAL_H_ 21 | #define CONF_GENERAL_H_ 22 | 23 | #include "conf_default.h" 24 | 25 | // CONF_GENERAL_H_ 26 | #endif 27 | -------------------------------------------------------------------------------- /float/float/konami.c: -------------------------------------------------------------------------------- 1 | #include "konami.h" 2 | 3 | void konami_init(Konami *konami, const FootpadSensorState *sequence, uint8_t sequence_size) { 4 | konami->time = 0; 5 | konami->state = 0; 6 | konami->sequence = sequence; 7 | konami->sequence_size = sequence_size; 8 | } 9 | 10 | static void konami_reset(Konami *konami) { 11 | konami->time = 0; 12 | konami->state = 0; 13 | } 14 | 15 | bool konami_check(Konami *konami, const FootpadSensor *fs, const float_config *config, float current_time) { 16 | if (konami->time > 0 && current_time - konami->time > 0.5) { 17 | konami_reset(konami); 18 | return false; 19 | } 20 | 21 | FootpadSensorState fs_state = footpad_sensor_state_evaluate(fs, config, true); 22 | if (fs_state == konami->sequence[konami->state]) { 23 | ++konami->state; 24 | if (konami->state == konami->sequence_size) { 25 | konami_reset(konami); 26 | return true; 27 | } 28 | 29 | konami->time = current_time; 30 | } else if (konami->state > 0 && fs_state != konami->sequence[konami->state - 1]) { 31 | konami_reset(konami); 32 | } 33 | 34 | return false; 35 | } 36 | -------------------------------------------------------------------------------- /lib_midi/midi/README.md: -------------------------------------------------------------------------------- 1 | 2 | # midi-parser 3 | 4 | This repository contains a simple midi parser 5 | which is [free software](LICENSE.md). 6 | It should be able to parse most `.midi` files out there. 7 | Since the parser returns a stream of events (see [the 8 | midi dump example](example/midi-dump.c)), it works without 9 | any runtime allocation. 10 | 11 | The parser has no dependencies, and supports most platforms 12 | due to its simple code and no use of file I/O. 13 | 14 | 15 | ## Use in your project 16 | 17 | You can build midi-parser via `cmake . && make`. 18 | 19 | Alternatively, to build midi-parser as part of your program, 20 | add `src/midi-parser.c` to your project's 21 | object files, and the `include/` folder to your include path. 22 | (For Visual Studio, you'll find the required fields in your 23 | project settings.) 24 | 25 | Example using gcc, assuming this repository is at `path-to-midi-parser`: 26 | 27 | ``` 28 | $ gcc -o myprogram my_own_code.c path-to-midi-parser/src/midi-parser.c -Ipath-to-midi-parser/include 29 | ``` 30 | 31 | 32 | ## Demo 33 | 34 | Running `cmake . && make` will also build the `example/mini-dump.c` demo 35 | as `midi-dump` executable. 36 | 37 | You can then use `./midi-dump mymidifile.mid` on any midi file to test. 38 | 39 | -------------------------------------------------------------------------------- /c_libs/examples/extension/code.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "vesc_c_if.h" 21 | 22 | HEADER 23 | 24 | static lbm_value ext_test(lbm_value *args, lbm_uint argn) { 25 | if (argn != 1 || !VESC_IF->lbm_is_number(args[0])) { 26 | return VESC_IF->lbm_enc_sym_eerror; 27 | } 28 | 29 | return VESC_IF->lbm_enc_i(VESC_IF->lbm_dec_as_i32(args[0]) * 3); 30 | } 31 | 32 | INIT_FUN(lib_info *info) { 33 | INIT_START 34 | 35 | (void)info; 36 | VESC_IF->lbm_add_extension("ext-test", ext_test); 37 | return true; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /lib_code_server/README.md: -------------------------------------------------------------------------------- 1 | # Code Server 2 | 3 | This library can be used for remote code execution over CAN-bus. The result of the code is sent back to the sender and a timeout can also be specified. This library requires firmware 6.05 or later. 4 | 5 | ## Functions 6 | 7 | ### start-code-server 8 | 9 | ```clj 10 | (start-code-server) 11 | ``` 12 | 13 | Start code server on local device. Note that a CAN-device can be a client and a server at the same time. 14 | 15 | ### rcode-run 16 | 17 | ```clj 18 | (rcode-run id tout code) 19 | ``` 20 | 21 | Run code on CAN-device with id. A timeout in seconds can be specified, which makes this function return the symbol timeout if the CAN-device does not respond. Note that start-code-server has to be used on the CAN-device for it to respond. Also note that the symbol eerror is returned if the code results in an error on the server. 22 | 23 | ### rcode-run-noret 24 | 25 | ```clj 26 | (rcode-run-noret id code) 27 | ``` 28 | 29 | Same as above, but does not wait for a response (fire and forget). 30 | 31 | ## Example 32 | 33 | ### Server 34 | 35 | ```clj 36 | (import "pkg@://vesc_packages/lib_code_server/code_server.vescpkg" 'code-server) 37 | (read-eval-program code-server) 38 | 39 | (start-code-server) 40 | ``` 41 | 42 | ### Client 43 | 44 | ```clj 45 | (import "pkg@://vesc_packages/lib_code_server/code_server.vescpkg" 'code-server) 46 | (read-eval-program code-server) 47 | 48 | ; Assume server has CAN-ID 26 49 | (print (list "Input Voltage" (rcode-run 26 0.5 '(get-vin)))) 50 | ``` 51 | -------------------------------------------------------------------------------- /lib_disp_ui/README.md: -------------------------------------------------------------------------------- 1 | # Display UI Library 2 | 3 | Work-in-progress high-level UI library for the VESC Express display driver. 4 | 5 | ## Text Module 6 | 7 | The text module is self-contained and is imported as follows: 8 | 9 | ```clj 10 | (import "pkg::disp-text@://vesc_packages/lib_disp_ui/disp_ui.vescpkg" 'disp-text) 11 | 12 | (read-eval-program disp-text) 13 | ``` 14 | 15 | ### txt-block-c 16 | 17 | ```clj 18 | (txt-block-c img col cx cy font txt) 19 | ``` 20 | 21 | Create centered text block. Arguments: 22 | 23 | | **Name** | **Description** | 24 | |----------|------------| 25 | | img | Image Buffer | 26 | | col | Color | 27 | | cx | Center X | 28 | | cy | Center Y | 29 | | font | Font to use | 30 | | text | Text. Can be a single string or a list of strings. | 31 | 32 | Example: 33 | 34 | ```clj 35 | (import "pkg::disp-text@://vesc_packages/lib_disp_ui/disp_ui.vescpkg" 'disp-text) 36 | (import "pkg::font_16_26@://vesc_packages/lib_files/files.vescpkg" 'font) 37 | (read-eval-program disp-text) 38 | 39 | (def img (img-buffer 'indexed2 200 200)) 40 | (txt-block-c img 1 100 100 font '("First Line" "Another Line")) 41 | ``` 42 | 43 | ## Button Module 44 | 45 | Create buttons. Depends on the text module. 46 | 47 | ```clj 48 | (import "pkg::disp-text@://vesc_packages/lib_disp_ui/disp_ui.vescpkg" 'disp-text) 49 | (import "pkg::disp-button@://vesc_packages/lib_disp_ui/disp_ui.vescpkg" 'disp-button) 50 | 51 | (read-eval-program disp-text) 52 | (read-eval-program disp-button) 53 | ``` 54 | 55 | ## Symbol Module 56 | 57 | Create various symbols. This module is self-contained. 58 | 59 | ## Gauge Module 60 | 61 | Create gauges. Depends on the text module. 62 | -------------------------------------------------------------------------------- /float/README.md: -------------------------------------------------------------------------------- 1 | # FLOAT PACKAGE 2 | 3 | A balance vehicle package specifically tailored for one wheeled skateboards, as invented by Ben Smither in 2007: http://www.robosys.co.uk/ 4 | 5 | Includes all the basics such as PID control, ATR, and Turntilt - but also has popular features such as remote support, dirty landings, push start, and many more. See help text in the tool/app for details on any feature. 6 | 7 | Now includes Quicksaves in the AppUI! 8 | 9 |

NEW USERS: DO NOT LOAD UNTIL YOU'VE CONFIGURED MOTOR AND IMU!!!

10 | 11 | After loading do not forget to configure your details in the Specs tab: voltages and ADC values (default assumes 15s pack and 3.0V ADC cutoffs). 12 | 13 | Once you've adjusted your voltages the default tune should provide you with a well behaving, rideable board. If it acts weird it's most likely a motor configuration or IMU calibration issue! 14 | 15 |

DISCLAIMER

16 | 17 | This package is not endorsed by the vesc-project. Use at your own risk. 18 | 19 |

CREDITS

20 | 21 | Based on Mitch Lustig's original Balance Package, but specifically tailored for one wheeled skateboards. 22 | 23 | Ported by Nico Aleman, heavily based on SurfDado's ATR Firmware: https://pev.dev/t/atr-firmware-101/43 24 | 25 | Removed unneeded parameters, added new features and behaviors and a more user-friendly configuration menu with usable default/min/max values and informative Help text. 26 | 27 |

RELEASE NOTES

28 | 29 | Release Changelogs: https://pev.dev/t/float-package-changelogs/499 30 | 31 |

BUILD INFO

32 | 33 | Source code can be found here: https://github.com/NicoAleman/vesc_pkg-float 34 | 35 | ####   36 | #### Build Info 37 | -------------------------------------------------------------------------------- /c_libs/utils/rb.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef RB_H_ 21 | #define RB_H_ 22 | 23 | #include 24 | #include 25 | #include "vesc_c_if.h" 26 | 27 | typedef struct { 28 | void *data; 29 | unsigned int head; 30 | unsigned int tail; 31 | unsigned int item_size; 32 | unsigned int item_count; 33 | lib_mutex mutex; 34 | bool full; 35 | } rb_t; 36 | 37 | void rb_init(rb_t *rb, void *buffer, int item_size, int item_count); 38 | void rb_init_alloc(rb_t *rb, int item_size, int item_count); 39 | void rb_free(rb_t *rb); 40 | void rb_flush(rb_t *rb); 41 | bool rb_insert(rb_t *rb, const void *data); 42 | unsigned int rb_insert_multi(rb_t *rb, const void *data, unsigned int count); 43 | bool rb_pop(rb_t *rb, void *data); 44 | unsigned int rb_pop_multi(rb_t *rb, void *data, unsigned int count); 45 | bool rb_is_full(rb_t *rb); 46 | bool rb_is_empty(rb_t *rb); 47 | unsigned int rb_get_item_count(rb_t *rb); 48 | unsigned int rb_get_free_space(rb_t *rb); 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /c_libs/examples/thread/code.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "vesc_c_if.h" 21 | 22 | HEADER 23 | 24 | typedef struct { 25 | int a; 26 | int b; 27 | lib_thread thread; 28 | } data; 29 | 30 | static void thd(void *arg) { 31 | data *d = (data*)arg; 32 | 33 | while (!VESC_IF->should_terminate()) { 34 | VESC_IF->printf("Hello Thd"); 35 | d->b++; 36 | VESC_IF->sleep_ms(1000); 37 | } 38 | } 39 | 40 | // Called when code is stopped 41 | static void stop(void *arg) { 42 | data *d = (data*)arg; 43 | VESC_IF->printf("a: %d, b: %d", d->a, d->b); 44 | VESC_IF->request_terminate(d->thread); 45 | VESC_IF->printf("Terminated"); 46 | VESC_IF->free(d); 47 | } 48 | 49 | INIT_FUN(lib_info *info) { 50 | INIT_START 51 | 52 | data *d = VESC_IF->malloc(sizeof(data)); 53 | d->a = 5; 54 | d->b = 6; 55 | d->thread = VESC_IF->spawn(thd, 1024, "LibThd", d); 56 | 57 | info->stop_fun = stop; 58 | info->arg = d; 59 | 60 | VESC_IF->printf("Hello Example!"); 61 | 62 | return true; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /lib_disp_ui/text.lisp: -------------------------------------------------------------------------------- 1 | @const-start 2 | 3 | ; Centered text block 4 | (defun txt-block-c (img col cx cy font txt) { 5 | (if (eq (type-of txt) type-array) (setq txt (list txt))) 6 | 7 | (var rows (length txt)) 8 | (var font-w (bufget-u8 font 0)) 9 | (var font-h (bufget-u8 font 1)) 10 | 11 | (looprange i 0 rows { 12 | (var chars (str-len (ix txt i))) 13 | 14 | (if (eq (type-of col) type-list) 15 | (img-text img 16 | (- cx (* font-w chars 0.5)) 17 | (+ (- cy (* font-h rows 0.5)) (* i font-h)) 18 | col font (ix txt i) 19 | ) 20 | 21 | (img-text img 22 | (- cx (* font-w chars 0.5)) 23 | (+ (- cy (* font-h rows 0.5)) (* i font-h)) 24 | col -1 font (ix txt i) 25 | ) 26 | ) 27 | }) 28 | }) 29 | 30 | ; Left aligned text block 31 | (defun txt-block-l (img col x y font txt) { 32 | (if (eq (type-of txt) type-array) (setq txt (list txt))) 33 | 34 | (var rows (length txt)) 35 | (var font-w (bufget-u8 font 0)) 36 | (var font-h (bufget-u8 font 1)) 37 | 38 | (looprange i 0 rows { 39 | (var chars (str-len (ix txt i))) 40 | 41 | (if (eq (type-of col) type-list) 42 | (img-text img 43 | x 44 | (+ y (* i font-h)) 45 | col font (ix txt i) 46 | ) 47 | (img-text img 48 | x 49 | (+ y (* i font-h)) 50 | col -1 font (ix txt i) 51 | ) 52 | ) 53 | }) 54 | }) 55 | 56 | @const-end 57 | -------------------------------------------------------------------------------- /lib_code_server/code_server.lisp: -------------------------------------------------------------------------------- 1 | ;@const-symbol-strings 2 | @const-start 3 | 4 | (defun code-server-worker (parent) 5 | (loopwhile t { 6 | (var rx (unflatten (canmsg-recv 0 -1))) 7 | (var id (first rx)) 8 | 9 | (send parent (list 'can-id id)) 10 | 11 | (if (>= id 0) 12 | (canmsg-send id 1 (flatten (eval (second rx)))) 13 | (eval (second rx)) 14 | ) 15 | })) 16 | 17 | (defun start-code-server () 18 | (spawn 50 (fn () { 19 | (var last-id 0) 20 | (var respawn true) 21 | 22 | (loopwhile t { 23 | (if respawn { 24 | (spawn-trap "CodeSrv" code-server-worker (self)) 25 | (setq respawn false) 26 | }) 27 | 28 | (recv 29 | ((exit-error (? tid) (? v)) { 30 | (setq respawn true) 31 | (if (>= last-id 0) 32 | (canmsg-send last-id 1 (flatten 'eerror)) 33 | ) 34 | }) 35 | 36 | ((can-id (? id)) { 37 | (setq last-id id) 38 | }) 39 | ) 40 | }) 41 | }))) 42 | 43 | (defun rcode-run (id tout code) { 44 | (canmsg-send id 0 (flatten (list (can-local-id) code))) 45 | (match (canmsg-recv 1 tout) 46 | (timeout timeout) 47 | ((? a) (unflatten a)) 48 | ) 49 | }) 50 | 51 | (defun rcode-run-noret (id code) { 52 | (canmsg-send id 0 (flatten (list -1 code))) 53 | }) 54 | 55 | @const-end -------------------------------------------------------------------------------- /lib_ws2812/README.md: -------------------------------------------------------------------------------- 1 | # WS2812 Driver 2 | 3 | This is a library for driving WS2812 and similar addressable LEDs. You can use it from your LispBM-scripts by importing it and loading it as a native library: 4 | 5 | ```clj 6 | (import "pkg::ws2812@://vesc_packages/lib_ws2812/ws2812.vescpkg" 'ws2812) 7 | (load-native-lib ws2812) 8 | ``` 9 | 10 | That will give you the following extensions 11 | 12 | ```clj 13 | (ext-ws2812-init led-num use-ch2 use-tim4 is-rgbw) 14 | (ext-ws2812-set-color index colorRgb) 15 | (ext-ws2812-set-brightness brightness) 16 | ``` 17 | 18 | The library uses timer 3 or timer 4 channel 1 or channel 2, meaning that you have 4 pins to choose from. On most hardwares hall 1 and hall 2 are channel 1 and channel 2 on timer 3 or timer 4, but you have to check the hwconf-file or schematic to make sure. To connect the LEDs you have to use a 1k pull-up resistor on that pin to 5v and connect it to the data input of the LEDs. 19 | 20 | ## Example 21 | 22 | This is a complete, hopefully self-explanatory, example on how to import the library, configure it and run a demo on the LEDs. You can copy and paste it into the lisp editor and give it a try. 23 | 24 | ```clj 25 | (import "pkg::ws2812@://vesc_packages/lib_ws2812/ws2812.vescpkg" 'ws2812) 26 | 27 | (load-native-lib ws2812) 28 | 29 | (def led-num 10) 30 | 31 | (let ( 32 | (use-ch2 0) ; 0 means CH1 33 | (use-tim4 0) ; 0 means TIM3 34 | (is-rgbw 1)) ; Some adressable LEDs have an extra white channel. Set this to 1 to use it 35 | (ext-ws2812-init led-num use-ch2 use-tim4 is-rgbw) 36 | ) 37 | 38 | (def colors '( 39 | 0x00550000i32 40 | 0x00005500i32 41 | 0x00000055i32 42 | 0x55000000i32 43 | )) 44 | 45 | (loopwhile t 46 | (loopforeach c colors 47 | (looprange i 0 led-num 48 | (progn 49 | (ext-ws2812-set-color (if (= i 0) (- led-num 1) (- i 1)) 0) 50 | (ext-ws2812-set-color i c) 51 | (sleep 0.02) 52 | )))) 53 | ``` -------------------------------------------------------------------------------- /float/float/footpad_sensor.c: -------------------------------------------------------------------------------- 1 | #include "footpad_sensor.h" 2 | 3 | #include "vesc_c_if.h" 4 | 5 | // ADC Hand-Press Scale Factor (Accomdate lighter presses than what's needed for engagement by foot) 6 | #define ADC_HAND_PRESS_SCALE 0.8f 7 | 8 | // Read ADCs and determine footpad sensor state 9 | FootpadSensorState footpad_sensor_state_evaluate(const FootpadSensor *fs, const float_config *config, bool handpress) { 10 | float adc1_threshold = handpress ? config->fault_adc1 * ADC_HAND_PRESS_SCALE : config->fault_adc1; 11 | float adc2_threshold = handpress ? config->fault_adc2 * ADC_HAND_PRESS_SCALE : config->fault_adc2; 12 | 13 | // Calculate sensor state from ADC values 14 | if (config->fault_adc1 == 0 && config->fault_adc2 == 0) { // No sensors 15 | return FS_BOTH; 16 | } else if (config->fault_adc2 == 0) { // Single sensor on ADC1 17 | if (fs->adc1 > adc1_threshold) { 18 | return FS_BOTH; 19 | } 20 | } else if (config->fault_adc1 == 0) { // Single sensor on ADC2 21 | if (fs->adc2 > adc2_threshold) { 22 | return FS_BOTH; 23 | } 24 | } else { // Double sensor 25 | if (fs->adc1 > adc1_threshold) { 26 | if (fs->adc2 > adc2_threshold) { 27 | return FS_BOTH; 28 | } else { 29 | return FS_LEFT; 30 | } 31 | } else { 32 | if (fs->adc2 > adc2_threshold) { 33 | return FS_RIGHT; 34 | } 35 | } 36 | } 37 | 38 | return FS_NONE; 39 | } 40 | 41 | void footpad_sensor_update(FootpadSensor *fs, const float_config *config) { 42 | fs->adc1 = VESC_IF->io_read_analog(VESC_PIN_ADC1); 43 | fs->adc2 = VESC_IF->io_read_analog(VESC_PIN_ADC2); // Returns -1.0 if the pin is missing on the hardware 44 | if (fs->adc2 < 0.0) { 45 | fs->adc2 = 0.0; 46 | } 47 | 48 | fs->state = footpad_sensor_state_evaluate(fs, config, false); 49 | } 50 | 51 | int footpad_sensor_state_to_switch_compat(FootpadSensorState v) { 52 | switch (v) { 53 | case FS_BOTH: 54 | return 2; 55 | case FS_LEFT: 56 | case FS_RIGHT: 57 | return 1; 58 | case FS_NONE: 59 | default: 60 | return 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lib_interpolation/README.md: -------------------------------------------------------------------------------- 1 | # Interpolation 2 | 3 | This library implements the interpolation methods described here http://paulbourke.net/miscellaneous/interpolation/. 4 | 5 | When loaded, the following extension is provided 6 | 7 | #### ext-interpolate 8 | ```clj 9 | (ext-interpolate value table optMethod) 10 | ``` 11 | 12 | Where value is the x-position in the table, table is the interpolation table and optMethod is an optional argument that specifies the interpolation method to use (by default it uses Catmull-Rom splines). 13 | 14 | The available methods are: 15 | 16 | 0. Linear 17 | 1. Cosine 18 | 2. Cubic splines 19 | 3. Catmull-Rom splines (recommended) 20 | 21 | Note: Outside of the table all points are set to the same value as the last point in the table. 22 | 23 | ## Example 24 | 25 | ```clj 26 | (import "pkg::interpolation@://vesc_packages/lib_interpolation/interpolation.vescpkg" 'interpolation) 27 | 28 | (load-native-lib interpolation) 29 | 30 | (def int-tab '( 31 | (-500.0 90.0) 32 | (0.0 80.0) 33 | (500.0 82.0) 34 | (1000.0 90.0) 35 | (1500.0 94.0) 36 | (3000.0 96.0) 37 | (5000.0 100.0) 38 | )) 39 | 40 | (ext-interpolate 1220 int-tab 3) 41 | > {92.216660} 42 | ``` 43 | 44 | ## Example: Plotting 45 | 46 | ```clj 47 | (import "pkg::interpolation@://vesc_packages/lib_interpolation/interpolation.vescpkg" 'interpolation) 48 | 49 | (load-native-lib interpolation) 50 | 51 | (def int-tab '( 52 | (-500.0 90.0) 53 | (0.0 80.0) 54 | (500.0 82.0) 55 | (1000.0 90.0) 56 | (1500.0 94.0) 57 | (1960.0 80.6) 58 | (3000.0 96.0) 59 | (5000.0 100.0) 60 | )) 61 | 62 | (plot-init "Val" "Output") 63 | (plot-add-graph "Linear") 64 | (plot-add-graph "Cosine") 65 | (plot-add-graph "Cubic") 66 | (plot-add-graph "Catmull-Rom") 67 | 68 | (looprange i 0 4 69 | (progn 70 | (plot-set-graph i) 71 | (loopfor j -1000 (< j 7000) (+ j 10) 72 | (plot-send-points j (ext-interpolate j int-tab i)) 73 | ))) 74 | ``` 75 | -------------------------------------------------------------------------------- /tnt/tnt/conf/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BUFFER_H_ 21 | #define BUFFER_H_ 22 | 23 | #include 24 | 25 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index); 26 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index); 27 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index); 28 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index); 29 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index); 30 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index); 31 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index); 32 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index); 33 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index); 34 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index); 35 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index); 36 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index); 37 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index); 38 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index); 39 | 40 | #endif /* BUFFER_H_ */ 41 | -------------------------------------------------------------------------------- /float/float/conf/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BUFFER_H_ 21 | #define BUFFER_H_ 22 | 23 | #include 24 | 25 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index); 26 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index); 27 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index); 28 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index); 29 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index); 30 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index); 31 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index); 32 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index); 33 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index); 34 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index); 35 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index); 36 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index); 37 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index); 38 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index); 39 | 40 | #endif /* BUFFER_H_ */ 41 | -------------------------------------------------------------------------------- /balance/balance/conf/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BUFFER_H_ 21 | #define BUFFER_H_ 22 | 23 | #include 24 | 25 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index); 26 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index); 27 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index); 28 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index); 29 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index); 30 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index); 31 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index); 32 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index); 33 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index); 34 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index); 35 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index); 36 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index); 37 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index); 38 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index); 39 | 40 | #endif /* BUFFER_H_ */ 41 | -------------------------------------------------------------------------------- /c_libs/examples/config/conf/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BUFFER_H_ 21 | #define BUFFER_H_ 22 | 23 | #include 24 | 25 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index); 26 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index); 27 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index); 28 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index); 29 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index); 30 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index); 31 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index); 32 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index); 33 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index); 34 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index); 35 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index); 36 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index); 37 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index); 38 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index); 39 | 40 | #endif /* BUFFER_H_ */ 41 | -------------------------------------------------------------------------------- /c_libs/examples/custom_data_comm/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BUFFER_H_ 21 | #define BUFFER_H_ 22 | 23 | #include 24 | 25 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index); 26 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index); 27 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index); 28 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index); 29 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index); 30 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index); 31 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index); 32 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index); 33 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index); 34 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index); 35 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index); 36 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index); 37 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index); 38 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index); 39 | 40 | #endif /* BUFFER_H_ */ 41 | -------------------------------------------------------------------------------- /c_libs/rules.mk: -------------------------------------------------------------------------------- 1 | 2 | CC = arm-none-eabi-gcc 3 | LD = arm-none-eabi-gcc 4 | OBJDUMP = arm-none-eabi-objdump 5 | OBJCOPY = arm-none-eabi-objcopy 6 | PYTHON = python3 7 | 8 | STLIB_PATH = $(VESC_C_LIB_PATH)/stdperiph_stm32f4/ 9 | 10 | ifeq ($(USE_STLIB),yes) 11 | SOURCES += \ 12 | $(STLIB_PATH)/src/misc.c \ 13 | $(STLIB_PATH)/src/stm32f4xx_adc.c \ 14 | $(STLIB_PATH)/src/stm32f4xx_dma.c \ 15 | $(STLIB_PATH)/src/stm32f4xx_exti.c \ 16 | $(STLIB_PATH)/src/stm32f4xx_flash.c \ 17 | $(STLIB_PATH)/src/stm32f4xx_rcc.c \ 18 | $(STLIB_PATH)/src/stm32f4xx_syscfg.c \ 19 | $(STLIB_PATH)/src/stm32f4xx_tim.c \ 20 | $(STLIB_PATH)/src/stm32f4xx_iwdg.c \ 21 | $(STLIB_PATH)/src/stm32f4xx_wwdg.c 22 | endif 23 | 24 | UTILS_PATH = $(VESC_C_LIB_PATH)/utils/ 25 | 26 | SOURCES += $(UTILS_PATH)/rb.c 27 | SOURCES += $(UTILS_PATH)/utils.c 28 | 29 | OBJECTS = $(SOURCES:.c=.so) 30 | 31 | ifeq ($(USE_OPT),) 32 | USE_OPT = 33 | endif 34 | 35 | CFLAGS = -fpic -Os -Wall -Wextra -Wundef -std=gnu99 -I$(VESC_C_LIB_PATH) 36 | CFLAGS += -I$(STLIB_PATH)/CMSIS/include -I$(STLIB_PATH)/CMSIS/ST -I$(UTILS_PATH)/ 37 | CFLAGS += -fomit-frame-pointer -falign-functions=16 -mthumb 38 | CFLAGS += -fsingle-precision-constant -Wdouble-promotion 39 | CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mcpu=cortex-m4 40 | CFLAGS += -fdata-sections -ffunction-sections 41 | CFLAGS += -DIS_VESC_LIB 42 | CFLAGS += $(USE_OPT) 43 | 44 | ifeq ($(USE_STLIB),yes) 45 | CFLAGS += -DUSE_STLIB -I$(STLIB_PATH)/inc 46 | endif 47 | 48 | LDFLAGS = -nostartfiles -static -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mcpu=cortex-m4 49 | LDFLAGS += -lm -Wl,--gc-sections,--undefined=init 50 | LDFLAGS += -T $(VESC_C_LIB_PATH)/link.ld 51 | 52 | .PHONY: default all clean 53 | 54 | default: $(TARGET) 55 | all: default 56 | 57 | %.so: %.c 58 | $(CC) $(CFLAGS) -c $< -o $@ 59 | 60 | .PRECIOUS: $(TARGET) $(OBJECTS) 61 | 62 | $(TARGET): $(OBJECTS) 63 | $(LD) $(OBJECTS) $(LDFLAGS) -o $@.elf 64 | $(OBJDUMP) -D $@.elf > $@.list 65 | $(OBJCOPY) -O binary $@.elf $@.bin --gap-fill 0x00 66 | $(PYTHON) $(VESC_C_LIB_PATH)/conv.py -f $@.bin -n $@ > $@.lisp 67 | 68 | clean: 69 | rm -f $(OBJECTS) $(TARGET).elf $(TARGET).list $(TARGET).lisp $(TARGET).bin $(ADD_TO_CLEAN) 70 | -------------------------------------------------------------------------------- /lib_pn532/examples/mifare_read.lisp: -------------------------------------------------------------------------------- 1 | (import "pkg@://vesc_packages/lib_pn532/pn532.vescpkg" 'pn532) 2 | (eval-program (read-program pn532)) 3 | 4 | (def is-esp false) 5 | (def pins nil) 6 | 7 | (if is-esp { 8 | (def pins '(3 2)) 9 | (rgbled-init 8 1) 10 | }) 11 | 12 | (defun led-on () (if is-esp (rgbled-color 0 0x00ff00))) 13 | (defun led-off () (if is-esp (rgbled-color 0 0))) 14 | 15 | (if (pn532-init pins) 16 | (loopwhile t { 17 | (var res (pn532-read-target-id 2)) 18 | (if res { 19 | (led-on) 20 | (var uuid-len (first res)) 21 | (var uuid (second res)) 22 | (print " ") 23 | (print (list "UUID:" uuid)) 24 | (cond 25 | ((= uuid-len 4) { 26 | (print "Most likely Mifare Classic") 27 | (var block 21) 28 | (print (list "Reading block" block)) 29 | (if (pn532-authenticate-block uuid block 0 '(0xff 0xff 0xff 0xff 0xff 0xff)) 30 | { 31 | (print "Authentication OK!") 32 | (print (list "Data:" (pn532-mifareclassic-read-block block))) 33 | } 34 | (print "Authentication failed, most likely the wrong key") 35 | ) 36 | }) 37 | ((= uuid-len 7) { 38 | (print "Most likely Mifare Ultralight or NTAG") 39 | (var page 4) 40 | (print (list "Reading page" page)) 41 | (print (list "Data:" (pn532-mifareul-read-page page))) 42 | }) 43 | (t (print (str-from-n uuid-len "No idea, UUID len: %d"))) 44 | ) 45 | 46 | (led-off) 47 | (sleep 1) 48 | }) 49 | }) 50 | (print "Init Failed") 51 | ) -------------------------------------------------------------------------------- /c_libs/examples/custom_data_comm/qml.qml: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | import QtQuick 2.5 21 | import QtQuick.Controls 2.2 22 | import QtQuick.Layouts 1.3 23 | 24 | import Vedder.vesc.commands 1.0 25 | import Vedder.vesc.configparams 1.0 26 | 27 | Item { 28 | id: container 29 | anchors.fill: parent 30 | anchors.margins: 10 31 | 32 | property Commands mCommands: VescIf.commands() 33 | 34 | ColumnLayout { 35 | anchors.fill: parent 36 | 37 | DoubleSpinBox { 38 | id: sb 39 | Layout.fillWidth: true 40 | } 41 | 42 | Item { 43 | Layout.fillHeight: true 44 | } 45 | } 46 | 47 | // Send the value of the spinbox every second 48 | Timer { 49 | running: true 50 | repeat: true 51 | interval: 1000 52 | 53 | onTriggered: { 54 | var buffer = new ArrayBuffer(4) 55 | var dv = new DataView(buffer) 56 | var ind = 0 57 | dv.setFloat32(ind, sb.realValue); ind += 4 58 | mCommands.sendCustomAppData(buffer) 59 | } 60 | } 61 | 62 | // Print the message counter and value that we sent the last time 63 | Connections { 64 | target: mCommands 65 | 66 | onCustomAppDataReceived: { 67 | var dv = new DataView(data) 68 | var ind = 0 69 | var msg_cnt = dv.getInt32(ind); ind += 4 70 | var msg_val = dv.getFloat32(ind); ind += 4 71 | console.log(msg_cnt + " " + msg_val) 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /c_libs/examples/speed_test/code.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "vesc_c_if.h" 21 | 22 | HEADER 23 | 24 | static int dec_cnt(volatile int x) { 25 | if (x == 0) { 26 | return 0; 27 | } else { 28 | return dec_cnt(x - 1); 29 | } 30 | } 31 | 32 | static lbm_value ext_dec_cnt(lbm_value *args, lbm_uint argn) { 33 | if (argn != 1 || !VESC_IF->lbm_is_number(args[0])) { 34 | return VESC_IF->lbm_enc_sym_eerror; 35 | } 36 | 37 | float t0 = VESC_IF->system_time(); 38 | dec_cnt(VESC_IF->lbm_dec_as_i32(args[0])); 39 | float t1 = VESC_IF->system_time(); 40 | 41 | return VESC_IF->lbm_enc_float(t1 - t0); 42 | } 43 | 44 | static int tak(volatile int x, volatile int y, volatile int z) { 45 | if (y >= x) { 46 | return z; 47 | } else { 48 | return tak( 49 | tak(x - 1, y, z), 50 | tak(y - 1, z, x), 51 | tak(z - 1, x, y)); 52 | } 53 | } 54 | 55 | static lbm_value ext_tak(lbm_value *args, lbm_uint argn) { 56 | if (argn != 3 || 57 | !VESC_IF->lbm_is_number(args[0]) || 58 | !VESC_IF->lbm_is_number(args[1]) || 59 | !VESC_IF->lbm_is_number(args[2])) { 60 | return VESC_IF->lbm_enc_sym_eerror; 61 | } 62 | 63 | float t0 = VESC_IF->system_time(); 64 | int res = tak(VESC_IF->lbm_dec_as_i32(args[0]), 65 | VESC_IF->lbm_dec_as_i32(args[1]), 66 | VESC_IF->lbm_dec_as_i32(args[2])); 67 | float t1 = VESC_IF->system_time(); 68 | 69 | VESC_IF->printf("C TakRes: %d", res); 70 | 71 | return VESC_IF->lbm_enc_float(t1 - t0); 72 | } 73 | 74 | INIT_FUN(lib_info *info) { 75 | INIT_START 76 | 77 | (void)info; 78 | VESC_IF->lbm_add_extension("ext-dec-cnt", ext_dec_cnt); 79 | VESC_IF->lbm_add_extension("ext-tak", ext_tak); 80 | return true; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /logui/README.md: -------------------------------------------------------------------------------- 1 | # LogUI 2 | 3 | This package can be used for logging data to CAN-connected log devices such as the VESC Express. When installed it provides a QML-page in VESC Tool where logging can be configured, started and stopped. There is also a lisp-script that handles the logging. 4 | 5 | After a log is started it can be stopped with the stop-button or when a shutdown even it detected (from e.g. a power button). The log will also be stopped if the input voltage drops below 18V. The automatic stop is done in order to prevent data corruption on the SD-card when the power goes down. 6 | 7 | ## Data Selection 8 | 9 | The following data can be selected for logging: 10 | 11 | * **GNSS Position** 12 | - This relies on a GNSS receiver being connected to the logger. The log will not start until a valid position is available. That means if the log is started indoors or without a GNSS-receiver connected it will never start. 13 | * **Local Values** 14 | - Such as input voltage, currents, ah and wh counters, speed , temperatures etc. 15 | * **CAN Values** 16 | - Selecting this option will monitor the CAN-bus when the log is started and add fields for all devices that are detected then. Then when the log is running it will keep updating the fields for those devices. If no CAN-devices are seen when the log is started they will also not be added to the log. For motor controllers with the VESC firmware to show up, CAN status messages must be activated in the App Settings. 17 | * **BMS Values** 18 | - If BMS-values are selected, they will be added to the log if a BMS is detected at the time the log is started. Otherwise the log will run without BMS values. 19 | 20 | ### Logger CAN ID 21 | 22 | The ID of the logger on the CAN-bus. Setting id to -1 will send log data to the log analysis page in the desktop version of VESC Tool. If LOGUI runs on the express directly (supported from firmware 6.02+) setting id to -2 logs to the local VESC Express. 23 | 24 | ### Log Rate 25 | 26 | Rate at which data is logged in Hz. 27 | 28 | ## Button Functions 29 | 30 | The UI has three buttons with the following functions: 31 | 32 | ### Start 33 | 34 | Start the log now with the settings above. 35 | 36 | ### Stop 37 | 38 | Stop the ongoing log if any. 39 | 40 | ### Save Config 41 | 42 | Save the log settings. If "Start logging at boot" is checked a log will be started automatically every boot with the settings above. 43 | 44 | ## Other Log Data 45 | 46 | If you want to log different fields it is quite straight forward to customize the log script. After installing this package you can go to VESC Dev Tools -> Lisp and click the Read Existing-button. Then you can edit the loglist in the beginning and upload the edited script using the upload-button. 47 | -------------------------------------------------------------------------------- /lib_nau7802/examples/measure_torque.lisp: -------------------------------------------------------------------------------- 1 | ; See 2 | ; https://www.youtube.com/watch?v=H0oRhapKZnM 3 | 4 | (import "pkg@://vesc_packages/lib_nau7802/nau7802.vescpkg" 'nau7802) 5 | (eval-program (read-program nau7802)) 6 | (nau-init) 7 | 8 | ; Run this function without any weight to calibrate the zero offset 9 | (defun zero-offset () 10 | (progn 11 | (def adc-ofs 0.0) 12 | (looprange i 0 100 13 | (progn 14 | (def adc-ofs (+ adc-ofs (nau-read-adc))) 15 | (sleep 0.01) 16 | )) 17 | (def adc-ofs (/ adc-ofs 100.0)) 18 | )) 19 | 20 | (defun read-avg (samples) 21 | (progn 22 | (let ((avg 0)) 23 | (progn 24 | (looprange it 0 samples 25 | (progn 26 | (setvar 'avg (+ avg (- (nau-read-adc) adc-ofs))) 27 | (sleep 0.01) 28 | )) 29 | (/ avg samples) 30 | )))) 31 | 32 | ; Used to calibrate scale. Put a known weight on the scale 33 | ; and use this function with the weight as an argument. 34 | ; zero-offset has to be run first. 35 | (defun cal-with-weight (weight) 36 | (setvar 'scale (/ weight (read-avg 100))) 37 | ) 38 | 39 | (defun read-grams () 40 | (* (- (nau-read-adc) adc-ofs) scale) 41 | ) 42 | 43 | (defun lpf (val sample) 44 | (- val (* 0.5 (- val sample))) 45 | ) 46 | 47 | (def scale 21572.6) ; Factor to convert voltage to grams 48 | (def grams 0) ; Weight in grams 49 | (def gramsf 0) ; Filtered weight 50 | 51 | (zero-offset) 52 | 53 | (defun calc-torque () 54 | (* 1.5 (conf-get 'si-motor-poles) 0.5 55 | (get-current) (conf-get 'foc-motor-flux-linkage) 0.001) 56 | ) 57 | 58 | (spawn (fn () (loopwhile t 59 | (progn 60 | (def adc (nau-read-adc)) 61 | (def grams (read-grams)) 62 | (def gramsf (lpf gramsf grams)) 63 | (def torque (* (* gramsf -0.01) 0.0424)) 64 | (def torque-calc (calc-torque)) 65 | (sleep 0.01) 66 | )))) 67 | 68 | (sleep 1.0) 69 | 70 | (plot-init "Current (A)" "Torque (Nm)") 71 | (plot-add-graph "Calculated") 72 | (plot-add-graph "Measured") 73 | (plot-add-graph "Ratio") 74 | 75 | (looprange i 5 120 76 | (let ( 77 | (i-now (* i 0.1)) 78 | ) 79 | (progn 80 | (set-current i-now) 81 | (looprange i 0 3 (progn (timeout-reset) (sleep 0.1))) 82 | (plot-set-graph 0) 83 | (plot-send-points i-now torque-calc) 84 | (plot-set-graph 1) 85 | (plot-send-points i-now torque) 86 | (plot-set-graph 2) 87 | (plot-send-points i-now (/ torque torque-calc)) 88 | ))) 89 | 90 | (set-current 0) 91 | -------------------------------------------------------------------------------- /c_libs/examples/ssd1306/code.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "vesc_c_if.h" 21 | 22 | HEADER 23 | 24 | static int abs(int x) { 25 | if (x >= 0) { 26 | return x; 27 | } else { 28 | return -x; 29 | } 30 | } 31 | 32 | static void set_pix(uint8_t *arr, int x, int y) { 33 | if (x < 0 || x >= 128 || y < 0 || y >= 64) { 34 | return; 35 | } 36 | unsigned int pos = 8 + x * 8 + y % 8 + (y / 8) * 1024; 37 | unsigned int bytepos = pos / 8; 38 | unsigned int bitpos = pos % 8; 39 | arr[bytepos] |= (1 << bitpos); 40 | } 41 | 42 | static void draw_line(uint8_t *arr, int x0, int y0, int x1, int y1) { 43 | int dx = abs(x1 - x0); 44 | int sx = x0 < x1 ? 1 : -1; 45 | int dy = -abs(y1 - y0); 46 | int sy = y0 < y1 ? 1 : -1; 47 | int error = dx + dy; 48 | 49 | while (true) { 50 | set_pix(arr, x0, y0); 51 | if (x0 == x1 && y0 == y1) { 52 | break; 53 | } 54 | if ((error * 2) >= dy) { 55 | if (x0 == x1) { 56 | break; 57 | } 58 | error += dy; 59 | x0 += sx; 60 | } 61 | if ((error * 2) <= dx) { 62 | if (y0 == y1) { 63 | break; 64 | } 65 | error += dx; 66 | y0 += sy; 67 | } 68 | } 69 | } 70 | 71 | static lbm_value ssd_drawline(lbm_value *args, lbm_uint argn) { 72 | lbm_value res = VESC_IF->lbm_enc_sym_eerror; 73 | 74 | if (argn != 5 || !VESC_IF->lbm_is_byte_array(args[0]) || 75 | !VESC_IF->lbm_is_number(args[1]) || !VESC_IF->lbm_is_number(args[2]) || 76 | !VESC_IF->lbm_is_number(args[3]) || !VESC_IF->lbm_is_number(args[4])) { 77 | return res; 78 | } 79 | 80 | uint8_t *pixbuf = (uint8_t*)(((lbm_array_header_t *)VESC_IF->lbm_car(args[0]))->data); 81 | int x0 = VESC_IF->lbm_dec_as_i32(args[1]); 82 | int y0 = VESC_IF->lbm_dec_as_i32(args[2]); 83 | int x1 = VESC_IF->lbm_dec_as_i32(args[3]); 84 | int y1 = VESC_IF->lbm_dec_as_i32(args[4]); 85 | 86 | draw_line(pixbuf, x0, y0, x1, y1); 87 | 88 | return VESC_IF->lbm_enc_sym_true; 89 | } 90 | 91 | INIT_FUN(lib_info *info) { 92 | INIT_START 93 | 94 | (void)info; 95 | VESC_IF->lbm_add_extension("ext-drawline", ssd_drawline); 96 | return true; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /c_libs/examples/custom_data_comm/code.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "vesc_c_if.h" 21 | #include "buffer.h" 22 | 23 | HEADER 24 | 25 | typedef struct { 26 | int msg_cnt; 27 | float msg_val; 28 | lib_thread thread; 29 | } my_data; 30 | 31 | // This thread sends the message counter and the last received data 32 | // back every second. The Commands-signal onCustomAppDataReceived 33 | // is received every time VESC_IF->send_app_data is used. 34 | static void thd(void *arg) { 35 | volatile my_data *d = (my_data*)arg; 36 | 37 | while (!VESC_IF->should_terminate()) { 38 | int32_t ind = 0; 39 | uint8_t buffer[10]; 40 | buffer_append_int32(buffer, d->msg_cnt, &ind); 41 | buffer_append_float32_auto(buffer, d->msg_val, &ind); 42 | VESC_IF->send_app_data(buffer, ind); 43 | VESC_IF->sleep_ms(1000); 44 | } 45 | } 46 | 47 | // This callback is called every time mCommands.sendCustomAppData is used 48 | // with the data it sends. The VESC buffer functions are compatible with 49 | // the JavaScript DataView, so we can even communicate floats as in this 50 | // example. Here we decode and save the data and increase a message 51 | // counter. 52 | static void data_rx_cb(unsigned char *data, unsigned int len) { 53 | volatile my_data *d = (my_data*)ARG; 54 | int32_t ind = 0; 55 | d->msg_val = buffer_get_float32_auto(data, &ind); 56 | d->msg_cnt++; 57 | VESC_IF->printf("Received %d bytes, number %.2f", len, (double)d->msg_val); 58 | } 59 | 60 | // Called when code is stopped 61 | static void stop(void *arg) { 62 | my_data *d = (my_data*)arg; 63 | VESC_IF->request_terminate(d->thread); 64 | VESC_IF->set_app_data_handler(0); // Unregisted callback-function 65 | VESC_IF->printf("Terminated"); 66 | VESC_IF->free(d); 67 | } 68 | 69 | INIT_FUN(lib_info *info) { 70 | INIT_START 71 | 72 | my_data *d = VESC_IF->malloc(sizeof(my_data)); 73 | d->msg_val = 0.0; 74 | d->msg_cnt = 0.0; 75 | d->thread = VESC_IF->spawn(thd, 2048, "LibThd", d); 76 | 77 | info->stop_fun = stop; 78 | info->arg = d; 79 | 80 | // Register callback function that is used when app data is received 81 | VESC_IF->set_app_data_handler(data_rx_cb); 82 | 83 | return true; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /lib_midi/midi/midi-parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple MIDI parser implementation. 3 | * I used the following reference: 4 | * http://www.sonicspot.com/guide/midifiles.html 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | enum midi_parser_status { 14 | MIDI_PARSER_EOB = -2, 15 | MIDI_PARSER_ERROR = -1, 16 | MIDI_PARSER_INIT = 0, 17 | MIDI_PARSER_HEADER = 1, 18 | MIDI_PARSER_TRACK = 2, 19 | MIDI_PARSER_TRACK_MIDI = 3, 20 | MIDI_PARSER_TRACK_META = 4, 21 | MIDI_PARSER_TRACK_SYSEX = 5, 22 | }; 23 | 24 | enum midi_file_format { 25 | MIDI_FILE_FORMAT_SINGLE_TRACK = 0, 26 | MIDI_FILE_FORMAT_MULTIPLE_TRACKS = 1, 27 | MIDI_FILE_FORMAT_MULTIPLE_SONGS = 2, 28 | }; 29 | 30 | struct midi_header { 31 | int32_t size; 32 | uint16_t format; 33 | int16_t tracks_count; 34 | int16_t time_division; 35 | }; 36 | 37 | struct midi_track { 38 | int32_t size; 39 | }; 40 | 41 | enum midi_status { 42 | MIDI_STATUS_NOTE_OFF = 0x8, 43 | MIDI_STATUS_NOTE_ON = 0x9, 44 | MIDI_STATUS_NOTE_AT = 0xA, // after touch 45 | MIDI_STATUS_CC = 0xB, // control change 46 | MIDI_STATUS_PGM_CHANGE = 0xC, 47 | MIDI_STATUS_CHANNEL_AT = 0xD, // after touch 48 | MIDI_STATUS_PITCH_BEND = 0xE, 49 | }; 50 | 51 | enum midi_meta { 52 | MIDI_META_SEQ_NUM = 0x00, 53 | MIDI_META_TEXT = 0x01, 54 | MIDI_META_COPYRIGHT = 0x02, 55 | MIDI_META_TRACK_NAME = 0x03, 56 | MIDI_META_INSTRUMENT_NAME = 0x04, 57 | MIDI_META_LYRICS = 0x05, 58 | MIDI_META_MAKER = 0x06, 59 | MIDI_META_CUE_POINT = 0x07, 60 | MIDI_META_CHANNEL_PREFIX = 0x20, 61 | MIDI_META_END_OF_TRACK = 0x2F, 62 | MIDI_META_SET_TEMPO = 0x51, 63 | MIDI_META_SMPTE_OFFSET = 0x54, 64 | MIDI_META_TIME_SIGNATURE = 0x58, 65 | MIDI_META_KEY_SIGNATURE = 0x59, 66 | MIDI_META_SEQ_SPECIFIC = 0x7F, 67 | }; 68 | 69 | struct midi_midi_event { 70 | unsigned status :4; 71 | unsigned channel :4; 72 | uint8_t param1; 73 | uint8_t param2; 74 | }; 75 | 76 | struct midi_meta_event { 77 | uint8_t type; 78 | int32_t length; 79 | const uint8_t *bytes; // reference to the input buffer 80 | }; 81 | 82 | struct midi_sysex_event { 83 | uint8_t sysex; 84 | uint8_t type; 85 | int32_t length; 86 | const uint8_t *bytes; // reference to the input buffer 87 | }; 88 | 89 | struct midi_parser { 90 | enum midi_parser_status state; 91 | enum midi_status buffered_status; 92 | unsigned buffered_channel; 93 | 94 | /* input buffer */ 95 | const uint8_t *in; 96 | int32_t size; 97 | 98 | /* result */ 99 | int64_t vtime; 100 | struct midi_header header; 101 | struct midi_track track; 102 | struct midi_midi_event midi; 103 | struct midi_meta_event meta; 104 | struct midi_sysex_event sysex; 105 | }; 106 | 107 | const char* midi_file_format_name(int fmt); 108 | int midi_event_datalen(int status); 109 | const char* midi_status_name(int status); 110 | const char* midi_meta_name(int type); 111 | enum midi_parser_status midi_parse(struct midi_parser *parser); 112 | -------------------------------------------------------------------------------- /balance/balance/conf/datatypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DATATYPES_H_ 21 | #define DATATYPES_H_ 22 | 23 | #include 24 | #include 25 | 26 | typedef enum { 27 | BALANCE_PID_MODE_ANGLE = 0, 28 | BALANCE_PID_MODE_ANGLE_RATE_CASCADE 29 | } BALANCE_PID_MODE; 30 | 31 | typedef struct { 32 | BALANCE_PID_MODE pid_mode; 33 | float kp; 34 | float ki; 35 | float kd; 36 | float kp2; 37 | float ki2; 38 | float kd2; 39 | uint16_t hertz; 40 | uint16_t loop_time_filter; 41 | float fault_pitch; 42 | float fault_roll; 43 | float fault_duty; 44 | float fault_adc1; 45 | float fault_adc2; 46 | uint16_t fault_delay_pitch; 47 | uint16_t fault_delay_roll; 48 | uint16_t fault_delay_duty; 49 | uint16_t fault_delay_switch_half; 50 | uint16_t fault_delay_switch_full; 51 | uint16_t fault_adc_half_erpm; 52 | bool fault_is_dual_switch; 53 | float tiltback_duty_angle; 54 | float tiltback_duty_speed; 55 | float tiltback_duty; 56 | float tiltback_hv_angle; 57 | float tiltback_hv_speed; 58 | float tiltback_hv; 59 | float tiltback_lv_angle; 60 | float tiltback_lv_speed; 61 | float tiltback_lv; 62 | float tiltback_return_speed; 63 | float tiltback_constant; 64 | uint16_t tiltback_constant_erpm; 65 | float tiltback_variable; 66 | float tiltback_variable_max; 67 | float noseangling_speed; 68 | float startup_pitch_tolerance; 69 | float startup_roll_tolerance; 70 | float startup_speed; 71 | float deadzone; 72 | bool multi_esc; 73 | float yaw_kp; 74 | float yaw_ki; 75 | float yaw_kd; 76 | float roll_steer_kp; 77 | float roll_steer_erpm_kp; 78 | float brake_current; 79 | uint16_t brake_timeout; 80 | float yaw_current_clamp; 81 | float ki_limit; 82 | uint16_t kd_pt1_lowpass_frequency; 83 | uint16_t kd_pt1_highpass_frequency; 84 | float booster_angle; 85 | float booster_ramp; 86 | float booster_current; 87 | float torquetilt_start_current; 88 | float torquetilt_angle_limit; 89 | float torquetilt_on_speed; 90 | float torquetilt_off_speed; 91 | float torquetilt_strength; 92 | float torquetilt_filter; 93 | float turntilt_strength; 94 | float turntilt_angle_limit; 95 | float turntilt_start_angle; 96 | uint16_t turntilt_start_erpm; 97 | float turntilt_speed; 98 | uint16_t turntilt_erpm_boost; 99 | uint16_t turntilt_erpm_boost_end; 100 | } balance_config; 101 | 102 | // DATATYPES_H_ 103 | #endif 104 | -------------------------------------------------------------------------------- /balance/balance/datatypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DATATYPES_H_ 21 | #define DATATYPES_H_ 22 | 23 | #include 24 | #include 25 | 26 | typedef enum { 27 | BALANCE_PID_MODE_ANGLE = 0, 28 | BALANCE_PID_MODE_ANGLE_RATE_CASCADE 29 | } BALANCE_PID_MODE; 30 | 31 | typedef struct { 32 | BALANCE_PID_MODE pid_mode; 33 | float kp; 34 | float ki; 35 | float kd; 36 | float kp2; 37 | float ki2; 38 | float kd2; 39 | uint16_t hertz; 40 | uint16_t loop_time_filter; 41 | float fault_pitch; 42 | float fault_roll; 43 | float fault_duty; 44 | float fault_adc1; 45 | float fault_adc2; 46 | uint16_t fault_delay_pitch; 47 | uint16_t fault_delay_roll; 48 | uint16_t fault_delay_duty; 49 | uint16_t fault_delay_switch_half; 50 | uint16_t fault_delay_switch_full; 51 | uint16_t fault_adc_half_erpm; 52 | bool fault_is_dual_switch; 53 | float tiltback_duty_angle; 54 | float tiltback_duty_speed; 55 | float tiltback_duty; 56 | float tiltback_hv_angle; 57 | float tiltback_hv_speed; 58 | float tiltback_hv; 59 | float tiltback_lv_angle; 60 | float tiltback_lv_speed; 61 | float tiltback_lv; 62 | float tiltback_return_speed; 63 | float tiltback_constant; 64 | uint16_t tiltback_constant_erpm; 65 | float tiltback_variable; 66 | float tiltback_variable_max; 67 | float noseangling_speed; 68 | float startup_pitch_tolerance; 69 | float startup_roll_tolerance; 70 | float startup_speed; 71 | float deadzone; 72 | bool multi_esc; 73 | float yaw_kp; 74 | float yaw_ki; 75 | float yaw_kd; 76 | float roll_steer_kp; 77 | float roll_steer_erpm_kp; 78 | float brake_current; 79 | uint16_t brake_timeout; 80 | float yaw_current_clamp; 81 | uint16_t kd_pt1_lowpass_frequency; 82 | uint16_t kd_pt1_highpass_frequency; 83 | float kd_biquad_lowpass; 84 | float kd_biquad_highpass; 85 | float booster_angle; 86 | float booster_ramp; 87 | float booster_current; 88 | float torquetilt_start_current; 89 | float torquetilt_angle_limit; 90 | float torquetilt_on_speed; 91 | float torquetilt_off_speed; 92 | float torquetilt_strength; 93 | float torquetilt_filter; 94 | float turntilt_strength; 95 | float turntilt_angle_limit; 96 | float turntilt_start_angle; 97 | uint16_t turntilt_start_erpm; 98 | float turntilt_speed; 99 | uint16_t turntilt_erpm_boost; 100 | uint16_t turntilt_erpm_boost_end; 101 | } balance_config; 102 | 103 | // DATATYPES_H_ 104 | #endif 105 | -------------------------------------------------------------------------------- /c_libs/examples/config/datatypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DATATYPES_H_ 21 | #define DATATYPES_H_ 22 | 23 | #include 24 | #include 25 | 26 | typedef enum { 27 | BALANCE_PID_MODE_ANGLE = 0, 28 | BALANCE_PID_MODE_ANGLE_RATE_CASCADE 29 | } BALANCE_PID_MODE; 30 | 31 | typedef struct { 32 | BALANCE_PID_MODE pid_mode; 33 | float kp; 34 | float ki; 35 | float kd; 36 | float kp2; 37 | float ki2; 38 | float kd2; 39 | uint16_t hertz; 40 | uint16_t loop_time_filter; 41 | float fault_pitch; 42 | float fault_roll; 43 | float fault_duty; 44 | float fault_adc1; 45 | float fault_adc2; 46 | uint16_t fault_delay_pitch; 47 | uint16_t fault_delay_roll; 48 | uint16_t fault_delay_duty; 49 | uint16_t fault_delay_switch_half; 50 | uint16_t fault_delay_switch_full; 51 | uint16_t fault_adc_half_erpm; 52 | bool fault_is_dual_switch; 53 | float tiltback_duty_angle; 54 | float tiltback_duty_speed; 55 | float tiltback_duty; 56 | float tiltback_hv_angle; 57 | float tiltback_hv_speed; 58 | float tiltback_hv; 59 | float tiltback_lv_angle; 60 | float tiltback_lv_speed; 61 | float tiltback_lv; 62 | float tiltback_return_speed; 63 | float tiltback_constant; 64 | uint16_t tiltback_constant_erpm; 65 | float tiltback_variable; 66 | float tiltback_variable_max; 67 | float noseangling_speed; 68 | float startup_pitch_tolerance; 69 | float startup_roll_tolerance; 70 | float startup_speed; 71 | float deadzone; 72 | bool multi_esc; 73 | float yaw_kp; 74 | float yaw_ki; 75 | float yaw_kd; 76 | float roll_steer_kp; 77 | float roll_steer_erpm_kp; 78 | float brake_current; 79 | uint16_t brake_timeout; 80 | float yaw_current_clamp; 81 | uint16_t kd_pt1_lowpass_frequency; 82 | uint16_t kd_pt1_highpass_frequency; 83 | float kd_biquad_lowpass; 84 | float kd_biquad_highpass; 85 | float booster_angle; 86 | float booster_ramp; 87 | float booster_current; 88 | float torquetilt_start_current; 89 | float torquetilt_angle_limit; 90 | float torquetilt_on_speed; 91 | float torquetilt_off_speed; 92 | float torquetilt_strength; 93 | float torquetilt_filter; 94 | float turntilt_strength; 95 | float turntilt_angle_limit; 96 | float turntilt_start_angle; 97 | uint16_t turntilt_start_erpm; 98 | float turntilt_speed; 99 | uint16_t turntilt_erpm_boost; 100 | uint16_t turntilt_erpm_boost_end; 101 | } balance_config; 102 | 103 | // DATATYPES_H_ 104 | #endif 105 | -------------------------------------------------------------------------------- /c_libs/examples/config/conf/datatypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DATATYPES_H_ 21 | #define DATATYPES_H_ 22 | 23 | #include 24 | #include 25 | 26 | typedef enum { 27 | BALANCE_PID_MODE_ANGLE = 0, 28 | BALANCE_PID_MODE_ANGLE_RATE_CASCADE 29 | } BALANCE_PID_MODE; 30 | 31 | typedef struct { 32 | BALANCE_PID_MODE pid_mode; 33 | float kp; 34 | float ki; 35 | float kd; 36 | float kp2; 37 | float ki2; 38 | float kd2; 39 | uint16_t hertz; 40 | uint16_t loop_time_filter; 41 | float fault_pitch; 42 | float fault_roll; 43 | float fault_duty; 44 | float fault_adc1; 45 | float fault_adc2; 46 | uint16_t fault_delay_pitch; 47 | uint16_t fault_delay_roll; 48 | uint16_t fault_delay_duty; 49 | uint16_t fault_delay_switch_half; 50 | uint16_t fault_delay_switch_full; 51 | uint16_t fault_adc_half_erpm; 52 | bool fault_is_dual_switch; 53 | float tiltback_duty_angle; 54 | float tiltback_duty_speed; 55 | float tiltback_duty; 56 | float tiltback_hv_angle; 57 | float tiltback_hv_speed; 58 | float tiltback_hv; 59 | float tiltback_lv_angle; 60 | float tiltback_lv_speed; 61 | float tiltback_lv; 62 | float tiltback_return_speed; 63 | float tiltback_constant; 64 | uint16_t tiltback_constant_erpm; 65 | float tiltback_variable; 66 | float tiltback_variable_max; 67 | float noseangling_speed; 68 | float startup_pitch_tolerance; 69 | float startup_roll_tolerance; 70 | float startup_speed; 71 | float deadzone; 72 | bool multi_esc; 73 | float yaw_kp; 74 | float yaw_ki; 75 | float yaw_kd; 76 | float roll_steer_kp; 77 | float roll_steer_erpm_kp; 78 | float brake_current; 79 | uint16_t brake_timeout; 80 | float yaw_current_clamp; 81 | uint16_t kd_pt1_lowpass_frequency; 82 | uint16_t kd_pt1_highpass_frequency; 83 | float kd_biquad_lowpass; 84 | float kd_biquad_highpass; 85 | float booster_angle; 86 | float booster_ramp; 87 | float booster_current; 88 | float torquetilt_start_current; 89 | float torquetilt_angle_limit; 90 | float torquetilt_on_speed; 91 | float torquetilt_off_speed; 92 | float torquetilt_strength; 93 | float torquetilt_filter; 94 | float turntilt_strength; 95 | float turntilt_angle_limit; 96 | float turntilt_start_angle; 97 | uint16_t turntilt_start_erpm; 98 | float turntilt_speed; 99 | uint16_t turntilt_erpm_boost; 100 | uint16_t turntilt_erpm_boost_end; 101 | } balance_config; 102 | 103 | // DATATYPES_H_ 104 | #endif 105 | -------------------------------------------------------------------------------- /c_libs/examples/config/code.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "vesc_c_if.h" 21 | 22 | #include "conf/datatypes.h" 23 | #include "conf/confparser.h" 24 | #include "conf/confxml.h" 25 | 26 | #include 27 | 28 | HEADER 29 | 30 | typedef struct { 31 | balance_config balance_conf; 32 | } data; 33 | 34 | static int get_cfg(uint8_t *buffer, bool is_default) { 35 | data *d = (data*)ARG; 36 | balance_config cfg = d->balance_conf; 37 | 38 | if (is_default) { 39 | confparser_set_defaults_balance_config(&cfg); 40 | } 41 | 42 | return confparser_serialize_balance_config(buffer, &cfg); 43 | } 44 | 45 | static bool set_cfg(uint8_t *buffer) { 46 | data *d = (data*)ARG; 47 | bool res = confparser_deserialize_balance_config(buffer, &(d->balance_conf)); 48 | 49 | // Store to EEPROM 50 | if (res) { 51 | uint32_t ints = sizeof(balance_config) / 4 + 1; 52 | uint32_t buffer[ints]; 53 | bool write_ok = true; 54 | memcpy(buffer, &(d->balance_conf), sizeof(balance_config)); 55 | for (uint32_t i = 0;i < ints;i++) { 56 | eeprom_var v; 57 | v.as_u32 = buffer[i]; 58 | if (!VESC_IF->store_eeprom_var(&v, i + 1)) { 59 | write_ok = false; 60 | break; 61 | } 62 | } 63 | 64 | if (write_ok) { 65 | eeprom_var v; 66 | v.as_u32 = BALANCE_CONFIG_SIGNATURE; 67 | VESC_IF->store_eeprom_var(&v, 0); 68 | } 69 | } 70 | 71 | return res; 72 | } 73 | 74 | static int get_cfg_xml(uint8_t **buffer) { 75 | // Note: As the address of data_balance_config_ is not known 76 | // at compile time it will be relative to where it is in the 77 | // linked binary. Therefore we add PROG_ADDR to it so that it 78 | // points to where it ends up on the STM32. 79 | *buffer = data_balance_config_ + PROG_ADDR; 80 | return DATA_BALANCE_CONFIG__SIZE; 81 | } 82 | 83 | // Called when code is stopped 84 | static void stop(void *arg) { 85 | (void)arg; 86 | VESC_IF->conf_custom_clear_configs(); 87 | } 88 | 89 | INIT_FUN(lib_info *info) { 90 | INIT_START 91 | 92 | data *d = VESC_IF->malloc(sizeof(data)); 93 | memset(d, 0, sizeof(data)); 94 | 95 | // Read config from EEPROM if signature is correct 96 | eeprom_var v; 97 | uint32_t ints = sizeof(balance_config) / 4 + 1; 98 | uint32_t buffer[ints]; 99 | bool read_ok = VESC_IF->read_eeprom_var(&v, 0); 100 | if (read_ok && v.as_u32 == BALANCE_CONFIG_SIGNATURE) { 101 | for (uint32_t i = 0;i < ints;i++) { 102 | if (!VESC_IF->read_eeprom_var(&v, i + 1)) { 103 | read_ok = false; 104 | break; 105 | } 106 | buffer[i] = v.as_u32; 107 | } 108 | } else { 109 | read_ok = false; 110 | } 111 | 112 | if (read_ok) { 113 | memcpy(&(d->balance_conf), buffer, sizeof(balance_config)); 114 | } else { 115 | confparser_set_defaults_balance_config(&(d->balance_conf)); 116 | } 117 | 118 | info->stop_fun = stop; 119 | info->arg = d; 120 | 121 | VESC_IF->conf_custom_add_config(get_cfg, set_cfg, get_cfg_xml); 122 | 123 | return true; 124 | } 125 | 126 | -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/CMSIS/include/arm_const_structs.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2013 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 17. January 2013 5 | * $Revision: V1.4.1 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_const_structs.h 9 | * 10 | * Description: This file has constant structs that are initialized for 11 | * user convenience. For example, some can be given as 12 | * arguments to the arm_cfft_f32() function. 13 | * 14 | * Target Processor: Cortex-M4/Cortex-M3 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * - Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * - Redistributions in binary form must reproduce the above copyright 22 | * notice, this list of conditions and the following disclaimer in 23 | * the documentation and/or other materials provided with the 24 | * distribution. 25 | * - Neither the name of ARM LIMITED nor the names of its contributors 26 | * may be used to endorse or promote products derived from this 27 | * software without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 32 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 33 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 34 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 39 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 40 | * POSSIBILITY OF SUCH DAMAGE. 41 | * -------------------------------------------------------------------- */ 42 | 43 | #ifndef _ARM_CONST_STRUCTS_H 44 | #define _ARM_CONST_STRUCTS_H 45 | 46 | #include "arm_math.h" 47 | #include "arm_common_tables.h" 48 | 49 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len16 = { 50 | 16, twiddleCoef_16, armBitRevIndexTable16, ARMBITREVINDEXTABLE__16_TABLE_LENGTH 51 | }; 52 | 53 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len32 = { 54 | 32, twiddleCoef_32, armBitRevIndexTable32, ARMBITREVINDEXTABLE__32_TABLE_LENGTH 55 | }; 56 | 57 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len64 = { 58 | 64, twiddleCoef_64, armBitRevIndexTable64, ARMBITREVINDEXTABLE__64_TABLE_LENGTH 59 | }; 60 | 61 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len128 = { 62 | 128, twiddleCoef_128, armBitRevIndexTable128, ARMBITREVINDEXTABLE_128_TABLE_LENGTH 63 | }; 64 | 65 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len256 = { 66 | 256, twiddleCoef_256, armBitRevIndexTable256, ARMBITREVINDEXTABLE_256_TABLE_LENGTH 67 | }; 68 | 69 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len512 = { 70 | 512, twiddleCoef_512, armBitRevIndexTable512, ARMBITREVINDEXTABLE_512_TABLE_LENGTH 71 | }; 72 | 73 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024 = { 74 | 1024, twiddleCoef_1024, armBitRevIndexTable1024, ARMBITREVINDEXTABLE1024_TABLE_LENGTH 75 | }; 76 | 77 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048 = { 78 | 2048, twiddleCoef_2048, armBitRevIndexTable2048, ARMBITREVINDEXTABLE2048_TABLE_LENGTH 79 | }; 80 | 81 | const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096 = { 82 | 4096, twiddleCoef_4096, armBitRevIndexTable4096, ARMBITREVINDEXTABLE4096_TABLE_LENGTH 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /c_libs/examples/speed_test/README.md: -------------------------------------------------------------------------------- 1 | # Speed Test 2 | 3 | C code for the speed test example in lisp. This is the corresponding code in lisp that loads the compiled binary of this example: 4 | 5 | ```clj 6 | (def example [ 7 | 0x00 0x00 0x00 0x00 0x0a 0x4b 0x0b 0x49 0x0b 0x48 0x10 0xb5 0x7b 0x44 0x07 0x4c 0x1b 0x68 0x23 0x68 8 | 0x79 0x44 0x78 0x44 0x98 0x47 0x08 0x49 0x08 0x48 0x23 0x68 0x79 0x44 0x78 0x44 0x98 0x47 0x01 0x20 9 | 0x10 0xbd 0x00 0xbf 0x00 0xf8 0x00 0x10 0xf0 0xff 0xff 0xff 0xc1 0x00 0x00 0x00 0x46 0x00 0x00 0x00 10 | 0x05 0x01 0x00 0x00 0x46 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 11 | 0x43 0x20 0x54 0x61 0x6b 0x52 0x65 0x73 0x3a 0x20 0x25 0x64 0x00 0x00 0x00 0x00 0x65 0x78 0x74 0x2d 12 | 0x64 0x65 0x63 0x2d 0x63 0x6e 0x74 0x00 0x65 0x78 0x74 0x2d 0x74 0x61 0x6b 0x00 0x82 0xb0 0x01 0x90 13 | 0x01 0x98 0x18 0xb1 0x01 0x98 0x01 0x38 0x02 0xb0 0xf7 0xe7 0x02 0xb0 0x70 0x47 0x30 0xb5 0x85 0xb0 14 | 0x03 0x90 0x02 0x91 0x01 0x92 0x02 0x9a 0x03 0x9b 0x9a 0x42 0x1a 0xda 0x03 0x98 0x02 0x99 0x01 0x9a 15 | 0x01 0x38 0xff 0xf7 0xf1 0xff 0x04 0x46 0x02 0x98 0x01 0x99 0x03 0x9a 0x01 0x38 0xff 0xf7 0xea 0xff 16 | 0x05 0x46 0x01 0x98 0x03 0x99 0x02 0x9a 0x01 0x38 0xff 0xf7 0xe3 0xff 0x29 0x46 0x02 0x46 0x20 0x46 17 | 0x05 0xb0 0xbd 0xe8 0x30 0x40 0xdb 0xe7 0x01 0x98 0x05 0xb0 0x30 0xbd 0x00 0x00 0x70 0xb5 0x01 0x29 18 | 0x2d 0xed 0x02 0x8b 0x05 0x46 0x10 0x4c 0x18 0xd1 0xe3 0x6f 0x00 0x68 0x98 0x47 0xa0 0xb1 0xd4 0xf8 19 | 0xac 0x30 0x98 0x47 0x63 0x6e 0x28 0x68 0xb0 0xee 0x40 0x8a 0x98 0x47 0xff 0xf7 0xb9 0xff 0xd4 0xf8 20 | 0xac 0x30 0x98 0x47 0x30 0xee 0x48 0x0a 0xbd 0xec 0x02 0x8b 0xe3 0x6c 0xbd 0xe8 0x70 0x40 0x18 0x47 21 | 0xbd 0xec 0x02 0x8b 0xd4 0xf8 0x94 0x00 0x70 0xbd 0x00 0xbf 0x00 0xf8 0x00 0x10 0x2d 0xe9 0xf0 0x41 22 | 0x03 0x29 0x2d 0xed 0x02 0x8b 0x05 0x46 0x1e 0x4c 0x35 0xd1 0xe3 0x6f 0x00 0x68 0x98 0x47 0x00 0x28 23 | 0x30 0xd0 0xe3 0x6f 0x68 0x68 0x98 0x47 0x60 0xb3 0xe3 0x6f 0xa8 0x68 0x98 0x47 0x40 0xb3 0xd4 0xf8 24 | 0xac 0x30 0x98 0x47 0x63 0x6e 0x28 0x68 0xb0 0xee 0x40 0x8a 0x98 0x47 0x63 0x6e 0x06 0x46 0x68 0x68 25 | 0x98 0x47 0x63 0x6e 0x07 0x46 0xa8 0x68 0x98 0x47 0x39 0x46 0x02 0x46 0x30 0x46 0xff 0xf7 0x86 0xff 26 | 0xd4 0xf8 0xac 0x30 0x05 0x46 0x98 0x47 0x0b 0x48 0xd4 0xf8 0xb4 0x30 0xf0 0xee 0x40 0x8a 0x29 0x46 27 | 0x78 0x44 0x98 0x47 0x38 0xee 0xc8 0x0a 0xbd 0xec 0x02 0x8b 0xe3 0x6c 0xbd 0xe8 0xf0 0x41 0x18 0x47 28 | 0xbd 0xec 0x02 0x8b 0xd4 0xf8 0x94 0x00 0xbd 0xe8 0xf0 0x81 0x00 0xf8 0x00 0x10 0xbc 0xfe 0xff 0xff 29 | ]) 30 | 31 | ; Provides ext-dec-cnt and ext-tak which are implemented as recursive functions in C 32 | ; like below. They take the same arguments, but return the number of seconds they took 33 | ; to run 34 | (load-native-lib example) 35 | 36 | (defun dec-cnt (x) 37 | (if (= x 0) 0 (dec-cnt (- x 1))) 38 | ) 39 | 40 | ; Seems to run faster using match instead of if 41 | (defun dec-cnt2 (x) 42 | (match x (0 0) (_ (dec-cnt2 (- x 1)))) 43 | ) 44 | 45 | (defun tak (x y z) 46 | (if (>= y x) 47 | z 48 | (tak 49 | (tak (- x 1) y z) 50 | (tak (- y 1) z x) 51 | (tak (- z 1) x y) 52 | ))) 53 | 54 | (print "\nTesting dec-cnt...") 55 | (looprange i 0 2 56 | (progn 57 | (print (str-from-n (+ i 1) "Try %d")) 58 | (print (str-from-n (ext-dec-cnt 100000) "C Time: %.5f s")) 59 | (define start (systime)) 60 | (dec-cnt2 100000) 61 | (def time (secs-since start)) 62 | (print (str-from-n time "LBM Time: %.3f s")) 63 | (print (str-from-n (/ time (ext-dec-cnt 100000)) "C Speed Diff: %.1f times")) 64 | (sleep 1) 65 | )) 66 | 67 | (print "\nTesting tak...") 68 | (looprange i 0 2 69 | (progn 70 | (print (str-from-n (+ i 1) "Try %d")) 71 | (print (str-from-n (ext-tak 18 12 6) "C Time: %.5f s")) 72 | (define start (systime)) 73 | (define takres (tak 18 12 6)) 74 | (def time (secs-since start)) 75 | (print (str-from-n time "LBM Time: %.3f s")) 76 | (print (str-from-n (/ time (ext-tak 18 12 6)) "C Speed Diff: %.1f times")) 77 | (sleep 1) 78 | )) 79 | ``` -------------------------------------------------------------------------------- /c_libs/st_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef ST_TYPES_H 21 | #define ST_TYPES_H 22 | 23 | #include 24 | #include 25 | #include "system_stm32f4xx.h" 26 | 27 | #ifdef USE_STLIB 28 | #include "stm32f4xx_conf.h" 29 | #endif 30 | 31 | typedef struct { 32 | volatile uint32_t MODER; 33 | volatile uint32_t OTYPER; 34 | volatile uint32_t OSPEEDR; 35 | volatile uint32_t PUPDR; 36 | volatile uint32_t IDR; 37 | volatile uint32_t ODR; 38 | volatile union { 39 | uint32_t W; 40 | struct { 41 | uint16_t set; 42 | uint16_t clear; 43 | } H; 44 | } BSRR; 45 | volatile uint32_t LCKR; 46 | volatile uint32_t AFRL; 47 | volatile uint32_t AFRH; 48 | volatile uint32_t BRR; 49 | } stm32_gpio_t; 50 | 51 | #undef GPIOA 52 | #undef GPIOB 53 | #undef GPIOC 54 | #undef GPIOD 55 | #undef GPIOE 56 | #undef GPIOF 57 | #undef GPIOG 58 | #undef GPIOH 59 | #undef GPIOI 60 | 61 | #define GPIOA ((stm32_gpio_t *)GPIOA_BASE) 62 | #define GPIOB ((stm32_gpio_t *)GPIOB_BASE) 63 | #define GPIOC ((stm32_gpio_t *)GPIOC_BASE) 64 | #define GPIOD ((stm32_gpio_t *)GPIOD_BASE) 65 | #define GPIOE ((stm32_gpio_t *)GPIOE_BASE) 66 | #define GPIOF ((stm32_gpio_t *)GPIOF_BASE) 67 | #define GPIOG ((stm32_gpio_t *)GPIOG_BASE) 68 | #define GPIOH ((stm32_gpio_t *)GPIOH_BASE) 69 | #define GPIOI ((stm32_gpio_t *)GPIOI_BASE) 70 | 71 | #define PAL_STM32_MODE_MASK (3U << 0U) 72 | #define PAL_STM32_MODE_INPUT (0U << 0U) 73 | #define PAL_STM32_MODE_OUTPUT (1U << 0U) 74 | #define PAL_STM32_MODE_ALTERNATE (2U << 0U) 75 | #define PAL_STM32_MODE_ANALOG (3U << 0U) 76 | 77 | #define PAL_STM32_OTYPE_MASK (1U << 2U) 78 | #define PAL_STM32_OTYPE_PUSHPULL (0U << 2U) 79 | #define PAL_STM32_OTYPE_OPENDRAIN (1U << 2U) 80 | 81 | #define PAL_STM32_OSPEED_MASK (3U << 3U) 82 | #define PAL_STM32_OSPEED_LOWEST (0U << 3U) 83 | #if defined(STM32F0XX) || defined(STM32F30X) || defined(STM32F37X) 84 | #define PAL_STM32_OSPEED_MID (1U << 3U) 85 | #else 86 | #define PAL_STM32_OSPEED_MID1 (1U << 3U) 87 | #define PAL_STM32_OSPEED_MID2 (2U << 3U) 88 | #endif 89 | #define PAL_STM32_OSPEED_HIGHEST (3U << 3U) 90 | 91 | #define PAL_STM32_PUDR_MASK (3U << 5U) 92 | #define PAL_STM32_PUDR_FLOATING (0U << 5U) 93 | #define PAL_STM32_PUDR_PULLUP (1U << 5U) 94 | #define PAL_STM32_PUDR_PULLDOWN (2U << 5U) 95 | 96 | #define PAL_STM32_ALTERNATE_MASK (15U << 7U) 97 | #define PAL_STM32_ALTERNATE(n) ((n) << 7U) 98 | 99 | #define PAL_STM32_MODE_MASK (3U << 0U) 100 | #define PAL_STM32_MODE_INPUT (0U << 0U) 101 | #define PAL_STM32_MODE_OUTPUT (1U << 0U) 102 | #define PAL_STM32_MODE_ALTERNATE (2U << 0U) 103 | #define PAL_STM32_MODE_ANALOG (3U << 0U) 104 | 105 | #define PAL_STM32_ALTERNATE(n) ((n) << 7U) 106 | 107 | #define PAL_MODE_ALTERNATE(n) (PAL_STM32_MODE_ALTERNATE | PAL_STM32_ALTERNATE(n)) 108 | 109 | #endif // ST_TYPES_H 110 | 111 | -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/inc/stm32f4xx_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_wwdg.h 4 | * @author MCD Application Team 5 | * @version V1.6.0 6 | * @date 10-July-2015 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2015 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_WWDG_H 31 | #define __STM32F4xx_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup WWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup WWDG_Prescaler 56 | * @{ 57 | */ 58 | 59 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 60 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 61 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 62 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 63 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 64 | ((PRESCALER) == WWDG_Prescaler_2) || \ 65 | ((PRESCALER) == WWDG_Prescaler_4) || \ 66 | ((PRESCALER) == WWDG_Prescaler_8)) 67 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 68 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /* Exported macro ------------------------------------------------------------*/ 79 | /* Exported functions --------------------------------------------------------*/ 80 | 81 | /* Function used to set the WWDG configuration to the default reset state ****/ 82 | void WWDG_DeInit(void); 83 | 84 | /* Prescaler, Refresh window and Counter configuration functions **************/ 85 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 86 | void WWDG_SetWindowValue(uint8_t WindowValue); 87 | void WWDG_EnableIT(void); 88 | void WWDG_SetCounter(uint8_t Counter); 89 | 90 | /* WWDG activation function ***************************************************/ 91 | void WWDG_Enable(uint8_t Counter); 92 | 93 | /* Interrupts and flags management functions **********************************/ 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F4xx_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 112 | -------------------------------------------------------------------------------- /lib_midi/midi_test.lisp: -------------------------------------------------------------------------------- 1 | (import "pkg::midi@://vesc_packages/lib_midi/midi.vescpkg" 'midi) 2 | (import "pkg::midi_axelf_base@://vesc_packages/lib_files/files.vescpkg" 'axelf-base) 3 | (import "pkg::midi_axelf_melody@://vesc_packages/lib_files/files.vescpkg" 'axelf-melody) 4 | 5 | (load-native-lib midi) 6 | 7 | (ext-midi-init 2) 8 | (ext-midi-open 0 axelf-melody) 9 | (ext-midi-open 1 axelf-base) 10 | 11 | (foc-play-stop) 12 | 13 | ; Channel format (ch note freq vol decay) 14 | ; Note 0 means nothing is playing 15 | (def num-chan 4) 16 | (def channels (map (fn (x) (list x 0 0 0 0)) (range num-chan))) 17 | 18 | (defun note-on (note vol decay) 19 | (atomic (loopforeach ch channels { 20 | (if (= (ix ch 1) 0) { 21 | (var freq (* 440.0 (pow 2.0 (/ (- note 69.0) 12.0)))) 22 | (setix ch 2 freq) 23 | (setix ch 3 vol) 24 | (setix ch 4 decay) 25 | (setix ch 1 note) 26 | (foc-play-tone (ix ch 0) freq vol) 27 | (break) 28 | }) 29 | }))) 30 | 31 | (defun note-off (note) 32 | (atomic (loopforeach ch channels { 33 | (if (= (ix ch 1) note) { 34 | (setix ch 1 0) 35 | (foc-play-tone (ix ch 0) 500 0) 36 | (break) 37 | }) 38 | }))) 39 | 40 | ; Exponential decay on active channels 41 | (loopwhile-thd 200 t { 42 | (loopforeach ch channels 43 | (atomic (if (not (= (ix ch 1) 0)) { 44 | (var ch-ind (ix ch 0)) 45 | (var freq (ix ch 2)) 46 | (var vol (ix ch 3)) 47 | (var decay (ix ch 4)) 48 | (setix ch 3 (* vol decay)) 49 | (foc-play-tone ch-ind freq vol) 50 | }))) 51 | (sleep 0.02) 52 | }) 53 | 54 | (def t-start (systime)) 55 | 56 | (defun play-midi (parser volts decay) { 57 | (var t-delta 0.0) 58 | (var midi-tdiv 100) 59 | (var midi-tempo 400000) 60 | 61 | (loopwhile t (match (ext-midi-parse parser) 62 | ((midi-header (? size) (? format) (? tracks) (? time-div)) { 63 | (setq midi-tdiv time-div) 64 | }) 65 | 66 | ((midi-track-midi (? time) (? status) (? chan) (? p1) (? p2)) { 67 | (var secs (/ (* midi-tempo (to-float time)) midi-tdiv 1000000.0)) 68 | (setq t-delta (+ t-delta secs)) 69 | 70 | (var to-sleep (- t-delta (secs-since t-start))) 71 | (if (> to-sleep 0.001) (sleep to-sleep)) 72 | 73 | ; Note on 74 | (if (= status 9) { 75 | (note-on p1 volts decay) 76 | }) 77 | 78 | ; Note off 79 | (if (= status 8) { 80 | (note-off p1) 81 | }) 82 | }) 83 | 84 | ((midi-track-meta (? time) (? type) (? len) (? data)) { 85 | ; Tempo 86 | (if (= type 81) 87 | (setq midi-tempo data) 88 | ) 89 | }) 90 | 91 | (midi-error { 92 | (print "Midi error") 93 | (break) 94 | }) 95 | 96 | (midi-eob { 97 | (print "End of file") 98 | (break) 99 | }) 100 | 101 | ((? a) { 102 | (print a) 103 | }) 104 | ) 105 | )}) 106 | 107 | (spawn 200 play-midi 0 0.7 0.92) 108 | (spawn 200 play-midi 1 0.4 0.92) 109 | -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/CMSIS/ST/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V2.1.0 6 | * @date 19-June-2014 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /** @addtogroup CMSIS 39 | * @{ 40 | */ 41 | 42 | /** @addtogroup stm32f4xx_system 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @brief Define to prevent recursive inclusion 48 | */ 49 | #ifndef __SYSTEM_STM32F4XX_H 50 | #define __SYSTEM_STM32F4XX_H 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /** @addtogroup STM32F4xx_System_Includes 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | /** @addtogroup STM32F4xx_System_Exported_types 66 | * @{ 67 | */ 68 | /* This variable is updated in three ways: 69 | 1) by calling CMSIS function SystemCoreClockUpdate() 70 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 71 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 72 | Note: If you use this function to configure the system clock; then there 73 | is no need to call the 2 first functions listed above, since SystemCoreClock 74 | variable is updated automatically. 75 | */ 76 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 77 | 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F4xx_System_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F4xx_System_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F4xx_System_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | extern void SystemInit(void); 104 | extern void SystemCoreClockUpdate(void); 105 | /** 106 | * @} 107 | */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /*__SYSTEM_STM32F4XX_H */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | -------------------------------------------------------------------------------- /lib_pn532/pn532.lisp: -------------------------------------------------------------------------------- 1 | (def pn532-addr 0x24) 2 | 3 | (def bufadd-u8 (macro (buf ind num) 4 | `(bufset-u8 ,buf (- (setq ,ind (+ ,ind 1)) 1) ,num)) 5 | ) 6 | 7 | (defun pn532-cmd (cmd) { 8 | (setq cmd (cons 0xd4 cmd)) ; Prepend host-to-pn532 9 | (var cmdlen (length cmd)) 10 | (var buffer (array-create (+ cmdlen 7))) 11 | (var ind 0) 12 | 13 | (bufadd-u8 buffer ind 0) ; Preamble 14 | (bufadd-u8 buffer ind 0) ; Startcode 1 15 | (bufadd-u8 buffer ind 0xFF) ; Startcode 2 16 | (bufadd-u8 buffer ind cmdlen) 17 | (bufadd-u8 buffer ind (+ (bitwise-not cmdlen) 1)) 18 | 19 | (var sum 0) 20 | (loopforeach c cmd { 21 | (bufadd-u8 buffer ind c) 22 | (setq sum (+ sum c)) 23 | }) 24 | 25 | (bufadd-u8 buffer ind (+ (bitwise-not sum) 1)) ; Checksum 26 | (bufadd-u8 buffer ind 0) ; Postamble 27 | 28 | (i2c-tx-rx pn532-addr buffer) 29 | (free buffer) 30 | }) 31 | 32 | (defun pn532-read (n) { 33 | (var rbuf (array-create (+ n 1))) 34 | (i2c-tx-rx pn532-addr nil rbuf) 35 | (var res (map (fn (x) (bufget-u8 rbuf x)) (range 1 (+ n 1)))) 36 | (free rbuf) 37 | res 38 | }) 39 | 40 | (def pn532-readybuf (array-create 1)) 41 | (defun pn532-isready () { 42 | (i2c-tx-rx pn532-addr nil pn532-readybuf) 43 | (= (bufget-u8 pn532-readybuf 0) 1) 44 | }) 45 | 46 | (defun pn532-waitready (tout) { 47 | (var start (systime)) 48 | (loopwhile t { 49 | (if (pn532-isready) (break true)) 50 | (if (> (secs-since start) tout) (break false)) 51 | (sleep 0.05) 52 | }) 53 | }) 54 | 55 | (defun pn532-readack () { 56 | (eq (pn532-read 6) '(0x00 0x00 0xff 0x00 0xff 0x00)) 57 | }) 58 | 59 | (defunret pn532-cmd-check-ack (cmd tout) { 60 | (pn532-cmd cmd) 61 | (sleep 0.001) 62 | (if (not (pn532-waitready tout)) (return false)) 63 | (if (not (pn532-readack)) (return false)) 64 | (sleep 0.001) 65 | (pn532-waitready tout) 66 | }) 67 | 68 | (defun pn532-read-fwversion () 69 | (if (pn532-cmd-check-ack '(0x02) 1) { 70 | (var data (pn532-read 13)) 71 | (map (fn (x) (ix data x)) '(7 8 9 10)) 72 | }) 73 | false 74 | ) 75 | 76 | ; Configure Secure Access Module 77 | (defun pn532-sam () 78 | (if (pn532-cmd-check-ack '(0x14 0x01 0x14 0x01) 1) { 79 | (var data (pn532-read 9)) 80 | (= (ix data 6) 0x15) 81 | }) 82 | false 83 | ) 84 | 85 | (defun pn532-read-target-id (tout) 86 | (if (pn532-cmd-check-ack '(0x4A 1 0) tout) { 87 | (var data (pn532-read 20)) 88 | (var uuid-len (ix data 12)) 89 | (var uuid (map (fn (x) (ix data x)) (range 13 (+ 13 uuid-len)))) 90 | (list uuid-len uuid) 91 | }) 92 | false 93 | ) 94 | 95 | (defun pn532-authenticate-block (uuid block keynum key) 96 | (if (pn532-cmd-check-ack `(0x40 1 ,(if (= keynum 0) 0x60 0x61) ,block ,@key ,@uuid) 1) { 97 | (var data (pn532-read 12)) 98 | (= (ix data 7) 0) 99 | }) 100 | false 101 | ) 102 | 103 | (defun pn532-mifareclassic-read-block (block) 104 | (if (pn532-cmd-check-ack `(0x40 1 0x30 ,block) 1) { 105 | (var data (pn532-read 26)) 106 | (if (= (ix data 7) 0) 107 | (map (fn (x) (ix data x)) (range 8 24)) 108 | false 109 | ) 110 | }) 111 | false 112 | ) 113 | 114 | (defun pn532-mifareclassic-write-block (block data) 115 | (if (pn532-cmd-check-ack `(0x40 1 0xA0 ,block ,@data) 1) { 116 | (pn532-read 26) 117 | true 118 | }) 119 | false 120 | ) 121 | 122 | (defun pn532-mifareul-read-page (page) 123 | (if (pn532-cmd-check-ack `(0x40 1 0x30 ,page) 1) { 124 | (var data (pn532-read 26)) 125 | (if (= (ix data 7) 0) 126 | (map (fn (x) (ix data x)) (range 8 12)) 127 | false 128 | ) 129 | }) 130 | false 131 | ) 132 | 133 | (defun pn532-mifareul-write-page (page data) 134 | (if (pn532-cmd-check-ack `(0x40 1 0xA2 ,page ,@data) 1) { 135 | (pn532-read 26) 136 | true 137 | }) 138 | false 139 | ) 140 | 141 | (defun pn532-init (pins) { 142 | (apply i2c-start (append '('rate-400k) pins)) 143 | (i2c-tx-rx pn532-addr '(0)) ; Required on the ESP for some reason 144 | (pn532-sam) 145 | }) 146 | -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/inc/stm32f4_gpio_af.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _STM32F4_GPIO_AF_H_ 3 | #define _STM32F4_GPIO_AF_H_ 4 | 5 | /** 6 | * @brief AF 0 selection 7 | */ 8 | #define GPIO_AF_RTC_50Hz ((uint8_t)0x00) /* RTC_50Hz Alternate Function mapping */ 9 | #define GPIO_AF_MCO ((uint8_t)0x00) /* MCO (MCO1 and MCO2) Alternate Function mapping */ 10 | #define GPIO_AF_TAMPER ((uint8_t)0x00) /* TAMPER (TAMPER_1 and TAMPER_2) Alternate Function mapping */ 11 | #define GPIO_AF_SWJ ((uint8_t)0x00) /* SWJ (SWD and JTAG) Alternate Function mapping */ 12 | #define GPIO_AF_TRACE ((uint8_t)0x00) /* TRACE Alternate Function mapping */ 13 | 14 | /** 15 | * @brief AF 1 selection 16 | */ 17 | #define GPIO_AF_TIM1 ((uint8_t)0x01) /* TIM1 Alternate Function mapping */ 18 | #define GPIO_AF_TIM2 ((uint8_t)0x01) /* TIM2 Alternate Function mapping */ 19 | 20 | /** 21 | * @brief AF 2 selection 22 | */ 23 | #define GPIO_AF_TIM3 ((uint8_t)0x02) /* TIM3 Alternate Function mapping */ 24 | #define GPIO_AF_TIM4 ((uint8_t)0x02) /* TIM4 Alternate Function mapping */ 25 | #define GPIO_AF_TIM5 ((uint8_t)0x02) /* TIM5 Alternate Function mapping */ 26 | 27 | /** 28 | * @brief AF 3 selection 29 | */ 30 | #define GPIO_AF_TIM8 ((uint8_t)0x03) /* TIM8 Alternate Function mapping */ 31 | #define GPIO_AF_TIM9 ((uint8_t)0x03) /* TIM9 Alternate Function mapping */ 32 | #define GPIO_AF_TIM10 ((uint8_t)0x03) /* TIM10 Alternate Function mapping */ 33 | #define GPIO_AF_TIM11 ((uint8_t)0x03) /* TIM11 Alternate Function mapping */ 34 | 35 | /** 36 | * @brief AF 4 selection 37 | */ 38 | #define GPIO_AF_I2C1 ((uint8_t)0x04) /* I2C1 Alternate Function mapping */ 39 | #define GPIO_AF_I2C2 ((uint8_t)0x04) /* I2C2 Alternate Function mapping */ 40 | #define GPIO_AF_I2C3 ((uint8_t)0x04) /* I2C3 Alternate Function mapping */ 41 | 42 | /** 43 | * @brief AF 5 selection 44 | */ 45 | #define GPIO_AF_SPI1 ((uint8_t)0x05) /* SPI1 Alternate Function mapping */ 46 | #define GPIO_AF_SPI2 ((uint8_t)0x05) /* SPI2/I2S2 Alternate Function mapping */ 47 | 48 | /** 49 | * @brief AF 6 selection 50 | */ 51 | #define GPIO_AF_SPI3 ((uint8_t)0x06) /* SPI3/I2S3 Alternate Function mapping */ 52 | 53 | /** 54 | * @brief AF 7 selection 55 | */ 56 | #define GPIO_AF_USART1 ((uint8_t)0x07) /* USART1 Alternate Function mapping */ 57 | #define GPIO_AF_USART2 ((uint8_t)0x07) /* USART2 Alternate Function mapping */ 58 | #define GPIO_AF_USART3 ((uint8_t)0x07) /* USART3 Alternate Function mapping */ 59 | #define GPIO_AF_I2S3ext ((uint8_t)0x07) /* I2S3ext Alternate Function mapping */ 60 | 61 | /** 62 | * @brief AF 8 selection 63 | */ 64 | #define GPIO_AF_UART4 ((uint8_t)0x08) /* UART4 Alternate Function mapping */ 65 | #define GPIO_AF_UART5 ((uint8_t)0x08) /* UART5 Alternate Function mapping */ 66 | #define GPIO_AF_USART6 ((uint8_t)0x08) /* USART6 Alternate Function mapping */ 67 | 68 | /** 69 | * @brief AF 9 selection 70 | */ 71 | #define GPIO_AF_CAN1 ((uint8_t)0x09) /* CAN1 Alternate Function mapping */ 72 | #define GPIO_AF_CAN2 ((uint8_t)0x09) /* CAN2 Alternate Function mapping */ 73 | #define GPIO_AF_TIM12 ((uint8_t)0x09) /* TIM12 Alternate Function mapping */ 74 | #define GPIO_AF_TIM13 ((uint8_t)0x09) /* TIM13 Alternate Function mapping */ 75 | #define GPIO_AF_TIM14 ((uint8_t)0x09) /* TIM14 Alternate Function mapping */ 76 | 77 | /** 78 | * @brief AF 10 selection 79 | */ 80 | #define GPIO_AF_OTG_FS ((uint8_t)0xA) /* OTG_FS Alternate Function mapping */ 81 | #define GPIO_AF_OTG_HS ((uint8_t)0xA) /* OTG_HS Alternate Function mapping */ 82 | 83 | /** 84 | * @brief AF 11 selection 85 | */ 86 | #define GPIO_AF_ETH ((uint8_t)0x0B) /* ETHERNET Alternate Function mapping */ 87 | 88 | /** 89 | * @brief AF 12 selection 90 | */ 91 | #define GPIO_AF_FSMC ((uint8_t)0xC) /* FSMC Alternate Function mapping */ 92 | #define GPIO_AF_OTG_HS_FS ((uint8_t)0xC) /* OTG HS configured in FS, Alternate Function mapping */ 93 | #define GPIO_AF_SDIO ((uint8_t)0xC) /* SDIO Alternate Function mapping */ 94 | 95 | /** 96 | * @brief AF 13 selection 97 | */ 98 | #define GPIO_AF_DCMI ((uint8_t)0x0D) /* DCMI Alternate Function mapping */ 99 | 100 | /** 101 | * @brief AF 15 selection 102 | */ 103 | #define GPIO_AF_EVENTOUT ((uint8_t)0x0F) /* EVENTOUT Alternate Function mapping */ 104 | 105 | #endif 106 | 107 | -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/inc/stm32f4xx_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_iwdg.h 4 | * @author MCD Application Team 5 | * @version V1.6.0 6 | * @date 10-July-2015 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2015 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_IWDG_H 31 | #define __STM32F4xx_IWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup IWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup IWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup IWDG_WriteAccess 56 | * @{ 57 | */ 58 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 59 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 60 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 61 | ((ACCESS) == IWDG_WriteAccess_Disable)) 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup IWDG_prescaler 67 | * @{ 68 | */ 69 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 70 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 71 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 72 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 73 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 74 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 75 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 76 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 77 | ((PRESCALER) == IWDG_Prescaler_8) || \ 78 | ((PRESCALER) == IWDG_Prescaler_16) || \ 79 | ((PRESCALER) == IWDG_Prescaler_32) || \ 80 | ((PRESCALER) == IWDG_Prescaler_64) || \ 81 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 82 | ((PRESCALER) == IWDG_Prescaler_256)) 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @defgroup IWDG_Flag 88 | * @{ 89 | */ 90 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 91 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 92 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 93 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /* Exported macro ------------------------------------------------------------*/ 103 | /* Exported functions --------------------------------------------------------*/ 104 | 105 | /* Prescaler and Counter configuration functions ******************************/ 106 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 107 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 108 | void IWDG_SetReload(uint16_t Reload); 109 | void IWDG_ReloadCounter(void); 110 | 111 | /* IWDG activation function ***************************************************/ 112 | void IWDG_Enable(void); 113 | 114 | /* Flag management function ***************************************************/ 115 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif /* __STM32F4xx_IWDG_H */ 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 132 | -------------------------------------------------------------------------------- /c_libs/stdperiph_stm32f4/CMSIS/include/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2013 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 17. January 2013 5 | * $Revision: V1.4.1 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions 16 | * are met: 17 | * - Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * - Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in 21 | * the documentation and/or other materials provided with the 22 | * distribution. 23 | * - Neither the name of ARM LIMITED nor the names of its contributors 24 | * may be used to endorse or promote products derived from this 25 | * software without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * -------------------------------------------------------------------- */ 40 | 41 | #ifndef _ARM_COMMON_TABLES_H 42 | #define _ARM_COMMON_TABLES_H 43 | 44 | #include "arm_math.h" 45 | 46 | extern const uint16_t armBitRevTable[1024]; 47 | extern const q15_t armRecipTableQ15[64]; 48 | extern const q31_t armRecipTableQ31[64]; 49 | extern const q31_t realCoefAQ31[1024]; 50 | extern const q31_t realCoefBQ31[1024]; 51 | extern const float32_t twiddleCoef_16[32]; 52 | extern const float32_t twiddleCoef_32[64]; 53 | extern const float32_t twiddleCoef_64[128]; 54 | extern const float32_t twiddleCoef_128[256]; 55 | extern const float32_t twiddleCoef_256[512]; 56 | extern const float32_t twiddleCoef_512[1024]; 57 | extern const float32_t twiddleCoef_1024[2048]; 58 | extern const float32_t twiddleCoef_2048[4096]; 59 | extern const float32_t twiddleCoef_4096[8192]; 60 | #define twiddleCoef twiddleCoef_4096 61 | extern const q31_t twiddleCoefQ31[6144]; 62 | extern const q15_t twiddleCoefQ15[6144]; 63 | extern const float32_t twiddleCoef_rfft_32[32]; 64 | extern const float32_t twiddleCoef_rfft_64[64]; 65 | extern const float32_t twiddleCoef_rfft_128[128]; 66 | extern const float32_t twiddleCoef_rfft_256[256]; 67 | extern const float32_t twiddleCoef_rfft_512[512]; 68 | extern const float32_t twiddleCoef_rfft_1024[1024]; 69 | extern const float32_t twiddleCoef_rfft_2048[2048]; 70 | extern const float32_t twiddleCoef_rfft_4096[4096]; 71 | 72 | 73 | #define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 ) 74 | #define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 ) 75 | #define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 ) 76 | #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 ) 77 | #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 ) 78 | #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 ) 79 | #define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800) 80 | #define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808) 81 | #define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032) 82 | 83 | extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH]; 84 | extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH]; 85 | extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH]; 86 | extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; 87 | extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; 88 | extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; 89 | extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH]; 90 | extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH]; 91 | extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH]; 92 | 93 | #endif /* ARM_COMMON_TABLES_H */ 94 | -------------------------------------------------------------------------------- /c_libs/utils/rb.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "rb.h" 21 | #include 22 | #include 23 | 24 | // Private functions (without locks) 25 | static unsigned int get_item_count(rb_t *rb); 26 | static unsigned int get_free_space(rb_t *rb); 27 | static bool is_empty(rb_t *rb); 28 | static bool pop(rb_t *rb, void *data); 29 | static bool insert(rb_t *rb, const void *data); 30 | 31 | void rb_init(rb_t *rb, void *buffer, int item_size, int item_count) { 32 | rb->mutex = VESC_IF->mutex_create(); 33 | rb->data = buffer; 34 | rb->item_size = item_size; 35 | rb->item_count = item_count; 36 | rb->head = 0; 37 | rb->tail = 0; 38 | rb->full = false; 39 | } 40 | 41 | void rb_init_alloc(rb_t *rb, int item_size, int item_count) { 42 | void *buffer = VESC_IF->malloc(item_size * item_count); 43 | rb_init(rb, buffer, item_size, item_count); 44 | } 45 | 46 | void rb_free(rb_t *rb) { 47 | VESC_IF->free(rb->mutex); 48 | VESC_IF->free(rb->data); 49 | } 50 | 51 | void rb_flush(rb_t *rb) { 52 | VESC_IF->mutex_lock(rb->mutex); 53 | rb->head = 0; 54 | rb->tail = 0; 55 | rb->full = false; 56 | VESC_IF->mutex_unlock(rb->mutex); 57 | } 58 | 59 | bool rb_insert(rb_t *rb, const void *data) { 60 | VESC_IF->mutex_lock(rb->mutex); 61 | bool res = insert(rb, data); 62 | VESC_IF->mutex_unlock(rb->mutex); 63 | return res; 64 | } 65 | 66 | unsigned int rb_insert_multi(rb_t *rb, const void *data, unsigned int count) { 67 | unsigned int cnt = 0; 68 | VESC_IF->mutex_lock(rb->mutex); 69 | while (!rb->full && cnt < count) { 70 | insert(rb, (char*)data + rb->item_size * cnt); 71 | cnt++; 72 | } 73 | VESC_IF->mutex_unlock(rb->mutex); 74 | return cnt; 75 | } 76 | 77 | bool rb_pop(rb_t *rb, void *data) { 78 | VESC_IF->mutex_lock(rb->mutex); 79 | bool res = pop(rb, data); 80 | VESC_IF->mutex_unlock(rb->mutex); 81 | return res; 82 | } 83 | 84 | unsigned int rb_pop_multi(rb_t *rb, void *data, unsigned int count) { 85 | unsigned int cnt = 0; 86 | VESC_IF->mutex_lock(rb->mutex); 87 | while (!is_empty(rb) && cnt < count) { 88 | if (data) { 89 | pop(rb, (char*)data + rb->item_size * cnt); 90 | } else { 91 | pop(rb, 0); 92 | } 93 | cnt++; 94 | } 95 | VESC_IF->mutex_unlock(rb->mutex); 96 | return cnt; 97 | } 98 | 99 | bool rb_is_full(rb_t *rb) { 100 | VESC_IF->mutex_lock(rb->mutex); 101 | bool res = rb->full; 102 | VESC_IF->mutex_unlock(rb->mutex); 103 | return res; 104 | } 105 | 106 | bool rb_is_empty(rb_t *rb) { 107 | VESC_IF->mutex_lock(rb->mutex); 108 | bool res = is_empty(rb); 109 | VESC_IF->mutex_unlock(rb->mutex); 110 | return res; 111 | } 112 | 113 | unsigned int rb_get_item_count(rb_t *rb) { 114 | VESC_IF->mutex_lock(rb->mutex); 115 | unsigned int res = get_item_count(rb); 116 | VESC_IF->mutex_unlock(rb->mutex); 117 | return res; 118 | } 119 | 120 | unsigned int rb_get_free_space(rb_t *rb) { 121 | VESC_IF->mutex_lock(rb->mutex); 122 | unsigned int res = get_free_space(rb); 123 | VESC_IF->mutex_unlock(rb->mutex); 124 | return res; 125 | } 126 | 127 | // Private function implementations 128 | 129 | static unsigned int get_item_count(rb_t *rb) { 130 | unsigned int res = rb->item_count; 131 | 132 | if (!rb->full) { 133 | if (rb->head >= rb->tail) { 134 | res = rb->head - rb->tail; 135 | } else { 136 | res = rb->item_count - rb->tail + rb->head; 137 | } 138 | } 139 | 140 | return res; 141 | } 142 | 143 | static unsigned int get_free_space(rb_t *rb) { 144 | return rb->item_count - get_item_count(rb); 145 | } 146 | 147 | static bool is_empty(rb_t *rb) { 148 | return rb->head == rb->tail && !rb->full; 149 | } 150 | 151 | static bool pop(rb_t *rb, void *data) { 152 | if (is_empty(rb)) { 153 | return false; 154 | } 155 | 156 | // Null will just advance the tail and discard the data 157 | if (data) { 158 | memcpy(data, (char*)(rb->data) + rb->tail * rb->item_size, rb->item_size); 159 | } 160 | 161 | rb->tail = (rb->tail + 1) % rb->item_count; 162 | rb->full = false; 163 | 164 | return true; 165 | } 166 | 167 | static bool insert(rb_t *rb, const void *data) { 168 | if (rb->full) { 169 | return false; 170 | } 171 | 172 | memcpy((char*)(rb->data) + rb->head * rb->item_size, data, rb->item_size); 173 | rb->head = (rb->head + 1) % rb->item_count; 174 | rb->full = rb->head == rb->tail; 175 | 176 | return true; 177 | } 178 | -------------------------------------------------------------------------------- /lib_midi/README.md: -------------------------------------------------------------------------------- 1 | # Midi Parser 2 | 3 | This library is a wrapper for the midi-parser here 4 | [https://github.com/abique/midi-parser](https://github.com/abique/midi-parser) 5 | 6 | When loaded, the following extensions are provided 7 | 8 | #### ext-midi-init 9 | 10 | ```clj 11 | (ext-midi-init num-parsers) 12 | ``` 13 | 14 | Load library and allocate memory for num-parsers parsers that can run simultaneously on different files. 15 | 16 | --- 17 | 18 | #### ext-midi-open 19 | 20 | ```clj 21 | (ext-midi-open parser-num file) 22 | ``` 23 | 24 | Open midi-file file on parser parser-num. 25 | 26 | #### ext-midi-parse 27 | 28 | ```clj 29 | (ext-midi-parse parser-num) 30 | ``` 31 | 32 | Parse next available block on parser-num. Returns one of the following lists: 33 | 34 | ```clj 35 | (midi-eob) 36 | (midi-error) 37 | (midi-init) 38 | (midi-header size format tracks time-dif) 39 | (midi-track size) 40 | (midi-track-midi vtime status channel param1 param2) 41 | (midi-track-meta vtime type length data) 42 | (midi-track-sysex vtime) 43 | ``` 44 | 45 | --- 46 | 47 | ## Example 48 | 49 | ```clj 50 | (import "pkg::midi@://vesc_packages/lib_midi/midi.vescpkg" 'midi) 51 | (import "pkg::midi_axelf_base@://vesc_packages/lib_files/files.vescpkg" 'axelf-base) 52 | (import "pkg::midi_axelf_melody@://vesc_packages/lib_files/files.vescpkg" 'axelf-melody) 53 | 54 | (load-native-lib midi) 55 | 56 | (ext-midi-init 2) 57 | (ext-midi-open 0 axelf-melody) 58 | (ext-midi-open 1 axelf-base) 59 | 60 | (foc-play-stop) 61 | 62 | ; Channel format (ch note freq vol decay) 63 | ; Note 0 means nothing is playing 64 | (def num-chan 4) 65 | (def channels (map (fn (x) (list x 0 0 0 0)) (range num-chan))) 66 | 67 | (defun note-on (note vol decay) 68 | (atomic (loopforeach ch channels { 69 | (if (= (ix ch 1) 0) { 70 | (var freq (* 440.0 (pow 2.0 (/ (- note 69.0) 12.0)))) 71 | (setix ch 2 freq) 72 | (setix ch 3 vol) 73 | (setix ch 4 decay) 74 | (setix ch 1 note) 75 | (foc-play-tone (ix ch 0) freq vol) 76 | (break) 77 | }) 78 | }))) 79 | 80 | (defun note-off (note) 81 | (atomic (loopforeach ch channels { 82 | (if (= (ix ch 1) note) { 83 | (setix ch 1 0) 84 | (foc-play-tone (ix ch 0) 500 0) 85 | (break) 86 | }) 87 | }))) 88 | 89 | ; Exponential decay on active channels 90 | (loopwhile-thd 200 t { 91 | (loopforeach ch channels 92 | (atomic (if (not (= (ix ch 1) 0)) { 93 | (var ch-ind (ix ch 0)) 94 | (var freq (ix ch 2)) 95 | (var vol (ix ch 3)) 96 | (var decay (ix ch 4)) 97 | (setix ch 3 (* vol decay)) 98 | (foc-play-tone ch-ind freq vol) 99 | }))) 100 | (sleep 0.02) 101 | }) 102 | 103 | (def t-start (systime)) 104 | 105 | (defun play-midi (parser volts decay) { 106 | (var t-delta 0.0) 107 | (var midi-tdiv 100) 108 | (var midi-tempo 400000) 109 | 110 | (loopwhile t (match (ext-midi-parse parser) 111 | ((midi-header (? size) (? format) (? tracks) (? time-div)) { 112 | (setq midi-tdiv time-div) 113 | }) 114 | 115 | ((midi-track-midi (? time) (? status) (? chan) (? p1) (? p2)) { 116 | (var secs (/ (* midi-tempo (to-float time)) midi-tdiv 1000000.0)) 117 | (setq t-delta (+ t-delta secs)) 118 | 119 | (var to-sleep (- t-delta (secs-since t-start))) 120 | (if (> to-sleep 0.001) (sleep to-sleep)) 121 | 122 | ; Note on 123 | (if (= status 9) { 124 | (note-on p1 volts decay) 125 | }) 126 | 127 | ; Note off 128 | (if (= status 8) { 129 | (note-off p1) 130 | }) 131 | }) 132 | 133 | ((midi-track-meta (? time) (? type) (? len) (? data)) { 134 | ; Tempo 135 | (if (= type 81) 136 | (setq midi-tempo data) 137 | ) 138 | }) 139 | 140 | (midi-error { 141 | (print "Midi error") 142 | (break) 143 | }) 144 | 145 | (midi-eob { 146 | (print "End of file") 147 | (break) 148 | }) 149 | 150 | ((? a) { 151 | (print a) 152 | }) 153 | ) 154 | )}) 155 | 156 | (spawn 200 play-midi 0 0.7 0.92) 157 | (spawn 200 play-midi 1 0.4 0.92) 158 | ``` 159 | -------------------------------------------------------------------------------- /tnt/README.md: -------------------------------------------------------------------------------- 1 | # Trick and Trail VESC Package 2 | by Mike Silberstein (send questions, comments, requests to izzyvesc@gmail.com) 3 | 4 | Trick and Trail Package was developed based on Float Package 1.2 by Surfdado and Niko for self-balanced boards. It departs from the traditional PID control scheme that is rooted in the balance robot design. This is replaced with a user defined, current output curve that is based on board pitch. This allows for an infinite number of throttle/braking curves that gives the user the ability to truly tune the board how they want. 5 | 6 | [READ THE WIKI](https://github.com/Izzygit/TrickandTrailReleases/wiki) https://github.com/Izzygit/TrickandTrailReleases/wiki 7 | 8 | ### Features 9 | * Current output defined by a series of points, input by the user 10 | * Alternative proportional gain user inputs 11 | * Optional independent brake curve 12 | * Roll gain curves for acceleration and braking 13 | * Roll gain modification for low speeds 14 | * Surge 15 | * Traction control 16 | * Sticky tilt 17 | * Dynamic Stability 18 | * Haptic Buzz 19 | 20 | ### Default Settings 21 | Default settings are based on 20s Hypercore (Future Motion motor) board set up. The default settings are what I ride for trails. The exceptions are surge and traction control which are disabled by default. These are more advanced behaviors that should be tuned by the user. For more instructions on setting up your board please refer to the [Set Up Guide.](https://github.com/Izzygit/TrickandTrailReleases/wiki/Set-Up-Guide) https://github.com/Izzygit/TrickandTrailReleases/wiki/Set-Up-Guide 22 | 23 | ## Change Log 24 | ### 1.2 25 | * **Version 1.2 parameters are not compatible with v1.1 and will be set to default. Screenshot your tunes to save.** 26 | * _Features_ 27 | * Haptic Buzz 28 | * Adopted haptic buzz implementation from Float Package 2.0 29 | * Overcurrent haptic buzz modifed to be instantaneous instead of continuous. Now called High Current. 30 | * High Current haptic buzz now has a user input duration to limit continuous buzz in high current situations. 31 | * BMS haptic buzz not implemented yet. 32 | * New Section "High Current" in Tune Modifiers 33 | * Allows the user to configure the maximum current of the motor 34 | * Adjust max current for higher duty cycles 35 | * Haptic buzz will activate at a user input margin from max current, if high current haptic buzz is enabled 36 | * Surge will activate at the max current, if surge is enabled 37 | * User input minimum ERPM implemented to prevent surge and/or haptic buzz in low speed situations. 38 | * Surge Overhaul 39 | * Changed surge trigger from pitch differential to high current, configured in the High Current section 40 | * Changed surge end condition to be based on a user input pitch to allow more flexible and stronger surges. 41 | * Adjustable surge ramp rate for more powerful boards. 42 | * AppUI Overhaul 43 | * Debug Overhaul 44 | * New options on Specs tab allow for different debug text on the AppUI screen. 45 | * Traction control debug 46 | * Surge debug 47 | * Tune debug. This includes pitch kp, stability, and roll kp information previously under Tune 48 | * New Trip data replaces Tune 49 | * Monitors board state to determine when the board is idle and displays ride vs rest time. 50 | * Ride/rest time is used to correct RT data for better ride data including current, speed and power averages. 51 | * Added last beep reason from Float Package 1.2 to AppUI screen 52 | * _Fixes/Improvements_ 53 | * Dynamic stability now works while riding switch 54 | * Fixed a bug originating in 1.1 that prevented traction control while riding switch 55 | * **Default settings are now based on 20S Hypercore configuration (30A battery, 150A peak)** 56 | 57 | ### 1.1 58 | * **Version 1.1 parameters are not compatible with v1.0 and will be set to default. Screenshot your tunes to save.** 59 | * _Features_ 60 | * Dynamic Stability 61 | * Increase pitch current and pitch rate response (kp rate) at higher speeds or with remote control. 62 | * Found in the tune modifiers menu. 63 | * Speed stability enabled by default 64 | * Enabling remote control stability disables remote tilt. 65 | * New indicators on AppUI for relative stability (0-100%) and the added kp and kp rate from stability applied to the pitch response. 66 | * Independent braking curve 67 | * New menu "Brake". 68 | * Disabled by default. 69 | * Uses the same layout and logic as the acceleration menu. 70 | * _Fixes/Improvements_ 71 | * Changed name of "Pitch" menu to "Acceleration". 72 | * Changed name of "Surge / Traction Control" menu to "Tune Modifiers" 73 | * Removed limitations on pitch current and kp that only allowed increasing values. Now decreasing or negative values are allowed. Pitch must still be increasing. 74 | * Added a significant digit to the first two pitch values on the acceleration and brake curves for more precision. 75 | * Reorganized the AppUI screen. 76 | * Cleaned up AppUI to remove unused quicksave buttons. 77 | * Updated traction control to remove false start scenario. 78 | ### 1.0 79 | * Initial release. 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VESC Packages 2 | 3 | This repository contains packages that show up in the package store in VESC Tool. A VESC Package consists of: 4 | 5 | * A description, which can include formatted text and images. 6 | * An optional LispBM-script with optional includes. 7 | - The includes can also contain one or more compiled C libraries. 8 | * An optional QML-file. 9 | 10 | Packages can be pulled and updated from VESC Tool on demand, so their development does not have to be synchronized with the VESC Tool development. This is an advantage for package developers and maintainers as they can control how and when they make their releases. There is also no need for users to update their VESC Tool and firmware, they can just refresh the package store in VESC Tool and reinstall the updated package. 11 | 12 | ## Package Types 13 | 14 | There are two types of packages: 15 | 16 | * Applications 17 | * Libraries 18 | 19 | At the moment they are implemented in the same way, the only difference is the naming and how you are supposed to use them. If you create a package or library you should make that clear in your description. 20 | 21 | ### Applications 22 | 23 | Application packages are intended to be installed and used either without configuration, or with a configuration GUI that they provide. That GUI can either be a QML-file or a custom configuration page in VESC Tool. 24 | 25 | ### Libraries 26 | 27 | Library packages are intended to be building blocks to be used from LisbBM-scripts. All libraries in this repository can be imported in LispBM-scripts without the need for installation. 28 | 29 | To declare a package as a library it should be placed in a directory that starts with the name **lib_**. That is enough to tell VESC Tool to list it under libraries and to disable the install button when it is selected. 30 | 31 | Libraries work by providing one or more files that can be imported in LispBM-scripts. These files can be anything, but are typically either LispBM-scripts or compiled native code that can be loaded after importing it. To make these files available they need a LispBM-script that imports all files meant to be provided in the VESC-package. Other LispBM-scripts can then import the files imported in the VESC-package. 32 | 33 | **Example** 34 | 35 | The WS2812-library wants to provide the file **c_lib/ws2812/ws2812.bin**. Therefore it contains a lisp-script with the line 36 | 37 | ```clj 38 | (import "c_lib/ws2812/ws2812.bin" 'ws2812) 39 | ``` 40 | 41 | which means that it imports that file under the label ws2812. Once the VESC Package is made this file is included in the package and thus available to other lisp-scripts that want to use it. 42 | 43 | Other lisp-scripts can then import that file by addressing the label ws2812 in that package: 44 | 45 | ```clj 46 | (import "pkg::ws2812@://vesc_packages/lib_ws2812/ws2812.vescpkg" 'ws2812) 47 | ``` 48 | 49 | Here the syntax means 50 | 51 | **pkg::** - Import a file from a VESC Package 52 | **ws2812** - The label in that package is ws2812 53 | **@://vesc_packages/lib_ws2812/ws2812.vescpkg** - The path of that VESC Package 54 | 55 | The **@**-sign is followed by a path to a package which can be any path on the local file system. The packages in this git-repository can be accessed from the base path **://vesc_packages/** (because they are loaded as a Qt resource there), which is what we have done here. 56 | 57 | Once the file is imported in your lisp-script you can use it as usual, e.g. in this case by loading it as a native library: 58 | 59 | ```clj 60 | (load-native-lib ws2812) ; Loading this library provides some extensions to control ws2812 addressable LEDs 61 | ``` 62 | 63 | **Note** 64 | 65 | VESC Tool does not automatically refresh the packages, it uses the ones that are downloaded and cached from the archive the last time. To update the archive you can use the **Update Archive**-button from the VESC Packages-page in VESC Tool. 66 | 67 | ## How to include your package 68 | 69 | To include your package in VESC Tool you can make a pull request to this repository. Your pull request should include: 70 | 71 | * A description of what your package does. 72 | * Instructions on how to use it. 73 | * If it contains compiled C libraries their source code must be included in the pull request under the GPL license (see the examples). 74 | 75 | ## Building 76 | 77 | To build all packages in the repository, run (in the root directory): 78 | ```sh 79 | make 80 | ``` 81 | 82 | If you make changes to the source files, it is important to run `make clean`, as `make` doesn't detect changes in files to regenerate them: 83 | ```sh 84 | make clean 85 | make 86 | ``` 87 | 88 | If you don't have `vesc_tool` in your path, you can specify the `vesc_tool` to use: 89 | ```sh 90 | make clean 91 | make VESC_TOOL=/path/to/vesc_tool 92 | ``` 93 | 94 | ### Notes 95 | 96 | * Make sure that you build a VESC Package file (\*.vescpkg) in the main directory of your package (e.g. euc/euc.vescpkg) 97 | * Make sure to add your package to res_all.qrc in the root of the repository. 98 | * Make sure all temporary files generated by your Makefiles are properly cleaned in the `clean` targets, otherwise you risk hard-to-debug failures of building from stale generated files. 99 | * Test your .vescpkg-file before making a pull request! 100 | -------------------------------------------------------------------------------- /float/float/conf/datatypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DATATYPES_H_ 21 | #define DATATYPES_H_ 22 | 23 | #include 24 | #include 25 | 26 | typedef enum { 27 | INPUTTILT_NONE = 0, 28 | INPUTTILT_UART, 29 | INPUTTILT_PPM 30 | } FLOAT_INPUTTILT_REMOTE_TYPE; 31 | 32 | typedef enum { 33 | HAPTIC_BUZZ_NONE = 0, 34 | HAPTIC_BUZZ_AUDIBLE1, 35 | HAPTIC_BUZZ_AUDIBLE2, 36 | HAPTIC_BUZZ_AUDIBLE3, 37 | HAPTIC_BUZZ_VIBRATING1, 38 | HAPTIC_BUZZ_VIBRATING2, 39 | HAPTIC_BUZZ_VIBRATING3, 40 | HAPTIC_BUZZ_ALTERNATING 41 | } HAPTIC_BUZZ_TYPE; 42 | 43 | typedef struct { 44 | float float_version; 45 | float float_disable; 46 | float kp; 47 | float ki; 48 | float kp2; 49 | float mahony_kp; 50 | float kp_brake; 51 | float kp2_brake; 52 | uint16_t kp_brake_erpm; 53 | uint16_t hertz; 54 | float fault_pitch; 55 | float fault_roll; 56 | float fault_adc1; 57 | float fault_adc2; 58 | uint16_t fault_delay_pitch; 59 | uint16_t fault_delay_roll; 60 | uint16_t fault_delay_switch_half; 61 | uint16_t fault_delay_switch_full; 62 | uint16_t fault_adc_half_erpm; 63 | bool fault_is_dual_switch; 64 | bool fault_moving_fault_disabled; 65 | bool fault_darkride_enabled; 66 | bool fault_reversestop_enabled; 67 | float tiltback_duty_angle; 68 | float tiltback_duty_speed; 69 | float tiltback_duty; 70 | float tiltback_hv_angle; 71 | float tiltback_hv_speed; 72 | float tiltback_hv; 73 | float tiltback_lv_angle; 74 | float tiltback_lv_speed; 75 | float tiltback_lv; 76 | float tiltback_return_speed; 77 | float tiltback_constant; 78 | int haptic_buzz_intensity; 79 | int haptic_buzz_min; 80 | HAPTIC_BUZZ_TYPE haptic_buzz_duty; 81 | HAPTIC_BUZZ_TYPE haptic_buzz_hv; 82 | HAPTIC_BUZZ_TYPE haptic_buzz_lv; 83 | HAPTIC_BUZZ_TYPE haptic_buzz_temp; 84 | HAPTIC_BUZZ_TYPE haptic_buzz_current; 85 | HAPTIC_BUZZ_TYPE haptic_buzz_bms; 86 | uint16_t tiltback_constant_erpm; 87 | float tiltback_variable; 88 | float tiltback_variable_max; 89 | uint16_t tiltback_variable_erpm; 90 | FLOAT_INPUTTILT_REMOTE_TYPE inputtilt_remote_type; 91 | float inputtilt_speed; 92 | float inputtilt_angle_limit; 93 | uint16_t inputtilt_smoothing_factor; 94 | bool inputtilt_invert_throttle; 95 | float inputtilt_deadband; 96 | float remote_throttle_current_max; 97 | float remote_throttle_grace_period; 98 | float noseangling_speed; 99 | float startup_pitch_tolerance; 100 | float startup_roll_tolerance; 101 | float startup_speed; 102 | float startup_click_current; 103 | bool startup_simplestart_enabled; 104 | bool startup_pushstart_enabled; 105 | bool startup_dirtylandings_enabled; 106 | float brake_current; 107 | float ki_limit; 108 | float booster_angle; 109 | float booster_ramp; 110 | float booster_current; 111 | float brkbooster_angle; 112 | float brkbooster_ramp; 113 | float brkbooster_current; 114 | float torquetilt_start_current; 115 | float torquetilt_angle_limit; 116 | float torquetilt_on_speed; 117 | float torquetilt_off_speed; 118 | float torquetilt_strength; 119 | float torquetilt_strength_regen; 120 | float atr_strength_up; 121 | float atr_strength_down; 122 | float atr_threshold_up; 123 | float atr_threshold_down; 124 | float atr_torque_offset; 125 | float atr_speed_boost; 126 | float atr_angle_limit; 127 | float atr_on_speed; 128 | float atr_off_speed; 129 | float atr_response_boost; 130 | float atr_transition_boost; 131 | float atr_filter; 132 | float atr_amps_accel_ratio; 133 | float atr_amps_decel_ratio; 134 | int atr_test1; 135 | float atr_test2; 136 | float atr_test3; 137 | float braketilt_strength; 138 | float braketilt_lingering; 139 | float turntilt_strength; 140 | float turntilt_angle_limit; 141 | float turntilt_start_angle; 142 | uint16_t turntilt_start_erpm; 143 | float turntilt_speed; 144 | uint16_t turntilt_erpm_boost; 145 | uint16_t turntilt_erpm_boost_end; 146 | int turntilt_yaw_aggregate; 147 | float dark_pitch_offset; 148 | bool is_beeper_enabled; 149 | bool is_dutybeep_enabled; 150 | bool is_footbeep_enabled; 151 | bool is_surgebeep_enabled; 152 | float surge_duty_start; 153 | float surge_angle; 154 | uint8_t led_type; 155 | uint8_t led_status_count; 156 | uint8_t led_forward_count; 157 | uint8_t led_rear_count; 158 | uint8_t led_brightness; 159 | uint8_t led_brightness_idle; 160 | uint8_t led_mode; 161 | uint8_t led_mode_idle; 162 | uint8_t led_status_brightness; 163 | uint8_t led_status_mode; 164 | int limit_current_accel; 165 | int limit_current_brake; 166 | int limit_current_cont; 167 | } float_config; 168 | 169 | // DATATYPES_H_ 170 | #endif 171 | -------------------------------------------------------------------------------- /lib_pn532/README.md: -------------------------------------------------------------------------------- 1 | # PN532 Driver 2 | 3 | This is a i2c-driver for the PN532 NFC-controller. It requires firmware 6.05 or later and works on ESC and Express hardware. So far there is authentication, read and write support for MiFare Classic tags as well as read and write support for MiFare Ultralight tags. 4 | 5 | The driver is tested with the Adafruit PN532-board which also has a good introduction to NFC and MiFare: 6 | 7 | [https://cdn-learn.adafruit.com/downloads/pdf/adafruit-pn532-rfid-nfc.pdf](https://cdn-learn.adafruit.com/downloads/pdf/adafruit-pn532-rfid-nfc.pdf) 8 | 9 | ## Functions 10 | 11 | ### pn532-init 12 | 13 | ```clj 14 | (pn532-init '(pins)) 15 | ``` 16 | 17 | Initialize and start the driver on the i2c-pins pins. If the pins are nil (an empty list) the default pins will be used. Example: 18 | 19 | ```clj 20 | (pn532-init nil) ; Initialize using default pins 21 | (pn532-init '(3 2)) ; Initialize using pin 3 for SDA and 2 for SCL on the express firmware 22 | (pn532-init '('pin-swdio 'pin-swclk)) ; Initialize using pin swdio for SDA and swclk for SCL on the ESC-firmware 23 | ``` 24 | 25 | The function return true if initialization was successful and false otherwise. 26 | 27 | ### pn532-read-fwversion 28 | 29 | ```clj 30 | (pn532-read-fwversion) 31 | ``` 32 | 33 | Read the firmware version of the PN532 chip. Returns the firmware version as a list on success and nil otherwise. 34 | 35 | ### pn532-read-target-id 36 | 37 | ```clj 38 | (pn532-read-target-id timeout) 39 | ``` 40 | 41 | Read the id of a tag. This functions blocks up to timeout seconds and returns the ID on success and nil of a timeout occurred. If the id has length 4 it is most likely a MiFare Classic tag and if it has length 7 it is most likely a MiFare Ultralight tag. 42 | 43 | ### pn532-authenticate-block 44 | 45 | ```clj 46 | (pn532-authenticate-block uuid block keynum key) 47 | ``` 48 | 49 | Authenticate block on MiFare Classic tag. UUID is the id of the card, which is returned from pn532-read-target-id, block is the block number (0 to 63 for 1k cards), keynum is the key number (0 or 1) and key is the key (a list with 6 numbers from 0 to 255). This function returns true on success and false otherwise. Each sector which contains 4 blocks has to be authenticated before it can be read or written. 50 | 51 | ### pn532-mifareclassic-read-block 52 | 53 | ```clj 54 | (pn532-mifareclassic-read-block block) 55 | ``` 56 | 57 | Read block from MiFare Classic tag. Returns a list of 16 bytes on success or nil on failure. 58 | 59 | ### pn532-mifareclassic-write-block 60 | 61 | ```clj 62 | (pn532-mifareclassic-write-block block data) 63 | ``` 64 | 65 | Write data to block. Data must be a list with 16 numbers where each number is 0 to 255. Returns true on success and nil on failure. 66 | 67 | ### pn532-mifareul-read-page 68 | 69 | ```clj 70 | (pn532-mifareul-read-page page) 71 | ``` 72 | 73 | Read page from MiFare Ultralight tag. Returns a list of 4 bytes on success or nil on failure. 74 | 75 | ### pn532-mifareul-write-page 76 | 77 | ```clj 78 | (pn532-mifareul-write-page page data) 79 | ``` 80 | 81 | Write data to page. Data must be a list with 4 numbers where each number is 0 to 255. Returns true on success and nil on failure. 82 | 83 | ## Example 84 | 85 | ```clj 86 | (import "pkg@://vesc_packages/lib_pn532/pn532.vescpkg" 'pn532) 87 | (eval-program (read-program pn532)) 88 | 89 | (def is-esp false) 90 | 91 | (def pins nil) 92 | (if is-esp { 93 | (def pins '(3 2)) 94 | (rgbled-init 8 1) 95 | }) 96 | 97 | (defun led-on () (if is-esp (rgbled-color 0 0x00ff00))) 98 | (defun led-off () (if is-esp (rgbled-color 0 0))) 99 | 100 | (if (pn532-init pins) 101 | (loopwhile t { 102 | (var res (pn532-read-target-id 2)) 103 | (if res { 104 | (led-on) 105 | (var uuid-len (first res)) 106 | (var uuid (second res)) 107 | (print " ") 108 | (print (list "UUID:" uuid)) 109 | (cond 110 | ((= uuid-len 4) { 111 | (print "Most likely Mifare Classic") 112 | (var block 21) 113 | (print (list "Reading block" block)) 114 | (if (pn532-authenticate-block uuid block 0 '(0xff 0xff 0xff 0xff 0xff 0xff)) 115 | { 116 | (print "Authentication OK!") 117 | (print (list "Data:" (pn532-mifareclassic-read-block block))) 118 | } 119 | (print "Authentication failed, most likely the wrong key") 120 | ) 121 | }) 122 | ((= uuid-len 7) { 123 | (print "Most likely Mifare Ultralight or NTAG") 124 | (var page 4) 125 | (print (list "Reading page" page)) 126 | (print (list "Data:" (pn532-mifareul-read-page page))) 127 | }) 128 | (t (print (str-from-n uuid-len "No idea, UUID len: %d"))) 129 | ) 130 | 131 | (led-off) 132 | (sleep 1) 133 | }) 134 | }) 135 | (print "Init Failed") 136 | ) 137 | ``` -------------------------------------------------------------------------------- /tnt/tnt/conf/datatypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DATATYPES_H_ 21 | #define DATATYPES_H_ 22 | 23 | #include 24 | #include 25 | 26 | typedef enum { 27 | INPUTTILT_NONE = 0, 28 | INPUTTILT_UART, 29 | INPUTTILT_PPM 30 | } INPUTTILT_REMOTE_TYPE; 31 | 32 | typedef enum { 33 | HAPTIC_BUZZ_NONE = 0, 34 | HAPTIC_BUZZ_AUDIBLE1, 35 | HAPTIC_BUZZ_AUDIBLE2, 36 | HAPTIC_BUZZ_AUDIBLE3, 37 | HAPTIC_BUZZ_VIBRATING1, 38 | HAPTIC_BUZZ_VIBRATING2, 39 | HAPTIC_BUZZ_VIBRATING3, 40 | HAPTIC_BUZZ_ALTERNATING 41 | } HAPTIC_BUZZ_TYPE; 42 | 43 | typedef struct { 44 | float version; 45 | float disable_pkg; 46 | float kp0; 47 | float current1; 48 | float current2; 49 | float current3; 50 | float current4; 51 | float current5; 52 | float current6; 53 | float pitch1; 54 | float pitch2; 55 | float pitch3; 56 | float pitch4; 57 | float pitch5; 58 | float pitch6; 59 | bool pitch_kp_input; 60 | float mahony_kp; 61 | float kp_rate; 62 | float pitch_filter; 63 | float kalman_factor1; 64 | float kalman_factor2; 65 | float kalman_factor3; 66 | bool brake_curve; 67 | float brake_kp0; 68 | float brakekp_rate; 69 | float brakecurrent1; 70 | float brakecurrent2; 71 | float brakecurrent3; 72 | float brakecurrent4; 73 | float brakecurrent5; 74 | float brakecurrent6; 75 | float brakepitch1; 76 | float brakepitch2; 77 | float brakepitch3; 78 | float brakepitch4; 79 | float brakepitch5; 80 | float brakepitch6; 81 | bool pitch_kp_input_brake; 82 | float roll_kp1; 83 | float roll_kp2; 84 | float roll_kp3; 85 | float roll1; 86 | float roll2; 87 | float roll3; 88 | float brkroll_kp1; 89 | float brkroll_kp2; 90 | float brkroll_kp3; 91 | float brkroll1; 92 | float brkroll2; 93 | float brkroll3; 94 | float rollkp_higherpm; 95 | float rollkp_lowerpm; 96 | float rollkp_maxscale; 97 | bool is_surge_enabled; 98 | float surge_startcurrent; 99 | float surge_start_hd_current; 100 | float surge_scaleduty; 101 | float surge_pitchmargin; 102 | float surge_maxangle; 103 | float surge_minerpm; 104 | float surge_duty; 105 | float tiltback_surge_speed; 106 | bool is_traction_enabled; 107 | float wheelslip_margin; 108 | float wheelslip_accelstart; 109 | float wheelslip_accelend; 110 | float wheelslip_scaleaccel; 111 | float wheelslip_scaleerpm; 112 | bool enable_speed_stability; 113 | bool enable_throttle_stability; 114 | float stabl_pitch_max_scale; 115 | float stabl_rate_max_scale; 116 | float stabl_min_erpm; 117 | float stabl_max_erpm; 118 | float stabl_ramp; 119 | uint16_t hertz; 120 | float fault_pitch; 121 | float fault_roll; 122 | float fault_adc1; 123 | float fault_adc2; 124 | uint16_t fault_delay_pitch; 125 | uint16_t fault_delay_roll; 126 | uint16_t fault_delay_switch_half; 127 | uint16_t fault_delay_switch_full; 128 | uint16_t fault_adc_half_erpm; 129 | bool fault_is_dual_switch; 130 | bool fault_moving_fault_disabled; 131 | float tiltback_duty_angle; 132 | float tiltback_duty_speed; 133 | float tiltback_duty; 134 | float tiltback_hv_angle; 135 | float tiltback_hv_speed; 136 | float tiltback_hv; 137 | float tiltback_lv_angle; 138 | float tiltback_lv_speed; 139 | float tiltback_lv; 140 | float tiltback_ht_angle; 141 | float tiltback_ht_speed; 142 | float tiltback_return_speed; 143 | float tiltback_constant; 144 | uint16_t tiltback_constant_erpm; 145 | int haptic_buzz_intensity; 146 | int haptic_buzz_min; 147 | HAPTIC_BUZZ_TYPE haptic_buzz_duty; 148 | HAPTIC_BUZZ_TYPE haptic_buzz_hv; 149 | HAPTIC_BUZZ_TYPE haptic_buzz_lv; 150 | HAPTIC_BUZZ_TYPE haptic_buzz_temp; 151 | HAPTIC_BUZZ_TYPE haptic_buzz_current; 152 | INPUTTILT_REMOTE_TYPE inputtilt_remote_type; 153 | float inputtilt_speed; 154 | float inputtilt_angle_limit; 155 | uint16_t inputtilt_smoothing_factor; 156 | bool inputtilt_invert_throttle; 157 | float inputtilt_deadband; 158 | float stickytiltval1; 159 | float stickytiltval2; 160 | bool is_stickytilt_enabled; 161 | uint16_t stickytilt_holdcurrent; 162 | float noseangling_speed; 163 | float startup_pitch_tolerance; 164 | float startup_roll_tolerance; 165 | float startup_speed; 166 | float startup_click_current; 167 | bool startup_simplestart_enabled; 168 | bool startup_pushstart_enabled; 169 | bool startup_dirtylandings_enabled; 170 | float brake_current; 171 | int overcurrent_margin; 172 | float overcurrent_period; 173 | bool is_beeper_enabled; 174 | bool is_dutybeep_enabled; 175 | bool is_footbeep_enabled; 176 | bool is_surgedebug_enabled; 177 | bool is_tcdebug_enabled; 178 | bool is_tunedebug_enabled; 179 | } tnt_config; 180 | 181 | // DATATYPES_H_ 182 | #endif 183 | -------------------------------------------------------------------------------- /tnt/tnt/conf/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "buffer.h" 21 | #include 22 | #include 23 | 24 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) { 25 | buffer[(*index)++] = number >> 8; 26 | buffer[(*index)++] = number; 27 | } 28 | 29 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) { 30 | buffer[(*index)++] = number >> 8; 31 | buffer[(*index)++] = number; 32 | } 33 | 34 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) { 35 | buffer[(*index)++] = number >> 24; 36 | buffer[(*index)++] = number >> 16; 37 | buffer[(*index)++] = number >> 8; 38 | buffer[(*index)++] = number; 39 | } 40 | 41 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) { 42 | buffer[(*index)++] = number >> 24; 43 | buffer[(*index)++] = number >> 16; 44 | buffer[(*index)++] = number >> 8; 45 | buffer[(*index)++] = number; 46 | } 47 | 48 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index) { 49 | buffer_append_int16(buffer, (int16_t)(number * scale), index); 50 | } 51 | 52 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index) { 53 | buffer_append_int32(buffer, (int32_t)(number * scale), index); 54 | } 55 | 56 | /* 57 | * See my question: 58 | * http://stackoverflow.com/questions/40416682/portable-way-to-serialize-float-as-32-bit-integer 59 | * 60 | * Regarding the float32_auto functions: 61 | * 62 | * Noticed that frexp and ldexp fit the format of the IEEE float representation, so 63 | * they should be quite fast. They are (more or less) equivalent with the following: 64 | * 65 | * float frexp_slow(float f, int *e) { 66 | * if (f == 0.0) { 67 | * *e = 0; 68 | * return 0.0; 69 | * } 70 | * 71 | * *e = ceilf(log2f(fabsf(f))); 72 | * float res = f / powf(2.0, (float)*e); 73 | * 74 | * if (res >= 1.0) { 75 | * res -= 0.5; 76 | * *e += 1; 77 | * } 78 | * 79 | * if (res <= -1.0) { 80 | * res += 0.5; 81 | * *e += 1; 82 | * } 83 | * 84 | * return res; 85 | * } 86 | * 87 | * float ldexp_slow(float f, int e) { 88 | * return f * powf(2.0, (float)e); 89 | * } 90 | * 91 | * 8388608.0 is 2^23, which scales the result to fit within 23 bits if sig_abs < 1.0. 92 | * 93 | * This should be a relatively fast and efficient way to serialize 94 | * floating point numbers in a fully defined manner. 95 | */ 96 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index) { 97 | // Set subnormal numbers to 0 as they are not handled properly 98 | // using this method. 99 | if (fabsf(number) < 1.5e-38) { 100 | number = 0.0; 101 | } 102 | 103 | int e = 0; 104 | float sig = frexpf(number, &e); 105 | float sig_abs = fabsf(sig); 106 | uint32_t sig_i = 0; 107 | 108 | if (sig_abs >= 0.5) { 109 | sig_i = (uint32_t)((sig_abs - 0.5f) * 2.0f * 8388608.0f); 110 | e += 126; 111 | } 112 | 113 | uint32_t res = ((e & 0xFF) << 23) | (sig_i & 0x7FFFFF); 114 | if (sig < 0) { 115 | res |= 1U << 31; 116 | } 117 | 118 | buffer_append_uint32(buffer, res, index); 119 | } 120 | 121 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) { 122 | int16_t res = ((uint16_t) buffer[*index]) << 8 | 123 | ((uint16_t) buffer[*index + 1]); 124 | *index += 2; 125 | return res; 126 | } 127 | 128 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { 129 | uint16_t res = ((uint16_t) buffer[*index]) << 8 | 130 | ((uint16_t) buffer[*index + 1]); 131 | *index += 2; 132 | return res; 133 | } 134 | 135 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { 136 | int32_t res = ((uint32_t) buffer[*index]) << 24 | 137 | ((uint32_t) buffer[*index + 1]) << 16 | 138 | ((uint32_t) buffer[*index + 2]) << 8 | 139 | ((uint32_t) buffer[*index + 3]); 140 | *index += 4; 141 | return res; 142 | } 143 | 144 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { 145 | uint32_t res = ((uint32_t) buffer[*index]) << 24 | 146 | ((uint32_t) buffer[*index + 1]) << 16 | 147 | ((uint32_t) buffer[*index + 2]) << 8 | 148 | ((uint32_t) buffer[*index + 3]); 149 | *index += 4; 150 | return res; 151 | } 152 | 153 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index) { 154 | return (float)buffer_get_int16(buffer, index) / scale; 155 | } 156 | 157 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index) { 158 | return (float)buffer_get_int32(buffer, index) / scale; 159 | } 160 | 161 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index) { 162 | uint32_t res = buffer_get_uint32(buffer, index); 163 | 164 | int e = (res >> 23) & 0xFF; 165 | uint32_t sig_i = res & 0x7FFFFF; 166 | bool neg = res & (1U << 31); 167 | 168 | float sig = 0.0; 169 | if (e != 0 || sig_i != 0) { 170 | sig = (float)sig_i / (8388608.0 * 2.0) + 0.5; 171 | e -= 126; 172 | } 173 | 174 | if (neg) { 175 | sig = -sig; 176 | } 177 | 178 | return ldexpf(sig, e); 179 | } 180 | -------------------------------------------------------------------------------- /float/float/conf/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "buffer.h" 21 | #include 22 | #include 23 | 24 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) { 25 | buffer[(*index)++] = number >> 8; 26 | buffer[(*index)++] = number; 27 | } 28 | 29 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) { 30 | buffer[(*index)++] = number >> 8; 31 | buffer[(*index)++] = number; 32 | } 33 | 34 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) { 35 | buffer[(*index)++] = number >> 24; 36 | buffer[(*index)++] = number >> 16; 37 | buffer[(*index)++] = number >> 8; 38 | buffer[(*index)++] = number; 39 | } 40 | 41 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) { 42 | buffer[(*index)++] = number >> 24; 43 | buffer[(*index)++] = number >> 16; 44 | buffer[(*index)++] = number >> 8; 45 | buffer[(*index)++] = number; 46 | } 47 | 48 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index) { 49 | buffer_append_int16(buffer, (int16_t)(number * scale), index); 50 | } 51 | 52 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index) { 53 | buffer_append_int32(buffer, (int32_t)(number * scale), index); 54 | } 55 | 56 | /* 57 | * See my question: 58 | * http://stackoverflow.com/questions/40416682/portable-way-to-serialize-float-as-32-bit-integer 59 | * 60 | * Regarding the float32_auto functions: 61 | * 62 | * Noticed that frexp and ldexp fit the format of the IEEE float representation, so 63 | * they should be quite fast. They are (more or less) equivalent with the following: 64 | * 65 | * float frexp_slow(float f, int *e) { 66 | * if (f == 0.0) { 67 | * *e = 0; 68 | * return 0.0; 69 | * } 70 | * 71 | * *e = ceilf(log2f(fabsf(f))); 72 | * float res = f / powf(2.0, (float)*e); 73 | * 74 | * if (res >= 1.0) { 75 | * res -= 0.5; 76 | * *e += 1; 77 | * } 78 | * 79 | * if (res <= -1.0) { 80 | * res += 0.5; 81 | * *e += 1; 82 | * } 83 | * 84 | * return res; 85 | * } 86 | * 87 | * float ldexp_slow(float f, int e) { 88 | * return f * powf(2.0, (float)e); 89 | * } 90 | * 91 | * 8388608.0 is 2^23, which scales the result to fit within 23 bits if sig_abs < 1.0. 92 | * 93 | * This should be a relatively fast and efficient way to serialize 94 | * floating point numbers in a fully defined manner. 95 | */ 96 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index) { 97 | // Set subnormal numbers to 0 as they are not handled properly 98 | // using this method. 99 | if (fabsf(number) < 1.5e-38) { 100 | number = 0.0; 101 | } 102 | 103 | int e = 0; 104 | float sig = frexpf(number, &e); 105 | float sig_abs = fabsf(sig); 106 | uint32_t sig_i = 0; 107 | 108 | if (sig_abs >= 0.5) { 109 | sig_i = (uint32_t)((sig_abs - 0.5f) * 2.0f * 8388608.0f); 110 | e += 126; 111 | } 112 | 113 | uint32_t res = ((e & 0xFF) << 23) | (sig_i & 0x7FFFFF); 114 | if (sig < 0) { 115 | res |= 1U << 31; 116 | } 117 | 118 | buffer_append_uint32(buffer, res, index); 119 | } 120 | 121 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) { 122 | int16_t res = ((uint16_t) buffer[*index]) << 8 | 123 | ((uint16_t) buffer[*index + 1]); 124 | *index += 2; 125 | return res; 126 | } 127 | 128 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { 129 | uint16_t res = ((uint16_t) buffer[*index]) << 8 | 130 | ((uint16_t) buffer[*index + 1]); 131 | *index += 2; 132 | return res; 133 | } 134 | 135 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { 136 | int32_t res = ((uint32_t) buffer[*index]) << 24 | 137 | ((uint32_t) buffer[*index + 1]) << 16 | 138 | ((uint32_t) buffer[*index + 2]) << 8 | 139 | ((uint32_t) buffer[*index + 3]); 140 | *index += 4; 141 | return res; 142 | } 143 | 144 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { 145 | uint32_t res = ((uint32_t) buffer[*index]) << 24 | 146 | ((uint32_t) buffer[*index + 1]) << 16 | 147 | ((uint32_t) buffer[*index + 2]) << 8 | 148 | ((uint32_t) buffer[*index + 3]); 149 | *index += 4; 150 | return res; 151 | } 152 | 153 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index) { 154 | return (float)buffer_get_int16(buffer, index) / scale; 155 | } 156 | 157 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index) { 158 | return (float)buffer_get_int32(buffer, index) / scale; 159 | } 160 | 161 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index) { 162 | uint32_t res = buffer_get_uint32(buffer, index); 163 | 164 | int e = (res >> 23) & 0xFF; 165 | uint32_t sig_i = res & 0x7FFFFF; 166 | bool neg = res & (1U << 31); 167 | 168 | float sig = 0.0; 169 | if (e != 0 || sig_i != 0) { 170 | sig = (float)sig_i / (8388608.0 * 2.0) + 0.5; 171 | e -= 126; 172 | } 173 | 174 | if (neg) { 175 | sig = -sig; 176 | } 177 | 178 | return ldexpf(sig, e); 179 | } 180 | -------------------------------------------------------------------------------- /balance/balance/conf/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "buffer.h" 21 | #include 22 | #include 23 | 24 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) { 25 | buffer[(*index)++] = number >> 8; 26 | buffer[(*index)++] = number; 27 | } 28 | 29 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) { 30 | buffer[(*index)++] = number >> 8; 31 | buffer[(*index)++] = number; 32 | } 33 | 34 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) { 35 | buffer[(*index)++] = number >> 24; 36 | buffer[(*index)++] = number >> 16; 37 | buffer[(*index)++] = number >> 8; 38 | buffer[(*index)++] = number; 39 | } 40 | 41 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) { 42 | buffer[(*index)++] = number >> 24; 43 | buffer[(*index)++] = number >> 16; 44 | buffer[(*index)++] = number >> 8; 45 | buffer[(*index)++] = number; 46 | } 47 | 48 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index) { 49 | buffer_append_int16(buffer, (int16_t)(number * scale), index); 50 | } 51 | 52 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index) { 53 | buffer_append_int32(buffer, (int32_t)(number * scale), index); 54 | } 55 | 56 | /* 57 | * See my question: 58 | * http://stackoverflow.com/questions/40416682/portable-way-to-serialize-float-as-32-bit-integer 59 | * 60 | * Regarding the float32_auto functions: 61 | * 62 | * Noticed that frexp and ldexp fit the format of the IEEE float representation, so 63 | * they should be quite fast. They are (more or less) equivalent with the following: 64 | * 65 | * float frexp_slow(float f, int *e) { 66 | * if (f == 0.0) { 67 | * *e = 0; 68 | * return 0.0; 69 | * } 70 | * 71 | * *e = ceilf(log2f(fabsf(f))); 72 | * float res = f / powf(2.0, (float)*e); 73 | * 74 | * if (res >= 1.0) { 75 | * res -= 0.5; 76 | * *e += 1; 77 | * } 78 | * 79 | * if (res <= -1.0) { 80 | * res += 0.5; 81 | * *e += 1; 82 | * } 83 | * 84 | * return res; 85 | * } 86 | * 87 | * float ldexp_slow(float f, int e) { 88 | * return f * powf(2.0, (float)e); 89 | * } 90 | * 91 | * 8388608.0 is 2^23, which scales the result to fit within 23 bits if sig_abs < 1.0. 92 | * 93 | * This should be a relatively fast and efficient way to serialize 94 | * floating point numbers in a fully defined manner. 95 | */ 96 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index) { 97 | // Set subnormal numbers to 0 as they are not handled properly 98 | // using this method. 99 | if (fabsf(number) < 1.5e-38) { 100 | number = 0.0; 101 | } 102 | 103 | int e = 0; 104 | float sig = frexpf(number, &e); 105 | float sig_abs = fabsf(sig); 106 | uint32_t sig_i = 0; 107 | 108 | if (sig_abs >= 0.5) { 109 | sig_i = (uint32_t)((sig_abs - 0.5f) * 2.0f * 8388608.0f); 110 | e += 126; 111 | } 112 | 113 | uint32_t res = ((e & 0xFF) << 23) | (sig_i & 0x7FFFFF); 114 | if (sig < 0) { 115 | res |= 1U << 31; 116 | } 117 | 118 | buffer_append_uint32(buffer, res, index); 119 | } 120 | 121 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) { 122 | int16_t res = ((uint16_t) buffer[*index]) << 8 | 123 | ((uint16_t) buffer[*index + 1]); 124 | *index += 2; 125 | return res; 126 | } 127 | 128 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { 129 | uint16_t res = ((uint16_t) buffer[*index]) << 8 | 130 | ((uint16_t) buffer[*index + 1]); 131 | *index += 2; 132 | return res; 133 | } 134 | 135 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { 136 | int32_t res = ((uint32_t) buffer[*index]) << 24 | 137 | ((uint32_t) buffer[*index + 1]) << 16 | 138 | ((uint32_t) buffer[*index + 2]) << 8 | 139 | ((uint32_t) buffer[*index + 3]); 140 | *index += 4; 141 | return res; 142 | } 143 | 144 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { 145 | uint32_t res = ((uint32_t) buffer[*index]) << 24 | 146 | ((uint32_t) buffer[*index + 1]) << 16 | 147 | ((uint32_t) buffer[*index + 2]) << 8 | 148 | ((uint32_t) buffer[*index + 3]); 149 | *index += 4; 150 | return res; 151 | } 152 | 153 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index) { 154 | return (float)buffer_get_int16(buffer, index) / scale; 155 | } 156 | 157 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index) { 158 | return (float)buffer_get_int32(buffer, index) / scale; 159 | } 160 | 161 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index) { 162 | uint32_t res = buffer_get_uint32(buffer, index); 163 | 164 | int e = (res >> 23) & 0xFF; 165 | uint32_t sig_i = res & 0x7FFFFF; 166 | bool neg = res & (1U << 31); 167 | 168 | float sig = 0.0; 169 | if (e != 0 || sig_i != 0) { 170 | sig = (float)sig_i / (8388608.0 * 2.0) + 0.5; 171 | e -= 126; 172 | } 173 | 174 | if (neg) { 175 | sig = -sig; 176 | } 177 | 178 | return ldexpf(sig, e); 179 | } 180 | -------------------------------------------------------------------------------- /c_libs/examples/config/conf/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "buffer.h" 21 | #include 22 | #include 23 | 24 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) { 25 | buffer[(*index)++] = number >> 8; 26 | buffer[(*index)++] = number; 27 | } 28 | 29 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) { 30 | buffer[(*index)++] = number >> 8; 31 | buffer[(*index)++] = number; 32 | } 33 | 34 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) { 35 | buffer[(*index)++] = number >> 24; 36 | buffer[(*index)++] = number >> 16; 37 | buffer[(*index)++] = number >> 8; 38 | buffer[(*index)++] = number; 39 | } 40 | 41 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) { 42 | buffer[(*index)++] = number >> 24; 43 | buffer[(*index)++] = number >> 16; 44 | buffer[(*index)++] = number >> 8; 45 | buffer[(*index)++] = number; 46 | } 47 | 48 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index) { 49 | buffer_append_int16(buffer, (int16_t)(number * scale), index); 50 | } 51 | 52 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index) { 53 | buffer_append_int32(buffer, (int32_t)(number * scale), index); 54 | } 55 | 56 | /* 57 | * See my question: 58 | * http://stackoverflow.com/questions/40416682/portable-way-to-serialize-float-as-32-bit-integer 59 | * 60 | * Regarding the float32_auto functions: 61 | * 62 | * Noticed that frexp and ldexp fit the format of the IEEE float representation, so 63 | * they should be quite fast. They are (more or less) equivalent with the following: 64 | * 65 | * float frexp_slow(float f, int *e) { 66 | * if (f == 0.0) { 67 | * *e = 0; 68 | * return 0.0; 69 | * } 70 | * 71 | * *e = ceilf(log2f(fabsf(f))); 72 | * float res = f / powf(2.0, (float)*e); 73 | * 74 | * if (res >= 1.0) { 75 | * res -= 0.5; 76 | * *e += 1; 77 | * } 78 | * 79 | * if (res <= -1.0) { 80 | * res += 0.5; 81 | * *e += 1; 82 | * } 83 | * 84 | * return res; 85 | * } 86 | * 87 | * float ldexp_slow(float f, int e) { 88 | * return f * powf(2.0, (float)e); 89 | * } 90 | * 91 | * 8388608.0 is 2^23, which scales the result to fit within 23 bits if sig_abs < 1.0. 92 | * 93 | * This should be a relatively fast and efficient way to serialize 94 | * floating point numbers in a fully defined manner. 95 | */ 96 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index) { 97 | // Set subnormal numbers to 0 as they are not handled properly 98 | // using this method. 99 | if (fabsf(number) < 1.5e-38) { 100 | number = 0.0; 101 | } 102 | 103 | int e = 0; 104 | float sig = frexpf(number, &e); 105 | float sig_abs = fabsf(sig); 106 | uint32_t sig_i = 0; 107 | 108 | if (sig_abs >= 0.5) { 109 | sig_i = (uint32_t)((sig_abs - 0.5f) * 2.0f * 8388608.0f); 110 | e += 126; 111 | } 112 | 113 | uint32_t res = ((e & 0xFF) << 23) | (sig_i & 0x7FFFFF); 114 | if (sig < 0) { 115 | res |= 1U << 31; 116 | } 117 | 118 | buffer_append_uint32(buffer, res, index); 119 | } 120 | 121 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) { 122 | int16_t res = ((uint16_t) buffer[*index]) << 8 | 123 | ((uint16_t) buffer[*index + 1]); 124 | *index += 2; 125 | return res; 126 | } 127 | 128 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { 129 | uint16_t res = ((uint16_t) buffer[*index]) << 8 | 130 | ((uint16_t) buffer[*index + 1]); 131 | *index += 2; 132 | return res; 133 | } 134 | 135 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { 136 | int32_t res = ((uint32_t) buffer[*index]) << 24 | 137 | ((uint32_t) buffer[*index + 1]) << 16 | 138 | ((uint32_t) buffer[*index + 2]) << 8 | 139 | ((uint32_t) buffer[*index + 3]); 140 | *index += 4; 141 | return res; 142 | } 143 | 144 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { 145 | uint32_t res = ((uint32_t) buffer[*index]) << 24 | 146 | ((uint32_t) buffer[*index + 1]) << 16 | 147 | ((uint32_t) buffer[*index + 2]) << 8 | 148 | ((uint32_t) buffer[*index + 3]); 149 | *index += 4; 150 | return res; 151 | } 152 | 153 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index) { 154 | return (float)buffer_get_int16(buffer, index) / scale; 155 | } 156 | 157 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index) { 158 | return (float)buffer_get_int32(buffer, index) / scale; 159 | } 160 | 161 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index) { 162 | uint32_t res = buffer_get_uint32(buffer, index); 163 | 164 | int e = (res >> 23) & 0xFF; 165 | uint32_t sig_i = res & 0x7FFFFF; 166 | bool neg = res & (1U << 31); 167 | 168 | float sig = 0.0; 169 | if (e != 0 || sig_i != 0) { 170 | sig = (float)sig_i / (8388608.0 * 2.0) + 0.5; 171 | e -= 126; 172 | } 173 | 174 | if (neg) { 175 | sig = -sig; 176 | } 177 | 178 | return ldexpf(sig, e); 179 | } 180 | -------------------------------------------------------------------------------- /c_libs/examples/custom_data_comm/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 Benjamin Vedder benjamin@vedder.se 3 | 4 | This file is part of the VESC firmware. 5 | 6 | The VESC firmware is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | The VESC firmware is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include "buffer.h" 21 | #include 22 | #include 23 | 24 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) { 25 | buffer[(*index)++] = number >> 8; 26 | buffer[(*index)++] = number; 27 | } 28 | 29 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) { 30 | buffer[(*index)++] = number >> 8; 31 | buffer[(*index)++] = number; 32 | } 33 | 34 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) { 35 | buffer[(*index)++] = number >> 24; 36 | buffer[(*index)++] = number >> 16; 37 | buffer[(*index)++] = number >> 8; 38 | buffer[(*index)++] = number; 39 | } 40 | 41 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) { 42 | buffer[(*index)++] = number >> 24; 43 | buffer[(*index)++] = number >> 16; 44 | buffer[(*index)++] = number >> 8; 45 | buffer[(*index)++] = number; 46 | } 47 | 48 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index) { 49 | buffer_append_int16(buffer, (int16_t)(number * scale), index); 50 | } 51 | 52 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index) { 53 | buffer_append_int32(buffer, (int32_t)(number * scale), index); 54 | } 55 | 56 | /* 57 | * See my question: 58 | * http://stackoverflow.com/questions/40416682/portable-way-to-serialize-float-as-32-bit-integer 59 | * 60 | * Regarding the float32_auto functions: 61 | * 62 | * Noticed that frexp and ldexp fit the format of the IEEE float representation, so 63 | * they should be quite fast. They are (more or less) equivalent with the following: 64 | * 65 | * float frexp_slow(float f, int *e) { 66 | * if (f == 0.0) { 67 | * *e = 0; 68 | * return 0.0; 69 | * } 70 | * 71 | * *e = ceilf(log2f(fabsf(f))); 72 | * float res = f / powf(2.0, (float)*e); 73 | * 74 | * if (res >= 1.0) { 75 | * res -= 0.5; 76 | * *e += 1; 77 | * } 78 | * 79 | * if (res <= -1.0) { 80 | * res += 0.5; 81 | * *e += 1; 82 | * } 83 | * 84 | * return res; 85 | * } 86 | * 87 | * float ldexp_slow(float f, int e) { 88 | * return f * powf(2.0, (float)e); 89 | * } 90 | * 91 | * 8388608.0 is 2^23, which scales the result to fit within 23 bits if sig_abs < 1.0. 92 | * 93 | * This should be a relatively fast and efficient way to serialize 94 | * floating point numbers in a fully defined manner. 95 | */ 96 | void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index) { 97 | // Set subnormal numbers to 0 as they are not handled properly 98 | // using this method. 99 | if (fabsf(number) < 1.5e-38) { 100 | number = 0.0; 101 | } 102 | 103 | int e = 0; 104 | float sig = frexpf(number, &e); 105 | float sig_abs = fabsf(sig); 106 | uint32_t sig_i = 0; 107 | 108 | if (sig_abs >= 0.5) { 109 | sig_i = (uint32_t)((sig_abs - 0.5f) * 2.0f * 8388608.0f); 110 | e += 126; 111 | } 112 | 113 | uint32_t res = ((e & 0xFF) << 23) | (sig_i & 0x7FFFFF); 114 | if (sig < 0) { 115 | res |= 1U << 31; 116 | } 117 | 118 | buffer_append_uint32(buffer, res, index); 119 | } 120 | 121 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) { 122 | int16_t res = ((uint16_t) buffer[*index]) << 8 | 123 | ((uint16_t) buffer[*index + 1]); 124 | *index += 2; 125 | return res; 126 | } 127 | 128 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { 129 | uint16_t res = ((uint16_t) buffer[*index]) << 8 | 130 | ((uint16_t) buffer[*index + 1]); 131 | *index += 2; 132 | return res; 133 | } 134 | 135 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { 136 | int32_t res = ((uint32_t) buffer[*index]) << 24 | 137 | ((uint32_t) buffer[*index + 1]) << 16 | 138 | ((uint32_t) buffer[*index + 2]) << 8 | 139 | ((uint32_t) buffer[*index + 3]); 140 | *index += 4; 141 | return res; 142 | } 143 | 144 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { 145 | uint32_t res = ((uint32_t) buffer[*index]) << 24 | 146 | ((uint32_t) buffer[*index + 1]) << 16 | 147 | ((uint32_t) buffer[*index + 2]) << 8 | 148 | ((uint32_t) buffer[*index + 3]); 149 | *index += 4; 150 | return res; 151 | } 152 | 153 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index) { 154 | return (float)buffer_get_int16(buffer, index) / scale; 155 | } 156 | 157 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index) { 158 | return (float)buffer_get_int32(buffer, index) / scale; 159 | } 160 | 161 | float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index) { 162 | uint32_t res = buffer_get_uint32(buffer, index); 163 | 164 | int e = (res >> 23) & 0xFF; 165 | uint32_t sig_i = res & 0x7FFFFF; 166 | bool neg = res & (1U << 31); 167 | 168 | float sig = 0.0; 169 | if (e != 0 || sig_i != 0) { 170 | sig = (float)sig_i / (8388608.0 * 2.0) + 0.5; 171 | e -= 126; 172 | } 173 | 174 | if (neg) { 175 | sig = -sig; 176 | } 177 | 178 | return ldexpf(sig, e); 179 | } 180 | --------------------------------------------------------------------------------