├── .gitmodules ├── LICENSE ├── README.md ├── VolvoCan ├── .gitignore ├── .travis.yml ├── .vscode │ └── extensions.json ├── bin │ └── nanoatmega328 │ │ ├── firmware.elf │ │ └── firmware.hex ├── include │ ├── CarState.h │ ├── ParkingBuzzer.h │ ├── README │ ├── Radio.h │ ├── Setup.h │ ├── VolvoCan.h │ └── WheelButtons.h ├── lib │ └── README ├── platformio.ini ├── src │ └── main.cpp └── test │ └── README ├── doc ├── VolvoModules │ ├── ccm.txt │ ├── cem.txt │ ├── gearbox.txt │ ├── lsm.txt │ ├── rem.txt │ └── swm.txt ├── adapter.jpg ├── schematic.PNG └── schematic.pdf ├── misc └── VolvoCanAdapterKikad.zip └── volvo.code-workspace /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "VolvoCan/lib/arduino-tone"] 2 | path = VolvoCan/lib/arduino-tone 3 | url = https://github.com/olegel/arduino-tone-library 4 | [submodule "VolvoCan/lib/arduino-mcp4xxx"] 5 | path = VolvoCan/lib/arduino-mcp4xxx 6 | url = https://github.com/olegel/arduino-mcp4xxx 7 | [submodule "VolvoCan/lib/arduino-mcp2515"] 8 | path = VolvoCan/lib/arduino-mcp2515 9 | url = https://github.com/olegel/arduino-mcp2515 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Volvo low-speed CAN bus adapter 2 | 3 |
Some time ago I had installed the Android radio into my Volvo XC90 and had removed the all useless modules (phone, CD-changer, audio module, amplifier, navigation, antenna). 4 | I think the car lost weight :) 5 | I have got all nice android stuff, bluetooth connection to phone, video-in for the video recorder, sub-woofer out and etc. 6 | But I have lost the parking assistant(it works through Volvo audio system), steering wheel buttons. 7 |
So I have decided to make my own CAN bus adapter. 8 | 9 | ## Features: 10 | 11 | * All information is received by low-speed car CAN bus, adapter works in Listen Only mode 12 | * Audio and navigation steering wheel buttons are mapped to two digital rheostats (sit to first, and six to second). It's simulated resistive buttons for Android audio 13 | * Rear gear output (0/12v) 14 | * Low ambient light detector output (0/12v) 15 | * Ignition key position I/II output (relay) 16 | * Parking assistant buzzer simulation (I've used central speaker) 17 | * Parking assistant control button allows to enable/disable parking buzzer 18 | 19 | ## Hardware 20 | 21 | * Arduino Nano 22 | * MCP2515 based CAN bus adapter 23 | * MCP4231 double digital potentiometer 24 | * ULN2003A for digital outputs 25 | * 12v relay 26 | 27 | ## Schematic 28 | 29 | * [PDF file](doc/schematic.pdf) 30 | ![Schematic](doc/schematic.PNG) 31 | 32 | ## Software 33 | 34 |
Libraries: 35 | * [Tone] (https://github.com/daniel-centore/arduino-tone-library) 36 | * [MCP4231] (https://github.com/jmalloc/arduino-mcp4xxx) 37 | * [MCP2515] (https://github.com/autowp/arduino-mcp2515) Has some changes, see forked version 38 | 39 |
Forked libraries: 40 | * [Tone] (https://github.com/olegel/arduino-tone-library) 41 | * [MCP4231] (https://github.com/olegel/arduino-mcp4xxx) 42 | * [MCP2515] (https://github.com/olegel/arduino-mcp2515) 43 | 44 | ## Compilation 45 | I've used Visual Studio Code with Platformio extension. 46 | Clone code, update sub-modules. 47 | Open volvo.code-workspace file, build and upload. 48 | NOTE: each car has own CAN module Id! You should detect it youself. 49 | 50 | ## My module: 51 | ![Hardware](doc/adapter.jpg) 52 | 53 | ## More information 54 | * More information you can find in my blog (Russian) (https://olegel.blogspot.com/2019/01/can-volvo-xc90.html) -------------------------------------------------------------------------------- /VolvoCan/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .pioenvs 3 | .piolibdeps 4 | .vscode/.browse.c_cpp.db* 5 | .vscode/c_cpp_properties.json 6 | .vscode/launch.json 7 | -------------------------------------------------------------------------------- /VolvoCan/.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < https://docs.platformio.org/page/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < https://docs.platformio.org/page/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < https://docs.platformio.org/page/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choose one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # - platformio update 39 | # 40 | # script: 41 | # - platformio run 42 | 43 | 44 | # 45 | # Template #2: The project is intended to be used as a library with examples. 46 | # 47 | 48 | # language: python 49 | # python: 50 | # - "2.7" 51 | # 52 | # sudo: false 53 | # cache: 54 | # directories: 55 | # - "~/.platformio" 56 | # 57 | # env: 58 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 59 | # - PLATFORMIO_CI_SRC=examples/file.ino 60 | # - PLATFORMIO_CI_SRC=path/to/test/directory 61 | # 62 | # install: 63 | # - pip install -U platformio 64 | # - platformio update 65 | # 66 | # script: 67 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N 68 | -------------------------------------------------------------------------------- /VolvoCan/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } -------------------------------------------------------------------------------- /VolvoCan/bin/nanoatmega328/firmware.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegel/VolvoCan/b381ce4a0dfe5f1ade60ffb4c1883d6a7bd7b0e5/VolvoCan/bin/nanoatmega328/firmware.elf -------------------------------------------------------------------------------- /VolvoCan/bin/nanoatmega328/firmware.hex: -------------------------------------------------------------------------------- 1 | :100000000C945F000C9436020C940F020C94870041 2 | :100010000C9487000C9487000C9487000C94B50214 3 | :100020000C9487000C9487000C9487000C940403B4 4 | :100030000C9487000C9487000C945F030C94870049 5 | :100040000C94C5010C9487000C9483020C945D02FF 6 | :100050000C9487000C9487000C9487000C94870004 7 | :100060000C9487000C94870002010000000000241B 8 | :100070000027002A0000000000250028002B0004B3 9 | :10008000040404040404040202020202020303033F 10 | :100090000303030102040810204080010204081039 11 | :1000A00020010204081020000000080002010000E6 12 | :1000B000030407000000000000000000A90C112448 13 | :1000C0001FBECFEFD8E0DEBFCDBF11E0A0E0B1E0B2 14 | :1000D000EAEBFAE102C005900D92A83FB107D9F70B 15 | :1000E00022E0A8EFB1E001C01D92A83FB207E1F7FE 16 | :1000F00010E0CFE5D0E004C02197FE010E94500D32 17 | :10010000CE35D107C9F70E9421090C945B0D0C94E0 18 | :10011000000081E08093040108950895CF92DF925A 19 | :10012000EF92FF920F931F93CF93DF936C017A01AD 20 | :100130008B01C0E0D0E0CE15DF0581F0D8016D91D4 21 | :100140008D01D601ED91FC910190F081E02DC60169 22 | :100150000995892B11F02196EECF7E01C701DF9121 23 | :10016000CF911F910F91FF90EF90DF90CF90089566 24 | :10017000089580E090E00895FC01538D448D252F73 25 | :1001800030E0842F90E0821B930B541710F0CF9631 26 | :10019000089501970895FC01918D828D981761F063 27 | :1001A000828DDF01A80FB11D5D968C91928D9F5FAE 28 | :1001B0009F73928F90E008958FEF9FEF0895FC0159 29 | :1001C000918D828D981731F0828DE80FF11D858D0C 30 | :1001D00090E008958FEF9FEF0895FC01918D228D9F 31 | :1001E000892F90E0805C9F4F821B91098F73992724 32 | :1001F000089581E292E00E94ED0021E0892B09F44C 33 | :1002000020E0822F0895FC01848DDF01A80FB11D2D 34 | :10021000A35ABF4F2C91848D90E001968F7399273C 35 | :10022000848FA689B7892C93A089B1898C9183701A 36 | :1002300080648C93938D848D981306C00288F38913 37 | :10024000E02D80818F7D80830895EF92FF920F9340 38 | :100250001F93CF93DF93EC0181E0888F9B8D8C8D72 39 | :10026000981305C0E889F989808185FD26C0F62E9E 40 | :100270000B8D10E00F5F1F4F0F731127E02E8C8D39 41 | :10028000E8120CC00FB607FCFACFE889F989808123 42 | :1002900085FFF5CFCE010E940301F1CF8B8DFE01CA 43 | :1002A000E80FF11DE35AFF4FF0829FB7F8940B8FD0 44 | :1002B000EA89FB89808180620AC09FB7F894EE8941 45 | :1002C000FF896083E889F9898081837080648083F5 46 | :1002D0009FBF81E090E0DF91CF911F910F91FF9040 47 | :1002E000EF900895CF93DF93EC01888D8823C9F0B8 48 | :1002F000EA89FB89808185FD05C0A889B9898C912F 49 | :1003000086FD0FC00FB607FCF5CF808185FFF2CFC9 50 | :10031000A889B9898C9185FFEDCFCE010E94030198 51 | :10032000E7CFDF91CF91089580E090E0892B29F00D 52 | :100330000E94F90081110C94000008950E94560D4E 53 | :100340003FB7F8948091080290910902A0910A02A7 54 | :10035000B0910B0226B5A89B05C02F3F19F001965E 55 | :10036000A11DB11D3FBFBA2FA92F982F8827820F3B 56 | :10037000911DA11DB11DBC01CD0142E0660F771F8B 57 | :10038000881F991F4A95D1F708951F920F920FB6B3 58 | :100390000F9211242F933F938F939F93AF93BF930B 59 | :1003A0008091100290911102A0911202B09113025B 60 | :1003B0003091070223E0230F2D3720F40196A11D71 61 | :1003C000B11D05C026E8230F0296A11DB11D209383 62 | :1003D00007028093100290931102A0931202B0932F 63 | :1003E00013028091080290910902A0910A02B09133 64 | :1003F0000B020196A11DB11D809308029093090282 65 | :10040000A0930A02B0930B02BF91AF919F918F917D 66 | :100410003F912F910F900FBE0F901F9018951F9234 67 | :100420000F920FB60F9211242F933F934F935F9328 68 | :100430006F937F938F939F93AF93BF93EF93FF93AC 69 | :10044000E0910201F09103010995FF91EF91BF91B5 70 | :10045000AF919F918F917F916F915F914F913F915C 71 | :100460002F910F900FBE0F901F9018951F920F9213 72 | :100470000FB60F9211242F933F934F935F936F9377 73 | :100480007F938F939F93AF93BF93EF93FF93E091ED 74 | :100490000001F09101010995FF91EF91BF91AF919A 75 | :1004A0009F918F917F916F915F914F913F912F918C 76 | :1004B0000F900FBE0F901F9018951F920F920FB6BE 77 | :1004C0000F9211242F933F934F935F936F937F93DA 78 | :1004D0008F939F93AF93BF93EF93FF9381E292E04B 79 | :1004E0000E940301FF91EF91BF91AF919F918F9176 80 | :1004F0007F916F915F914F913F912F910F900FBE20 81 | :100500000F901F9018951F920F920FB60F92112403 82 | :100510002F938F939F93EF93FF93E0913102F0918C 83 | :1005200032028081E0913702F091380282FD12C0E0 84 | :10053000908180913A028F5F8F7320913B028217E6 85 | :1005400051F0E0913A02F0E0EF5DFD4F958F80931E 86 | :100550003A0201C08081FF91EF919F918F912F917D 87 | :100560000F900FBE0F901F9018951F920F920FB60D 88 | :100570000F9211242F933F938F939F93AF93BF9329 89 | :10058000EF93FF938091150290911602A0911702AC 90 | :10059000B09118020097A105B10591F03091F901D1 91 | :1005A000E091FA01F091FB012081232720831816A6 92 | :1005B00019061A061B069CF40197A109B1090FC080 93 | :1005C000209170002D7F209370002091F901E0911F 94 | :1005D000FA01F091FB013081209523232083809341 95 | :1005E000150290931602A0931702B0931802FF9180 96 | :1005F000EF91BF91AF919F918F913F912F910F906C 97 | :100600000FBE0F901F9018951F920F920FB60F926A 98 | :1006100011248F939F93AF93BF93EF93FF93809198 99 | :10062000190290911A02A0911B02B0911C02892B11 100 | :100630008A2B8B2B51F19091FC01E091FD01F091FF 101 | :10064000FE018081892780838091190290911A028E 102 | :10065000A0911B02B0911C02181619061A061B065F 103 | :100660001CF58091190290911A02A0911B02B09181 104 | :100670001C020197A109B1098093190290931A02F3 105 | :10068000A0931B02B0931C020FC080916F008D7F5E 106 | :1006900080936F008091FC01E091FD01F091FE01DB 107 | :1006A0009081809589238083FF91EF91BF91AF91D5 108 | :1006B0009F918F910F900FBE0F901F9018951F92D2 109 | :1006C0000F920FB60F9211248F939F93AF93BF9306 110 | :1006D000EF93FF9380911D0290911E02A0911F0243 111 | :1006E000B0912002892B8A2B8B2B51F19091FF0125 112 | :1006F000E0910002F091010280818927808380913E 113 | :100700001D0290911E02A0911F02B09120021816A6 114 | :1007100019061A061B061CF580911D0290911E02F7 115 | :10072000A0911F02B09120020197A109B109809305 116 | :100730001D0290931E02A0931F02B09320020FC0CF 117 | :1007400080916E008D7F80936E008091FF01E0911B 118 | :100750000002F09101029081809589238083FF91AE 119 | :10076000EF91BF91AF919F918F910F900FBE0F901E 120 | :100770001F901895FC01258136812150310936835F 121 | :100780002583232B21F461E080810C949906089540 122 | :10079000FC01258136812F5F3F4F36832583213031 123 | :1007A000310581F48CB58F7D8CBD8CB5837F8CBD7C 124 | :1007B0008CB583608CBD8DB58E7F8DBD60E08081F2 125 | :1007C0000C949906089561E0FC0180810C949906CF 126 | :1007D0008EBD00000DB407FEFDCF8EB50895AF921B 127 | :1007E000BF92CF92DF92EF92FF920F931F93CF931E 128 | :1007F000DF938C01C62FB42E0E94C803F8018181BB 129 | :100800009281019711F4C295C07FC8010E94C8036C 130 | :100810008FE40E94E803D82FF82FF270AF2E81FFEB 131 | :1008200008C08FEF0E94E803D170DD2EC12C760145 132 | :10083000E82AC8010E94BA03AA2081F0BB2011F067 133 | :10084000CE2902C0C095CE214C2F50E0516064E00B 134 | :1008500070E0C8010E941605C82F01C0C0E0C801A1 135 | :100860000E94BA038C2FDF91CF911F910F91FF90BF 136 | :10087000EF90DF90CF90BF90AF900895CF93CFB718 137 | :10088000F8948091F801811127C0E9E8F0E08491A3 138 | :10089000EDE9F0E09491E82FF0E0EE0FFF1FE5594D 139 | :1008A000FF4FA591B491EC91E92321F461E08AE036 140 | :1008B0000E94990661E08AE00E9446088CB580613A 141 | :1008C0008CBD8CB580648CBD61E08DE00E944608D3 142 | :1008D00061E08BE00E9446088091F8018F5F809371 143 | :1008E000F801CFBFCF910895009769F0FC01019006 144 | :1008F0000020E9F73197AF01481B590BBC0181E299 145 | :1009000092E00C948E0080E090E008950C947404C2 146 | :100910008F929F92AF92BF920F931F93CF93DF93CB 147 | :10092000CDB7DEB7A1970FB6F894DEBF0FBECDBF2F 148 | :1009300019A2423008F44AE08E010F5D1F4F842E49 149 | :10094000912CA12CB12CA50194010E941F0DE62F22 150 | :10095000B901CA0101501109EA3014F4E05D01C087 151 | :10096000E95CD801EC93232B242B252B61F7C801DC 152 | :100970000E947404A1960FB6F894DEBF0FBECDBFDF 153 | :10098000DF91CF911F910F91BF90AF909F908F906B 154 | :100990000895CF92DF92EF92FF92CF93DF936C0195 155 | :1009A000990FEE08FF08F7FE13C06DE281E292E0B6 156 | :1009B0000E942501EC0166277727CB016C197D0980 157 | :1009C0008E099F094AE00E948804C80FD91F06C0FB 158 | :1009D0004AE0C701B6010E948804EC0188E991E071 159 | :1009E0000E9474048C0F9D1FDF91CF91FF90EF90B8 160 | :1009F000DF90CF900895CF93DF93AB01682F41151F 161 | :100A0000510529F481E292E00E94250105C070E0C1 162 | :100A100080E090E00E948804EC0188E991E00E9467 163 | :100A200074048C0F9D1FDF91CF910895EF92FF9278 164 | :100A30000F931F93CF93DF937C018B01EA010E94F8 165 | :100A4000C80384E0000F111F8A95E1F70260D1709E 166 | :100A5000D02B8D2F0E94E80311E081FD02C010E031 167 | :100A600003C08C2F0E94E803C7010E94BA03812FA4 168 | :100A7000DF91CF911F910F91FF90EF900895CF9349 169 | :100A8000DF930E947404EC0188E991E00E947404F1 170 | :100A90008C0F9D1FDF91CF910895CF93DF938091AD 171 | :100AA000C8029091C902A091CA02B091CB02BF7155 172 | :100AB0008093C8029093C902A093CA02B093CB025C 173 | :100AC000823424E0920720EEA207B10509F458C051 174 | :100AD00070F4863620E49207A207B10509F4CDC070 175 | :100AE000883F9F47A146B10509F49DC0EFC08E32F3 176 | :100AF00022E5920720EEA20721E0B20709F479C0AF 177 | :100B000088329043A105B34009F0E0C08091D20241 178 | :100B1000877090E0209105013091060182179307BC 179 | :100B200071F090930601809305018BE991E00E949A 180 | :100B3000860480910501909106010E94C90480916C 181 | :100B4000D202807790E025E0959587952A95E1F788 182 | :100B500020910701309108018217930709F4B6C06C 183 | :100B6000909308018093070181EA91E00E94860436 184 | :100B70008091070190910801DF91CF910C94C904F5 185 | :100B80008091D202C1E0982F907486FFC0E08091DE 186 | :100B90000A01C817D9F0C0930A01992331F0909146 187 | :100BA000090181E089278093090188EA91E00E9488 188 | :100BB00086048C2F90E00E94C90484EB91E00E948F 189 | :100BC00086048091090190E00E94C9048091D302BB 190 | :100BD0008F7090910B01891709F478C080930B01F5 191 | :100BE0008EEB91E00E9486046AE070E080910B0138 192 | :100BF00016C09091D3029695969596958FE1891B94 193 | :100C000090910E01891709F461C080930E018AEC5E 194 | :100C100091E00E9486046AE070E080910E01DF910D 195 | :100C2000CF910C94FB04C091D602D0E085E0D5951D 196 | :100C3000C7958A95E1F781E0C2FF80E090910C01B1 197 | :100C4000891759F080930C0184ED91E00E9486048D 198 | :100C500080910C0190E00E94C904C37080910D0145 199 | :100C6000C817A1F1C0930D0189ED91E00E9486049F 200 | :100C70006AE070E080910D01D2CF2091D6022F73EF 201 | :100C80008091D70290E0809590958F739927922B51 202 | :100C900020910F013091100182179307B9F09093C2 203 | :100CA000100180930F0182EE91E00E948604609112 204 | :100CB0000F017091100180E090E040E10E948804F3 205 | :100CC00088E991E0DF91CF910C947404DF91CF918A 206 | :100CD0000895CF93DF938BEE91E00E948604C8EED7 207 | :100CE000D2E06D8570E080E090E04AE00E948804E8 208 | :100CF0002D8530E0A0EDB7E00E94410D2FE130E0FE 209 | :100D000040E050E00E941F0D29873A874B875C879F 210 | :100D100082EF91E00E94860469857A858B859C85A7 211 | :100D20004AE00E94880488E991E0DF91CF910C9419 212 | :100D3000740490E0FC01E955FF4F2491FC01ED564D 213 | :100D4000FF4F3491FC01E158FF4FE491EE2309F489 214 | :100D50003CC0222339F1233091F038F42130A9F03E 215 | :100D6000223001F584B58F7D12C0273091F02830F4 216 | :100D7000A1F02430B9F4809180008F7D03C0809170 217 | :100D800080008F77809380000DC084B58F7784BDFD 218 | :100D900009C08091B0008F7703C08091B0008F7D33 219 | :100DA0008093B000F0E0EE0FFF1FEB58FF4FA591CE 220 | :100DB000B4919FB7F894611104C08C913095382399 221 | :100DC00002C0EC913E2B3C939FBF089580E58CBD03 222 | :100DD00081E08DBD60E08091C0020C949906CF93B4 223 | :100DE000C82F0E94E60683E00E94E8038C2F0E9431 224 | :100DF000E80380E00E94E803C82F80EC92E00E94A4 225 | :100E0000E3038C2FCF9108951F93CF93DF93182F77 226 | :100E1000D62FC42F0E94E60685E00E94E803812FAA 227 | :100E20000E94E8038D2F0E94E8038C2F0E94E803A4 228 | :100E300080EC92E0DF91CF911F910C94E303CF926D 229 | :100E4000DF92EF92FF92CF93C82F482F60EE8FE092 230 | :100E50000E9404078FB7F894C0901002D09011023E 231 | :100E6000E0901202F09013028FBF8AE0C80ED11CEE 232 | :100E7000E11CF11C2FB7F89480911002909111029F 233 | :100E8000A0911202B09113022FBF8C159D05AE05E3 234 | :100E9000BF0540F48EE00E94EF06807EC813EACFC3 235 | :100EA00091E001C090E081E0892790E0CF91FF9030 236 | :100EB000EF90DF90CF900895CF93DF93D82FC62F78 237 | :100EC0000E94E60682E00E94E8038D2F0E94E8035C 238 | :100ED0008C2F0E94E80380EC92E0DF91CF910C947C 239 | :100EE000E3030F931F93CF93DF93C82F8B010E94CF 240 | :100EF000E60682E00E94E8038C2F0E94E803E801E6 241 | :100F0000025F1F4F89910E94E803C017D107D1F7F4 242 | :100F100080EC92E0DF91CF911F910F910C94E3034D 243 | :100F2000FF920F931F93CF93DF93C82FF62E072FB7 244 | :100F3000142F0E94E60683E00E94E8038C2F0E9493 245 | :100F4000E803CF2DD02FCE01810F911D8C01C0174A 246 | :100F5000D10729F080E00E94E8038993F8CF80EC64 247 | :100F600092E0DF91CF911F910F91FF900C94E303DA 248 | :100F7000BF92CF92DF92EF92FF920F931F93CF9386 249 | :100F8000DF9300D000D01F92CDB7DEB78C01000FE9 250 | :100F9000111F000F111FF801E95EFE4F45E0BE0171 251 | :100FA0006F5F7F4F81810E9490078A819981C82E4F 252 | :100FB000D12C55E0D594C7945A95E1F728E0929F3B 253 | :100FC000C00CD11C11240D2C000CEE08FF0883FF6F 254 | :100FD00020C092E0CC0CDD1CEE1CFF1C9A95D1F7D2 255 | :100FE0008370C80ED11CE11CF11CFE2CED2CDC2CF6 256 | :100FF000CC248B81C80ED11CE11CF11CFE2CED2CE5 257 | :10100000DC2CCC248C81C80ED11CE11CF11C689412 258 | :10101000F7F88D818F70B82E88E08B1530F1F801CC 259 | :10102000E95EFE4F80810E94EF0683FF02C0689454 260 | :10103000F6F8C092C802D092C902E092CA02F092B9 261 | :10104000CB02B092CC02095E1E4F4B2D60ED72E0D8 262 | :10105000F80182810E94900740E0F80163818CE2F0 263 | :101060000E94040780E090E002C081E090E00F90D1 264 | :101070000F900F900F900F90DF91CF911F910F91D4 265 | :10108000FF90EF90DF90CF90BF900895CF93DF93C4 266 | :1010900090E0FC01ED56FF4F2491FC01E158FF4F19 267 | :1010A0008491882361F190E0880F991FFC01E55934 268 | :1010B000FF4FC591D491FC01EB58FF4FA591B4911E 269 | :1010C000611109C09FB7F894888120958223888395 270 | :1010D000EC912E230BC0623061F49FB7F8948881A5 271 | :1010E000322F309583238883EC912E2B2C939FBF36 272 | :1010F00006C08FB7F894E8812E2B28838FBFDF912D 273 | :10110000CF91089561E08091E8020E9446088091A5 274 | :10111000E902882351F0823071F48091B100887F18 275 | :1011200083608093B1009CEF3EC085B5887F83606B 276 | :1011300085BD9DE725C08130F1F480918100887FD5 277 | :1011400081608093810080EA9FE190938900809381 278 | :10115000880085E991E0A0E0B0E0809319029093C7 279 | :101160001A02A0931B02B0931C0280916F00826050 280 | :1011700080936F00089590EA8230A9F0811126C013 281 | :1011800097BD85E991E0A0E0B0E080931D029093C7 282 | :101190001E02A0931F02B093200280916E00826015 283 | :1011A00080936E0008959093B30085E991E0A0E0EC 284 | :1011B000B0E08093150290931602A0931702B093AB 285 | :1011C00018028091700082608093700008958F9261 286 | :1011D0009F92AF92BF92CF92DF92EF92FF926B01FC 287 | :1011E0007C010E94A0014B015C01C114D104E10407 288 | :1011F000F104F1F00E94A001DC01CB0188199909EA 289 | :10120000AA09BB09883E9340A105B10570F321E00E 290 | :10121000C21AD108E108F10888EE880E83E0981E12 291 | :10122000A11CB11CC114D104E104F10419F7DDCFF4 292 | :10123000FF90EF90DF90CF90BF90AF909F908F90F6 293 | :101240000895CF93DF93CDB7DEB72E970FB6F894FE 294 | :10125000DEBF0FBECDBF789484B5826084BD84B5F7 295 | :10126000816084BD85B5826085BD85B5816085BDA1 296 | :1012700080916E00816080936E0010928100809159 297 | :1012800081008260809381008091810081608093E1 298 | :101290008100809180008160809380008091B10006 299 | :1012A00084608093B1008091B00081608093B00031 300 | :1012B00080917A00846080937A0080917A008260C5 301 | :1012C00080937A0080917A00816080937A00809187 302 | :1012D0007A00806880937A001092C100E091310218 303 | :1012E000F091320282E08083E0912D02F0912E0293 304 | :1012F0001082E0912F02F091300280E18083109201 305 | :101300003902E0913502F091360286E08083E09167 306 | :101310003302F0913402808180618083E091330256 307 | :10132000F0913402808188608083E0913302F091F3 308 | :101330003402808180688083E0913302F09134022E 309 | :1013400080818F7D808382E391E00E943F050E942F 310 | :101350003E0462E08091C1020E94460889E890E064 311 | :101360009093010180930001809169008C7F8260DD 312 | :1013700080936900E89A0E94E60680EC0E94E803E8 313 | :1013800080EC92E00E94E3036AE070E080E090E08D 314 | :101390000E94E7088E010F5F1F4F8EE0F801119247 315 | :1013A0008A95E9F7B80180E30E947107B80180E4EB 316 | :1013B0000E947107B80180E50E94710760E080E635 317 | :1013C0000E945C0760E080E70E945C0763EA8BE2B2 318 | :1013D0000E945C0744E064E680E60E94040740E067 319 | :1013E00060E680E70E94040780E80E941F07892BBF 320 | :1013F00029F088E391E00E943F0511C061E08AE294 321 | :101400000E945C0761EB89E20E945C0765E888E264 322 | :101410000E945C0780E60E941F07892B51F741E07C 323 | :1014200064E088ED92E00E94EF03882309F48CC207 324 | :1014300041E064E08FED92E00E94EF03882309F41D 325 | :1014400083C240E062E088ED92E00E94EF038823CF 326 | :1014500009F47AC240E062E08FED92E00E94EF036F 327 | :10146000882309F471C280910202833008F083C09E 328 | :1014700093E09093E802E82FF0E0E859FF4FE49101 329 | :10148000E093E9028F5F80930202E13009F44CC0DF 330 | :1014900050F1E23009F072C01092B0001092B10029 331 | :1014A0008091B00082608093B0008091B100816033 332 | :1014B0008093B1008091E80290E0FC01E158FF4F79 333 | :1014C000E491F0E0EE0FFF1FEB58FF4F25913491B0 334 | :1014D0003093FB012093FA01FC01ED56FF4FE4919C 335 | :1014E000E093F9014BC014BC15BC84B5826084BD87 336 | :1014F00085B5816085BD8091E80290E0FC01E158EE 337 | :10150000FF4FE491F0E0EE0FFF1FEB58FF4F2591E6 338 | :1015100034913093010220930002FC01ED56FF4FFD 339 | :10152000E491E093FF012AC01092800010928100A4 340 | :10153000809181008860809381008091810081602A 341 | :10154000809381008091E80290E0FC01E158FF4F18 342 | :10155000E491F0E0EE0FFF1FEB58FF4F259134911F 343 | :101560003093FE012093FD01FC01ED56FF4FE49105 344 | :10157000E093FC0103C08FEF8093E90261E085E016 345 | :101580000E94460861E084E00E94460861E086E02F 346 | :101590000E94460861E085E00E94990660E084E0D0 347 | :1015A0000E94990660E086E00E9499066AEF70E06A 348 | :1015B00080E090E00E94E70888E491E00E943F0507 349 | :1015C00032E0A32EB12C8FB7F894409010025090C7 350 | :1015D000110260901202709013028FBF809104017B 351 | :1015E000882309F443C0109204018CE20E94EF06A4 352 | :1015F000182F8823D9F185FF19C08DE20E94EF06CC 353 | :10160000082F40E060EC8DE20E94040740E060E2B9 354 | :101610008CE20E94040706FF09C08CE491E00E945E 355 | :10162000860460E170E0802F0E94FB0417FF09C070 356 | :1016300040E060E88CE20E94040787E591E00E94A8 357 | :101640003F0510FF08C080E090E00E94B807892B9A 358 | :1016500011F40E944D0511FFC8CF81E090E00E9477 359 | :10166000B807892B11F60E944D05BFCF10910E01CE 360 | :101670008091050190910601029719F4809109016A 361 | :1016800001C080E09091EC02882321F081E01F31BD 362 | :1016900008F080E08093EC020091F5021093F502CF 363 | :1016A000981721F1811122C01092EB021092EA02E8 364 | :1016B0008091E902813051F0823071F0811111C0C6 365 | :1016C00080916E008D7F80936E000BC080916F00C3 366 | :1016D0008D7F80936F0005C0809170008D7F809317 367 | :1016E000700060E08091E8020E9499068091EC020F 368 | :1016F000882309F451C08091EA029091EB0200978F 369 | :10170000A9F481E090E09093EB028093EA0240928A 370 | :10171000ED025092EE026092EF027092F002809120 371 | :10172000E90287FD39C00E94820836C04091ED026F 372 | :101730005091EE026091EF027091F002730162012C 373 | :10174000C41AD50AE60AF70A0197A9F4F9ECCF16EC 374 | :10175000D104E104F10400F10E946906B092EB02A9 375 | :10176000A092EA024092ED025092EE026092EF02E5 376 | :101770007092F00211C010130E9469068091F1026C 377 | :101780009091F202A091F302B091F4028C159D05A4 378 | :10179000AE05BF0508F4B5CFE0900F01F090100141 379 | :1017A0008091E6029091E7028E159F0509F46CC0C6 380 | :1017B000F092E702E092E602E114F10409F454C069 381 | :1017C00010E0E0FE4AC0E12FE770E63008F045C0C7 382 | :1017D000012F06950695069529F02FEDC22E22E0E1 383 | :1017E000D22E04C098EDC92E92E0D92EF0E0EF5E23 384 | :1017F000FE4F9080892D90E0F6014381548184173B 385 | :10180000950708F4AC01F60161817281C6010E945E 386 | :10181000160541E062E0C6010E94EF0381E691E017 387 | :101820000E948604602F70E080E090E04AE00E9411 388 | :10183000880488E691E00E948604692D70E080E0CB 389 | :1018400090E04AE00E94880480E791E00E948604CC 390 | :101850006AE070E0812F0E94FB04F694E7941F5F1A 391 | :10186000103109F0AECF10C040E062E088ED92E0A8 392 | :101870000E94EF0340E062E08FED92E00E94EF03F0 393 | :1018800089E791E00E943F0510910D0100910B0145 394 | :10189000209105013091060181E02230310509F0E7 395 | :1018A00080E090910402891759F08093040222305D 396 | :1018B000310511F460E001C061E085E00E94990605 397 | :1018C00081E00A3008F080E090910502891751F01C 398 | :1018D000809305020A3010F460E001C061E084E00A 399 | :1018E0000E9499068FEF810F91E0823008F090E01E 400 | :1018F00020910602921751F090930602823010F464 401 | :1019000061E001C060E086E00E94990680910302D8 402 | :10191000882361F0F9EC4F1651046104710430F032 403 | :101920001092100110920F011092030281E292E0D6 404 | :101930000E94ED00892B29F081E292E00E94CB0009 405 | :10194000F5CF0E9494013FCE84E891E00E943F05CC 406 | :101950008ACDFF920F931F93CF93DF93E1E2F2E0E2 407 | :101960001382128288EE93E0A0E0B0E08483958336 408 | :10197000A683B78384E291E09183808385EC90E035 409 | :101980009587848784EC90E09787868780EC90E049 410 | :10199000918B808B81EC90E0938B828B82EC90E03A 411 | :1019A000958B848B86EC90E0978B868B118E128EB4 412 | :1019B000138E148EE8EEF2E0138212821482C8EDC8 413 | :1019C000D2E087E0F82EF8821A82198200E810E04F 414 | :1019D0001C830B831E821D820E943E0461E088816D 415 | :1019E0000E94460861E088810E949906FF8281E09A 416 | :1019F00090E0998788871B870A871D861C860E942E 417 | :101A00003E0461E08F810E94460861E08F810E9460 418 | :101A100099061F861E860E943E04C0ECD2E08AE032 419 | :101A2000888361E00E944608CE010E94E30382E0C1 420 | :101A30008983DF91CF911F910F91FF900895A1E2CB 421 | :101A40001A2EAA1BBB1BFD010DC0AA1FBB1FEE1F38 422 | :101A5000FF1FA217B307E407F50720F0A21BB30B83 423 | :101A6000E40BF50B661F771F881F991F1A9469F7FF 424 | :101A700060957095809590959B01AC01BD01CF015B 425 | :101A80000895A29FB001B39FC001A39F700D811D57 426 | :101A90001124911DB29F700D811D1124911D089577 427 | :101AA000EE0FFF1F0590F491E02D099481E090E086 428 | :0A1AB000F8940C945B0DF894FFCF3E 429 | :101ABA008D008D00010000000001000000001F00E1 430 | :101ACA00000A283C50647F606166017071760200EA 431 | :101ADA000000000025018E00BC007201ED00CB0061 432 | :101AEA00DF00736574757000566F6C766F43616EB4 433 | :101AFA00206661696C656400656E640043616E20EE 434 | :101B0A004552524946200043616E204D4552524685 435 | :101B1A0000776970657220002076616C7565200017 436 | :101B2A0020627574746F6E20007769706572732015 437 | :101B3A006F666600576865656C427574746F6E737C 438 | :101B4A00206661696C6564000D0A00476561722050 439 | :101B5A0000476561723220005061726B427574747D 440 | :101B6A006F6E200020656E61626C656420004C69AE 441 | :101B7A006768744D65746572200044697374616E98 442 | :101B8A00636520004B657920004B657920706F737F 443 | :101B9A002000427574746F6E732000646973742038 444 | :081BAA003D002073696C3D0051 445 | :00000001FF 446 | -------------------------------------------------------------------------------- /VolvoCan/include/CarState.h: -------------------------------------------------------------------------------- 1 | #ifndef _CARSTATE_H_ 2 | #define _CARSTATE_H_ 3 | 4 | #include 5 | 6 | namespace GearBox 7 | { 8 | enum Enum 9 | { 10 | Unknown = 0, 11 | Parking = 1, 12 | Rear = 2, 13 | Neutral = 3, 14 | Drive = 4, 15 | DrivingRear = 7, 16 | DrivingNeutral = 0 17 | }; 18 | } 19 | 20 | struct CCarState 21 | { 22 | static const uint8_t MaxParkingDistance = 0x1F; 23 | 24 | GearBox::Enum _gear = GearBox::Unknown; 25 | GearBox::Enum _drivingGear = GearBox::Unknown; 26 | bool _parkingAssistance = true; 27 | bool _parkingButtonPressed = false; 28 | uint8_t _lightMeter = 0; 29 | bool _keyInLock = false; 30 | uint8_t _keyPosition = 0; 31 | 32 | uint8_t _parkingDistance = MaxParkingDistance; 33 | uint16_t _wheelButtons = 0; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /VolvoCan/include/ParkingBuzzer.h: -------------------------------------------------------------------------------- 1 | #ifndef _PARKINGBUZZER_H_ 2 | #define _PARKINGBUZZER_H_ 3 | 4 | #include "CarState.h" 5 | #include "Tone.h" 6 | 7 | class CParkingBuzzer 8 | { 9 | public: 10 | void Setup(uint8_t pin) 11 | { 12 | _tone.begin(pin); 13 | } 14 | 15 | void Process( const unsigned long &time, bool enabled, uint8_t distance ) 16 | { 17 | bool wasEnabled = _isEnabled; 18 | _isEnabled = enabled && distance < CCarState::MaxParkingDistance; 19 | bool isDistanceUpdated = _lastDistance != distance; 20 | _lastDistance = distance; 21 | 22 | if(wasEnabled != _isEnabled) 23 | { 24 | if(!_isEnabled) 25 | Stop(); 26 | } 27 | 28 | if(!_isEnabled) 29 | return; 30 | 31 | if(_mode == modeOff) 32 | { 33 | Beep(time); 34 | return; 35 | } 36 | 37 | unsigned long elapsed = time - _modeStartTime; 38 | if(_mode == modeBeep) 39 | { 40 | if(elapsed > BeepInterval) 41 | Silence(time); 42 | } 43 | else // silence 44 | { 45 | if(isDistanceUpdated) 46 | UpdateSilenceInterval(); 47 | if(elapsed > _silenceInterval) 48 | Beep(time); 49 | } 50 | } 51 | 52 | private: 53 | enum Mode { modeOff, modeBeep, modeSilence }; 54 | 55 | static const unsigned long MaxSilenceInterval = 2000; 56 | static const uint32_t BeepInterval = 200; 57 | 58 | Tone _tone; 59 | Mode _mode = modeOff; 60 | bool _isEnabled = false; 61 | unsigned long _modeStartTime; 62 | unsigned long _silenceInterval; 63 | uint8_t _lastDistance; 64 | 65 | 66 | void Beep( const unsigned long &time ) 67 | { 68 | _mode = modeBeep; 69 | _modeStartTime = time; 70 | _tone.play(NOTE_B5, BeepInterval + 5); 71 | } 72 | 73 | void Silence( const unsigned long &time ) 74 | { 75 | UpdateSilenceInterval(); 76 | _mode = modeSilence; 77 | _modeStartTime = time; 78 | } 79 | 80 | void UpdateSilenceInterval() 81 | { 82 | Serial.print("dist ="); 83 | Serial.print(_lastDistance); 84 | _silenceInterval = MaxSilenceInterval * _lastDistance / CCarState::MaxParkingDistance; 85 | Serial.print(" sil="); 86 | Serial.println(_silenceInterval); 87 | } 88 | 89 | void Stop() 90 | { 91 | _mode = modeOff; 92 | _tone.stop(); 93 | } 94 | 95 | }; 96 | 97 | 98 | #endif -------------------------------------------------------------------------------- /VolvoCan/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /VolvoCan/include/Radio.h: -------------------------------------------------------------------------------- 1 | #ifndef _RADIO_H_ 2 | #define _RADIO_H_ 3 | 4 | #include "Setup.h" 5 | 6 | class CRadio 7 | { 8 | public: 9 | void Setup() 10 | { 11 | pinMode(PIN::RadioRearGear, OUTPUT); 12 | pinMode(PIN::RadioIllum, OUTPUT); 13 | pinMode(PIN::KeyPos2, OUTPUT); 14 | digitalWrite(PIN::RadioRearGear, HIGH); 15 | digitalWrite(PIN::RadioIllum, LOW); 16 | digitalWrite(PIN::KeyPos2, LOW); 17 | } 18 | 19 | void Process( bool rearGear, uint8_t lightMeter, uint8_t keyPos ) 20 | { 21 | if(_rearGear != rearGear) 22 | { 23 | _rearGear = rearGear; 24 | if(_rearGear) 25 | digitalWrite(PIN::RadioRearGear, LOW); 26 | else 27 | digitalWrite(PIN::RadioRearGear, HIGH); 28 | } 29 | 30 | bool illum = lightMeter < 0xA; 31 | 32 | if(illum != _illum) 33 | { 34 | _illum = illum; 35 | if(_illum) 36 | digitalWrite(PIN::RadioIllum, LOW); 37 | else 38 | digitalWrite(PIN::RadioIllum, HIGH); 39 | } 40 | 41 | bool keyOn = keyPos == 1 || keyPos == 2; 42 | if(keyOn != _keyOn) 43 | { 44 | _keyOn = keyOn; 45 | if(_keyOn) 46 | digitalWrite(PIN::KeyPos2, HIGH); 47 | else 48 | digitalWrite(PIN::KeyPos2, LOW); 49 | } 50 | } 51 | 52 | private: 53 | bool _rearGear = false; 54 | bool _illum = false; 55 | bool _keyOn = false; 56 | }; 57 | 58 | #endif -------------------------------------------------------------------------------- /VolvoCan/include/Setup.h: -------------------------------------------------------------------------------- 1 | #ifndef _SETUP_H_ 2 | #define _SETUP_H_ 3 | 4 | 5 | #include 6 | 7 | namespace PIN 8 | { 9 | enum Enum { Buzzer = 3, PotSpiCs = 7, CanSpiCs = 10, CanInterrupt = 2, RadioRearGear = 5, RadioIllum = 4, KeyPos2 = 6 }; 10 | } 11 | 12 | #endif -------------------------------------------------------------------------------- /VolvoCan/include/VolvoCan.h: -------------------------------------------------------------------------------- 1 | #ifndef _VOLVOCAN_H_ 2 | #define _VOLVOCAN_H_ 3 | 4 | #include "mcp2515.h" 5 | #include "CarState.h" 6 | 7 | class CVolvoCan 8 | { 9 | public: 10 | CVolvoCan(uint8_t pinSpiCs, uint8_t pinInterrupt) : _mcp2515( pinSpiCs ), _pinInterrupt(pinInterrupt) 11 | { 12 | } 13 | 14 | static void OnInterrupt() 15 | { 16 | _onInterrupt = true; 17 | } 18 | 19 | bool Setup() 20 | { 21 | pinMode(_pinInterrupt, INPUT_PULLUP); 22 | attachInterrupt(digitalPinToInterrupt(2), OnInterrupt, FALLING ); 23 | 24 | if ( MCP2515::ERROR_OK != _mcp2515.reset() ) 25 | return false; 26 | if ( MCP2515::ERROR_OK != _mcp2515.setBitrate( CAN_125KBPS, MCP_8MHZ ) ) 27 | return false; 28 | if ( MCP2515::ERROR_OK != _mcp2515.setListenOnlyMode() ) 29 | return false; 30 | 31 | return true; 32 | } 33 | 34 | void Process(const unsigned long &time, CCarState &carState) 35 | { 36 | if(!_onInterrupt) 37 | return; 38 | _onInterrupt = false; 39 | //Serial.println("Interrupt"); 40 | 41 | while(true) 42 | { 43 | uint8_t irq = _mcp2515.getInterrupts(); 44 | if(irq == 0) 45 | break; 46 | // Serial.print("irq "); 47 | // Serial.println(irq, HEX); 48 | 49 | if(irq & MCP2515::CANINTF_ERRIF) 50 | { 51 | uint8_t error = _mcp2515.getErrorFlags(); 52 | _mcp2515.clearRXnOVRFlags(); 53 | _mcp2515.clearERRIF(); 54 | if(error & MCP2515::EFLG_RX0OVR) // ignore EFLG_RX0OVR 55 | { 56 | Serial.print("Can ERRIF "); 57 | Serial.println(error, HEX); 58 | } 59 | } 60 | if(irq & MCP2515::CANINTF_MERRF) 61 | { 62 | _mcp2515.clearMERR(); 63 | Serial.println("Can MERRF"); 64 | } 65 | 66 | if (irq & MCP2515::CANINTF_RX0IF) 67 | { 68 | if (_mcp2515.readMessage(MCP2515::RXB0, &_canMsg) == MCP2515::ERROR_OK) 69 | ProcessMessage(_canMsg, carState); 70 | } 71 | 72 | if (irq & MCP2515::CANINTF_RX1IF) 73 | { 74 | if (_mcp2515.readMessage(MCP2515::RXB1, &_canMsg) == MCP2515::ERROR_OK) 75 | ProcessMessage(_canMsg, carState); 76 | } 77 | } 78 | } 79 | 80 | private: 81 | static const unsigned long GearBoxId = 0x3003028; 82 | static const unsigned long CcmId = 0xE00442; 83 | static const unsigned long RemId = 0x1E0522E; 84 | static const unsigned long CemId = 0x617FF8; 85 | static const unsigned long SwmId = 0x404066; 86 | 87 | void ProcessMessage(can_frame &msg, CCarState &carState) 88 | { 89 | msg.can_id &= CAN_EFF_MASK; 90 | 91 | //PrintMessage(msg); 92 | 93 | switch(msg.can_id) 94 | { 95 | case GearBoxId: 96 | { 97 | GearBox::Enum gear = (GearBox::Enum)(msg.data[2] & 0x7); 98 | if( carState._gear != gear ) 99 | { 100 | carState._gear = gear; 101 | Serial.print("Gear "); 102 | Serial.println(carState._gear); 103 | } 104 | gear = (GearBox::Enum)((msg.data[2] & 0x70) >> 5); 105 | if( carState._drivingGear != gear ) 106 | { 107 | carState._drivingGear = gear; 108 | Serial.print("Gear2 "); 109 | Serial.println(carState._drivingGear); 110 | } 111 | break; 112 | } 113 | case CcmId: 114 | { 115 | bool parkingButtonPressed = (msg.data[2] & 0x40) > 0; 116 | 117 | if(parkingButtonPressed != carState._parkingButtonPressed) 118 | { 119 | carState._parkingButtonPressed = parkingButtonPressed; 120 | if(parkingButtonPressed) 121 | carState._parkingAssistance = ! carState._parkingAssistance; 122 | 123 | Serial.print("ParkButton "); 124 | Serial.println(parkingButtonPressed); 125 | Serial.print(" enabled "); 126 | Serial.println(carState._parkingAssistance); 127 | } 128 | 129 | uint8_t light = msg.data[3] & 0xF; 130 | if( carState._lightMeter != light ) 131 | { 132 | carState._lightMeter = light; 133 | Serial.print("LightMeter "); 134 | Serial.println(carState._lightMeter); 135 | } 136 | break; 137 | } 138 | case RemId: 139 | { 140 | uint8_t distance = CCarState::MaxParkingDistance - (msg.data[3] >> 3); 141 | //uint8_t distance = msg.data[3] >> 3; 142 | if( carState._parkingDistance != distance ) 143 | { 144 | carState._parkingDistance = distance; 145 | Serial.print("Distance "); 146 | Serial.println(carState._parkingDistance); 147 | } 148 | break; 149 | } 150 | case CemId: 151 | { 152 | uint8_t keyPosition = msg.data[6] >> 5; 153 | bool key = (keyPosition & 0x4) > 0; 154 | if( carState._keyInLock != key ) 155 | { 156 | carState._keyInLock = key; 157 | Serial.print("Key "); 158 | Serial.println(carState._keyInLock); 159 | } 160 | keyPosition = keyPosition & 0x3; 161 | if( carState._keyPosition != keyPosition ) 162 | { 163 | carState._keyPosition = keyPosition; 164 | Serial.print("Key pos "); 165 | Serial.println(carState._keyPosition); 166 | } 167 | break; 168 | } 169 | case SwmId: 170 | { 171 | uint16_t buttons = msg.data[6] & 0x3F; 172 | buttons = (buttons<<8) | ((~msg.data[7]) & 0x3F); 173 | if( carState._wheelButtons != buttons ) 174 | { 175 | carState._wheelButtons = buttons; 176 | Serial.print("Buttons "); 177 | Serial.println(carState._wheelButtons, HEX); 178 | } 179 | break; 180 | } 181 | default: 182 | //PrintMessage(msg); 183 | break; 184 | } 185 | } 186 | 187 | void PrintMessage(can_frame &msg) 188 | { 189 | Serial.print(msg.can_id & CAN_EFF_MASK, HEX); // print ID 190 | Serial.print(" "); 191 | Serial.print(msg.can_dlc, HEX); // print DLC 192 | Serial.print(" "); 193 | 194 | for (int i = 0; i>= 1; 59 | } 60 | } 61 | else 62 | { 63 | _pot1.set_wiper_status(false); 64 | _pot2.set_wiper_status(false); 65 | Serial.println("wipers off"); 66 | } 67 | } 68 | 69 | private: 70 | icecave::arduino::MCP4XXX _pot1; 71 | icecave::arduino::MCP4XXX _pot2; 72 | 73 | uint16_t _lastWheelButtons = 0; 74 | }; 75 | 76 | #endif -------------------------------------------------------------------------------- /VolvoCan/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /VolvoCan/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:nanoatmega328] 12 | platform = atmelavr 13 | board = nanoatmega328 14 | framework = arduino 15 | monitor_speed = 115200 16 | 17 | -------------------------------------------------------------------------------- /VolvoCan/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Setup.h" 5 | #include "CarState.h" 6 | #include "VolvoCan.h" 7 | #include "WheelButtons.h" 8 | #include "ParkingBuzzer.h" 9 | #include "Radio.h" 10 | 11 | CCarState _carState; 12 | CParkingBuzzer _parkingBuzzer; 13 | CWheelButtons _wheelButtons( PIN::PotSpiCs ); 14 | CVolvoCan _volvoCan( PIN::CanSpiCs, PIN::CanInterrupt ); 15 | CRadio _radio; 16 | 17 | void setup() 18 | { 19 | Serial.begin(115200); 20 | Serial.println("setup"); 21 | 22 | SPI.begin(); 23 | 24 | if(!_volvoCan.Setup()) 25 | Serial.println("VolvoCan failed"); 26 | 27 | if( !_wheelButtons.Setup() ) 28 | Serial.println("WheelButtons failed"); 29 | 30 | _parkingBuzzer.Setup(PIN::Buzzer); 31 | 32 | _radio.Setup(); 33 | 34 | delay(250); 35 | Serial.println("end"); 36 | } 37 | 38 | void ProcessSerialData(const unsigned long &time); 39 | 40 | void loop() 41 | { 42 | auto time = millis(); 43 | 44 | _volvoCan.Process(time, _carState); 45 | _parkingBuzzer.Process( time, _carState._gear == GearBox::Rear && _carState._parkingAssistance, _carState._parkingDistance ); 46 | _wheelButtons.Process( time, _carState._wheelButtons ); 47 | _radio.Process(_carState._gear == GearBox::Rear, _carState._lightMeter, _carState._keyPosition); 48 | 49 | ProcessSerialData(time); 50 | } 51 | 52 | void ProcessSerialData(const unsigned long &time) 53 | { 54 | static bool wiperConnected = false; 55 | static unsigned long buttonTime = 0; 56 | static bool pod1 = false; 57 | 58 | 59 | if(wiperConnected && (time - buttonTime) > 200) 60 | { 61 | _carState._wheelButtons = 0; 62 | wiperConnected = false; 63 | } 64 | 65 | while(Serial.available()) 66 | { 67 | int byte = Serial.read(); 68 | continue; 69 | 70 | if(byte >= '1' && byte <= '6') 71 | { 72 | uint8_t b = byte - '1'; 73 | _carState._wheelButtons = 1 << b; 74 | if(!pod1) 75 | _carState._wheelButtons <<= 8; 76 | 77 | wiperConnected = true; 78 | buttonTime = time; 79 | 80 | Serial.print("button "); 81 | Serial.println(_carState._wheelButtons, HEX); 82 | continue; 83 | } 84 | 85 | switch(byte) 86 | { 87 | case 'p': 88 | Serial.println("parking"); 89 | _carState._gear = GearBox::Parking; 90 | break; 91 | case 'P': 92 | Serial.println("parking button"); 93 | _carState._parkingAssistance = !_carState._parkingAssistance; 94 | break; 95 | case 'r': 96 | Serial.println("rear"); 97 | _carState._gear = GearBox::Rear; 98 | break; 99 | case '[': 100 | Serial.print("p- "); 101 | if(_carState._parkingDistance > 0) 102 | _carState._parkingDistance--; 103 | Serial.println(_carState._parkingDistance); 104 | break; 105 | case ']': 106 | Serial.print("p+ "); 107 | if(_carState._parkingDistance < CCarState::MaxParkingDistance) 108 | _carState._parkingDistance++; 109 | Serial.println(_carState._parkingDistance); 110 | break; 111 | case '0': 112 | pod1 = !pod1; 113 | Serial.println("pod "); 114 | Serial.println(pod1); 115 | break; 116 | case 'l': 117 | if(_carState._lightMeter > 0xA ) 118 | _carState._lightMeter = 1; 119 | else 120 | _carState._lightMeter = 0xF; 121 | Serial.println("light "); 122 | Serial.println(_carState._lightMeter); 123 | break; 124 | case 'k': 125 | if(_carState._keyPosition == 2 ) 126 | _carState._keyPosition = 0; 127 | else 128 | _carState._keyPosition = 2; 129 | Serial.println("key "); 130 | Serial.println(_carState._keyPosition); 131 | break; 132 | default: 133 | Serial.println(byte); 134 | break; 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /VolvoCan/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /doc/VolvoModules/ccm.txt: -------------------------------------------------------------------------------- 1 | 00e00442 ccm 2 | 3 | 00000000.00000000.0P000000.0000YYYY:00000000.00000000.xxxxxxxx.00000000 4 | 5 | inside temperature? : 6 | xxxxxxx - 7 | 4a ~8 degrees 8 | 63 ~18 9 | 10 | ambient light meter: 11 | yyyy 5 dark E cloud F sun 12 | 13 | park assistant button: 14 | P - park assist 1 - pressed, 0 - unpressed (not LED value!, just press) -------------------------------------------------------------------------------- /doc/VolvoModules/cem.txt: -------------------------------------------------------------------------------- 1 | cem 00617ff8 2 | 00000000.00000000.00000000.00000000:00000000.QQQ00000.abb00000.00000000 3 | 4 | Ignition key position: 5 | a - 1 - key present, 0 - no key 6 | bb - key position 0,1,2,3 7 | 8 | QQQ 9 | 2 - light off 10 | 4 - parking lights 11 | 8 - headlamps on 12 | -------------------------------------------------------------------------------- /doc/VolvoModules/gearbox.txt: -------------------------------------------------------------------------------- 1 | 03003028 2 | 3 | 00000000.00000000.0YYY0XXX.00000000:00000000.00000000.00000000.00000000 4 | 5 | XXX - selected gear 6 | P - 1 7 | R - 2 8 | N - 3 9 | D - 4 10 | 11 | YYY - actual gear 1-5, 7 rear, 0 - neutral -------------------------------------------------------------------------------- /doc/VolvoModules/lsm.txt: -------------------------------------------------------------------------------- 1 | 02605020 2 | 3 | ........ ........ ........ ........:XXXX.... ........ ........ ........ 4 | 5 | panel light brightness level: 6 | XXXX 0-A -------------------------------------------------------------------------------- /doc/VolvoModules/rem.txt: -------------------------------------------------------------------------------- 1 | 01e0522e 2 | 3 | 00000000.00000000.00010000.xxxxx000:00000000.10010010.00000000.00000000 4 | 5 | Parking assistans distance: 6 | x - 7 | 0 unable detect (0m or oo) 8 | 1 - max dist 9 | 11111 - min dist -------------------------------------------------------------------------------- /doc/VolvoModules/swm.txt: -------------------------------------------------------------------------------- 1 | swm 00404066 2 | wheel buttons: 3 | enter 4 | ........ ........ ........ ........:........ ........ ........ ...0.... 5 | exit 6 | ........ ........ ........ ........:........ ........ ........ ..0..... 7 | volume+ 8 | ........ ........ ........ ........:........ ........ ........ ....0... 9 | volume- 10 | ........ ........ ........ ........:........ ........ ........ .....0.. 11 | next 12 | ........ ........ ........ ........:........ ........ ........ ......0. 13 | prev 14 | ........ ........ ........ ........:........ ........ ........ .......0 15 | nav enter 16 | ........ ........ ........ ........:........ ........ ..1..... ........ 17 | nav back 18 | ........ ........ ........ ........:........ ........ ...1.... ........ 19 | nav up 20 | ........ ........ ........ ........:........ ........ ....1... ........ 21 | nav down 22 | ........ ........ ........ ........:........ ........ .....1.. ........ 23 | nav left 24 | ........ ........ ........ ........:........ ........ .......1 ........ 25 | nav right 26 | ........ ........ ........ ........:........ ........ ......1. ........ 27 | cruize 28 | ........ ........ ........ ........:........ .......1 ........ ........ 29 | cruise+ 30 | ........ ........ ........ ........:........ ......1. ........ ........ 31 | cruise- 32 | ........ ........ ........ ........:........ .....1.. ........ ........ 33 | cruise zero 34 | ........ ........ ........ ........:........ ...1.... ........ ........ 35 | cruise resume 36 | ........ ........ ........ ........:........ ....1... ........ ........ 37 | 38 | enter, exit, volume+/-, next, prev are inverted! 39 | 40 | swm2 0221300A 41 | wiper and flush light control -------------------------------------------------------------------------------- /doc/adapter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegel/VolvoCan/b381ce4a0dfe5f1ade60ffb4c1883d6a7bd7b0e5/doc/adapter.jpg -------------------------------------------------------------------------------- /doc/schematic.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegel/VolvoCan/b381ce4a0dfe5f1ade60ffb4c1883d6a7bd7b0e5/doc/schematic.PNG -------------------------------------------------------------------------------- /doc/schematic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegel/VolvoCan/b381ce4a0dfe5f1ade60ffb4c1883d6a7bd7b0e5/doc/schematic.pdf -------------------------------------------------------------------------------- /misc/VolvoCanAdapterKikad.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegel/VolvoCan/b381ce4a0dfe5f1ade60ffb4c1883d6a7bd7b0e5/misc/VolvoCanAdapterKikad.zip -------------------------------------------------------------------------------- /volvo.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "VolvoCan" 5 | } 6 | ], 7 | "settings": { 8 | "terminal.integrated.env.windows": {}, 9 | "platformio-ide.updateTerminalPathConfiguration": false, 10 | "platformio-ide.forceUploadAndMonitor": true 11 | } 12 | } --------------------------------------------------------------------------------