diff --git a/circuit/mkstepper/eagle.epf b/circuit/mkstepper/eagle.epf index b7746cf26b4f7763ac0627626eaeaad333b0513f..5984c9008ef22b223c9c5b90821511dba6670b2d 100644 --- a/circuit/mkstepper/eagle.epf +++ b/circuit/mkstepper/eagle.epf @@ -37,58 +37,12 @@ UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/rload.lbr" UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/sym.lbr" [Win_1] -Type="Library Editor" -Loc="0 0 1919 1039" -State=1 -Number=3 -File="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/sparkfun/SparkFun-Connectors.lbr" -View="-2.33078 -5.6861 6.58531 3.73563" -WireWidths=" 0.0762 0.1016 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524 0.127" -PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0" -PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6" -ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0" -ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35" -HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35" -TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778 1.27" -PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27" -PolygonIsolates=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0" -MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0" -DimensionWidths=" 0 0.127 0.254 0.1 0.26 0.13" -DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0" -DimensionExtLengths=" 1.27 2.54 1 2 3 0" -DimensionExtOffsets=" 1.27 2.54 1 2 3 0" -SmdSizes=" 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635 5 0.76" -WireBend=5 -WireBendSet=0 -WireCap=1 -MiterStyle=0 -PadShape=0 -ViaShape=1 -PolygonPour=0 -PolygonRank=0 -PolygonThermals=1 -PolygonOrphans=0 -TextRatio=8 -DimensionUnit=1 -DimensionPrecision=2 -DimensionShowUnit=0 -PinDirection=3 -PinFunction=0 -PinLength=2 -PinVisible=3 -SwapLevel=0 -ArcDirection=0 -AddLevel=2 -PadsSameType=0 -Layer=51 - -[Win_2] Type="Schematic Editor" -Loc="0 0 1919 1039" -State=1 +Loc="926 0 1910 1007" +State=2 Number=1 File="mkstepper.sch" -View="25.2163 35.6215 155.675 146.596" +View="69.3549 41.988 159.951 129.374" WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524" PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0" PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6" @@ -127,16 +81,16 @@ ArcDirection=0 AddLevel=2 PadsSameType=0 Layer=91 -Views=" 1: 25.2163 35.6215 155.675 146.596" +Views=" 1: 69.3549 41.988 159.951 129.374" Sheet="1" -[Win_3] +[Win_2] Type="Board Editor" Loc="0 0 1919 1016" State=1 Number=2 File="mkstepper.brd" -View="0.634931 11.1659 35.9723 37.4943" +View="10.3097 24.4002 22.1441 33.2175" WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524" PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0" PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6" @@ -176,7 +130,7 @@ AddLevel=2 PadsSameType=0 Layer=1 -[Win_4] +[Win_3] Type="Control Panel" Loc="0 0 1919 1016" State=1 @@ -187,4 +141,3 @@ Screen="3840 1080" Window="Win_1" Window="Win_2" Window="Win_3" -Window="Win_4" diff --git a/circuit/mkstepper/mkstepper.brd b/circuit/mkstepper/mkstepper.brd index 44b7ee31fccd0b307c1928b533f6d44ecffc101f..86826669b459e6349c1cdf4c8e13b66f6426f4f3 100644 --- a/circuit/mkstepper/mkstepper.brd +++ b/circuit/mkstepper/mkstepper.brd @@ -20,12 +20,12 @@ <layer number="24" name="bOrigins" color="15" fill="1" visible="yes" active="yes"/> <layer number="25" name="tNames" color="7" fill="1" visible="no" active="yes"/> <layer number="26" name="bNames" color="7" fill="1" visible="no" active="yes"/> -<layer number="27" name="tValues" color="7" fill="1" visible="no" active="yes"/> +<layer number="27" name="tValues" color="7" fill="1" visible="yes" active="yes"/> <layer number="28" name="bValues" color="7" fill="1" visible="no" active="yes"/> -<layer number="29" name="tStop" color="7" fill="3" visible="yes" active="yes"/> -<layer number="30" name="bStop" color="7" fill="6" visible="yes" active="yes"/> -<layer number="31" name="tCream" color="7" fill="4" visible="yes" active="yes"/> -<layer number="32" name="bCream" color="7" fill="5" visible="yes" active="yes"/> +<layer number="29" name="tStop" color="7" fill="3" visible="no" active="yes"/> +<layer number="30" name="bStop" color="7" fill="6" visible="no" active="yes"/> +<layer number="31" name="tCream" color="7" fill="4" visible="no" active="yes"/> +<layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/> <layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/> <layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/> <layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/> @@ -39,9 +39,9 @@ <layer number="43" name="vRestrict" color="2" fill="10" visible="no" active="yes"/> <layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/> <layer number="45" name="Holes" color="7" fill="1" visible="yes" active="yes"/> -<layer number="46" name="Milling" color="3" fill="1" visible="yes" active="yes"/> +<layer number="46" name="Milling" color="3" fill="1" visible="no" active="yes"/> <layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/> -<layer number="48" name="Document" color="7" fill="1" visible="no" active="yes"/> +<layer number="48" name="Document" color="7" fill="1" visible="yes" active="yes"/> <layer number="49" name="Reference" color="7" fill="1" visible="no" active="yes"/> <layer number="50" name="dxf" color="7" fill="1" visible="no" active="no"/> <layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/> @@ -1090,15 +1090,15 @@ design rules under a new name.</description> <attribute name="TYPE" value="" x="21.15" y="41.05" size="1.778" layer="27" rot="R180" display="off"/> <attribute name="VOLTAGE" value="" x="21.15" y="41.05" size="1.778" layer="27" rot="R180" display="off"/> </element> -<element name="R4" library="borkedlabs-passives" package="0805" value="3k3" x="18.75" y="47.7" rot="R90"> +<element name="R4" library="borkedlabs-passives" package="0805" value="150R" x="18.75" y="47.7" rot="R90"> <attribute name="PACKAGE" value="0805" x="18.75" y="47.7" size="1.778" layer="27" rot="R90" display="off"/> <attribute name="PRECISION" value="" x="18.75" y="47.7" size="1.778" layer="27" rot="R90" display="off"/> </element> -<element name="R5" library="borkedlabs-passives" package="0805" value="1k8" x="17.35" y="47.7" rot="R90"> +<element name="R5" library="borkedlabs-passives" package="0805" value="10R" x="17.35" y="47.7" rot="R90"> <attribute name="PACKAGE" value="0805" x="17.35" y="47.7" size="1.778" layer="27" rot="R90" display="off"/> <attribute name="PRECISION" value="" x="17.35" y="47.7" size="1.778" layer="27" rot="R90" display="off"/> </element> -<element name="R6" library="borkedlabs-passives" package="0805" value="3k3" x="15.95" y="47.7" rot="R90"> +<element name="R6" library="borkedlabs-passives" package="0805" value="100R" x="15.95" y="47.7" rot="R90"> <attribute name="PACKAGE" value="0805" x="15.95" y="47.7" size="1.778" layer="27" rot="R90" display="off"/> <attribute name="PRECISION" value="" x="15.95" y="47.7" size="1.778" layer="27" rot="R90" display="off"/> </element> @@ -1225,22 +1225,22 @@ design rules under a new name.</description> <element name="U$10" library="lights" package="LED0805" value="LED0805" x="15.95" y="50.6" rot="R270"/> <element name="J8" library="connector" package="RJ12-6-SMT-TOPENTRY" value="RJ12-6-SMTTOP" x="19.75" y="8.75" rot="MR270"/> <element name="J10" library="connector" package="RJ12-6-SMT-TOPENTRY" value="RJ12-6-SMTTOP" x="40.5" y="8.75" rot="MR270"/> -<element name="R9" library="borkedlabs-passives" package="0805" value="3k3" x="11" y="17" rot="R270"> +<element name="R9" library="borkedlabs-passives" package="0805" value="150R" x="11" y="17" rot="R270"> <attribute name="PACKAGE" value="0805" x="16.9" y="17" size="0.6096" layer="27" rot="R270" display="off"/> <attribute name="PRECISION" value="" x="16.9" y="17" size="0.6096" layer="27" rot="R270" display="off"/> </element> <element name="U$11" library="lights" package="LED0805" value="LED0805" x="3.25" y="3.5" rot="R90"/> -<element name="R10" library="borkedlabs-passives" package="0805" value="3k3" x="9.5" y="17" rot="R270"> +<element name="R10" library="borkedlabs-passives" package="0805" value="10R" x="9.5" y="17" rot="R270"> <attribute name="PACKAGE" value="0805" x="15.4" y="17" size="0.6096" layer="27" rot="R270" display="off"/> <attribute name="PRECISION" value="" x="15.4" y="17" size="0.6096" layer="27" rot="R270" display="off"/> </element> <element name="U$12" library="lights" package="LED0805" value="LED0805" x="3.25" y="14" rot="R270"/> -<element name="R11" library="borkedlabs-passives" package="0805" value="3k3" x="12.5" y="17" rot="R270"> +<element name="R11" library="borkedlabs-passives" package="0805" value="150R" x="12.5" y="17" rot="R270"> <attribute name="PACKAGE" value="0805" x="24.2" y="17" size="0.6096" layer="27" rot="R270" display="off"/> <attribute name="PRECISION" value="" x="24.2" y="17" size="0.6096" layer="27" rot="R270" display="off"/> </element> <element name="U$13" library="lights" package="LED0805" value="LED0805" x="24" y="3.5" rot="R90"/> -<element name="R12" library="borkedlabs-passives" package="0805" value="3k3" x="14" y="17" rot="R270"> +<element name="R12" library="borkedlabs-passives" package="0805" value="10R" x="14" y="17" rot="R270"> <attribute name="PACKAGE" value="0805" x="14.9" y="20.6" size="0.6096" layer="27" rot="R270" display="off"/> <attribute name="PRECISION" value="" x="14.9" y="20.6" size="0.6096" layer="27" rot="R270" display="off"/> </element> diff --git a/circuit/mkstepper/mkstepper.sch b/circuit/mkstepper/mkstepper.sch index aeb0ce7a25c2eba07b150d26e448a8379aa55f93..e76a19a6653326a8a607c29b2ae5968bf85c452e 100644 --- a/circuit/mkstepper/mkstepper.sch +++ b/circuit/mkstepper/mkstepper.sch @@ -3481,9 +3481,9 @@ PTH and SMD connector options available.</p> <part name="+3V6" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="+3V3" device=""/> <part name="C14" library="borkedlabs-passives" deviceset="CAP" device="0603-CAP" value="0.1uF"/> <part name="GND13" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="GND" device=""/> -<part name="R4" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="3k3"/> -<part name="R5" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="1k8"/> -<part name="R6" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="3k3"/> +<part name="R4" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="150R"/> +<part name="R5" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="10R"/> +<part name="R6" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="100R"/> <part name="+3V7" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="+3V3" device=""/> <part name="GND14" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="GND" device=""/> <part name="GND15" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="GND" device=""/> @@ -3533,14 +3533,14 @@ PTH and SMD connector options available.</p> <part name="J10" library="connector" deviceset="RJ12-6-SMT" device="TOP" value="RJ12-6-SMTTOP"/> <part name="+3V1" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="+3V3" device=""/> <part name="GND10" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="GND" device=""/> -<part name="R9" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="3k3"/> +<part name="R9" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="150R"/> <part name="U$11" library="lights" deviceset="LED" device="0805"/> -<part name="R10" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="3k3"/> +<part name="R10" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="10R"/> <part name="U$12" library="lights" deviceset="LED" device="0805"/> <part name="+3V8" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="+3V3" device=""/> -<part name="R11" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="3k3"/> +<part name="R11" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="150R"/> <part name="U$13" library="lights" deviceset="LED" device="0805"/> -<part name="R12" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="3k3"/> +<part name="R12" library="borkedlabs-passives" deviceset="RESISTOR" device="0805-RES" value="10R"/> <part name="U$14" library="lights" deviceset="LED" device="0805"/> <part name="+3V9" library="supply1" library_urn="urn:adsk.eagle:library:371" deviceset="+3V3" device=""/> <part name="J5" library="power" deviceset="PWRPAD" device="M3"/> diff --git a/datasheet/AS5045B_Datasheet_EN_v2.pdf b/datasheet/AS5045B_Datasheet_EN_v2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..da240c1d2980aa0f487ae831919aaa52c03d1393 Binary files /dev/null and b/datasheet/AS5045B_Datasheet_EN_v2.pdf differ diff --git a/embedded/mkstepper-v011/.vs/mkstepper-v011/v14/.atsuo b/embedded/mkstepper-v011/.vs/mkstepper-v011/v14/.atsuo index 2a163195ec2d360f156b89f2e032ad41f585a747..55e60fb340b458c9138b47408fd1140916de7ca5 100644 Binary files a/embedded/mkstepper-v011/.vs/mkstepper-v011/v14/.atsuo and b/embedded/mkstepper-v011/.vs/mkstepper-v011/v14/.atsuo differ diff --git a/embedded/mkstepper-v011/mkstepper-v011/apahandler.c b/embedded/mkstepper-v011/mkstepper-v011/apahandler.c index ac9c4b80a0709ac7785d7f038f8ebd7f828d4309..ae796b24588979e22622fe25411d915f299abbc1 100644 --- a/embedded/mkstepper-v011/mkstepper-v011/apahandler.c +++ b/embedded/mkstepper-v011/mkstepper-v011/apahandler.c @@ -11,7 +11,7 @@ void apa_handle_packet(uint8_t *packet, uint8_t length){ // dirty debug reply - uart_sendchars_buffered(&up0, packet, length); + apa_return_packet(packet, length); // through packet int i = 0; int apa_handler_state = APA_HANDLER_OUTSIDE; @@ -20,7 +20,7 @@ void apa_handle_packet(uint8_t *packet, uint8_t length){ pin_clear(&stlr); switch (apa_handler_state){ case APA_HANDLER_OUTSIDE: - if (packet[i] == APA_END_ADDR_DELIMITER){ + if (packet[i] == APA_END_ROUTE_DELIMITER){ apa_handler_state = APA_HANDLER_INSIDE; } else { // @@ -84,4 +84,35 @@ void apa_handle_packet(uint8_t *packet, uint8_t length){ } // end y/n switch } pin_set(&stlr); +} + + +void apa_return_packet(uint8_t *packet, uint8_t length){ + uint8_t ackpack[length]; + ackpack[0] = length; + // find route header + int i = 2; + int stop = 0; + while(i < length){ + if(packet[i] == APA_END_ROUTE_DELIMITER){ + stop = i; + break; + } + i ++; + } + // do the business + if(!stop){ + // error if stop == 0 + } else { + // reverse the address header + for(int a = stop - 1, b = 1; a >= 1; a--, b++){ + ackpack[b] = packet[a]; + } + // fill the rest with same packet data + ackpack[stop] = APA_END_ROUTE_DELIMITER; + for(int u = stop; u < length; u ++){ + ackpack[u] = packet[u]; + } + uart_sendchars_buffered(ups[ackpack[1]], ackpack, length); + } } \ No newline at end of file diff --git a/embedded/mkstepper-v011/mkstepper-v011/apahandler.h b/embedded/mkstepper-v011/mkstepper-v011/apahandler.h index fbda15f6e56d2bda5ed75adbb3f0d5e82018105a..1f7c5dc67fe1b75a2f07b6d632c87a57df0689c9 100644 --- a/embedded/mkstepper-v011/mkstepper-v011/apahandler.h +++ b/embedded/mkstepper-v011/mkstepper-v011/apahandler.h @@ -20,5 +20,6 @@ #define DELIM_KEY_SPEED_STEPS 130 // is 32 bit int void apa_handle_packet(uint8_t *packet, uint8_t length); +void apa_return_packet(uint8_t *packet, uint8_t length); #endif /* APAHANDLER_H_ */ \ No newline at end of file diff --git a/embedded/mkstepper-v011/mkstepper-v011/apaport.c b/embedded/mkstepper-v011/mkstepper-v011/apaport.c index 40a6e260eb3eed24d27a50d88697561fb5ef632c..fc4701bf3a83fbfd7311fd29d16cbb58bf96354b 100644 --- a/embedded/mkstepper-v011/mkstepper-v011/apaport.c +++ b/embedded/mkstepper-v011/mkstepper-v011/apaport.c @@ -8,11 +8,9 @@ #include "apaport.h" #include "hardware.h" -void apaport_build(apaport_t *apap, uint8_t portnum, uartport_t *uart, uartport_t **uarts, uint8_t numports, pin_t *stlr, pin_t *stlb){ +void apaport_build(apaport_t *apap, uint8_t portnum, uartport_t *uart, pin_t *stlr, pin_t *stlb){ apap->uart = uart; - apap->uarts = uarts; apap->portnum = portnum; - apap->numports = numports; apap->stlr = stlr; apap->stlb = stlb; } @@ -32,7 +30,7 @@ void apaport_scan(apaport_t *apap, uint32_t maxpackets){ while(apap->packets_ready <= maxpackets){ // check that we have bytes to read out of the buffer if(rb_empty(apap->uart->rbrx)){ - //pin_set(apap->stlr); + pin_set(apap->stlr); break; } // pull bytes out of buffer into the packet structure @@ -56,35 +54,31 @@ void apaport_scan(apaport_t *apap, uint32_t maxpackets){ while(apap->packets_ready > 0){ // the particular packet index uint32_t p = (apap->packet_num + APAPORT_NUM_STATIC_PACKETS - apap->packets_ready) % APAPORT_NUM_STATIC_PACKETS; + // first we shift the old pointer out (p[1] is, at the moment, the port the last node tx'd on) + apapacket_shift_pointer(apap->packets[p], apap->portnum); + // now p[1] is next port // now to handle // [p][0] is length of packet - if(apap->packets[p][1] == APA_ADDR_POINTER){ + if(apap->packets[p][1] == APA_ROUTE_POINTER){ apa_handle_packet(apap->packets[p], apap->packets[p][0]); - } else if(apap->packets[p][1] == APA_ADDR_FLOOD){ + } else if(apap->packets[p][1] == APA_ROUTE_FLOOD){ // loop through bytes to find pointer and increment - apapacket_increment_pointer(apap->packets[p], apap->portnum); // now ship it out on all ports for(int i = 0; i < APAPORT_NUM_PORTS; i ++){ if(i == apap->portnum){ // don't flood back } else { - uart_sendchars_buffered(apap->uarts[i], apap->packets[p], apap->packets[p][0]); + uart_sendchars_buffered(ups[i], apap->packets[p], apap->packets[p][0]); } } } else { // packet is for a particular port, - // we pull that out of the packet now in case the pointer decrements into [1] - uint8_t port = apap->packets[p][1]; - // and check that we're sending it out on a port that exists - if (port >= APAPORT_NUM_PORTS){ - port = APAPORT_NUM_PORTS - 1; + if(apap->packets[p][1] > APAPORT_NUM_PORTS){ + // port does not exist, throw error + // pin_clear(&stlr); + } else { + uart_sendchars_buffered(ups[apap->packets[p][1]], apap->packets[p], apap->packets[p][0]); } - // now we can increment, safely moving pointer - apapacket_increment_pointer(apap->packets[p], apap->portnum); - // send on next port - // HERE: failing on send to other ports? - // double / triple check pointer to pointer - uart_sendchars_buffered(apap->uarts[port], apap->packets[p], apap->packets[p][0]); } // debug reply (at the moment, reply is handled in apa_handle_packet // uart_sendchars_buffered(apap->uart, apap->packets[p], apap->packets[p][0]); @@ -92,13 +86,29 @@ void apaport_scan(apaport_t *apap, uint32_t maxpackets){ } } -void apapacket_increment_pointer(uint8_t *packet, uint8_t portnum){ - for(int i = 2; i < packet[0]; i ++){ - // loop through bytes to find pointer and increment - if(packet[i] == APA_ADDR_POINTER){ - packet[i-1] = APA_ADDR_POINTER; // increment pointer forwards - packet[i] = portnum; // port received on is this one - break; // we can finish scan now, not looping senselessly through rest of packet +void apapacket_shift_pointer(uint8_t *packet, uint8_t portnum){ + int i = 2; + while(i < packet[0]){ // while less than length + if(packet[i] == APA_END_ROUTE_DELIMITER){ + // put our port in tail + packet[i-1] = portnum; + break; + } else { + // shift 'em down + packet[i-1] = packet[i]; } + i ++; } -} \ No newline at end of file +} + +// UNIT TESTS: +/* + flood packets + multiple receptions? handle in app? + packets no end addr bar delimiter, packets no pointer, general white noise + packets varying length + packets wrong length ? very hard to catch w/o hella state ... timeout? + packets no end addr delimiter? + packets to ports not existing + // next: write javascript terminal packet builder for unit tests! +*/ \ No newline at end of file diff --git a/embedded/mkstepper-v011/mkstepper-v011/apaport.h b/embedded/mkstepper-v011/mkstepper-v011/apaport.h index 248733a29a249885d243c300f01643aba913cd34..5ff68b400fb92c709e1a0b159bb64efadea64866 100644 --- a/embedded/mkstepper-v011/mkstepper-v011/apaport.h +++ b/embedded/mkstepper-v011/mkstepper-v011/apaport.h @@ -14,23 +14,21 @@ #include "pin.h" #define APAPORT_NUM_STATIC_PACKETS 4 -#define APAPORT_NUM_PORTS 5 +#define APAPORT_NUM_PORTS 2 #define APAPORT_OUTSIDE_PACKET 0 #define APAPORT_INSIDE_PACKET 1 -#define APA_END_ADDR_DELIMITER 255 -#define APA_ADDR_POINTER 254 -#define APA_ADDR_FLOOD 253 +#define APA_END_ROUTE_DELIMITER 255 +#define APA_ROUTE_POINTER 254 +#define APA_ROUTE_FLOOD 253 typedef struct{ uartport_t *uart; - uartport_t **uarts; // ptr to array of ptrs ? pin_t *stlr; pin_t *stlb; uint8_t portnum; // which port are we - uint8_t numports; // how many in the array we got uint32_t packet_num; uint32_t packet_position; @@ -39,12 +37,12 @@ typedef struct{ uint8_t packets[APAPORT_NUM_STATIC_PACKETS][256]; // packets for handling by app }apaport_t; -void apaport_build(apaport_t *apap, uint8_t portnum, uartport_t *uart, uartport_t **uarts, uint8_t numports, pin_t *stlr, pin_t *stlb); +void apaport_build(apaport_t *apap, uint8_t portnum, uartport_t *uart, pin_t *stlr, pin_t *stlb); void apaport_reset(apaport_t *apap); void apaport_scan(apaport_t *apap, uint32_t maxpackets); -void apapacket_increment_pointer(uint8_t *packet, uint8_t portnum); +void apapacket_shift_pointer(uint8_t *packet, uint8_t portnum); #endif /* APAPORT_H_ */ \ No newline at end of file diff --git a/embedded/mkstepper-v011/mkstepper-v011/main.c b/embedded/mkstepper-v011/mkstepper-v011/main.c index 25747e0b3df7ad7ff2e8d392cbebf22efd29f50b..ddf48c88b602719fc010a60f059e71f7b5967a9e 100644 --- a/embedded/mkstepper-v011/mkstepper-v011/main.c +++ b/embedded/mkstepper-v011/mkstepper-v011/main.c @@ -202,8 +202,10 @@ int main(void) ups[0] = &up0; ups[1] = &up1; - apaport_build(&apap0, 0, &up0, ups, 2, &up0_stlr, &up0_stlb); + apaport_build(&apap0, 0, &up0, &up0_stlr, &up0_stlb); apaport_reset(&apap0); + apaport_build(&apap1, 1, &up1, &up1_stlr, &up1_stlb); + apaport_reset(&apap1); // SPI // TMC_MOSI PA07 / SER0-3 @@ -254,13 +256,12 @@ int main(void) while (1) { apaport_scan(&apap0, 2); - lpcnt ++; - pin_toggle(&stlb); + apaport_scan(&apap1, 2); if(stepper.position_ticks_target == stepper.position_ticks){ stpcnt ++; - //stepper_targetposition_steps(&stepper, 1000 * (stpcnt %2)); - //stepper_targetspeed_steps(&stepper, 10000); + stepper_targetposition_steps(&stepper, 1000 * (stpcnt %2)); + stepper_targetspeed_steps(&stepper, 500); //stepper_goto(&stepper, 360 * (stpcnt % 2), 1200); } } @@ -268,10 +269,10 @@ int main(void) /* next steps (haha) -- plug into mods -- do float positions / conversions +- mkteriminal to write float values for keys ... +- do float positions / conversions / speeds / etc -> setup and doc values, types, what units are - make sure you can run -ve positions -- mostly, build the thing, put it together so that you can test +- this quickly so that you can mods compose further reading: - quadratic interpolation for position @ time w/ velocity @ endpoint step commands @@ -280,14 +281,10 @@ minors: - bring baud rate to 1M, at least! what the heck, FTDI! */ - - void SysTick_Handler(void){ // slow ticker - /* - lpcnt ++; pin_toggle(&stlb); - + /* if(stepper.position_ticks_target == stepper.position_ticks){ stpcnt ++; stepper_targetposition_steps(&stepper, 500 * (stpcnt %2)); diff --git a/embedded/mkstepper-v011/mkstepper-v011/mkstepper-v011.componentinfo.xml b/embedded/mkstepper-v011/mkstepper-v011/mkstepper-v011.componentinfo.xml index 4c98a9531734e0eb51472ba69b7e1fd2ceb317d2..517a711ec4290c071de610dc1471e5cb9e8d7912 100644 --- a/embedded/mkstepper-v011/mkstepper-v011/mkstepper-v011.componentinfo.xml +++ b/embedded/mkstepper-v011/mkstepper-v011/mkstepper-v011.componentinfo.xml @@ -91,7 +91,7 @@ <Attribute>template</Attribute> <Category>source</Category> <Condition>C Exe</Condition> - <FileContentHash>AkDwjED0tMpIjyJPo6itfg==</FileContentHash> + <FileContentHash>o0ncidL5gR0Z0YwWJ1YroQ==</FileContentHash> <FileVersion></FileVersion> <Name>templates/main.c</Name> <SelectString>Main file (.c)</SelectString> diff --git a/embedded/mkstepper-v011/mkstepper-v011/tmc26.c b/embedded/mkstepper-v011/mkstepper-v011/tmc26.c index ab250780528e5716fcf7c6062df6aa20aea727fd..23fc47cfa184ecc894e8c099e6dce15237429c91 100644 --- a/embedded/mkstepper-v011/mkstepper-v011/tmc26.c +++ b/embedded/mkstepper-v011/mkstepper-v011/tmc26.c @@ -41,7 +41,7 @@ void tmc26_init(tmc26_t *tmc){ uint32_t sgthresh_mask = 0b00000111111100000000; int32_t sgthres_val = 60; uint32_t cscale_mask = 0b00000000000000011111; - uint32_t cscale_val = 28; + uint32_t cscale_val = 9; uint32_t sgcsconf = 0b11010000000000000000 | ((sgthres_val << 8) & sgthresh_mask) | (cscale_val & cscale_mask); tmc26_write(tmc, sgcsconf);