Compare commits

7 Commits

29 changed files with 59533 additions and 42836 deletions

View File

@@ -1,7 +1,7 @@
(kicad_symbol_lib (kicad_symbol_lib
(version 20241209) (version 20251024)
(generator "kicad_symbol_editor") (generator "kicad_symbol_editor")
(generator_version "9.0") (generator_version "10.0")
(symbol "DOZ50N03" (symbol "DOZ50N03"
(pin_names (pin_names
(offset 0) (offset 0)
@@ -10,8 +10,12 @@
(exclude_from_sim no) (exclude_from_sim no)
(in_bom yes) (in_bom yes)
(on_board yes) (on_board yes)
(in_pos_files yes)
(duplicate_pin_numbers_are_jumpers no)
(property "Reference" "Q4" (property "Reference" "Q4"
(at 6.35 1.2701 0) (at 6.35 1.2701 0)
(show_name no)
(do_not_autoplace no)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -21,6 +25,8 @@
) )
(property "Value" "DOZ50N03" (property "Value" "DOZ50N03"
(at 6.35 -1.2699 0) (at 6.35 -1.2699 0)
(show_name no)
(do_not_autoplace no)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -30,74 +36,90 @@
) )
(property "Footprint" "Package_SON:VSON-8_3.3x3.3mm_P0.65mm_NexFET" (property "Footprint" "Package_SON:VSON-8_3.3x3.3mm_P0.65mm_NexFET"
(at 5.08 2.54 0) (at 5.08 2.54 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(property "Datasheet" "https://www.lcsc.com/datasheet/C36499165.pdf" (property "Datasheet" "https://www.lcsc.com/datasheet/C36499165.pdf"
(at 0 0 0) (at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(property "Description" "C36499165" (property "Description" "C36499165"
(at 0 0 0) (at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(property "NOTES" "" (property "NOTES" ""
(at 0 0 0) (at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(property "Part Number" "" (property "Part Number" ""
(at 0 0 0) (at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(property "Supplier PN" "" (property "Supplier PN" ""
(at 0 0 0) (at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(property "Supplier link" "" (property "Supplier link" ""
(at 0 0 0) (at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(property "ki_keywords" "transistor NMOS N-MOS N-MOSFET" (property "ki_keywords" "transistor NMOS N-MOS N-MOSFET"
(at 0 0 0) (at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(symbol "DOZ50N03_0_1" (symbol "DOZ50N03_0_1"
@@ -268,6 +290,62 @@
) )
) )
(symbol "DOZ50N03_1_1" (symbol "DOZ50N03_1_1"
(pin passive line
(at 2.54 -5.08 90)
(length 2.54)
(name "D"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "1"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin passive line
(at 2.54 -5.08 90)
(length 2.54)
(hide yes)
(name "D"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "2"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin passive line
(at 2.54 -5.08 90)
(length 2.54)
(hide yes)
(name "D"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "3"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin input line (pin input line
(at -5.08 0 0) (at -5.08 0 0)
(length 5.08) (length 5.08)
@@ -289,62 +367,6 @@
(pin passive line (pin passive line
(at 2.54 5.08 270) (at 2.54 5.08 270)
(length 2.54) (length 2.54)
(name "D"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "1"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin passive line
(at 2.54 5.08 270)
(length 2.54)
(hide yes)
(name "D"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "2"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin passive line
(at 2.54 5.08 270)
(length 2.54)
(hide yes)
(name "D"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "3"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin passive line
(at 2.54 -5.08 90)
(length 2.54)
(name "S" (name "S"
(effects (effects
(font (font
@@ -367,8 +389,12 @@
(exclude_from_sim no) (exclude_from_sim no)
(in_bom yes) (in_bom yes)
(on_board yes) (on_board yes)
(in_pos_files yes)
(duplicate_pin_numbers_are_jumpers no)
(property "Reference" "U" (property "Reference" "U"
(at 13.208 -26.67 0) (at 13.208 -26.67 0)
(show_name no)
(do_not_autoplace no)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -377,6 +403,8 @@
) )
(property "Value" "TI DRV8701ERGER" (property "Value" "TI DRV8701ERGER"
(at -10.922 26.924 0) (at -10.922 26.924 0)
(show_name no)
(do_not_autoplace no)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -385,31 +413,37 @@
) )
(property "Footprint" "Package_DFN_QFN:VQFN-24-1EP_4x4mm_P0.5mm_EP2.45x2.45mm_ThermalVias" (property "Footprint" "Package_DFN_QFN:VQFN-24-1EP_4x4mm_P0.5mm_EP2.45x2.45mm_ThermalVias"
(at 9.144 -28.956 0) (at 9.144 -28.956 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(justify left) (justify left)
(hide yes)
) )
) )
(property "Datasheet" "kicad-embed://drv8701.pdf" (property "Datasheet" "kicad-embed://drv8701.pdf"
(at 9.398 -30.734 0) (at 9.398 -30.734 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(justify left) (justify left)
(hide yes)
) )
) )
(property "Description" "" (property "Description" ""
(at 0 0 0) (at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
(hide yes)
) )
) )
(symbol "DRV8701E_1_1" (symbol "DRV8701E_1_1"
@@ -424,6 +458,24 @@
(type background) (type background)
) )
) )
(pin power_in line
(at 0 27.94 270)
(length 2.54)
(name "VM"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "1"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin power_out line (pin power_out line
(at -16.51 22.86 0) (at -16.51 22.86 0)
(length 2.54) (length 2.54)
@@ -478,17 +530,35 @@
) )
) )
) )
(pin power_out line (pin power_in line
(at -16.51 12.7 0) (at 0 -27.94 90)
(length 2.54) (length 2.54)
(name "DVDD" (name "GND"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
) )
) )
(number "8" (number "5"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin input line
(at -16.51 7.62 0)
(length 2.54)
(name "VREF"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "6"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -514,17 +584,107 @@
) )
) )
) )
(pin input line (pin power_out line
(at -16.51 7.62 0) (at -16.51 12.7 0)
(length 2.54) (length 2.54)
(name "VREF" (name "DVDD"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
) )
) )
(number "6" (number "8"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin open_collector line
(at -16.51 -22.86 0)
(length 2.54)
(name "nFAULT"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "9"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin open_collector line
(at -16.51 -20.32 0)
(length 2.54)
(name "SNSOUT"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "10"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin output line
(at -16.51 -3.81 0)
(length 2.54)
(name "SO"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "11"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin input line
(at -16.51 -12.7 0)
(length 2.54)
(name "IDRIVE"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "12"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin input line
(at -16.51 -10.16 0)
(length 2.54)
(name "nSLEEP"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "13"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -568,114 +728,6 @@
) )
) )
) )
(pin output line
(at -16.51 -3.81 0)
(length 2.54)
(name "SO"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "11"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin input line
(at -16.51 -10.16 0)
(length 2.54)
(name "nSLEEP"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "13"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin input line
(at -16.51 -12.7 0)
(length 2.54)
(name "IDRIVE"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "12"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin open_collector line
(at -16.51 -20.32 0)
(length 2.54)
(name "SNSOUT"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "10"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin open_collector line
(at -16.51 -22.86 0)
(length 2.54)
(name "nFAULT"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "9"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin power_in line
(at 0 27.94 270)
(length 2.54)
(name "VM"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "1"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin power_in line (pin power_in line
(at 0 -27.94 90) (at 0 -27.94 90)
(length 2.54) (length 2.54)
@@ -695,43 +747,6 @@
) )
) )
) )
(pin power_in line
(at 0 -27.94 90)
(length 2.54)
(hide yes)
(name "GND"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "25"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin power_in line
(at 0 -27.94 90)
(length 2.54)
(name "GND"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "5"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin output line (pin output line
(at 16.51 17.78 180) (at 16.51 17.78 180)
(length 2.54) (length 2.54)
@@ -786,17 +801,17 @@
) )
) )
) )
(pin output line (pin input line
(at 16.51 2.54 180) (at 16.51 -17.78 180)
(length 2.54) (length 2.54)
(name "GH2" (name "SN"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
) )
) )
(number "24" (number "20"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -805,16 +820,16 @@
) )
) )
(pin input line (pin input line
(at 16.51 0 180) (at 16.51 -12.7 180)
(length 2.54) (length 2.54)
(name "SH2" (name "SP"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
) )
) )
(number "23" (number "21"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -841,16 +856,16 @@
) )
) )
(pin input line (pin input line
(at 16.51 -12.7 180) (at 16.51 0 180)
(length 2.54) (length 2.54)
(name "SP" (name "SH2"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
) )
) )
(number "21" (number "23"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
@@ -858,17 +873,36 @@
) )
) )
) )
(pin input line (pin output line
(at 16.51 -17.78 180) (at 16.51 2.54 180)
(length 2.54) (length 2.54)
(name "SN" (name "GH2"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)
) )
) )
) )
(number "20" (number "24"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin power_in line
(at 0 -27.94 90)
(length 2.54)
(hide yes)
(name "GND"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "25"
(effects (effects
(font (font
(size 1.27 1.27) (size 1.27 1.27)

View File

@@ -5,6 +5,129 @@
(uuid "1a26a228-6eb3-45fe-98b2-d5a826508636") (uuid "1a26a228-6eb3-45fe-98b2-d5a826508636")
(paper "A4") (paper "A4")
(lib_symbols (lib_symbols
(symbol "Connector:TestPoint"
(pin_numbers
(hide yes)
)
(pin_names
(offset 0.762)
(hide yes)
)
(exclude_from_sim no)
(in_bom yes)
(on_board yes)
(in_pos_files yes)
(duplicate_pin_numbers_are_jumpers no)
(property "Reference" "TP"
(at 0 6.858 0)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Value" "TestPoint"
(at 0 5.08 0)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Footprint" ""
(at 5.08 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Datasheet" ""
(at 5.08 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Description" "test point"
(at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "ki_keywords" "test point tp"
(at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "ki_fp_filters" "Pin* Test*"
(at 0 0 0)
(show_name no)
(do_not_autoplace no)
(hide yes)
(effects
(font
(size 1.27 1.27)
)
)
)
(symbol "TestPoint_0_1"
(circle
(center 0 3.302)
(radius 0.762)
(stroke
(width 0)
(type default)
)
(fill
(type none)
)
)
)
(symbol "TestPoint_1_1"
(pin passive line
(at 0 0 90)
(length 2.54)
(name "1"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "1"
(effects
(font
(size 1.27 1.27)
)
)
)
)
)
(embedded_fonts no)
)
(symbol "Connector_Generic:Conn_01x03" (symbol "Connector_Generic:Conn_01x03"
(pin_names (pin_names
(offset 1.016) (offset 1.016)
@@ -4575,14 +4698,6 @@
(at 100.33 153.67) (at 100.33 153.67)
(uuid "41d4dceb-a576-4429-a735-b52754f3ea41") (uuid "41d4dceb-a576-4429-a735-b52754f3ea41")
) )
(no_connect
(at 100.33 176.53)
(uuid "4bf4f931-f3ba-4556-b73b-79e6d8d15ac3")
)
(no_connect
(at 100.33 173.99)
(uuid "699d7af2-89c6-4387-ae88-0b98473f9d89")
)
(no_connect (no_connect
(at 100.33 156.21) (at 100.33 156.21)
(uuid "bdfe21fa-bdf8-4547-8a8c-980823f6d305") (uuid "bdfe21fa-bdf8-4547-8a8c-980823f6d305")
@@ -7575,6 +7690,129 @@
) )
) )
) )
(symbol
(lib_id "Connector:TestPoint")
(at 100.33 176.53 270)
(unit 1)
(body_style 1)
(exclude_from_sim no)
(in_bom no)
(on_board yes)
(in_pos_files yes)
(dnp no)
(uuid "28380973-eb1f-42c1-bccb-bafa1d41b1aa")
(property "Reference" "TP2"
(at 105.664 176.784 90)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
(justify left)
)
)
(property "Value" "TestPoint"
(at 105.41 177.7999 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
(justify left)
)
)
(property "Footprint" "TestPoint:TestPoint_Pad_2.0x2.0mm"
(at 100.33 181.61 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Datasheet" ""
(at 100.33 181.61 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Description" "test point"
(at 100.33 176.53 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "NOTES" ""
(at 100.33 176.53 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Supplier link" ""
(at 100.33 176.53 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Supplier PN" ""
(at 100.33 176.53 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Part Number" ""
(at 100.33 176.53 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(pin "1"
(uuid "d341d7c3-98a3-412a-a5d0-041d92e49f6f")
)
(instances
(project "esp32-racer"
(path "/1d580319-54a9-438f-a4a3-ea2f61f357b8/2d868a8b-8f53-45e0-b871-4d23b4a3af01"
(reference "TP2")
(unit 1)
)
)
)
)
(symbol (symbol
(lib_id "Device:FerriteBead") (lib_id "Device:FerriteBead")
(at 33.02 83.82 180) (at 33.02 83.82 180)
@@ -11912,6 +12150,129 @@
) )
) )
) )
(symbol
(lib_id "Connector:TestPoint")
(at 100.33 173.99 270)
(unit 1)
(body_style 1)
(exclude_from_sim no)
(in_bom no)
(on_board yes)
(in_pos_files yes)
(dnp no)
(uuid "9516846e-5e4a-46fa-b6c1-34b8862062c3")
(property "Reference" "TP1"
(at 105.664 174.244 90)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
(justify left)
)
)
(property "Value" "TestPoint"
(at 105.41 175.2599 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
(justify left)
)
)
(property "Footprint" "TestPoint:TestPoint_Pad_2.0x2.0mm"
(at 100.33 179.07 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Datasheet" ""
(at 100.33 179.07 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Description" "test point"
(at 100.33 173.99 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "NOTES" ""
(at 100.33 173.99 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Supplier link" ""
(at 100.33 173.99 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Supplier PN" ""
(at 100.33 173.99 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Part Number" ""
(at 100.33 173.99 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(pin "1"
(uuid "7d0a6099-dd13-4b83-8a74-b0d6a3b9291c")
)
(instances
(project "esp32-racer"
(path "/1d580319-54a9-438f-a4a3-ea2f61f357b8/2d868a8b-8f53-45e0-b871-4d23b4a3af01"
(reference "TP1")
(unit 1)
)
)
)
)
(symbol (symbol
(lib_id "LED:SK6812") (lib_id "LED:SK6812")
(at 173.99 46.99 0) (at 173.99 46.99 0)

View File

@@ -1168,7 +1168,7 @@
) )
(symbol "DOZ50N03_1_1" (symbol "DOZ50N03_1_1"
(pin passive line (pin passive line
(at 2.54 5.08 270) (at 2.54 -5.08 90)
(length 2.54) (length 2.54)
(name "D" (name "D"
(effects (effects
@@ -1186,7 +1186,7 @@
) )
) )
(pin passive line (pin passive line
(at 2.54 5.08 270) (at 2.54 -5.08 90)
(length 2.54) (length 2.54)
(hide yes) (hide yes)
(name "D" (name "D"
@@ -1205,7 +1205,7 @@
) )
) )
(pin passive line (pin passive line
(at 2.54 5.08 270) (at 2.54 -5.08 90)
(length 2.54) (length 2.54)
(hide yes) (hide yes)
(name "D" (name "D"
@@ -1242,7 +1242,7 @@
) )
) )
(pin passive line (pin passive line
(at 2.54 -5.08 90) (at 2.54 5.08 270)
(length 2.54) (length 2.54)
(name "S" (name "S"
(effects (effects

View File

@@ -4654,16 +4654,6 @@
) )
(uuid "3db405c1-a0f1-4f1e-9c58-0efe3c3ec006") (uuid "3db405c1-a0f1-4f1e-9c58-0efe3c3ec006")
) )
(wire
(pts
(xy 48.26 111.76) (xy 52.07 111.76)
)
(stroke
(width 0)
(type default)
)
(uuid "3de2c821-682f-430a-98ea-21355f1cca93")
)
(wire (wire
(pts (pts
(xy 160.02 85.09) (xy 171.45 85.09) (xy 160.02 85.09) (xy 171.45 85.09)
@@ -5434,6 +5424,16 @@
) )
(uuid "ae958790-b0ec-44e1-b41a-85c846afe8b3") (uuid "ae958790-b0ec-44e1-b41a-85c846afe8b3")
) )
(wire
(pts
(xy 48.26 111.76) (xy 52.07 111.76)
)
(stroke
(width 0)
(type default)
)
(uuid "af47384e-fad6-42f7-bbf7-62e24015d21d")
)
(wire (wire
(pts (pts
(xy 262.89 30.48) (xy 265.43 30.48) (xy 262.89 30.48) (xy 265.43 30.48)
@@ -8689,7 +8689,7 @@
) )
) )
) )
(property "Footprint" "Package_DFN_QFN:DFN-12-1EP_4x4mm_P0.65mm_EP2.64x3.54mm" (property "Footprint" "Package_DFN_QFN:DFN-12-1EP_3x3mm_P0.45mm_EP1.65x2.38mm"
(at 76.454 151.384 0) (at 76.454 151.384 0)
(hide yes) (hide yes)
(show_name no) (show_name no)
@@ -11717,6 +11717,150 @@
) )
) )
) )
(symbol
(lib_id "Device:R")
(at 44.45 111.76 90)
(unit 1)
(body_style 1)
(exclude_from_sim no)
(in_bom yes)
(on_board yes)
(in_pos_files yes)
(dnp no)
(uuid "48259959-a703-42ba-b75a-5bc82d7fd3c6")
(property "Reference" "R65"
(at 44.45 114.3 90)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Value" "0"
(at 44.45 111.76 90)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Footprint" "Resistor_SMD:R_0603_1608Metric"
(at 44.45 113.538 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Datasheet" ""
(at 44.45 111.76 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Description" "Resistor"
(at 44.45 111.76 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Notes" ""
(at 44.45 111.76 0)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "PN" " RC0603JR-070RL "
(at 44.45 111.76 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "supplier link" "https://nz.mouser.com/ProductDetail/YAGEO/RC0603JR-070RL?qs=2cAdsCoAWRGWyPcuXgGiXQ%3D%3D"
(at 44.45 111.76 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Manufactor Part Number" ""
(at 44.45 111.76 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Supplier Part Number" ""
(at 44.45 111.76 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Sipplier PN" " 603-RC0603JR-070RL "
(at 44.45 111.76 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(pin "1"
(uuid "30f894a3-f030-447e-9d08-27ea33f7253c")
)
(pin "2"
(uuid "5218291b-cca8-47cd-a89b-66918ed5422b")
)
(instances
(project "esp32-racer"
(path "/1d580319-54a9-438f-a4a3-ea2f61f357b8/12408af9-30e9-42ec-a388-fbb9bc2a9d16"
(reference "R65")
(unit 1)
)
)
)
)
(symbol (symbol
(lib_id "power:GND") (lib_id "power:GND")
(at 158.75 137.16 0) (at 158.75 137.16 0)
@@ -13606,7 +13750,7 @@
) )
) )
) )
(property "Footprint" "Package_DFN_QFN:DFN-12-1EP_4x4mm_P0.65mm_EP2.64x3.54mm" (property "Footprint" "Package_DFN_QFN:DFN-12-1EP_3x3mm_P0.45mm_EP1.65x2.38mm"
(at 76.454 89.154 0) (at 76.454 89.154 0)
(hide yes) (hide yes)
(show_name no) (show_name no)
@@ -22899,150 +23043,6 @@
) )
) )
) )
(symbol
(lib_id "Device:R")
(at 44.45 111.76 90)
(unit 1)
(body_style 1)
(exclude_from_sim no)
(in_bom yes)
(on_board yes)
(in_pos_files yes)
(dnp no)
(uuid "f47a2fca-cf94-47c5-a084-fd9e13dd2fe7")
(property "Reference" "R65"
(at 44.45 114.3 90)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Value" "0"
(at 44.45 111.76 90)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Footprint" "Resistor_SMD:R_0603_1608Metric"
(at 44.45 113.538 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Datasheet" ""
(at 44.45 111.76 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Description" "Resistor"
(at 44.45 111.76 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Notes" ""
(at 44.45 111.76 0)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "PN" " RC0603JR-070RL "
(at 44.45 111.76 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "supplier link" "https://nz.mouser.com/ProductDetail/YAGEO/RC0603JR-070RL?qs=2cAdsCoAWRGWyPcuXgGiXQ%3D%3D"
(at 44.45 111.76 0)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Manufactor Part Number" ""
(at 44.45 111.76 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Supplier Part Number" ""
(at 44.45 111.76 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Sipplier PN" " 603-RC0603JR-070RL "
(at 44.45 111.76 90)
(hide yes)
(show_name no)
(do_not_autoplace no)
(effects
(font
(size 1.27 1.27)
)
)
)
(pin "1"
(uuid "eb34f315-6354-4968-8713-977aa1d091bd")
)
(pin "2"
(uuid "ed918021-4fcb-42dc-95ad-2bdea1b77164")
)
(instances
(project "esp32-racer"
(path "/1d580319-54a9-438f-a4a3-ea2f61f357b8/12408af9-30e9-42ec-a388-fbb9bc2a9d16"
(reference "R65")
(unit 1)
)
)
)
)
(symbol (symbol
(lib_id "Device:R") (lib_id "Device:R")
(at 160.02 88.9 0) (at 160.02 88.9 0)

View File

@@ -3084,7 +3084,7 @@
) )
(symbol "DOZ50N03_1_1" (symbol "DOZ50N03_1_1"
(pin passive line (pin passive line
(at 2.54 5.08 270) (at 2.54 -5.08 90)
(length 2.54) (length 2.54)
(name "D" (name "D"
(effects (effects
@@ -3102,7 +3102,7 @@
) )
) )
(pin passive line (pin passive line
(at 2.54 5.08 270) (at 2.54 -5.08 90)
(length 2.54) (length 2.54)
(hide yes) (hide yes)
(name "D" (name "D"
@@ -3121,7 +3121,7 @@
) )
) )
(pin passive line (pin passive line
(at 2.54 5.08 270) (at 2.54 -5.08 90)
(length 2.54) (length 2.54)
(hide yes) (hide yes)
(name "D" (name "D"
@@ -3158,7 +3158,7 @@
) )
) )
(pin passive line (pin passive line
(at 2.54 -5.08 90) (at 2.54 5.08 270)
(length 2.54) (length 2.54)
(name "S" (name "S"
(effects (effects

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"board": { "board": {
"active_layer": 5, "active_layer": 0,
"active_layer_preset": "", "active_layer_preset": "",
"auto_track_width": true, "auto_track_width": true,
"hidden_netclasses": [], "hidden_netclasses": [],

View File

@@ -769,7 +769,7 @@
"uuid": "1d580319-54a9-438f-a4a3-ea2f61f357b8" "uuid": "1d580319-54a9-438f-a4a3-ea2f61f357b8"
} }
], ],
"used_designators": "", "used_designators": "R65,TP1-2",
"variants": [] "variants": []
}, },
"sheets": [ "sheets": [

View File

@@ -0,0 +1,22 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.20)
set(ENV{IDF_COMPONENT_MANAGER} "0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# add the component directories that we want to use
set(EXTRA_COMPONENT_DIRS
"components/"
)
set(
COMPONENTS
"main esptool_py i2c lsm6dso filters"
CACHE STRING
"List of components to include"
)
project(lsm6dso_example)
set(CMAKE_CXX_STANDARD 20)

View File

@@ -0,0 +1,50 @@
# LSM6DSO Example
This example demonstrates how to use the espp LSM6DSO 6-axis IMU driver with the
ESP-IDF. The example is modeled after the ICM42607 example and shows how to
configure the IMU, read accelerometer and gyroscope data, and use orientation
filtering (e.g., Madgwick filter).
![CleanShot 2025-06-18 at 14 16 01](https://github.com/user-attachments/assets/10b15539-688b-4711-b1ce-e7bb33f7e343)
## Features
- I2C communication with the LSM6DSO
- Configurable accelerometer and gyroscope range and output data rate
- Periodic reading of accelerometer, gyroscope, and temperature data
- Orientation filtering using Madgwick filter
## Usage
- Configure the I2C pins and address in `sdkconfig` or via Kconfig options
- Build and flash the example to your ESP32/ESP-IDF target
- The example will print IMU data and orientation to the serial console
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view
serial output:
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
![CleanShot 2025-06-18 at 14 15 13](https://github.com/user-attachments/assets/26b07fa0-4e4a-4025-a5a7-135322da8d3b)
![CleanShot 2025-06-18 at 14 16 01](https://github.com/user-attachments/assets/10b15539-688b-4711-b1ce-e7bb33f7e343)
## Example Code
See `main/lsm6dso_example.cpp` for the full example source code.
## Configuration
- Default I2C address: 0x6A (can be changed in Kconfig or via config struct)
- Example I2C pins: SDA = 21, SCL = 22
## Documentation
See the [documentation](https://esp-cpp.github.io/espp/imu/lsm6dso.html) for
full API details.

View File

@@ -0,0 +1,2 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,46 @@
menu "Example Configuration"
choice EXAMPLE_HARDWARE
prompt "Hardware"
default EXAMPLE_HARDWARE_QTPYPICO
help
Select the hardware to run this example on.
config EXAMPLE_HARDWARE_QTPYPICO
depends on IDF_TARGET_ESP32
bool "Qt Py PICO"
config EXAMPLE_HARDWARE_QTPYS3
depends on IDF_TARGET_ESP32S3
bool "Qt Py S3"
config EXAMPLE_HARDWARE_CUSTOM
bool "Custom"
endchoice
config EXAMPLE_I2C_SCL_GPIO
int "SCL GPIO Num"
range 0 50
default 19 if EXAMPLE_HARDWARE_QTPYPICO
default 40 if EXAMPLE_HARDWARE_QTPYS3
default 19 if EXAMPLE_HARDWARE_CUSTOM
help
GPIO number for I2C Master clock line.
config EXAMPLE_I2C_SDA_GPIO
int "SDA GPIO Num"
range 0 50
default 22 if EXAMPLE_HARDWARE_QTPYPICO
default 41 if EXAMPLE_HARDWARE_QTPYS3
default 22 if EXAMPLE_HARDWARE_CUSTOM
help
GPIO number for I2C Master data line.
config EXAMPLE_I2C_CLOCK_SPEED_HZ
int "I2C Clock Speed"
range 100 1000000
default 400000
help
I2C clock speed in Hz.
endmenu

View File

@@ -0,0 +1,199 @@
#include <chrono>
#include <cmath>
#include <vector>
#include "i2c.hpp"
#include "kalman_filter.hpp"
#include "logger.hpp"
#include "lsm6dso.hpp"
#include "madgwick_filter.hpp"
using namespace std::chrono_literals;
extern "C" void app_main(void) {
espp::Logger logger({.tag = "LSM6DSO Example", .level = espp::Logger::Verbosity::INFO});
logger.info("Starting LSM6DSO example!");
//! [lsm6dso example]
using Imu = espp::Lsm6dso<espp::lsm6dso::Interface::I2C>;
// I2C config (customize as needed)
static constexpr auto i2c_port = I2C_NUM_0;
static constexpr auto i2c_clock_speed = CONFIG_EXAMPLE_I2C_CLOCK_SPEED_HZ; // Set in sdkconfig
static constexpr gpio_num_t i2c_sda = (gpio_num_t)CONFIG_EXAMPLE_I2C_SDA_GPIO; // Set in sdkconfig
static constexpr gpio_num_t i2c_scl = (gpio_num_t)CONFIG_EXAMPLE_I2C_SCL_GPIO; // Set in sdkconfig
espp::I2c i2c({.port = i2c_port,
.sda_io_num = i2c_sda,
.scl_io_num = i2c_scl,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.clk_speed = i2c_clock_speed});
// make the orientation filter to compute orientation from accel + gyro
static constexpr float angle_noise = 0.001f;
static constexpr float rate_noise = 0.1f;
static espp::KalmanFilter<2> kf;
kf.set_process_noise(rate_noise);
kf.set_measurement_noise(angle_noise);
auto kalman_filter_fn = [](float dt, const Imu::Value &accel,
const Imu::Value &gyro) -> Imu::Value {
// Apply Kalman filter
float accelRoll = atan2(accel.y, accel.z);
float accelPitch = atan2(-accel.x, sqrt(accel.y * accel.y + accel.z * accel.z));
kf.predict({espp::deg_to_rad(gyro.x), espp::deg_to_rad(gyro.y)}, dt);
kf.update({accelRoll, accelPitch});
float roll, pitch;
std::tie(roll, pitch) = kf.get_state();
// return the computed orientation
Imu::Value orientation{};
orientation.roll = roll;
orientation.pitch = pitch;
orientation.yaw = 0.0f;
return orientation;
};
// Madgwick filter for orientation
static constexpr float beta = 0.1f;
static espp::MadgwickFilter madgwick(beta);
auto madgwick_filter_fn = [](float dt, const Imu::Value &accel,
const Imu::Value &gyro) -> Imu::Value {
madgwick.update(dt, accel.x, accel.y, accel.z, espp::deg_to_rad(gyro.x),
espp::deg_to_rad(gyro.y), espp::deg_to_rad(gyro.z));
float roll, pitch, yaw;
madgwick.get_euler(roll, pitch, yaw);
Imu::Value orientation{};
orientation.roll = espp::deg_to_rad(roll);
orientation.pitch = espp::deg_to_rad(pitch);
orientation.yaw = espp::deg_to_rad(yaw);
return orientation;
};
// IMU config
Imu::Config config{
.device_address = Imu::DEFAULT_I2C_ADDRESS,
.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3),
.read = std::bind(&espp::I2c::read, &i2c, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3),
.imu_config =
{
.accel_range = Imu::AccelRange::RANGE_2G,
.accel_odr = Imu::AccelODR::ODR_416_HZ,
.gyro_range = Imu::GyroRange::DPS_2000,
.gyro_odr = Imu::GyroODR::ODR_416_HZ,
},
.orientation_filter = kalman_filter_fn,
.auto_init = true,
.log_level = espp::Logger::Verbosity::INFO,
};
logger.info("Creating LSM6DSO IMU");
Imu imu(config);
std::error_code ec;
// set the accel / gyro on-chip filters
static constexpr uint8_t accel_filter_bandwidth = 0b001; // ODR / 10
static constexpr uint8_t gyro_lpf_bandwidth = 0b001; // ODR / 3
static constexpr bool gyro_hpf_enabled = false; // disable high-pass filter on gyro
static constexpr auto gyro_hpf_bandwidth = Imu::GyroHPF::HPF_0_26_HZ; // 0.26Hz
if (!imu.set_accelerometer_filter(accel_filter_bandwidth, Imu::AccelFilter::LOWPASS, ec)) {
logger.error("Failed to set accelerometer filter: {}", ec.message());
}
// set the gyroscope filter to have lowpass
if (!imu.set_gyroscope_filter(gyro_lpf_bandwidth, gyro_hpf_enabled, gyro_hpf_bandwidth, ec)) {
logger.error("Failed to set gyroscope filter: {}", ec.message());
}
// make a task to read out the IMU data and print it to console
espp::Task imu_task({.callback = [&](std::mutex &m, std::condition_variable &cv) -> bool {
static auto start = std::chrono::steady_clock::now();
auto now = esp_timer_get_time(); // time in microseconds
static auto t0 = now;
auto t1 = now;
float dt = (t1 - t0) / 1'000'000.0f; // convert us to s
t0 = t1;
std::error_code ec;
// update the imu data
if (!imu.update(dt, ec)) {
return false;
}
// get accel
auto accel = imu.get_accelerometer();
auto gyro = imu.get_gyroscope();
auto temp = imu.get_temperature();
auto orientation = imu.get_orientation();
auto gravity_vector = imu.get_gravity_vector();
[[maybe_unused]] auto t2 = esp_timer_get_time(); // time in microseconds
auto madgwick_orientation = madgwick_filter_fn(dt, accel, gyro);
float roll = madgwick_orientation.roll;
float pitch = madgwick_orientation.pitch;
float yaw = madgwick_orientation.yaw;
float vx = sin(pitch);
float vy = -cos(pitch) * sin(roll);
float vz = -cos(pitch) * cos(roll);
// print time and raw IMU data
std::string text = "";
text += fmt::format("{:.3f},", now / 1'000'000.0f);
text += fmt::format("{:02.3f},{:02.3f},{:02.3f},", (float)accel.x,
(float)accel.y, (float)accel.z);
text += fmt::format("{:03.3f},{:03.3f},{:03.3f},", (float)gyro.x,
(float)gyro.y, (float)gyro.z);
text += fmt::format("{:02.1f},", temp);
// print kalman filter outputs
text += fmt::format("{:03.3f},{:03.3f},{:03.3f},", (float)orientation.x,
(float)orientation.y, (float)orientation.z);
text += fmt::format("{:03.3f},{:03.3f},{:03.3f},", (float)gravity_vector.x,
(float)gravity_vector.y, (float)gravity_vector.z);
// print madgwick filter outputs
text += fmt::format("{:03.3f},{:03.3f},{:03.3f},", roll, pitch, yaw);
text += fmt::format("{:03.3f},{:03.3f},{:03.3f}", vx, vy, vz);
fmt::print("{}\n", text);
// fmt::print("IMU update took {:.3f} ms\n", (t2 - t0) / 1000.0f);
// sleep first in case we don't get IMU data and need to exit early
{
std::unique_lock<std::mutex> lock(m);
cv.wait_until(lock, start + 10ms);
}
return false;
},
.task_config = {
.name = "IMU",
.stack_size_bytes = 6 * 1024,
.priority = 10,
.core_id = 0,
}});
// print the header for the IMU data (for plotting)
fmt::print("% Time (s), "
// raw IMU data (accel, gyro, temp)
"Accel X (m/s^2), Accel Y (m/s^2), Accel Z (m/s^2), "
"Gyro X (rad/s), Gyro Y (rad/s), Gyro Z (rad/s), "
"Temp (C), "
// kalman filter outputs
"Kalman Roll (rad), Kalman Pitch (rad), Kalman Yaw (rad), "
"Kalman Gravity X, Kalman Gravity Y, Kalman Gravity Z, "
// madgwick filter outputs
"Madgwick Roll (rad), Madgwick Pitch (rad), Madgwick Yaw (rad), "
"Madgwick Gravity X, Madgwick Gravity Y, Madgwick Gravity Z\n");
logger.info("Starting IMU task");
imu_task.start();
// loop forever
while (true) {
std::this_thread::sleep_for(1s);
}
//! [lsm6dso example]
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,20 @@
CONFIG_FREERTOS_HZ=1000
# set compiler optimization level to -O2 (compile for performance)
CONFIG_COMPILER_OPTIMIZATION_PERF=y
# ESP32-specific
#
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=240
# Common ESP-related
#
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096
CONFIG_ESP_MAIN_TASK_STACK_SIZE=16384
# Set esp-timer task stack size to 6KB
CONFIG_ESP_TIMER_TASK_STACK_SIZE=6144
# set the functions into IRAM
CONFIG_SPI_MASTER_IN_IRAM=y

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.22)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(wacky_bully)

View File

@@ -0,0 +1,3 @@
idf_component_register(SRCS "drv8701.c"
INCLUDE_DIRS "include"
REQUIRES esp_driver_mcpwm esp_driver_gpio)

View File

@@ -0,0 +1,105 @@
#include <math.h>
#include <stdio.h>
#include "drv8701.h"
#include "driver/mcpwm_cmpr.h"
#include "driver/mcpwm_gen.h"
#include "driver/mcpwm_oper.h"
#include "driver/mcpwm_timer.h"
#include "driver/mcpwm_types.h"
#include "driver/gpio.h"
#include "esp_err.h"
#include "freertos/idf_additions.h"
#include "hal/gpio_types.h"
#include "portmacro.h"
#define PWM_RESOLUTION_HZ 2000000
#define PWM_TIMEBASE_PERIOD PWM_RESOLUTION_HZ/20000
void drv8701_task(void *args) {
drv8701_task_config_t *motor_cfg = ((drv8701_task_config_t *)args);
motor_cfg->in_ctrl_queue = xQueueCreate(3, sizeof(float));
motor_cfg->current_mutex = xSemaphoreCreateMutex();
// --------------------- Configure PWM -------------------------
mcpwm_timer_handle_t timer = NULL;
mcpwm_timer_config_t timer_cfg = {
.group_id = motor_cfg->pwm_group_num,
.clk_src = MCPWM_TIMER_CLK_SRC_DEFAULT,
.resolution_hz = PWM_RESOLUTION_HZ,
.count_mode = MCPWM_TIMER_COUNT_MODE_UP,
.period_ticks = PWM_TIMEBASE_PERIOD,
};
ESP_ERROR_CHECK(mcpwm_new_timer(&timer_cfg, &timer));
mcpwm_oper_handle_t oper = NULL;
mcpwm_operator_config_t oper_cfg = {
.group_id = motor_cfg->pwm_group_num,
};
ESP_ERROR_CHECK(mcpwm_new_operator(&oper_cfg, &oper));
ESP_ERROR_CHECK(mcpwm_operator_connect_timer(oper, timer));
mcpwm_cmpr_handle_t cmpr = NULL;
mcpwm_comparator_config_t cmpr_cfg = {
.flags.update_cmp_on_tep = true,
};
ESP_ERROR_CHECK(mcpwm_new_comparator(oper, &cmpr_cfg, &cmpr));
mcpwm_gen_handle_t gen = NULL;
mcpwm_generator_config_t gen_cfg = {
.gen_gpio_num = motor_cfg->en_pin,
};
ESP_ERROR_CHECK(mcpwm_new_generator(oper, &gen_cfg, &gen));
ESP_ERROR_CHECK(mcpwm_comparator_set_compare_value(cmpr, 0));
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(gen,
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH)));
ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(gen,
MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, cmpr, MCPWM_GEN_ACTION_LOW)));
ESP_ERROR_CHECK(mcpwm_timer_enable(timer));
ESP_ERROR_CHECK(mcpwm_timer_start_stop(timer, MCPWM_TIMER_START_NO_STOP));
// --------------------- Configure Direction -------------------------
printf("Configuring Direction\n");
gpio_config_t phase_cfg = {
.pin_bit_mask = 1ULL << motor_cfg->ph_pin,
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_OUTPUT,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.pull_up_en = GPIO_PULLUP_DISABLE
};
gpio_config(&phase_cfg);
// Main Loop
float target_velocity = 0.0;
while(1) {
// Get new velocity if it has changed
if(xQueueReceive(motor_cfg->in_ctrl_queue, &target_velocity, 0)){
target_velocity = fmaxf(-1.0, fminf(1.0, target_velocity));
}
uint32_t abs_scaled_vel = (uint32_t) (fabsf(target_velocity) * ((float)PWM_TIMEBASE_PERIOD));
mcpwm_comparator_set_compare_value(cmpr, abs_scaled_vel);
if (target_velocity > 0.0) {
gpio_set_level(motor_cfg->ph_pin, 1);
}
else {
gpio_set_level(motor_cfg->ph_pin, 0);
}
vTaskDelay(50 / portTICK_PERIOD_MS);
}
}
void set_motor_vel(drv8701_task_config_t *motor_cfg, float velocity) {
xQueueSend(motor_cfg->in_ctrl_queue, &velocity, 0);
}

View File

@@ -0,0 +1,38 @@
#ifndef DRV8701_H
#define DRV8701_H
#include "freertos/idf_additions.h"
// Enable PWM for speed control
// Phase chooses direction
typedef struct {
uint8_t en_pin;
uint8_t ph_pin;
uint8_t pwm_group_num;
// Do not populate, done as part of task creation
QueueHandle_t in_ctrl_queue;
SemaphoreHandle_t current_mutex;
} drv8701_task_config_t;
/**
* @brief Launch the motor driver task
*
* @param motor_cfg The configuration for the motor driver
*/
void drv8701_task(void *args);
/**
* @brief Set the velocity of a specific motor driver
*
* @param motor_cfg The configuration for the specific motor driver
* @param velocity -1.0 to 1.0
*/
void set_motor_vel(drv8701_task_config_t *motor_cfg, float velocity);
#endif

View File

@@ -0,0 +1,3 @@
idf_component_register(SRCS "xbox_controller.c"
PRIV_REQUIRES bt esp_hid driver mbedtls nvs_flash
INCLUDE_DIRS "include")

View File

@@ -0,0 +1,7 @@
#ifndef XBOX_CONTROLLER_H
#define XBOX_CONTROLLER_H
void init_controller(void);
void print_state(void);
#endif

View File

@@ -0,0 +1,673 @@
#include <stdio.h>
#include <stdint.h>
#include "xbox_controller.h"
#include "nvs_flash.h"
#include "esp_err.h"
#include "esp_hidh.h"
#include "esp_hid_common.h"
#include "esp_gattc_api.h"
#include "esp_bt_main.h"
#include "esp_bt.h"
#include "esp_log.h"
#include "esp_gap_ble_api.h"
#include "freertos/idf_additions.h"
#define HIDH_IDLE_MODE 0x00
#define HIDH_BLE_MODE 0x01
#define HIDH_BT_MODE 0x02
#define HIDH_BTDM_MODE 0x03
#define XBOX_CONTROLLER_INDEX_BUTTONS_DIR 12
#define XBOX_CONTROLLER_INDEX_BUTTONS_MAIN 13
#define XBOX_CONTROLLER_INDEX_BUTTONS_CENTER 14
#define XBOX_CONTROLLER_INDEX_BUTTONS_SHARE 15
typedef struct {
bool A;
bool B;
bool X;
bool Y;
bool UP;
bool DOWN;
bool LEFT;
bool RIGHT;
bool RB;
bool LB;
bool START;
bool SELECT;
bool XBOX_BUT;
bool RS;
bool LS;
uint16_t joyLX;
uint16_t joyLY;
uint16_t joyRX;
uint16_t joyRY;
uint16_t trigL;
uint16_t trigR;
}controller_state_t;
controller_state_t xbox_state;
void print_state(void) {
ESP_LOGI("xbox_ctrl_output", "A:%1d,B:%1d,X:%1d,Y:%1d,U:%1d,D:%1d,L%1d,R:%1d\n",
xbox_state.A, xbox_state.B, xbox_state.X, xbox_state.Y,
xbox_state.UP, xbox_state.DOWN, xbox_state.LEFT, xbox_state.RIGHT);
ESP_LOGI("xbox_ctrl_output", "RB:%1d,LB:%1d,RS:%1d,LS:%1d,START:%1d,SELECT:%1d,XBOX:%1d",
xbox_state.RB, xbox_state.LB, xbox_state.RS, xbox_state.LS,
xbox_state.START, xbox_state.SELECT, xbox_state.XBOX_BUT);
ESP_LOGI("xbox_ctrl_output", "jLX:%5d,jLY:%5d,jRX:%5d,jRY:%5d,tL:%5d,tR:%5d",
xbox_state.joyLX, xbox_state.joyLY, xbox_state.joyRX, xbox_state.joyRY,
xbox_state.trigL, xbox_state.trigR);
}
const char *esp_ble_key_type_str(esp_ble_key_type_t key_type)
{
const char *key_str = NULL;
switch (key_type) {
case ESP_LE_KEY_NONE:
key_str = "ESP_LE_KEY_NONE";
break;
case ESP_LE_KEY_PENC:
key_str = "ESP_LE_KEY_PENC";
break;
case ESP_LE_KEY_PID:
key_str = "ESP_LE_KEY_PID";
break;
case ESP_LE_KEY_PCSRK:
key_str = "ESP_LE_KEY_PCSRK";
break;
case ESP_LE_KEY_PLK:
key_str = "ESP_LE_KEY_PLK";
break;
case ESP_LE_KEY_LLK:
key_str = "ESP_LE_KEY_LLK";
break;
case ESP_LE_KEY_LENC:
key_str = "ESP_LE_KEY_LENC";
break;
case ESP_LE_KEY_LID:
key_str = "ESP_LE_KEY_LID";
break;
case ESP_LE_KEY_LCSRK:
key_str = "ESP_LE_KEY_LCSRK";
break;
default:
key_str = "INVALID BLE KEY TYPE";
break;
}
return key_str;
}
void controller_msg_callback(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) {
esp_hidh_event_t event = (esp_hidh_event_t)id;
esp_hidh_event_data_t *param = (esp_hidh_event_data_t *) event_data;
switch (event)
{
case ESP_HIDH_OPEN_EVENT:
{
if (param->open.status == ESP_OK)
{
const uint8_t *bda = esp_hidh_dev_bda_get(param->open.dev);
ESP_LOGI("xbox_ctrl", ESP_BD_ADDR_STR " OPEN: %s", ESP_BD_ADDR_HEX(bda), esp_hidh_dev_name_get(param->open.dev));
esp_hidh_dev_dump(param->open.dev, stdout);
}
else
{
ESP_LOGE("xbox_ctrl", " OPEN failed!");
}
break;
}
case ESP_HIDH_BATTERY_EVENT:
{
const uint8_t *bda = esp_hidh_dev_bda_get(param->battery.dev);
ESP_LOGI("xbox_ctrl", ESP_BD_ADDR_STR " BATTERY: %d%%", ESP_BD_ADDR_HEX(bda), param->battery.level);
break;
}
case ESP_HIDH_INPUT_EVENT:
{
uint8_t btnBits;
btnBits = param->input.data[XBOX_CONTROLLER_INDEX_BUTTONS_MAIN];
xbox_state.A = (btnBits & (1 << 0) << 0);
xbox_state.B = (btnBits & (1 << 1) << 1);
xbox_state.X = (btnBits & (1 << 2) << 2);
xbox_state.Y = (btnBits & (1 << 3) << 3);
xbox_state.LB = (btnBits & (1 << 6) << 6);
xbox_state.RB = (btnBits & (1 << 7) << 7);
btnBits = param->input.data[XBOX_CONTROLLER_INDEX_BUTTONS_CENTER];
xbox_state.SELECT = (btnBits & (1 << 2) << 2);
xbox_state.START = (btnBits & (1 << 3) << 3);
xbox_state.XBOX_BUT = (btnBits & (1 << 4) << 4);
xbox_state.LS = (btnBits & (1 << 5) << 5);
xbox_state.RS = (btnBits & (1 << 6) << 6);
btnBits = param->input.data[XBOX_CONTROLLER_INDEX_BUTTONS_DIR];
xbox_state.UP = btnBits == 1 || btnBits == 2 || btnBits == 8;
xbox_state.RIGHT = 2 <= btnBits && btnBits <= 4;
xbox_state.DOWN = 4 <= btnBits && btnBits <= 6;
xbox_state.LEFT = 6 <= btnBits && btnBits <= 8;
xbox_state.joyLX = (uint16_t)param->input.data[0] | ((uint16_t)param->input.data[1] << 8); // 0-65535
xbox_state.joyLY = (uint16_t)param->input.data[2] | ((uint16_t)param->input.data[3] << 8);
xbox_state.joyRX = (uint16_t)param->input.data[4] | ((uint16_t)param->input.data[5] << 8);
xbox_state.joyRY = (uint16_t)param->input.data[6] | ((uint16_t)param->input.data[7] << 8);
xbox_state.trigL = (uint16_t)param->input.data[8] | ((uint16_t)param->input.data[9] << 8); // 0-1024
xbox_state.trigR = (uint16_t)param->input.data[10] | ((uint16_t)param->input.data[11] << 8);
break;
}
case ESP_HIDH_FEATURE_EVENT:
{
const uint8_t *bda = esp_hidh_dev_bda_get(param->feature.dev);
ESP_LOGI("xbox_ctrl", ESP_BD_ADDR_STR " FEATURE: %8s, MAP: %2u, ID: %3u, Len: %d", ESP_BD_ADDR_HEX(bda),
esp_hid_usage_str(param->feature.usage), param->feature.map_index, param->feature.report_id,
param->feature.length);
ESP_LOG_BUFFER_HEX("xbox_ctrl", param->feature.data, param->feature.length);
break;
}
case ESP_HIDH_CLOSE_EVENT:
{
const uint8_t *bda = esp_hidh_dev_bda_get(param->close.dev);
ESP_LOGI("xbox_ctrl", ESP_BD_ADDR_STR " CLOSE: %s", ESP_BD_ADDR_HEX(bda), esp_hidh_dev_name_get(param->close.dev));
break;
}
default:
ESP_LOGI("xbox_ctrl", "EVENT: %d", event);
break;
}
}
static const char *ble_addr_type_names[] = {"PUBLIC", "RANDOM", "RPA_PUBLIC", "RPA_RANDOM"};
typedef struct esp_hidh_scan_result_s {
struct esp_hidh_scan_result_s *next;
esp_bd_addr_t bda;
const char *name;
int8_t rssi;
esp_hid_usage_t usage;
esp_hid_transport_t transport; //BT, BLE or USB
union {
struct {
esp_bt_uuid_t uuid;
} bt;
struct {
esp_ble_addr_type_t addr_type;
uint16_t appearance;
} ble;
};
} esp_hid_scan_result_t;
static esp_hid_scan_result_t *bt_scan_results = NULL;
static size_t num_bt_scan_results = 0;
static esp_hid_scan_result_t *ble_scan_results = NULL;
static size_t num_ble_scan_results = 0;
static SemaphoreHandle_t bt_hidh_cb_semaphore = NULL;
#define WAIT_BT_CB() xSemaphoreTake(bt_hidh_cb_semaphore, portMAX_DELAY)
#define SEND_BT_CB() xSemaphoreGive(bt_hidh_cb_semaphore)
static SemaphoreHandle_t ble_hidh_cb_semaphore = NULL;
#define WAIT_BLE_CB() xSemaphoreTake(ble_hidh_cb_semaphore, portMAX_DELAY)
#define SEND_BLE_CB() xSemaphoreGive(ble_hidh_cb_semaphore)
#define SIZEOF_ARRAY(a) (sizeof(a)/sizeof(*a))
static esp_ble_scan_params_t hid_scan_params = {
.scan_type = BLE_SCAN_TYPE_ACTIVE,
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
.scan_interval = 0x50,
.scan_window = 0x30,
.scan_duplicate = BLE_SCAN_DUPLICATE_ENABLE,
};
static esp_err_t start_ble_scan(uint32_t seconds)
{
esp_err_t ret = ESP_OK;
if ((ret = esp_ble_gap_set_scan_params(&hid_scan_params)) != ESP_OK) {
ESP_LOGE("xbox_ctrl", "esp_ble_gap_set_scan_params failed: %d", ret);
return ret;
}
WAIT_BLE_CB();
if ((ret = esp_ble_gap_start_scanning(seconds)) != ESP_OK) {
ESP_LOGE("xbox_ctrl", "esp_ble_gap_start_scanning failed: %d", ret);
return ret;
}
return ret;
}
esp_err_t esp_hid_scan(uint32_t seconds, size_t *num_results, esp_hid_scan_result_t **results)
{
if (num_bt_scan_results || bt_scan_results || num_ble_scan_results || ble_scan_results) {
ESP_LOGE("xbox_ctrl", "There are old scan results. Free them first!");
return ESP_FAIL;
}
if (start_ble_scan(seconds) == ESP_OK) {
WAIT_BLE_CB();
} else {
return ESP_FAIL;
}
*num_results = num_bt_scan_results + num_ble_scan_results;
*results = bt_scan_results;
if (num_bt_scan_results) {
while (bt_scan_results->next != NULL) {
bt_scan_results = bt_scan_results->next;
}
bt_scan_results->next = ble_scan_results;
} else {
*results = ble_scan_results;
}
num_bt_scan_results = 0;
bt_scan_results = NULL;
num_ble_scan_results = 0;
ble_scan_results = NULL;
return ESP_OK;
}
const char *ble_addr_type_str(esp_ble_addr_type_t ble_addr_type)
{
if (ble_addr_type > BLE_ADDR_TYPE_RPA_RANDOM) {
return "UNKNOWN";
}
return ble_addr_type_names[ble_addr_type];
}
void esp_hid_scan_results_free(esp_hid_scan_result_t *results)
{
esp_hid_scan_result_t *r = NULL;
while (results) {
r = results;
results = results->next;
if (r->name != NULL) {
free((char *)r->name);
}
free(r);
}
}
#define SCAN_DURATION_SECONDS 10
void hid_task(void *pvParameters)
{
size_t results_len = 0;
esp_hid_scan_result_t *results = NULL;
ESP_LOGI("xbox_ctrl", "SCAN...");
// start scan for HID devices
esp_hid_scan(SCAN_DURATION_SECONDS, &results_len, &results);
ESP_LOGI("xbox_ctrl", "SCAN: %u results", results_len);
if (results_len)
{
esp_hid_scan_result_t *r = results;
esp_hid_scan_result_t *cr = NULL;
while (r)
{
printf(" %s: " ESP_BD_ADDR_STR ", ", (r->transport == ESP_HID_TRANSPORT_BLE) ? "BLE" : "BT ", ESP_BD_ADDR_HEX(r->bda));
printf("RSSI: %d, ", r->rssi);
printf("USAGE: %s, ", esp_hid_usage_str(r->usage));
if (r->transport == ESP_HID_TRANSPORT_BLE)
{
if (r->ble.appearance == 0x03c4)
cr = r;
printf("APPEARANCE: 0x%04x, ", r->ble.appearance);
printf("ADDR_TYPE: '%s', ", ble_addr_type_str(r->ble.addr_type));
}
printf("NAME: %s ", r->name ? r->name : "");
printf("\n");
r = r->next;
}
if (cr)
{
// open the last result
esp_hidh_dev_open(cr->bda, cr->transport, cr->ble.addr_type);
}
// free the results
esp_hid_scan_results_free(results);
}
vTaskDelete(NULL);
}
#define GAP_DBG_PRINTF(...) printf(__VA_ARGS__)
static esp_hid_scan_result_t *find_scan_result(esp_bd_addr_t bda, esp_hid_scan_result_t *results)
{
esp_hid_scan_result_t *r = results;
while (r) {
if (memcmp(bda, r->bda, sizeof(esp_bd_addr_t)) == 0) {
return r;
}
r = r->next;
}
return NULL;
}
static void add_ble_scan_result(esp_bd_addr_t bda, esp_ble_addr_type_t addr_type, uint16_t appearance, uint8_t *name, uint8_t name_len, int rssi)
{
if (find_scan_result(bda, ble_scan_results)) {
ESP_LOGW("xbox_controller", "Result already exists!");
return;
}
esp_hid_scan_result_t *r = (esp_hid_scan_result_t *)malloc(sizeof(esp_hid_scan_result_t));
if (r == NULL) {
ESP_LOGE("xbox_controller", "Malloc ble_hidh_scan_result_t failed!");
return;
}
r->transport = ESP_HID_TRANSPORT_BLE;
memcpy(r->bda, bda, sizeof(esp_bd_addr_t));
r->ble.appearance = appearance;
r->ble.addr_type = addr_type;
r->usage = esp_hid_usage_from_appearance(appearance);
r->rssi = rssi;
r->name = NULL;
if (name_len && name) {
char *name_s = (char *)malloc(name_len + 1);
if (name_s == NULL) {
free(r);
ESP_LOGE("xbox_controller", "Malloc result name failed!");
return;
}
memcpy(name_s, name, name_len);
name_s[name_len] = 0;
r->name = (const char *)name_s;
}
r->next = ble_scan_results;
ble_scan_results = r;
num_ble_scan_results++;
}
static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst)
{
uint16_t uuid = 0;
uint16_t appearance = 0;
char name[64] = {0};
uint8_t uuid_len = 0;
uint8_t *uuid_d = esp_ble_resolve_adv_data(scan_rst->ble_adv, ESP_BLE_AD_TYPE_16SRV_CMPL, &uuid_len);
if (uuid_d != NULL && uuid_len) {
uuid = uuid_d[0] + (uuid_d[1] << 8);
}
uint8_t appearance_len = 0;
uint8_t *appearance_d = esp_ble_resolve_adv_data(scan_rst->ble_adv, ESP_BLE_AD_TYPE_APPEARANCE, &appearance_len);
if (appearance_d != NULL && appearance_len) {
appearance = appearance_d[0] + (appearance_d[1] << 8);
}
uint8_t adv_name_len = 0;
uint8_t *adv_name = esp_ble_resolve_adv_data(scan_rst->ble_adv, ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len);
if (adv_name == NULL) {
adv_name = esp_ble_resolve_adv_data(scan_rst->ble_adv, ESP_BLE_AD_TYPE_NAME_SHORT, &adv_name_len);
}
if (adv_name != NULL && adv_name_len) {
memcpy(name, adv_name, adv_name_len);
name[adv_name_len] = 0;
}
GAP_DBG_PRINTF("BLE: " ESP_BD_ADDR_STR ", ", ESP_BD_ADDR_HEX(scan_rst->bda));
GAP_DBG_PRINTF("RSSI: %d, ", scan_rst->rssi);
GAP_DBG_PRINTF("UUID: 0x%04x, ", uuid);
GAP_DBG_PRINTF("APPEARANCE: 0x%04x, ", appearance);
GAP_DBG_PRINTF("ADDR_TYPE: '%s'", ble_addr_type_str(scan_rst->ble_addr_type));
if (adv_name_len) {
GAP_DBG_PRINTF(", NAME: '%s'", name);
}
GAP_DBG_PRINTF("\n");
if (uuid == ESP_GATT_UUID_HID_SVC) {
add_ble_scan_result(scan_rst->bda, scan_rst->ble_addr_type, appearance, adv_name, adv_name_len, scan_rst->rssi);
}
}
static const char *ble_gap_evt_names[] = { "ADV_DATA_SET_COMPLETE", "SCAN_RSP_DATA_SET_COMPLETE", "SCAN_PARAM_SET_COMPLETE", "SCAN_RESULT", "ADV_DATA_RAW_SET_COMPLETE", "SCAN_RSP_DATA_RAW_SET_COMPLETE", "ADV_START_COMPLETE", "SCAN_START_COMPLETE", "AUTH_CMPL", "KEY", "SEC_REQ", "PASSKEY_NOTIF", "PASSKEY_REQ", "OOB_REQ", "LOCAL_IR", "LOCAL_ER", "NC_REQ", "ADV_STOP_COMPLETE", "SCAN_STOP_COMPLETE", "SET_STATIC_RAND_ADDR", "UPDATE_CONN_PARAMS", "SET_PKT_LENGTH_COMPLETE", "SET_LOCAL_PRIVACY_COMPLETE", "REMOVE_BOND_DEV_COMPLETE", "CLEAR_BOND_DEV_COMPLETE", "GET_BOND_DEV_COMPLETE", "READ_RSSI_COMPLETE", "UPDATE_WHITELIST_COMPLETE"};
const char *ble_gap_evt_str(uint8_t event)
{
if (event >= SIZEOF_ARRAY(ble_gap_evt_names)) {
return "UNKNOWN";
}
return ble_gap_evt_names[event];
}
static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
{
switch (event) {
/*
* SCAN
* */
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
ESP_LOGV("xbox_controller", "BLE GAP EVENT SCAN_PARAM_SET_COMPLETE");
SEND_BLE_CB();
break;
}
case ESP_GAP_BLE_SCAN_RESULT_EVT: {
esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
switch (scan_result->scan_rst.search_evt) {
case ESP_GAP_SEARCH_INQ_RES_EVT: {
handle_ble_device_result(&scan_result->scan_rst);
break;
}
case ESP_GAP_SEARCH_INQ_CMPL_EVT:
ESP_LOGV("xbox_controller", "BLE GAP EVENT SCAN DONE: %d", scan_result->scan_rst.num_resps);
SEND_BLE_CB();
break;
default:
break;
}
break;
}
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: {
ESP_LOGV("xbox_controller", "BLE GAP EVENT SCAN CANCELED");
break;
}
/*
* ADVERTISEMENT
* */
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
ESP_LOGV("xbox_controller", "BLE GAP ADV_DATA_SET_COMPLETE");
break;
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
ESP_LOGV("xbox_controller", "BLE GAP ADV_START_COMPLETE");
break;
/*
* AUTHENTICATION
* */
case ESP_GAP_BLE_AUTH_CMPL_EVT:
if (!param->ble_security.auth_cmpl.success) {
ESP_LOGE("xbox_controller", "BLE GAP AUTH ERROR: 0x%x", param->ble_security.auth_cmpl.fail_reason);
} else {
ESP_LOGI("xbox_controller", "BLE GAP AUTH SUCCESS");
}
break;
case ESP_GAP_BLE_KEY_EVT: //shows the ble key info share with peer device to the user.
ESP_LOGI("xbox_controller", "BLE GAP KEY type = %s", esp_ble_key_type_str(param->ble_security.ble_key.key_type));
break;
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: // ESP_IO_CAP_OUT
// The app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
// Show the passkey number to the user to input it in the peer device.
ESP_LOGI("xbox_controller", "BLE GAP PASSKEY_NOTIF passkey:%"PRIu32, param->ble_security.key_notif.passkey);
break;
case ESP_GAP_BLE_NC_REQ_EVT: // ESP_IO_CAP_IO
// The app will receive this event when the IO has DisplayYesNO capability and the peer device IO also has DisplayYesNo capability.
// show the passkey number to the user to confirm it with the number displayed by peer device.
ESP_LOGI("xbox_controller", "BLE GAP NC_REQ passkey:%"PRIu32, param->ble_security.key_notif.passkey);
esp_ble_confirm_reply(param->ble_security.key_notif.bd_addr, true);
break;
case ESP_GAP_BLE_PASSKEY_REQ_EVT: // ESP_IO_CAP_IN
// The app will receive this evt when the IO has Input capability and the peer device IO has Output capability.
// See the passkey number on the peer device and send it back.
ESP_LOGI("xbox_controller", "BLE GAP PASSKEY_REQ");
//esp_ble_passkey_reply(param->ble_security.ble_req.bd_addr, true, 1234);
break;
case ESP_GAP_BLE_SEC_REQ_EVT:
ESP_LOGI("xbox_controller", "BLE GAP SEC_REQ");
// Send the positive(true) security response to the peer device to accept the security request.
// If not accept the security request, should send the security response with negative(false) accept value.
esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, true);
break;
default:
ESP_LOGV("xbox_controller", "BLE GAP EVENT %s", ble_gap_evt_str(event));
break;
}
}
static esp_err_t init_ble_gap(void)
{
esp_err_t ret;
if ((ret = esp_ble_gap_register_callback(ble_gap_event_handler)) != ESP_OK) {
ESP_LOGE("xbox_controller", "esp_ble_gap_register_callback failed: %d", ret);
return ret;
}
return ret;
}
static esp_err_t init_low_level(uint8_t mode)
{
esp_err_t ret;
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
{
ret = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
if (ret) {
ESP_LOGE("xbox_controller", "esp_bt_controller_mem_release failed: %d", ret);
return ret;
}
}
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
ESP_LOGE("xbox_controller", "esp_bt_controller_init failed: %d", ret);
return ret;
}
ret = esp_bt_controller_enable(mode);
if (ret) {
ESP_LOGE("xbox_controller", "esp_bt_controller_enable failed: %d", ret);
return ret;
}
ret = esp_bluedroid_init();
if (ret) {
ESP_LOGE("xbox_controller", "esp_bluedroid_init failed: %d", ret);
return ret;
}
ret = esp_bluedroid_enable();
if (ret) {
ESP_LOGE("xbox_controller", "esp_bluedroid_enable failed: %d", ret);
return ret;
}
if (mode & ESP_BT_MODE_BLE) {
ret = init_ble_gap();
if (ret) {
return ret;
}
}
return ret;
}
esp_err_t esp_hid_gap_init(uint8_t mode)
{
esp_err_t ret;
if (!mode || mode > ESP_BT_MODE_BTDM) {
ESP_LOGE("xbox_controller", "Invalid mode given!");
return ESP_FAIL;
}
if (bt_hidh_cb_semaphore != NULL) {
ESP_LOGE("xbox_controller", "Already initialised");
return ESP_FAIL;
}
bt_hidh_cb_semaphore = xSemaphoreCreateBinary();
if (bt_hidh_cb_semaphore == NULL) {
ESP_LOGE("xbox_controller", "xSemaphoreCreateMutex failed!");
return ESP_FAIL;
}
ble_hidh_cb_semaphore = xSemaphoreCreateBinary();
if (ble_hidh_cb_semaphore == NULL) {
ESP_LOGE("xbox_controller", "xSemaphoreCreateMutex failed!");
vSemaphoreDelete(bt_hidh_cb_semaphore);
bt_hidh_cb_semaphore = NULL;
return ESP_FAIL;
}
ret = init_low_level(mode);
if (ret != ESP_OK) {
vSemaphoreDelete(bt_hidh_cb_semaphore);
bt_hidh_cb_semaphore = NULL;
vSemaphoreDelete(ble_hidh_cb_semaphore);
ble_hidh_cb_semaphore = NULL;
return ret;
}
return ESP_OK;
}
void init_controller(void)
{
esp_err_t ret;
ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_ERROR_CHECK(esp_hid_gap_init(HIDH_BLE_MODE));
ble_hidh_cb_semaphore = xSemaphoreCreateBinary();
ESP_ERROR_CHECK(esp_ble_gattc_register_callback(esp_hidh_gattc_event_handler));
esp_hidh_config_t cfg = {
.callback = controller_msg_callback,
.event_stack_size = 4096,
.callback_arg = NULL
};
ESP_ERROR_CHECK(esp_hidh_init(&cfg));
xTaskCreate(&hid_task, "hid_task", 6 * 1024, NULL, 2, NULL);
}

View File

@@ -0,0 +1,10 @@
dependencies:
idf:
source:
type: idf
version: 6.1.0
direct_dependencies:
- idf
manifest_hash: e44bf68eca6b7b264ddae08cd014cd3294c0473230381b6d6f88ed18ec879038
target: esp32s3
version: 3.0.0

View File

@@ -0,0 +1,3 @@
idf_component_register(SRCS "wacky_bully.c"
REQUIRES bt "drv8701" freertos xbox_controller
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,16 @@
## IDF Component Manager Manifest File
dependencies:
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true

View File

@@ -0,0 +1,55 @@
#include <stdio.h>
#include "drv8701.h"
#include "freertos/idf_additions.h"
#include "portmacro.h"
#include "soc/gpio_num.h"
#include "xbox_controller.h"
drv8701_task_config_t motor1 = {
.ph_pin = GPIO_NUM_13,
.en_pin = GPIO_NUM_14,
.pwm_group_num = 0,
};
drv8701_task_config_t motor2 = {
.ph_pin = GPIO_NUM_21,
.en_pin = GPIO_NUM_45,
.pwm_group_num = 0,
};
drv8701_task_config_t motor3 = {
.ph_pin = GPIO_NUM_9,
.en_pin = GPIO_NUM_10,
.pwm_group_num = 1,
};
drv8701_task_config_t motor4 = {
.ph_pin = GPIO_NUM_11,
.en_pin = GPIO_NUM_12,
.pwm_group_num = 1,
};
void app_main(void)
{
printf("Starting\n");
init_controller();
xTaskCreate(drv8701_task, "Motor1 Task", 2048, (void *)&motor1, 4, NULL);
xTaskCreate(drv8701_task, "Motor2 Task", 2048, (void *)&motor2, 4, NULL);
xTaskCreate(drv8701_task, "Motor3 Task", 2048, (void *)&motor3, 4, NULL);
xTaskCreate(drv8701_task, "Motor4 Task", 2048, (void *)&motor4, 4, NULL);
vTaskDelay(500 / portTICK_PERIOD_MS);
float motor1_vel = 0.0;
while(true) {
print_state();
motor1_vel = motor1_vel + 0.1;
if (motor1_vel > 1.0)
motor1_vel = -1.0;
printf("Motor1 velocity: %0.2f\n", motor1_vel);
set_motor_vel(&motor1, motor1_vel);
set_motor_vel(&motor2, motor1_vel);
set_motor_vel(&motor3, motor1_vel);
set_motor_vel(&motor4, motor1_vel);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff