├── .gitignore ├── LICENSE ├── README.md ├── examples ├── gpio │ ├── button.ino │ ├── joystick.ino │ ├── led.ino │ └── light.ino ├── gyro │ └── gyro.ino ├── lcd │ ├── display.ino │ ├── particles.ino │ └── text.ino ├── microphone │ ├── loudness.ino │ └── microphone.ino └── sound │ └── music.ino ├── lib └── cyberpi │ ├── library.properties │ ├── platform.local.txt │ └── src │ ├── cyberpi.cpp │ ├── cyberpi.h │ ├── gyro │ ├── gyro.c │ └── gyro.h │ ├── i2c │ ├── i2c.c │ └── i2c.h │ ├── io │ ├── aw9523b.c │ └── aw9523b.h │ ├── lcd │ ├── GT30L24A3W.h │ ├── lcd.c │ ├── lcd.h │ └── libGT30L24A3W.a │ ├── microphone │ ├── es8218e.c │ └── es8218e.h │ └── sound │ ├── synth.h │ └── tables.h ├── platformio.ini └── src └── main.ino /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | .pio 33 | .vscode 34 | CMakeLists.txt -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cyberpi library for arduino 2 | 3 | ### using Arduino IDE 4 | 1. Search and install esp32 from Arduino IDE's Boards Manager 5 | 6 | 2. copy "lib/cyberpi/platform.local.txt" to Arduino IDE's resources folder "/packages/esp32/hardware/esp32/1.0.4/" 7 | 8 | 3. copy "lib/cyberpi" to "Documents/Arduino/libraries" 9 | 10 | 4. "/examples" for reference only. 11 | 12 | ### using VSCode+PlatformIO 13 | 1. the git repo is a full project with pio 14 | 15 | 2. copy "lib/cyberpi" to your pio project 16 | 17 | 3. modify "upload_port" which is the connected cyberpi board in file "platform.ini" 18 | 19 | 4. "/examples" for reference only. 20 | 21 | 22 | ```c++ 23 | #include "cyberpi.h" 24 | 25 | CyberPi cyber; 26 | void setup() 27 | { 28 | cyber.begin(); 29 | } 30 | float j, f, k; 31 | 32 | void loop() 33 | { 34 | for(uint8_t t = 0; t < 5; t++) 35 | { 36 | uint8_t red = 32 * (1 + sin(t / 2.0 + j / 4.0) ); 37 | uint8_t green = 32 * (1 + sin(t / 1.0 + f / 9.0 + 2.1) ); 38 | uint8_t blue = 32 * (1 + sin(t / 3.0 + k / 14.0 + 4.2) ); 39 | cyber.set_rgb(t, red, green, blue); 40 | } 41 | j += random(1, 6) / 6.0; 42 | f += random(1, 6) / 6.0; 43 | k += random(1, 6) / 6.0; 44 | delay(10); 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /examples/gpio/button.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | void setup() 5 | { 6 | Serial.begin(115200); 7 | cyber.begin(); 8 | } 9 | 10 | void loop() 11 | { 12 | Serial.print("a:"); 13 | Serial.print(cyber.get_button_a()); 14 | Serial.print(" b:"); 15 | Serial.print(cyber.get_button_b()); 16 | Serial.print(" menu:"); 17 | Serial.println(cyber.get_button_menu()); 18 | delay(500); 19 | } -------------------------------------------------------------------------------- /examples/gpio/joystick.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | void setup() 5 | { 6 | Serial.begin(115200); 7 | cyber.begin(); 8 | } 9 | 10 | void loop() 11 | { 12 | Serial.print("x:"); 13 | Serial.print(cyber.get_joystick_x()); 14 | Serial.print(" y:"); 15 | Serial.print(cyber.get_joystick_y()); 16 | Serial.print(" pressed:"); 17 | Serial.println(cyber.get_joystick_pressed()); 18 | delay(500); 19 | } -------------------------------------------------------------------------------- /examples/gpio/led.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | void setup() 5 | { 6 | cyber.begin(); 7 | } 8 | float j, f, k; 9 | 10 | void loop() 11 | { 12 | for(uint8_t t = 0; t < 5; t++) 13 | { 14 | uint8_t red = 32 * (1 + sin(t / 2.0 + j / 4.0) ); 15 | uint8_t green = 32 * (1 + sin(t / 1.0 + f / 9.0 + 2.1) ); 16 | uint8_t blue = 32 * (1 + sin(t / 3.0 + k / 14.0 + 4.2) ); 17 | cyber.set_rgb(t, red, green, blue); 18 | } 19 | j += random(1, 6) / 6.0; 20 | f += random(1, 6) / 6.0; 21 | k += random(1, 6) / 6.0; 22 | delay(10); 23 | } -------------------------------------------------------------------------------- /examples/gpio/light.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | void setup() 5 | { 6 | Serial.begin(115200); 7 | cyber.begin(); 8 | } 9 | 10 | void loop() 11 | { 12 | Serial.print("light:"); 13 | Serial.println(cyber.get_light()); 14 | delay(500); 15 | } -------------------------------------------------------------------------------- /examples/gyro/gyro.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | void setup() 5 | { 6 | Serial.begin(115200); 7 | cyber.begin(); 8 | } 9 | 10 | void loop() 11 | { 12 | Serial.print("roll:"); 13 | Serial.print(cyber.get_roll()); 14 | Serial.print(" pitch:"); 15 | Serial.println(cyber.get_pitch()); 16 | delay(25); 17 | } -------------------------------------------------------------------------------- /examples/lcd/display.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | void setup() 5 | { 6 | Serial.begin(115200); 7 | cyber.begin(); 8 | for(int y=0;y<128;y++) 9 | { 10 | for(int x=0;x<128;x++) 11 | { 12 | int R = (128-x)*255/128; 13 | int G = x*255/128; 14 | int B = y*255/128; 15 | cyber.set_lcd_pixel(x,y,cyber.swap_color(cyber.color24_to_16((R<<16)+(G<<8)+B))); 16 | } 17 | } 18 | cyber.render_lcd(); 19 | } 20 | void loop() 21 | { 22 | cyber.set_lcd_light(false); 23 | delay(2000); 24 | cyber.set_lcd_light(true); 25 | delay(2000); 26 | } 27 | -------------------------------------------------------------------------------- /examples/lcd/particles.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | #define POINTS_COUNT 200 5 | Bitmap points[POINTS_COUNT]; 6 | float speed_x[POINTS_COUNT]; 7 | float speed_y[POINTS_COUNT]; 8 | void setup() { 9 | Serial.begin(112500); 10 | delay(1000); 11 | cyber.begin(); 12 | for(int i=0;i127||points[i].y>127) 34 | { 35 | points[i].x = 64; 36 | points[i].y = 64; 37 | } 38 | } 39 | cyber.render_lcd(); 40 | } -------------------------------------------------------------------------------- /examples/lcd/text.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | uint8_t samples[128]; 5 | int idx = 0; 6 | 7 | void setup() 8 | { 9 | Serial.begin(112500); 10 | delay(1000); 11 | cyber.begin(); 12 | int font_size = 16; 13 | Bitmap *bitmap1 = cyber.create_text(L"你好",0xffff,font_size); 14 | cyber.set_bitmap(4,4,bitmap1); 15 | Bitmap *bitmap2 = cyber.create_text(L"簡體",0xff00,font_size); 16 | cyber.set_bitmap(4,24,bitmap2); 17 | Bitmap *bitmap3 = cyber.create_text(L"hello",0x00ff,font_size); 18 | cyber.set_bitmap(4,44,bitmap3); 19 | Bitmap *bitmap4 = cyber.create_text(L"こんにちは",0x0ff0,font_size); 20 | cyber.set_bitmap(4,64,bitmap4); 21 | Bitmap *bitmap5 = cyber.create_text(L"여보세요",0x0f0f,font_size); 22 | cyber.set_bitmap(4,84,bitmap5); 23 | Bitmap *bitmap6 = cyber.create_text(L"Привет",0xf0f0,font_size); 24 | cyber.set_bitmap(4,104,bitmap6); 25 | cyber.render_lcd(); 26 | } 27 | 28 | void loop() 29 | { 30 | 31 | } -------------------------------------------------------------------------------- /examples/microphone/loudness.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | uint8_t samples[128]; 5 | int idx = 0; 6 | 7 | void setup() { 8 | Serial.begin(112500); 9 | delay(1000); 10 | cyber.begin(); 11 | } 12 | 13 | void loop() 14 | { 15 | if(idx<128) 16 | { 17 | samples[idx] = cyber.get_loudness()>>5; 18 | idx++; 19 | } 20 | else 21 | { 22 | for(int i=0;i<128;i++) 23 | { 24 | samples[i] = samples[i+1]; 25 | } 26 | samples[idx-1] = cyber.get_loudness()>>5; 27 | } 28 | cyber.clean_lcd(); 29 | for(int i=0;i<128;i++) 30 | { 31 | if(i==0) 32 | cyber.set_lcd_pixel(i,127-samples[i],0xffff); 33 | else 34 | { 35 | int min_level = MIN(samples[i-1],samples[i]); 36 | int max_level = MAX(samples[i-1],samples[i]); 37 | for(int j=min_level;j<=max_level;j++) 38 | { 39 | cyber.set_lcd_pixel(i,127-j,0xffff); 40 | } 41 | } 42 | 43 | } 44 | cyber.render_lcd(); 45 | delay(25); 46 | } -------------------------------------------------------------------------------- /examples/microphone/microphone.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | 5 | int lo[7] = {48,50,52,53,55,57,59}; 6 | int mo[7] = {60,62,64,65,67,69,71}; 7 | int ho[7] = {72,74,76,77,79,81,83}; 8 | void mic_recv(uint8_t* samples,int len) 9 | { 10 | cyber.clean_lcd(); 11 | for(int i=0;i-64&¤t<64) 15 | { 16 | cyber.set_lcd_pixel(i/8,current+64,0xffff); 17 | } 18 | } 19 | cyber.render_lcd(); 20 | } 21 | 22 | void setup() 23 | { 24 | Serial.begin(112500); 25 | delay(1000); 26 | cyber.begin(); 27 | cyber.on_microphone_data(mic_recv); 28 | for(int i=0;i<14;i++) 29 | { 30 | cyber.set_instrument(i); 31 | int idx = 0; 32 | while(idx<7) 33 | { 34 | cyber.set_pitch(0,lo[idx],100); 35 | delay(600); 36 | idx++; 37 | } 38 | idx = 0; 39 | while(idx<7) 40 | { 41 | cyber.set_pitch(0,mo[idx],100); 42 | delay(600); 43 | idx++; 44 | } 45 | idx = 0; 46 | while(idx<7) 47 | { 48 | cyber.set_pitch(0,ho[idx],100); 49 | delay(600); 50 | idx++; 51 | } 52 | } 53 | } 54 | 55 | void loop() 56 | { 57 | 58 | } 59 | -------------------------------------------------------------------------------- /examples/sound/music.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | 5 | int lo[7] = {48,50,52,53,55,57,59}; 6 | int mo[7] = {60,62,64,65,67,69,71}; 7 | int ho[7] = {72,74,76,77,79,81,83}; 8 | void data_recv(uint8_t* samples,int len) 9 | { 10 | cyber.clean_lcd(); 11 | for(int i=0;i 5 | sentence= Use to drive all devices provided by Makeblock company. 6 | paragraph=This library allows an cyberpi board to control all devices provided by Makeblock company. 7 | category=Device Control 8 | url=http://www.makeblock.com/ 9 | architectures=* 10 | includes=cyberpi.h 11 | compiler.libraries.ldflags=src/lcd/libGT30L24A3W.a 12 | -------------------------------------------------------------------------------- /lib/cyberpi/platform.local.txt: -------------------------------------------------------------------------------- 1 | compiler.libraries.ldflags= -------------------------------------------------------------------------------- /lib/cyberpi/src/cyberpi.cpp: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | #include "driver/i2s.h" 3 | #include "driver/dac.h" 4 | extern "C" { 5 | #include "io/aw9523b.h" 6 | #include "lcd/lcd.h" 7 | #include "i2c/i2c.h" 8 | #include "gyro/gyro.h" 9 | #include "sound/synth.h" 10 | #include "microphone/es8218e.h" 11 | } 12 | static MSynth _audio; 13 | static uint16_t *_framebuffer; 14 | static uint8_t*_led_data; 15 | static uint8_t*_gyro_data; 16 | static SemaphoreHandle_t _render_ready; 17 | static bool sound_enabled = false; 18 | static bool microphone_enabled = false; 19 | data_callback _mic_callback; 20 | data_callback _sound_callback; 21 | static long prev_time = 0; 22 | static int _loudness; 23 | CyberPi::CyberPi() 24 | { 25 | _render_ready = xSemaphoreCreateBinary(); 26 | _led_data = this->malloc(15); 27 | _gyro_data = this->malloc(14); 28 | 29 | memset(_led_data,0,15); 30 | } 31 | void CyberPi::begin() 32 | { 33 | i2c_init(); 34 | aw_init(); 35 | begin_gpio(); 36 | begin_lcd(); 37 | begin_gyro(); 38 | begin_sound(); 39 | begin_microphone(); 40 | 41 | TaskHandle_t threadTask_lcd; 42 | xTaskCreatePinnedToCore(this->_on_lcd_thread,"_on_lcd_thread",4096,NULL,10,&threadTask_lcd,1); 43 | TaskHandle_t threadTask_sensor; 44 | xTaskCreatePinnedToCore(this->_on_sensor_thread, "on_sensor_read", 10000, this, 8, &threadTask_sensor, 1); 45 | TaskHandle_t threadTask_sound; 46 | xTaskCreatePinnedToCore(this->_on_sound_thread, "on_sound_read", 10000, this, 9, &threadTask_sound, 1); 47 | } 48 | void CyberPi::_on_lcd_thread(void *p) 49 | { 50 | while(true) 51 | { 52 | if(xSemaphoreTake(_render_ready, 25)==pdTRUE) 53 | { 54 | lcd_draw(_framebuffer,128,128); 55 | } 56 | } 57 | } 58 | 59 | 60 | void CyberPi::begin_gpio() 61 | { 62 | pinMode(33,INPUT); 63 | aw_pinMode(AW_P1_3,AW_GPIO_MODE_OUTPUT); 64 | aw_pinMode(JOYSTICK_UP_IO,AW_GPIO_MODE_INPUT); 65 | aw_pinMode(JOYSTICK_DOWN_IO,AW_GPIO_MODE_INPUT); 66 | aw_pinMode(JOYSTICK_RIGHT_IO,AW_GPIO_MODE_INPUT); 67 | aw_pinMode(JOYSTICK_LEFT_IO,AW_GPIO_MODE_INPUT); 68 | aw_pinMode(JOYSTICK_CENTER_IO,AW_GPIO_MODE_INPUT); 69 | aw_pinMode(BUTTON_A_IO,AW_GPIO_MODE_INPUT); 70 | aw_pinMode(BUTTON_B_IO,AW_GPIO_MODE_INPUT); 71 | aw_pinMode(BUTTON_MENU_IO,AW_GPIO_MODE_INPUT); 72 | } 73 | 74 | void CyberPi::begin_lcd() 75 | { 76 | _framebuffer = (uint16_t*)this->malloc(128*128*2); 77 | memset(_framebuffer,0,128*128*2); 78 | lcd_init(); 79 | } 80 | 81 | void CyberPi::set_lcd_light(bool on) 82 | { 83 | if(on) 84 | { 85 | lcd_on(); 86 | } 87 | else 88 | { 89 | lcd_off(); 90 | } 91 | } 92 | Bitmap* CyberPi::create_text(wchar_t*chars,uint16_t color,uint8_t font_size) 93 | { 94 | Bitmap *bitmap = new Bitmap(); 95 | int cx=0,cy=0,x=0,y=0; 96 | int i=0; 97 | uint32_t c; 98 | uint8_t font_width = font_size; 99 | uint8_t font_height = font_size; 100 | uint8_t font_max_height = font_size; 101 | uint8_t *buf = (uint8_t*)MALLOC_SPI(400); 102 | bool elongate = false; 103 | uint8_t font = 10; 104 | while((c = *(chars + i)) != 0) 105 | { 106 | if(c == 0x08) 107 | { // Backspace 108 | cx -= font_width; 109 | } 110 | else if(c == 0x0A) 111 | {// New line 112 | cx = 0; 113 | cy += font_height; 114 | } 115 | else 116 | { 117 | get_utf8_data(c, c<256?6:font,buf,&elongate,&font_width,&font_height); 118 | cx += font_width*font_max_height/font_height+0.5f; 119 | } 120 | i++; 121 | } 122 | bitmap->width = cx; 123 | bitmap->height = cy+font_max_height+1; 124 | bitmap->buffer = (uint16_t*)this->malloc(bitmap->width*bitmap->height*2); 125 | memset(bitmap->buffer,0,bitmap->width*bitmap->height*2); 126 | cx = 0; 127 | cy = 0; 128 | i = 0; 129 | while((c = *(chars + i)) != 0) 130 | { 131 | if(c == 0x08) 132 | { 133 | cx -= font_width; 134 | } 135 | else if(c == 0x0A) 136 | { 137 | cx = 0; 138 | cy += font_height; 139 | } 140 | else 141 | { 142 | get_utf8_data(c, c<256?6:font,buf,&elongate,&font_width,&font_height); 143 | read_char(bitmap,cx, cy,font_size,font_max_height, buf+(elongate?2:0), font_width,font_height,elongate,color); 144 | cx += font_width*font_max_height/font_height+0.5f; 145 | } 146 | i++; 147 | } 148 | free(buf); 149 | return bitmap; 150 | } 151 | void CyberPi::read_char(Bitmap*bitmap,int x,int y,float w,float h,uint8_t* buffer, float font_width,float font_height,bool elongate,uint16_t color) 152 | { 153 | if(buffer) 154 | { 155 | float width = font_width,height = font_height; 156 | int widthBytes = (int)ceil((double)width / 8); 157 | float scale = h/height; 158 | if(scale==1) 159 | { 160 | for(int v=0; v> 3; 165 | int bit = ~u & 7; 166 | if((buffer[widthBytes * v + b]>>bit)&1) 167 | { 168 | bitmap->buffer[x+u+(y+v)*bitmap->width] = color; 169 | } 170 | } 171 | } 172 | } 173 | else 174 | { 175 | uint8_t *buf = (uint8_t*)this->malloc(width*height); 176 | memset(buf,0,width*height); 177 | for(int v=0,hh=height; v> 3; 182 | int bit = ~u & 7; 183 | if((buffer[widthBytes * v + b]>>bit)&1) 184 | { 185 | buf[u+(v*ww)] = 1; 186 | bitmap->buffer[x+(int)(u*scale)+(y+(int)(v*scale))*bitmap->width] = color; 187 | } 188 | } 189 | } 190 | for(int i=0,hh=height*scale+0.5f;ibuffer[x+j+(y+i)*bitmap->width] = color; 197 | } 198 | } 199 | } 200 | free(buf); 201 | } 202 | } 203 | } 204 | void CyberPi::clean_lcd() 205 | { 206 | memset(_framebuffer,0x0,128*128*2); 207 | } 208 | 209 | void CyberPi::set_lcd_pixel(uint8_t x,uint8_t y,uint16_t color) 210 | { 211 | if(y>=0&&y<128&&x>=0&&x<128) 212 | { 213 | _framebuffer[y*128+x] = color; 214 | } 215 | } 216 | 217 | void CyberPi::set_bitmap(uint8_t x,uint8_t y, Bitmap* bitmap) 218 | { 219 | Serial.printf("%d,%d\n",bitmap->width,bitmap->height); 220 | for(int i=0;iheight;i++) 221 | { 222 | for(int j=0;jwidth;j++) 223 | { 224 | set_lcd_pixel(x+j,y+i,bitmap->buffer[i*bitmap->width+j]); 225 | } 226 | } 227 | } 228 | uint16_t CyberPi::color24_to_16(uint32_t rgb) 229 | { 230 | return color24to16(rgb); 231 | } 232 | 233 | uint16_t CyberPi::swap_color(uint16_t color) 234 | { 235 | return ((color&0xff)<<8)|(color>>8); 236 | } 237 | void CyberPi::render_lcd() 238 | { 239 | if(millis()-lastTime>20) 240 | { 241 | lastTime = millis(); 242 | xSemaphoreGive(_render_ready); 243 | } 244 | } 245 | 246 | void CyberPi::set_rgb(int idx,uint8_t red,uint8_t greeen,uint8_t blue) 247 | { 248 | _led_data[idx*3] = red; 249 | _led_data[idx*3+1] = greeen; 250 | _led_data[idx*3+2] = blue; 251 | i2c_write_data(0x5B, REG_DIM00, _led_data, 15); 252 | } 253 | uint16_t CyberPi::get_gpio() 254 | { 255 | return aw_get_gpio(); 256 | } 257 | uint16_t CyberPi::get_light() 258 | { 259 | return analogRead(33); 260 | } 261 | int CyberPi::get_joystick_x() 262 | { 263 | if(aw_digitalRead(JOYSTICK_RIGHT_IO)) 264 | { 265 | return 1; 266 | } 267 | if(aw_digitalRead(JOYSTICK_LEFT_IO)) 268 | { 269 | return -1; 270 | } 271 | return 0; 272 | } 273 | int CyberPi::get_joystick_y() 274 | { 275 | if(aw_digitalRead(JOYSTICK_DOWN_IO)) 276 | { 277 | return 1; 278 | } 279 | if(aw_digitalRead(JOYSTICK_UP_IO)) 280 | { 281 | return -1; 282 | } 283 | return 0; 284 | } 285 | bool CyberPi::get_joystick_pressed() 286 | { 287 | return aw_digitalRead(JOYSTICK_CENTER_IO); 288 | } 289 | 290 | bool CyberPi::get_button_a() 291 | { 292 | return aw_digitalRead(BUTTON_A_IO); 293 | } 294 | bool CyberPi::get_button_b() 295 | { 296 | return aw_digitalRead(BUTTON_B_IO); 297 | } 298 | bool CyberPi::get_button_menu() 299 | { 300 | return aw_digitalRead(BUTTON_MENU_IO); 301 | } 302 | 303 | void CyberPi::begin_gyro() 304 | { 305 | gyro_init(); 306 | } 307 | float CyberPi::get_gyro_x() 308 | { 309 | return get_gyro_data(0); 310 | } 311 | float CyberPi::get_gyro_y() 312 | { 313 | return get_gyro_data(1); 314 | } 315 | float CyberPi::get_gyro_z() 316 | { 317 | return get_gyro_data(2); 318 | } 319 | float CyberPi::get_acc_x() 320 | { 321 | return get_acc_data(0); 322 | } 323 | float CyberPi::get_acc_y() 324 | { 325 | return get_acc_data(1); 326 | } 327 | float CyberPi::get_acc_z() 328 | { 329 | return get_acc_data(2); 330 | } 331 | float CyberPi::get_roll() 332 | { 333 | return get_gyro_roll(); 334 | } 335 | float CyberPi::get_pitch() 336 | { 337 | return get_gyro_pitch(); 338 | } 339 | void CyberPi::begin_sound() 340 | { 341 | sound_enabled = true; 342 | aw_digitalWrite(AW_P1_3, HIGH); 343 | i2s_config_t i2s_config = { 344 | .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN), 345 | .sample_rate = 20000, 346 | .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, 347 | .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, 348 | .intr_alloc_flags = 0, 349 | .dma_buf_count = 16, 350 | .dma_buf_len = 256, 351 | .use_apll = 0, 352 | .tx_desc_auto_clear = 0, 353 | }; 354 | i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); 355 | i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN); 356 | 357 | _audio.begin((AudioBack)&CyberPi::_render_audio); 358 | } 359 | void CyberPi::set_pitch(uint8_t channel, uint8_t pitch,uint8_t time) 360 | { 361 | _audio.addNote(channel,pitch,time); 362 | } 363 | void CyberPi::set_instrument(uint8_t instrument) 364 | { 365 | _audio.setInstrument(instrument); 366 | } 367 | void CyberPi::_render_audio(uint8_t *audio_buf,uint16_t audio_buf_len) 368 | { 369 | if(sound_enabled) 370 | { 371 | size_t bytes_written; 372 | i2s_write(I2S_NUM_0, audio_buf, audio_buf_len, &bytes_written, portMAX_DELAY); 373 | if(_sound_callback) 374 | { 375 | _sound_callback(audio_buf, audio_buf_len); 376 | } 377 | } 378 | } 379 | void CyberPi::_on_sound_thread(void*p) 380 | { 381 | while(1) 382 | { 383 | if(sound_enabled) 384 | { 385 | _audio.render(); 386 | } 387 | } 388 | } 389 | void CyberPi::_on_sensor_thread(void* p) { 390 | size_t bytes_read = 0; 391 | int mic_length = 1024; 392 | uint8_t *samples = (uint8_t*)((CyberPi*)p)->malloc(1024); 393 | while (true) 394 | { 395 | long current_time = millis(); 396 | if(current_time-prev_time>25) 397 | { 398 | prev_time = current_time; 399 | gyro_read(); 400 | } 401 | if(microphone_enabled) 402 | { 403 | i2s_read(I2S_NUM_1, samples, mic_length, &bytes_read, portMAX_DELAY); 404 | int32_t dac_value = 0; 405 | int32_t dac_value_addition = 0; 406 | int16_t maximum_value = 0; 407 | for(int i = 0; i < mic_length; i += 16) 408 | { 409 | val2byte.byteVal[1] = samples[i + 1]; 410 | val2byte.byteVal[0] = samples[i + 0]; 411 | dac_value = val2byte.shortVal; 412 | dac_value_addition = dac_value_addition + abs(dac_value); 413 | if(abs(dac_value) > maximum_value) 414 | { 415 | maximum_value = abs(dac_value); 416 | } 417 | } 418 | _loudness = 16 * dac_value_addition / mic_length; 419 | if(_mic_callback) 420 | { 421 | _mic_callback(samples,mic_length); 422 | } 423 | } 424 | } 425 | } 426 | int CyberPi::get_loudness() 427 | { 428 | return _loudness; 429 | } 430 | void CyberPi::begin_microphone () 431 | { 432 | microphone_enabled = true; 433 | _mic_callback = NULL; 434 | i2s_config_t i2s_config = 435 | { 436 | .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX), 437 | .sample_rate = 160000, 438 | .bits_per_sample = (i2s_bits_per_sample_t)16, 439 | .channel_format = (i2s_channel_fmt_t)I2S_CHANNEL_FMT_ONLY_RIGHT, 440 | .communication_format = I2S_COMM_FORMAT_STAND_I2S, 441 | .intr_alloc_flags = 0, 442 | .dma_buf_count = 2, 443 | .dma_buf_len = 1024, 444 | .use_apll = true 445 | }; 446 | i2s_driver_install(I2S_NUM_1, &i2s_config, 0, NULL); 447 | i2s_pin_config_t pin_config = 448 | { 449 | .bck_io_num = 13, 450 | .ws_io_num = 14, 451 | .data_out_num = -1, 452 | .data_in_num = 35 453 | }; 454 | i2s_set_pin(I2S_NUM_1, &pin_config); 455 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); 456 | es8218e_start(); 457 | } 458 | 459 | void CyberPi::on_microphone_data(data_callback func) 460 | { 461 | _mic_callback = func; 462 | } 463 | 464 | void CyberPi::on_sound_data(data_callback func) 465 | { 466 | _sound_callback = func; 467 | } 468 | uint8_t* CyberPi::malloc(uint32_t len) 469 | { 470 | if (heap_caps_get_free_size( MALLOC_CAP_SPIRAM )==0) 471 | { 472 | return (uint8_t*)MALLOC_INTERNAL(len); 473 | } 474 | return (uint8_t*)MALLOC_SPI(len); 475 | } 476 | -------------------------------------------------------------------------------- /lib/cyberpi/src/cyberpi.h: -------------------------------------------------------------------------------- 1 | #ifndef __CYBER_PI__ 2 | #define __CYBER_PI__ 3 | #include 4 | #include 5 | extern "C" 6 | { 7 | #include "esp_heap_caps.h" 8 | } 9 | #define MALLOC_SPI(a) (heap_caps_malloc((a),MALLOC_CAP_SPIRAM)) 10 | #define MALLOC_INTERNAL(a) (heap_caps_malloc((a),MALLOC_CAP_DMA)) 11 | 12 | #define JOYSTICK_UP_IO AW_P0_1 13 | #define JOYSTICK_DOWN_IO AW_P0_4 14 | #define JOYSTICK_RIGHT_IO AW_P0_2 15 | #define JOYSTICK_LEFT_IO AW_P0_0 16 | #define JOYSTICK_CENTER_IO AW_P0_3 17 | #define BUTTON_A_IO AW_P0_6 18 | #define BUTTON_B_IO AW_P0_5 19 | #define BUTTON_MENU_IO AW_P1_0 20 | 21 | union 22 | { 23 | uint8_t byteVal[2]; 24 | int16_t shortVal; 25 | }val2byte; 26 | 27 | #define ROUND_X(x) ((int)(x + 0.5f)) 28 | #ifndef MAX 29 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) 30 | #endif 31 | #ifndef MIN 32 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 33 | #endif 34 | typedef void (*data_callback)(uint8_t*,int); 35 | 36 | struct Bitmap 37 | { 38 | float x; 39 | float y; 40 | uint8_t width; 41 | uint8_t height; 42 | uint16_t *buffer; 43 | }; 44 | 45 | class CyberPi 46 | { 47 | public: 48 | CyberPi(); 49 | void begin(); 50 | 51 | void set_lcd_light(bool on); 52 | void clean_lcd(); 53 | void set_lcd_pixel(uint8_t x,uint8_t y,uint16_t color); 54 | Bitmap* create_text(wchar_t*chars,uint16_t color,uint8_t font_size); 55 | void set_bitmap(uint8_t x,uint8_t y, Bitmap* buffer); 56 | uint16_t color24_to_16(uint32_t rgb); 57 | uint16_t swap_color(uint16_t color); 58 | void render_lcd(); 59 | 60 | void set_rgb(int idx,uint8_t red,uint8_t greeen,uint8_t blue); 61 | 62 | uint16_t get_gpio(); 63 | 64 | int get_joystick_x(); 65 | int get_joystick_y(); 66 | bool get_joystick_pressed(); 67 | 68 | bool get_button_a(); 69 | bool get_button_b(); 70 | bool get_button_menu(); 71 | 72 | uint16_t get_light(); 73 | 74 | float get_gyro_x(); 75 | float get_gyro_y(); 76 | float get_gyro_z(); 77 | float get_acc_x(); 78 | float get_acc_y(); 79 | float get_acc_z(); 80 | float get_roll(); 81 | float get_pitch(); 82 | 83 | void set_pitch(uint8_t channel, uint8_t pitch,uint8_t time); 84 | void set_instrument(uint8_t instrument); 85 | int get_loudness(); 86 | void on_microphone_data(data_callback func); 87 | void on_sound_data(data_callback func); 88 | uint8_t* malloc(uint32_t len); 89 | private: 90 | long lastTime; 91 | void begin_gyro(); 92 | void begin_gpio(); 93 | void begin_lcd(); 94 | void begin_sound(); 95 | void begin_microphone(); 96 | void read_char(Bitmap*bitmap,int x,int y,float w,float h,uint8_t* buffer, float font_width,float font_height,bool elongate,uint16_t color); 97 | static void _on_sound_thread(void*p); 98 | static void _on_sensor_thread(void* parameter); 99 | static void _on_lcd_thread(void *p); 100 | static void _render_audio(uint8_t *audio_buf,uint16_t audio_buf_len); 101 | }; 102 | #endif -------------------------------------------------------------------------------- /lib/cyberpi/src/gyro/gyro.c: -------------------------------------------------------------------------------- 1 | #include "gyro.h" 2 | #include "../i2c/i2c.h" 3 | static uint8_t* data_buf; 4 | static int16_t* acc_value; 5 | static int16_t* gyro_value; 6 | static float* gyro_data; 7 | static float* acc_data; 8 | 9 | static bool first_update = true; 10 | static float acc_x_static = 0.0; 11 | static float acc_y_static = 0.0; 12 | static float acc_z_static = 0.0; 13 | bool gyro_init() 14 | { 15 | uint8_t chip_id = i2c_read( MPU6887_ADDR, WHO_AM_I); 16 | if(chip_id != MPU6887_DEVICE_ID) 17 | { 18 | return false; 19 | } 20 | data_buf = (uint8_t*)malloc(14); 21 | acc_value = (int16_t*)malloc(6); 22 | gyro_value = (int16_t*)malloc(6); 23 | gyro_data = (float*)malloc(12); 24 | acc_data = (float*)malloc(12); 25 | /* close the sleep mode */ 26 | i2c_write( MPU6887_ADDR, PWR_MGMT_1, 0x00); 27 | /* configurate the digital low pass filter */ 28 | i2c_write( MPU6887_ADDR, CONFIG, 0x01); 29 | /* set the gyro scale to 500 deg/s */ 30 | i2c_write( MPU6887_ADDR, GYRO_CONFIG, 0x08); 31 | /* set the acc scale to 4g */ 32 | i2c_write( MPU6887_ADDR, ACCEL_CONFIG, 0x08); 33 | /* set the Sampling Rate 100Hz */ 34 | i2c_write( MPU6887_ADDR, SMPLRT_DI, 0x09); 35 | return true; 36 | } 37 | bool gyro_read() 38 | { 39 | i2c_read_data(MPU6887_ADDR, ACCEL_XOUT_H, data_buf, 14); 40 | acc_value[0] = (int16_t)((data_buf[0] << 8) | data_buf[1]); 41 | acc_value[1] = (int16_t)((data_buf[2] << 8) | data_buf[3]); 42 | acc_value[2] = (int16_t)((data_buf[4] << 8) | data_buf[5]); 43 | 44 | gyro_value[0] = (int16_t)((data_buf[8] << 8) | data_buf[9]); 45 | gyro_value[1] = (int16_t)((data_buf[10] << 8) | data_buf[11]); 46 | gyro_value[2] = (int16_t)((data_buf[12] << 8) | data_buf[13]); 47 | 48 | /* calculate other value by acc */ 49 | float acc_filter = 0.8; 50 | if(first_update) 51 | { 52 | acc_x_static = acc_value[0]; 53 | acc_y_static = acc_value[1]; 54 | acc_z_static = acc_value[2]; 55 | first_update = false; 56 | } 57 | else 58 | { 59 | acc_x_static = acc_x_static * acc_filter + acc_value[0] * (1 - acc_filter); 60 | acc_y_static = acc_y_static * acc_filter + acc_value[1] * (1 - acc_filter); 61 | acc_z_static = acc_z_static * acc_filter + acc_value[2] * (1 - acc_filter); 62 | } 63 | acc_data[0] = acc_x_static; 64 | acc_data[1] = acc_y_static; 65 | acc_data[2] = acc_z_static; 66 | 67 | gyro_data[0] = gyro_value[0] / GTRO_SENSITIVITY_DEFAULT; 68 | gyro_data[1] = gyro_value[1] / GTRO_SENSITIVITY_DEFAULT; 69 | gyro_data[2] = gyro_value[2] / GTRO_SENSITIVITY_DEFAULT; 70 | return true; 71 | } 72 | float get_acc_data(uint8_t axis) 73 | { 74 | return acc_data[axis]; 75 | } 76 | float get_gyro_data(uint8_t axis) 77 | { 78 | return gyro_data[axis]; 79 | } 80 | float get_gyro_roll() 81 | { 82 | if(acc_data[2] > 0) 83 | { 84 | return atan2(acc_data[0], -sqrt(pow(acc_data[1], 2) + pow(acc_data[2], 2))) * 180 / PI; 85 | 86 | } 87 | else 88 | { 89 | return atan2(acc_data[0], sqrt(pow(acc_data[1], 2) + pow(acc_data[2], 2))) * 180 / PI; 90 | } 91 | } 92 | float get_gyro_pitch() 93 | { 94 | if(acc_data[2] > 0) 95 | { 96 | return atan2(-acc_data[1], -sqrt(pow(acc_data[0], 2) + pow(acc_data[2], 2))) * 180 / PI; 97 | } 98 | else 99 | { 100 | return atan2(-acc_data[1], sqrt(pow(acc_data[0], 2) + pow(acc_data[2], 2))) * 180 / PI; 101 | } 102 | } -------------------------------------------------------------------------------- /lib/cyberpi/src/gyro/gyro.h: -------------------------------------------------------------------------------- 1 | #ifndef __GYRO__ 2 | #define __GYRO__ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #define MPU6887_ADDR 0x69 8 | #define MPU6887_DEVICE_ID (0x2E) 9 | 10 | /********* REGISTERS ADDRESS *************/ 11 | #define XG_OFFS_TC_H 0x04 12 | #define XG_OFFS_TC_L 0x05 13 | #define YG_OFFS_TC_H 0x07 14 | #define YG_OFFS_TC_L 0x08 15 | #define ZG_OFFS_TC_H 0x0A 16 | #define ZG_OFFS_TC_L 0x0B 17 | 18 | #define SELF_TEST_X_ACCEL 0x0D 19 | #define SELF_TEST_Y_ACCEL 0x0E 20 | #define SELF_TEST_Z_ACCEL 0x0F 21 | 22 | #define XG_OFFS_USRH 0x13 23 | #define XG_OFFS_USRL 0x14 24 | #define YG_OFFS_USRH 0x15 25 | #define YG_OFFS_USRL 0x16 26 | #define ZG_OFFS_USRH 0x17 27 | #define ZG_OFFS_USRL 0x18 28 | 29 | #define SMPLRT_DI 0x19 30 | 31 | #define CONFIG 0x1A 32 | #define GYRO_CONFIG 0x1B 33 | #define ACCEL_CONFIG 0x1C 34 | #define ACCEL_CONFIG_2 0x1D 35 | #define LP_MODE_CFG 0x1E 36 | 37 | #define ACCEL_WOM_X_THR 0x20 38 | #define ACCEL_WOM_Y_THR 0x21 39 | #define ACCEL_WOM_Z_THR 0x22 40 | #define FIFO_EN 0x23 41 | 42 | #define FSYNC_INT 0x36 43 | #define INT_PIN_CFG 0x37 44 | #define INT_ENABLE 0x38 45 | #define FIFO_WM_INT_STATUS 0x39 46 | #define INTSTATU 0x3A 47 | 48 | #define ACCEL_XOUT_H 0x3B 49 | #define ACCEL_XOUT_L 0x3C 50 | #define ACCEL_YOUT_H 0x3D 51 | #define ACCEL_YOUT_L 0x3E 52 | #define ACCEL_ZOUT_H 0x3F 53 | #define ACCEL_ZOUT_L 0x40 54 | #define TEMP_OUT_H 0x41 55 | #define TEMP_OUT_L 0x42 56 | #define GYRO_XOUT_H 0x43 57 | #define GYRO_XOUT_L 0x44 58 | #define GYRO_YOUT_H 0x45 59 | #define GYRO_YOUT_L 0x46 60 | #define GYRO_ZOUT_H 0x47 61 | #define GYRO_ZOUT_L 0x48 62 | 63 | #define SELF_TEST_X_GYRO 0x50 64 | #define SELF_TEST_Y_GYRO 0x51 65 | #define SELF_TEST_Z_GYRO 0x52 66 | #define E_ID0 0x53 67 | #define E_ID1 0x54 68 | #define E_ID2 0x55 69 | #define E_ID3 0x56 70 | #define E_ID4 0x57 71 | #define E_ID5 0x58 72 | #define E_ID6 0x59 73 | #define FIFO_WM_TH1 0x60 74 | #define FIFO_WM_TH2 0x61 75 | 76 | #define SIGNAL_PATH_RESET 0x68 77 | #define ACCEL_INTEL_CTRL 0x69 78 | #define USER_CTRL 0x6A 79 | #define PWR_MGMT_1 0x6B 80 | #define PWR_MGMT_2 0x6C 81 | 82 | #define I2C_IF 0x70 83 | #define FIFO_COUNTH 0x72 84 | #define FIFO_COUNTL 0x73 85 | #define FIFO_R_W 0x74 86 | #define WHO_AM_I 0x75 87 | 88 | #define XA_OFFSET_H 0x77 89 | #define XA_OFFSET_L 0x78 90 | #define YA_OFFSET_H 0x7A 91 | #define YA_OFFSET_L 0x7B 92 | #define ZA_OFFSET_H 0x7D 93 | #define ZA_OFFSET_L 0x7E 94 | 95 | #define GYRO_AXIS_DIR {1, 2, 3} 96 | 97 | #define MAX_I2C_RESTORE_SCL_CNT (8 * 32) 98 | #ifndef PI 99 | #define PI 3.1415926535 100 | #endif 101 | #define ACC_FILTER (0.8) 102 | #define TILT_ANGLE_FILTER (0.4) 103 | #define TILT_RANGE_GAIN (0.2588) // cos(75) 104 | #define ARROW_ORIENTATION_RANGE_GAIN (0.2588) // cos(75) 105 | #define SCREEN_STATUS_RANGE_GAIN (0.906) // cos(25) 106 | #define SHAKE_CHECK_DATA_BUFFER_SIZE (60) 107 | #define GRAVITY_DEFAULT_VALUE (17000 / 2) 108 | #define I2C_NUM (I2C_NUM_1) 109 | #define I2C_FREQUENCY (400000) 110 | 111 | #define SHAKE_STRENGTH_FREQUENCY_GAIN (4) // this is a empirical value (0 - 20) 112 | #define SHAKE_STRENGTH_ACC_VALUE_GAIN (5.0 / GRAVITY_DEFAULT_VALUE) // this is a empirical value 113 | #define SHAKE_STRENGTH_START_CHECK_GAIN (0.05) 114 | 115 | #define SHAKED_THRESHOLD_DEFAULT (20) 116 | #define SHAKED_THRESHOLD_MAX (80) 117 | #define SHAKED_THRESHOLD_MIN (10) 118 | 119 | #define BRANDISH_CHECK_START_THRESHOLD (100) 120 | #define BRANDISH_CHECK_THRESHOLD (300) 121 | 122 | #define GTRO_SENSITIVITY_DEFAULT (65.5) // for 500 deg/s, check data sheet 123 | #define GYRO_UPDATE_THRESHOLD_ACC (100) // acc 124 | #define GYRO_UPDATE_THRESHOLD_GYRO (10) // gyro 125 | bool gyro_init(); 126 | bool gyro_read(); 127 | float get_acc_data(uint8_t axis); 128 | float get_gyro_data(uint8_t axis); 129 | float get_gyro_roll(); 130 | float get_gyro_pitch(); 131 | #endif -------------------------------------------------------------------------------- /lib/cyberpi/src/i2c/i2c.c: -------------------------------------------------------------------------------- 1 | #include "i2c.h" 2 | void i2c_init() 3 | { 4 | gpio_config_t io_conf; 5 | io_conf.intr_type = GPIO_PIN_INTR_DISABLE; 6 | io_conf.mode = GPIO_MODE_DISABLE; 7 | io_conf.pin_bit_mask = (1 << I2C_MASTER_SCL_IO); 8 | io_conf.pull_down_en = 0; 9 | io_conf.pull_up_en = 0; 10 | gpio_config(&io_conf); 11 | io_conf.pin_bit_mask = (1 << I2C_MASTER_SDA_IO); 12 | gpio_config(&io_conf); 13 | 14 | int i2c_master_port = I2C_NUM_1; 15 | i2c_config_t conf; 16 | conf.mode = I2C_MODE_MASTER; 17 | conf.sda_io_num = I2C_MASTER_SDA_IO; 18 | conf.scl_io_num = I2C_MASTER_SCL_IO; 19 | conf.sda_pullup_en = GPIO_PULLUP_ENABLE; 20 | conf.scl_pullup_en = GPIO_PULLUP_ENABLE; 21 | conf.master.clk_speed = 400000; 22 | conf.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL; 23 | i2c_param_config(i2c_master_port, &conf); 24 | i2c_driver_install(i2c_master_port, conf.mode,0,0,0); 25 | 26 | } 27 | 28 | void i2c_write(uint8_t addr, uint8_t reg, uint8_t val) 29 | { 30 | i2c_cmd_handle_t cmd = i2c_cmd_link_create(); 31 | i2c_master_start(cmd); 32 | i2c_master_write_byte(cmd, addr<<1, 1); 33 | i2c_master_write_byte(cmd, reg, 1); 34 | i2c_master_write_byte(cmd, val, 1); 35 | i2c_master_stop(cmd); 36 | i2c_master_cmd_begin(I2C_NUM_1, cmd, 1000 / portTICK_RATE_MS); 37 | i2c_cmd_link_delete(cmd); 38 | } 39 | uint8_t i2c_read(uint8_t addr, uint8_t reg) 40 | { 41 | uint8_t data = 0; 42 | i2c_cmd_handle_t cmd = i2c_cmd_link_create(); 43 | 44 | i2c_master_start(cmd); 45 | i2c_master_write_byte(cmd, (addr << 1) | 0, 1); 46 | i2c_master_write_byte(cmd, reg, 1); 47 | // i2c_master_stop(cmd); 48 | 49 | i2c_master_start(cmd); 50 | i2c_master_write_byte(cmd, (addr << 1) | 1, 1); 51 | i2c_master_read_byte(cmd, &data, 1); 52 | i2c_master_stop(cmd); 53 | 54 | i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 100 / portTICK_RATE_MS); 55 | i2c_cmd_link_delete(cmd); 56 | 57 | return data; 58 | } 59 | void i2c_write_data(uint8_t slaver_addr, uint8_t reg_addr, uint8_t *data, uint16_t size) 60 | { 61 | 62 | i2c_cmd_handle_t cmd = i2c_cmd_link_create(); // create a command link,command data will be added to this link and then sent at once 63 | i2c_master_start(cmd); // I2C logic has been packaged in these functions 64 | i2c_master_write_byte(cmd, (slaver_addr << 1), 1); 65 | i2c_master_write(cmd, ®_addr, 1, 1); 66 | for(uint16_t i = 0; i < size; i++) 67 | { 68 | i2c_master_write(cmd, (data + i), 1, 1); 69 | } 70 | 71 | i2c_master_stop(cmd); 72 | i2c_master_cmd_begin(I2C_NUM_1, cmd, 1000 / portTICK_RATE_MS); 73 | i2c_cmd_link_delete(cmd); 74 | } 75 | 76 | void i2c_read_data(uint8_t slaver_addr, uint8_t start, uint8_t *buffer, uint16_t size) 77 | { 78 | i2c_cmd_handle_t cmd = i2c_cmd_link_create(); 79 | i2c_master_start(cmd); 80 | i2c_master_write_byte(cmd, (slaver_addr << 1) | 0, 1); 81 | i2c_master_write(cmd, &start, 1, 1); 82 | 83 | i2c_master_start(cmd); 84 | i2c_master_write_byte(cmd, (slaver_addr << 1) | 1, 1); 85 | if(size > 1) 86 | { 87 | i2c_master_read(cmd, buffer, size - 1, 0); 88 | } 89 | i2c_master_read_byte(cmd, buffer + size - 1, 1); //the lastest byte will not give a ASK 90 | i2c_master_stop(cmd); 91 | i2c_master_cmd_begin(I2C_NUM_1, cmd, 100 / portTICK_RATE_MS); 92 | i2c_cmd_link_delete(cmd); 93 | } -------------------------------------------------------------------------------- /lib/cyberpi/src/i2c/i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C__ 2 | #define __I2C__ 3 | #include 4 | #include "driver/i2c.h" 5 | 6 | #define I2C_MASTER_SCL_IO 18 /*!< gpio number for I2C master clock */ 7 | #define I2C_MASTER_SDA_IO 19 /*!< gpio number for I2C master data */ 8 | #define I2C_MASTER_NUM I2C_NUM_1 /*!< I2C port number for master dev */ 9 | #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ 10 | #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ 11 | 12 | 13 | void i2c_init(); 14 | void i2c_write(uint8_t addr, uint8_t reg, uint8_t val); 15 | uint8_t i2c_read(uint8_t addr, uint8_t reg); 16 | void i2c_write_data(uint8_t slaver_addr, uint8_t reg_addr, uint8_t *data, uint16_t size); 17 | void i2c_read_data(uint8_t slaver_addr, uint8_t reg_addr, uint8_t *data, uint16_t size); 18 | #endif -------------------------------------------------------------------------------- /lib/cyberpi/src/io/aw9523b.c: -------------------------------------------------------------------------------- 1 | #include "aw9523b.h" 2 | #include 3 | #include "../i2c/i2c.h" 4 | uint8_t _portIn = AW9523B_P0_IN_STATE; 5 | uint8_t _portOut = AW9523B_P0_OUT_STATE; 6 | uint8_t pinDataP0 = 0; 7 | uint8_t pinDataP1 = 0; 8 | uint8_t pinModeP0 = 0xff; 9 | uint8_t pinModeP1 = 0xff; 10 | enum AW9523BPortMode portMode = MODE_OPEN_DRAIN; 11 | static uint8_t s_i2c_address[2] = {0x5b,0x58}; 12 | void aw_init() 13 | { 14 | uint8_t index = 0; 15 | i2c_write( s_i2c_address[index], REG_SWRST, 0x00); 16 | vTaskDelay(10/portTICK_RATE_MS); 17 | // config all IO led mode 18 | i2c_write( s_i2c_address[index], REG_WORK_MODE_P0, 0x00); // default as gpio mode 19 | i2c_write( s_i2c_address[index], REG_WORK_MODE_P1, 0x00); 20 | // config Imax/1 21 | i2c_write( s_i2c_address[index], REG_CTRL, 0x00); 22 | 23 | ////////////////////////////// init aw9523 chip 1 24 | // reset 25 | index = 1; 26 | i2c_write( s_i2c_address[index], REG_SWRST, 0x00); 27 | vTaskDelay(10/portTICK_RATE_MS); 28 | 29 | i2c_write( s_i2c_address[index], configPort0, pinDataP0); // 00: default all as output. 30 | i2c_write( s_i2c_address[index], configPort1, pinDataP1); // 00: default all as output. 31 | 32 | i2c_write( s_i2c_address[index], REG_WORK_MODE_P0, 0xff); // default as gpio mode 33 | i2c_write( s_i2c_address[index], REG_WORK_MODE_P1, 0xf9); // 1 1 1 1 1 0 0 0:config as gpio/led mode 34 | // config Imax/1 35 | i2c_write( s_i2c_address[index], REG_CTRL, 0x00); 36 | } 37 | 38 | int modifyBit(int currentByte, int position, int bit) // bit field, change position, change value 39 | { 40 | int mask = 1 << position; 41 | return (currentByte & ~mask) | ((bit << position) & mask); 42 | } 43 | void aw_pinMode(enum aw_gpio_num_t pin, uint8_t mode) 44 | { 45 | if(pin < 8) 46 | { 47 | pinModeP0 = modifyBit(pinModeP0, pin, !mode); 48 | i2c_write(s_i2c_address[1], 0x4, pinModeP0); // config register p0 49 | } 50 | else 51 | { 52 | pinModeP1 = modifyBit(pinModeP1 , (pin - 8), !mode); 53 | i2c_write(s_i2c_address[1], 0x5, pinModeP1); // config register p0 54 | } 55 | } 56 | 57 | void aw_digitalWrite(enum aw_gpio_num_t pin, uint8_t value) 58 | { 59 | if(pin<8) 60 | { 61 | // for 02H register 62 | pinDataP0 = modifyBit(pinDataP0, pin, value); // change relavent bit in pin mode 63 | i2c_write(s_i2c_address[1], 0x2, pinDataP0); // config register p0 64 | } 65 | else 66 | { 67 | pinDataP1 = modifyBit(pinDataP1, pin-8, value); // change relavent bit in pin mode 68 | i2c_write(s_i2c_address[1], 0x3, pinDataP1); // config register p0 69 | } 70 | } 71 | bool aw_digitalRead(enum aw_gpio_num_t pin) 72 | { 73 | uint8_t ret = 0; 74 | uint8_t reg_data = 0; 75 | if(pin<8) 76 | { 77 | reg_data = i2c_read(s_i2c_address[1], inputPort0); 78 | ret = (reg_data >> pin)&0x01; 79 | } 80 | else 81 | { 82 | reg_data = i2c_read(s_i2c_address[1], inputPort1); 83 | ret = (reg_data >> (pin-8))&0x01; 84 | } 85 | return 1-ret; 86 | } 87 | uint16_t aw_get_gpio() 88 | { 89 | return i2c_read(s_i2c_address[1], inputPort0)+(i2c_read(s_i2c_address[1], inputPort1)<<8); 90 | } 91 | void aw_config_inout(enum AW9523BPort port, uint8_t inout) 92 | { 93 | i2c_write(s_i2c_address[port],AW9523B_P0_CONF_STATE, inout); 94 | } 95 | 96 | void aw_config_led_gpio(enum AW9523BPort port, uint8_t ledGpio) 97 | { 98 | i2c_write(s_i2c_address[port], AW9523B_P0_LED_MODE, ledGpio); 99 | } 100 | 101 | uint8_t aw_read(enum AW9523BPort port) 102 | { 103 | return i2c_read(s_i2c_address[port], AW9523B_P0_IN_STATE); 104 | } 105 | 106 | void aw_write(enum AW9523BPort port, uint8_t data) 107 | { 108 | i2c_write(s_i2c_address[port],AW9523B_P0_OUT_STATE, data); 109 | } 110 | 111 | void aw_reset(enum AW9523BPort port) 112 | { 113 | i2c_write(s_i2c_address[port],AW9523B_REG_SOFT_RST, 0); 114 | } 115 | -------------------------------------------------------------------------------- /lib/cyberpi/src/io/aw9523b.h: -------------------------------------------------------------------------------- 1 | #ifndef __AW9523B__ 2 | #define __AW9523B__ 3 | 4 | #include 5 | #include 6 | #include "driver/i2c.h" 7 | #define _REG(port, reg) (port == P0 ? reg : reg + 1) 8 | /** Registers */ 9 | #define AW9523B_I2C_ADDRESS 0x58 ///< I2C base address for AW9523B 10 | #define AW9523B_REG_ID 0x10 ///< id register 11 | #define AW9523B_ID 0x23 ///< id value 12 | #define AW9523B_P0_IN_STATE 0x00 ///< P0 port input state 13 | #define AW9523B_P1_IN_STATE 0x01 ///< P1 port input state 14 | #define AW9523B_P0_OUT_STATE 0x02 ///< P0 port output state 15 | #define AW9523B_P1_OUT_STATE 0x03 ///< P1 port output state 16 | #define AW9523B_P0_CONF_STATE 0x04 ///< P0 port config state 17 | #define AW9523B_P1_CONF_STATE 0x05 ///< P1 port config state 18 | #define AW9523B_REG_GLOB_CTR 0x11 ///< Global control register 19 | #define AW9523B_P0_LED_MODE 0x12 ///< P0 port led mode switch register 20 | #define AW9523B_P1_LED_MODE 0x13 ///< P1 port led mode switch register 21 | #define AW9523B_REG_SOFT_RST 0x7F ///< Soft reset register 22 | 23 | #define I2C_SDA_PIN 19 24 | #define I2C_SCL_PIN 18 25 | 26 | #define AW_GPIO_MODE_INPUT 0 27 | #define AW_GPIO_MODE_OUTPUT 1 28 | 29 | /** AW9523B Port constants */ 30 | typedef enum AW9523BPort 31 | { 32 | P0 = 0x00, // Port 0 33 | P1 = 0x01, // Port 1 34 | } 35 | AW9523BPort; 36 | 37 | typedef enum aw_gpio_num_t{ 38 | AW_P0_0 = 0x00, 39 | AW_P0_1 = 0x01, 40 | AW_P0_2 = 0x02, 41 | AW_P0_3 = 0x03, 42 | AW_P0_4 = 0x04, 43 | AW_P0_5 = 0x05, 44 | AW_P0_6 = 0x06, 45 | AW_P0_7 = 0x07, 46 | AW_P1_0 = 0x08, 47 | AW_P1_1 = 0x09, 48 | AW_P1_2 = 0x0a, 49 | AW_P1_3 = 0x0b, 50 | AW_P1_4 = 0x0c, 51 | AW_P1_5 = 0x0d, 52 | AW_P1_6 = 0x0e, 53 | AW_P1_7 = 0x0f, 54 | } 55 | aw_gpio_num_t; 56 | 57 | #define inputPort0 0x00 58 | #define inputPort1 0x01 59 | 60 | #define outputPort0 0x02 61 | #define outputPort1 0x03 62 | 63 | #define configPort0 0x04 64 | #define configPort1 0x05 65 | 66 | #define AW_GPIO_MODE_INPUT 0 67 | #define AW_GPIO_MODE_OUTPUT 1 68 | 69 | #define REG_INPUT_P0 0x00 70 | #define REG_INPUT_P1 0x01 71 | #define REG_OUTPUT_P0 0x02 72 | #define REG_OUTPUT_P1 0x03 73 | #define REG_CONFIG_P0 0x04 74 | #define REG_CONFIG_P1 0x05 75 | #define REG_INT_P0 0x06 76 | #define REG_INT_P1 0x07 77 | #define REG_ID 0x10 78 | #define REG_CTRL 0x11 79 | #define REG_WORK_MODE_P0 0x12 80 | #define REG_WORK_MODE_P1 0x13 81 | #define REG_DIM00 0x20 82 | #define REG_DIM01 0x21 83 | #define REG_DIM02 0x22 84 | #define REG_DIM03 0x23 85 | #define REG_DIM04 0x24 86 | #define REG_DIM05 0x25 87 | #define REG_DIM06 0x26 88 | #define REG_DIM07 0x27 89 | #define REG_DIM08 0x28 90 | #define REG_DIM09 0x29 91 | #define REG_DIM10 0x2a 92 | #define REG_DIM11 0x2b 93 | #define REG_DIM12 0x2c 94 | #define REG_DIM13 0x2d 95 | #define REG_DIM14 0x2e 96 | #define REG_DIM15 0x2f 97 | #define REG_SWRST 0x7F 98 | typedef enum AW9523BPortMode 99 | { 100 | MODE_OPEN_DRAIN = 0x00, // Port 0 open drain mode 101 | MODE_PUSH_PULL = 1 << 4 // Port 0 push pull mode 102 | } 103 | AW9523BPortMode; 104 | #define REG_DIM00 0x20 105 | 106 | void aw_init(); 107 | 108 | int modifyBit(int currentByte, int position, int bit); 109 | void aw_pinMode(enum aw_gpio_num_t pin, uint8_t mode); 110 | void aw_digitalWrite(enum aw_gpio_num_t pin, uint8_t value); 111 | bool aw_digitalRead(enum aw_gpio_num_t pin); 112 | uint16_t aw_get_gpio(); 113 | void aw_config_inout(enum AW9523BPort port, uint8_t inout); 114 | 115 | void aw_config_led_gpio(enum AW9523BPort port, uint8_t ledGpio); 116 | void aw_update_leds(uint8_t*data,uint8_t len); 117 | uint8_t aw_read(enum AW9523BPort port); 118 | 119 | void aw_write(enum AW9523BPort port, uint8_t data); 120 | 121 | void aw_reset(enum AW9523BPort port); 122 | 123 | #endif -------------------------------------------------------------------------------- /lib/cyberpi/src/lcd/GT30L24A3W.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _GT30L24A3W_H_ 3 | #define _GT30L24A3W_H_ 4 | 5 | 6 | typedef enum 7 | { 8 | FONT_SIZE_5_7 = 1, 9 | FONT_SIZE_7_8, 10 | FONT_SIZE_6_12, 11 | FONT_SIZE_12_12, 12 | FONT_SIZE_8_16, 13 | FONT_SIZE_12_24_A, 14 | FONT_SIZE_12_24_P, 15 | FONT_SIZE_16_32, 16 | FONT_SIZE_16_16, 17 | FONT_SIZE_24_24, 18 | FONT_SIZE_32_32, 19 | }GT3024_FONT_SIZE; 20 | 21 | #define ASCII_5X7 1 22 | #define ASCII_7X8 2 23 | #define ASCII_6X12 3 24 | #define ASCII_12_A 4 25 | #define ASCII_8X16 5 26 | #define ASCII_12X24_A 6 27 | #define ASCII_12X24_P 7 28 | #define ASCII_16X32 8 29 | #define ASCII_16_A 9 30 | #define ASCII_24_B 10 31 | #define ASCII_32_B 11 32 | 33 | //code1 page ���� 34 | #define CP_437 0 35 | #define CP_737 1 36 | #define CP_775 2 37 | #define CP_850 3 38 | #define CP_852 4 39 | #define CP_855 5 40 | #define CP_857 6 41 | #define CP_858 7 42 | #define CP_860 8 43 | #define CP_862 9 44 | #define CP_863 10 45 | #define CP_864 11 46 | #define CP_865 12 47 | #define CP_866 13 48 | #define CP_1251 14 49 | #define CP_1252 15 50 | #define CP_1253 16 51 | #define CP_1254 17 52 | #define CP_1255 18 53 | #define CP_1256 19 54 | #define CP_1257 20 55 | #define CP_928 21 56 | #define CP_HEBREW 22 57 | #define CP_KATAKANA 23 58 | 59 | #define USA 0x2B825EUL 60 | #define FRANCE 0x2B8276UL 61 | #define GERMANY 0x2B828EUL 62 | #define UK 0x2B82A6UL 63 | #define DENMARK 0x2B82BEUL 64 | #define SWEDEN 0x2B82D6UL 65 | #define LTALY 0x2B82EEUL 66 | #define SPAIN 0x2B8306UL 67 | #define JAPAN 0x2B831EUL 68 | #define NORWAY 0x2B8336UL 69 | #define DENMARK_II 0x2B834EUL 70 | 71 | extern unsigned char r_dat_bat(unsigned long ReadAddr,unsigned int NumByteToRead,unsigned char* pBuffer); 72 | 73 | unsigned char ASCII_GetData(unsigned char asc,unsigned long ascii_kind,unsigned char *DZ_Data); 74 | void gt_12_GetData (unsigned char MSB,unsigned char LSB,unsigned char *DZ_Data); 75 | void gt_16_GetData (unsigned char MSB,unsigned char LSB,unsigned char *DZ_Data); 76 | unsigned long GBK_24_GetData (unsigned char c1, unsigned char c2,unsigned char *DZ_Data) ; 77 | unsigned long Shift_Jis_8X16_GetData(unsigned int code,unsigned char *DZ_Data); 78 | unsigned long Unicode_Shift_Jis_GetData(unsigned int code,unsigned char *DZ_Data); 79 | unsigned long JIS0208_16X16_GetData(unsigned char MSB,unsigned char LSB,unsigned char *DZ_Data); 80 | unsigned long JIS0208_24X24_GetData(unsigned char MSB,unsigned char LSB,unsigned char *DZ_Data); 81 | unsigned long KSC5601_F_16_GetData(unsigned char MSB,unsigned char LSB,unsigned char *DZ_Data); 82 | unsigned long KSC5601_F_24_GetData(unsigned char MSB,unsigned char LSB,unsigned char *DZ_Data); 83 | unsigned long LATIN_8X16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 84 | unsigned long GREECE_8X16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 85 | unsigned long CYRILLIC_8X16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 86 | unsigned long HEBREW_8X16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 87 | unsigned long THAILAND_8X16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 88 | unsigned long LATIN_16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 89 | unsigned long GREECE_16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 90 | unsigned long CYRILLIC_16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 91 | unsigned long ALB_16_GetData(unsigned int unicode_alb,unsigned char *DZ_Data); 92 | unsigned long Indic_16_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 93 | unsigned long LATIN_12X24_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 94 | unsigned long GREECE_12X24_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 95 | unsigned long CYRILLIC_12X24_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 96 | unsigned long HEBREW_12X24_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 97 | unsigned long THAILAND_16X24_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 98 | unsigned long ALB_24_GetData(unsigned int UNIcode_alb,unsigned char *DZ_Data); 99 | unsigned long Khmer_24_GetData(unsigned int Fontcode,unsigned char *DZ_Data); 100 | unsigned long ICCS_Addr(unsigned char Icode,unsigned long BaseAddr); 101 | unsigned long Katakana_GetData(unsigned char code,unsigned char *DZ_Data); 102 | unsigned long CP_Patch_8X16_GetData(unsigned int code,unsigned char *DZ_Data); 103 | unsigned long CP_Patch_16X16_GetData(unsigned int code,unsigned char *DZ_Data); 104 | unsigned long CP_P_KATAKANA_16X16_GetData(unsigned int code,unsigned char *DZ_Data); 105 | unsigned long cp_patch_12x24(unsigned int code,unsigned char *DZ_Data); 106 | unsigned long ISO8859_8X16_GetData(unsigned int Fontcode,unsigned char Num,unsigned char *DZ_Data); 107 | unsigned long U2J_GetData(unsigned int Unicode,unsigned char *DZ_Data); 108 | unsigned long Shift_JIS_TO_JIS0208(unsigned int code16); 109 | unsigned long U2K_GetData_16X16(unsigned int Unicode,unsigned char *DZ_Data); 110 | unsigned long U2K_GetData_24X24(unsigned int Unicode,unsigned char *DZ_Data); 111 | unsigned long U2G_GetData_12X12(unsigned int unicode,unsigned char *DZ_Data); 112 | unsigned long U2G_GetData_16X16(unsigned int unicode,unsigned char *DZ_Data); 113 | unsigned long U2G_GetData_24X24(unsigned int unicode,unsigned char *DZ_Data); 114 | unsigned long BIG5_GBK( unsigned char h,unsigned char l); 115 | unsigned long U2G(unsigned int unicode); 116 | 117 | unsigned long U2K(unsigned int Unicode); 118 | unsigned long U2J(unsigned int Unicode); 119 | 120 | void CP_12X24_GetData(unsigned int code,unsigned char cpsel,unsigned char *DZ_data); 121 | void INTERNATIONAL_CHARACTER_12X24(unsigned char Icode,unsigned long INTERNATIONAL_CHARACTER,unsigned char *DZ_Data); 122 | 123 | 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /lib/cyberpi/src/lcd/lcd.c: -------------------------------------------------------------------------------- 1 | #include "lcd.h" 2 | #include "GT30L24A3W.h" 3 | 4 | 5 | #define CONFIG_LIBRARY_SPI_NUM (1) 6 | #define CONFIG_LIBRARY_SPI_CLOCK (20000000) 7 | #define CONFIG_LIBRARY_MOSI_GPIO (2) 8 | #define CONFIG_LIBRARY_MISO_GPIO (26) 9 | #define CONFIG_LIBRARY_CLK_GPIO (4) 10 | 11 | #define CONFIG_LIBRARY_CS_GPIO (27) 12 | #define CONFIG_LIBRARY_BCKL_ACTIVE_LEVEL (1) 13 | static spi_device_handle_t spi_wr_library; 14 | 15 | void library_spi_cmd(spi_device_handle_t spi, const uint8_t cmd) 16 | { 17 | esp_err_t ret; 18 | spi_transaction_t t = { 19 | .length = 8, // Command is 8 bits 20 | .tx_buffer = &cmd, // The data is the cmd itself 21 | }; 22 | ret = _lcd_spi_send(spi, &t); // Transmit! 23 | } 24 | 25 | uint8_t library_get_data(spi_device_handle_t spi, uint8_t *data_out, int len) 26 | { 27 | esp_err_t ret; 28 | spi_transaction_t t; 29 | memset(&t, 0, sizeof(t)); 30 | t.length= 8 * len; 31 | t.rx_buffer = data_out; 32 | ret = _lcd_spi_send(spi, &t); 33 | 34 | // assert( ret == ESP_OK ); 35 | 36 | return 0; 37 | } 38 | unsigned char r_dat_bat(unsigned long ReadAddr,unsigned int NumByteToRead,unsigned char* pBuffer) 39 | { 40 | unsigned long j = 0; 41 | gpio_set_level(CONFIG_LIBRARY_CS_GPIO, 0); 42 | 43 | library_spi_cmd(spi_wr_library, 0x03); //发送命令 44 | library_spi_cmd(spi_wr_library, (unsigned char)(ReadAddr >> 16)); //发送地址 45 | library_spi_cmd(spi_wr_library, (unsigned char)(ReadAddr >> 8)); 46 | library_spi_cmd(spi_wr_library, (unsigned char)(ReadAddr >> 0)); 47 | 48 | library_get_data(spi_wr_library, pBuffer, NumByteToRead); 49 | gpio_set_level(CONFIG_LIBRARY_CS_GPIO, 1); 50 | return 0; 51 | } 52 | 53 | static uint32_t library_spi_init(spi_device_handle_t *spi_wr_dev_library, int dma_chan) 54 | { 55 | spi_device_interface_config_t devcfg = { 56 | // Use low speed to read ID. 57 | .clock_speed_hz = 4 * 1000 * 1000, //Clock out frequency 58 | .mode = 0, //SPI mode 0 59 | .spics_io_num = CONFIG_LIBRARY_CS_GPIO, //CS pin 60 | .queue_size = 7, //We want to be able to queue 7 transactions at a time 61 | }; 62 | 63 | // Use high speed to write library 64 | devcfg.clock_speed_hz = CONFIG_LIBRARY_SPI_CLOCK; 65 | //devcfg.flags = SPI_DEVICE_HALFDUPLEX; 66 | esp_err_t r1 = spi_bus_add_device((spi_host_device_t)CONFIG_LIBRARY_SPI_NUM, &devcfg, spi_wr_dev_library); 67 | 68 | return ESP_OK; 69 | } 70 | static void mb_library_config_t() 71 | { 72 | library_spi_init( &spi_wr_library, 1); 73 | } 74 | int get_utf8_data(uint32_t letter, uint8_t word_size, uint8_t *map, bool *elongate,uint8_t *width,uint8_t* height) 75 | { 76 | uint8_t gb_msb,gb_lsb; 77 | unsigned short Unicode = 0; 78 | unsigned long GB_Code = 0x0000; 79 | int use_word_size = 0; 80 | 81 | if((letter >= 0x00) && ( letter <= 0x7F)) //ascii码 82 | { 83 | use_word_size = word_size; 84 | ASCII_GetData(letter, use_word_size, map); 85 | 86 | if(use_word_size == ASCII_12_A || 87 | use_word_size == ASCII_16_A || 88 | use_word_size == ASCII_24_B || 89 | use_word_size == ASCII_32_B) 90 | { 91 | *elongate = true; 92 | if(width!=0)*width = map[1]; 93 | } 94 | 95 | } 96 | //法语、德语、西班牙语、意大利、荷兰(拉丁文) 97 | else if((letter >= 0x0020 && letter <= 0x007F) || (letter >= 0x00A0 && letter <= 0x017F) || (letter >= 0x01A0 && letter <= 0x1CF) \ 98 | || (letter >= 0x01F0 && letter <= 0x01FF) || (letter >= 0x0210 && letter <= 0x021F) || (letter >= 0x1EA0 && letter <= 0x1EFF)) 99 | { 100 | if(word_size <= ASCII_8X16) 101 | { 102 | LATIN_8X16_GetData(letter, map); 103 | use_word_size = ASCII_8X16; 104 | } 105 | else if(word_size == ASCII_16_A) 106 | { 107 | LATIN_16_GetData(letter, map); 108 | // *elongate = true; 109 | use_word_size = ASCII_16_A; 110 | // if(width!=0)*width = map[1]; 111 | } 112 | else if(word_size >= ASCII_12X24_A) 113 | { 114 | LATIN_12X24_GetData(letter, map); 115 | use_word_size = ASCII_12X24_A; 116 | } 117 | } 118 | //俄语(西尔里文) 119 | else if((letter >= 0x0400 && letter <= 0x045F) || (letter >= 0x0490 && letter <= 0x04FF)) 120 | { 121 | if(word_size <= ASCII_8X16) 122 | { 123 | CYRILLIC_8X16_GetData(letter, map); 124 | use_word_size = ASCII_8X16; 125 | } 126 | else if(word_size == ASCII_16_A) 127 | { 128 | CYRILLIC_16_GetData(letter, map); 129 | // *elongate = true; 130 | use_word_size = ASCII_16_A; 131 | // if(width!=0)*width = map[1]; 132 | } 133 | else if(word_size >= ASCII_12X24_A) 134 | { 135 | CYRILLIC_12X24_GetData(letter, map); 136 | use_word_size = ASCII_12X24_A; 137 | } 138 | } 139 | // 希腊文 140 | else if(letter >= 0x0370 && letter <= 0x03CF) 141 | { 142 | if(word_size <= ASCII_8X16) 143 | { 144 | GREECE_8X16_GetData(letter, map); 145 | use_word_size = ASCII_8X16; 146 | } 147 | else if(word_size == ASCII_16_A) 148 | { 149 | GREECE_16_GetData(letter, map); 150 | // *elongate = true; 151 | use_word_size = ASCII_16_A; 152 | // if(width!=0)*width = map[1]; 153 | } 154 | else if(word_size >= ASCII_12X24_A) 155 | { 156 | GREECE_12X24_GetData(letter, map); 157 | use_word_size = ASCII_12X24_A; 158 | } 159 | } 160 | // 希伯来文 161 | else if((letter >= 0x0590 && letter <= 0x05FF) || (letter >= 0xFB1D && letter <= 0xFB4F)) 162 | { 163 | if(word_size <= ASCII_8X16) 164 | { 165 | HEBREW_8X16_GetData(letter, map); 166 | use_word_size = ASCII_8X16; 167 | } 168 | else if(word_size >= ASCII_12X24_A) 169 | { 170 | HEBREW_12X24_GetData(letter, map); 171 | use_word_size = ASCII_12X24_A; 172 | } 173 | } 174 | // 阿拉伯文 175 | else if((letter >= 0x0600 && letter <= 0x06FF) || (letter >= 0xFB50 && letter <= 0xFBFF) || (letter >= 0xFE70 && letter <= 0xFEFF)) 176 | { 177 | if(word_size <= ASCII_16_A) 178 | { 179 | ALB_16_GetData(letter, map); 180 | use_word_size = ASCII_16_A; 181 | // if(width!=0)*width = map[1]; 182 | // *elongate = true; 183 | } 184 | else 185 | { 186 | ALB_24_GetData(letter, map); 187 | use_word_size = ASCII_24_B; 188 | if(width!=0)*width = map[1]; 189 | *elongate = true; 190 | } 191 | } 192 | // 泰文 193 | else if(letter >= 0x0E00 && letter <= 0x0E5F) 194 | { 195 | if(word_size <= ASCII_8X16) 196 | { 197 | THAILAND_8X16_GetData(letter, map); 198 | use_word_size = ASCII_8X16; 199 | } 200 | else if(word_size >= ASCII_12X24_A) 201 | { 202 | THAILAND_16X24_GetData(letter, map); 203 | use_word_size = ASCII_12X24_A; 204 | } 205 | } 206 | // 中、日、韩 207 | else if((letter >= 0x00A0 && letter <= 0x0451) || (letter >= 0x2010 && letter <= 0x2642) || (letter >= 0x3000 && letter <= 0x33D5) \ 208 | || (letter >= 0x4E00 && letter <= 0x9FA5) || (letter >= 0xFE30 && letter <= 0xFE6B) || (letter >= 0xFF01 && letter <= 0xFF5E) \ 209 | || (letter >= 0xFFE0 && letter <= 0xFFE5) || (letter >= 0xF92C && letter <= 0xFA29) || (letter >= 0xE816 && letter <= 0xE864) \ 210 | || (letter >= 0x2E81 && letter <= 0x2ECA) || (letter >= 0x4947 && letter <= 0x49b7) || (letter >= 0x4C77 && letter <= 0x4DAE) \ 211 | || (letter >= 0x3447 && letter <= 0x3CE0) || (letter >= 0x4056 && letter <= 0x478D) || (letter >= 0x0020 && letter < 0x07FF) || (letter >= 0x2000 && letter < 0x27FF) || (letter >= 0x3000 && letter < 0x30FF) \ 212 | || (letter >= 0x3200 && letter < 0x33FF) || (letter >= 0x4E00 && letter < 0x9FFF) || (letter >= 0xFE00 && letter < 0xFFFF) \ 213 | || (letter >= 0x2B05 && letter < 0x2B07) || (letter >= 0x00A1 && letter <= 0x0451) || (letter >= 0x2015 && letter <= 0x266D) || (letter >= 0x3000 && letter <= 0x30FF) \ 214 | || (letter >= 0xAC00 && letter <= 0xD79D) || (letter >= 0xF900 && letter <= 0xFFFF)) 215 | { 216 | GB_Code = U2G(letter); 217 | gb_msb = GB_Code >> 8; 218 | gb_lsb = GB_Code & 0x00ff; 219 | 220 | if((gb_lsb == 0x7F) || (gb_msb >= 0xA1 && gb_msb <= 0xA3 && gb_lsb >= 0xA1) || (gb_msb == 0xA6 && gb_lsb >= 0xA1) \ 221 | || (gb_msb == 0xA9 && gb_lsb >= 0xA1) || (gb_msb >= 0xB0 && gb_msb <= 0xF7 && gb_lsb >= 0xA1) || (gb_msb < 0xA1 && gb_msb >= 0x81 && gb_lsb >= 0x40) || (gb_msb >= 0xAA && gb_lsb < 0xA1)) 222 | { 223 | if(word_size <= ASCII_12_A && 224 | ((gb_msb==0xA9UL && gb_lsb >=0xA4UL) || 225 | (gb_msb >=0xA1UL && gb_msb <= 0XA3UL && gb_lsb >=0xA1UL) || 226 | (gb_msb >=0xB0UL && gb_msb <= 0xF7UL && gb_lsb >=0xA1UL))) 227 | { 228 | gt_12_GetData(gb_msb, gb_lsb, map); 229 | use_word_size = ASCII_12_A; 230 | if(width!=0)*width = map[1]; 231 | } 232 | else if(word_size == ASCII_16_A && 233 | ((gb_msb==0xA9UL && gb_lsb >=0xA4UL) || 234 | (gb_msb >=0xA1UL && gb_msb <= 0XA3UL && gb_lsb >=0xA1UL) || 235 | (gb_msb >=0xB0UL && gb_msb <= 0xF7UL && gb_lsb >=0xA1UL))) 236 | { 237 | gt_16_GetData(gb_msb, gb_lsb, map); 238 | use_word_size = ASCII_16_A; 239 | // if(width!=0)*width = map[1]; 240 | } 241 | else// if(word_size <= ASCII_24_B) 242 | { 243 | GBK_24_GetData(gb_msb, gb_lsb, map); 244 | use_word_size = ASCII_24_B; 245 | } 246 | } 247 | else 248 | { 249 | GB_Code = U2J(letter); 250 | gb_msb = GB_Code >> 8; 251 | gb_lsb = GB_Code & 0x00ff; 252 | if(((gb_msb <= 0x85 && gb_msb >= 0x01) && (gb_lsb <= 0x94 && gb_lsb >= 0x01)) || ((gb_msb <= 0x89 && gb_msb >= 0x88) && (gb_lsb <= 0x94 && gb_lsb >= 0x01))) 253 | { 254 | if(word_size <= ASCII_8X16) 255 | { 256 | JIS0208_16X16_GetData(gb_msb, gb_lsb, map); 257 | use_word_size = ASCII_16_A; 258 | // *elongate = true; 259 | } 260 | else if(word_size == ASCII_16_A) 261 | { 262 | JIS0208_16X16_GetData(gb_msb, gb_lsb, map); 263 | use_word_size = ASCII_16_A; 264 | // if(width!=0)*width = map[1]; 265 | // *elongate = true; 266 | } 267 | else if(word_size >= ASCII_24_B) 268 | { 269 | JIS0208_24X24_GetData(gb_msb, gb_lsb, map); 270 | use_word_size = ASCII_24_B; 271 | } 272 | } 273 | else 274 | { 275 | GB_Code = U2K(letter); 276 | gb_msb = GB_Code >> 8; 277 | gb_lsb = GB_Code & 0x00ff; 278 | if((gb_msb >= 0xA1 && gb_msb < 0xAD && gb_lsb >= 0xA1) || (gb_msb >= 0xB0 && gb_msb <= 0xC8 && gb_lsb >= 0xA1)) 279 | { 280 | if(word_size <= ASCII_16_A) 281 | { 282 | KSC5601_F_16_GetData(gb_msb, gb_lsb, map); 283 | use_word_size = ASCII_16_A; 284 | // if(width!=0)*width = map[1]; 285 | // *elongate = true; 286 | } 287 | else if(word_size >= ASCII_24_B) 288 | { 289 | KSC5601_F_24_GetData(gb_msb, gb_lsb, map); 290 | use_word_size = ASCII_24_B; 291 | } 292 | } 293 | } 294 | } 295 | } 296 | if(width!=0&&height!=0) 297 | { 298 | switch(use_word_size) 299 | { 300 | case ASCII_5X7: 301 | { 302 | *width = 5; 303 | *height = 7; 304 | } 305 | break; 306 | case ASCII_7X8: 307 | { 308 | *width = 7; 309 | *height = 8; 310 | } 311 | break; 312 | case ASCII_6X12: 313 | { 314 | *width = 6; 315 | *height = 12; 316 | } 317 | break; 318 | case ASCII_12_A: 319 | { 320 | *width = 12; 321 | *height = 12; 322 | } 323 | break; 324 | case ASCII_8X16: 325 | { 326 | *width = 8; 327 | *height = 16; 328 | } 329 | break; 330 | case ASCII_12X24_A: 331 | { 332 | *width = 12; 333 | *height = 24; 334 | } 335 | break; 336 | case ASCII_12X24_P: 337 | { 338 | *width = 12; 339 | *height = 24; 340 | } 341 | break; 342 | case ASCII_16X32: 343 | { 344 | *width = 16; 345 | *height = 32; 346 | } 347 | break; 348 | case ASCII_16_A: 349 | { 350 | *width = 16; 351 | *height = 16; 352 | } 353 | break; 354 | case ASCII_24_B: 355 | { 356 | *width = 24; 357 | *height = 24; 358 | } 359 | break; 360 | case ASCII_32_B: 361 | { 362 | *width = 32; 363 | *height = 32; 364 | } 365 | break; 366 | } 367 | } 368 | return use_word_size; 369 | } 370 | 371 | lcd_info_t lcd_info = 372 | { 373 | .height = LCD_TFTHEIGHT, 374 | .width = LCD_TFTWIDTH, 375 | .dma_mode = true, 376 | .dma_buf_size = SPI_DMA_BUFFER_SIZE, 377 | .dma_chan = SPI_DMA_CHANNEL, 378 | .spi_wr = NULL, 379 | .lcd_conf = 380 | { 381 | .lcd_model = LCD_MOD_AUTO_DET, 382 | .pin_num_miso = CONFIG_LCD_MISO_GPIO, 383 | .pin_num_mosi = CONFIG_LCD_MOSI_GPIO, 384 | .pin_num_clk = CONFIG_LCD_CLK_GPIO, 385 | .pin_num_cs = CONFIG_LCD_CS_GPIO, 386 | .pin_num_dc = CONFIG_LCD_DC_GPIO, 387 | .pin_num_rst = CONFIG_LCD_RESET_GPIO, 388 | .pin_num_bckl = CONFIG_LCD_BL_GPIO, 389 | .clk_freq = CONFIG_LCD_SPI_CLOCK, 390 | .rst_active_level = 0, 391 | .bckl_active_level = CONFIG_LCD_BCKL_ACTIVE_LEVEL, 392 | .spi_host = (spi_host_device_t)CONFIG_LCD_SPI_NUM, 393 | .init_spi_bus = true, 394 | } 395 | }; 396 | 397 | SemaphoreHandle_t _spi_mux = NULL; 398 | 399 | const lcd_init_cmd_t st7735_init_cmds[] = 400 | { 401 | // software reset with delay 402 | {ST77XX_SWRESET, {0}, ST_CMD_DELAY}, 403 | // Out of sleep mode with delay 404 | {ST77XX_SLPOUT, {0}, ST_CMD_DELAY}, 405 | // Framerate ctrl - normal mode. Rate = fosc/(1x2+40) * (LINE+2C+2D) 406 | {ST7735_FRMCTR1, {0x01, 0x2C, 0x2D}, 3}, 407 | // Framerate ctrl - idle mode. Rate = fosc/(1x2+40) * (LINE+2C+2D) 408 | {ST7735_FRMCTR2, {0x01, 0x2C, 0x2D}, 3}, 409 | // Framerate - partial mode. Dot/Line inversion mode 410 | {ST7735_FRMCTR3, {0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D}, 6}, 411 | // Display inversion ctrl: No inversion 412 | {ST7735_INVCTR, {0x07}, 1}, 413 | // Power control1 set GVDD: -4.6V, AUTO mode. 414 | {ST7735_PWCTR1, {0xA2, 0x02, 0x84}, 3}, 415 | // Power control2 set VGH/VGL: VGH25=2.4C VGSEL=-10 VGH=3 * AVDD 416 | {ST7735_PWCTR2, {0xC5}, 1}, 417 | // Power control3 normal mode(Full color): Op-amp current small, booster voltage 418 | {ST7735_PWCTR3, {0x0A, 0x00}, 2}, 419 | // Power control4 idle mode(8-colors): Op-amp current small & medium low 420 | {ST7735_PWCTR4, {0x8A, 0x2A}, 2}, 421 | // Power control5 partial mode + full colors 422 | {ST7735_PWCTR5, {0x8A, 0xEE}, 2}, 423 | // VCOMH VoltageVCOM control 1: VCOMH=0x0E=2.850 424 | {ST7735_VMCTR1, {0x0E}, 1}, 425 | // Display Inversion Off 426 | {ST77XX_INVOFF, {1}, 1}, 427 | // Memory Data Access Control: top-bottom/left-right refresh 428 | {ST77XX_MADCTL, {0xA8}, 1}, 429 | // Color mode, Interface Pixel Format: RGB-565, 16-bit/pixel 430 | {ST77XX_COLMOD, {0x05}, 1}, 431 | 432 | // Column Address Set: 2, 127+2 433 | {ST77XX_CASET, {0x00, 0x02, 0x00, 0x7F + 0x02}, 4}, 434 | // Row Address Set: 1,159+1 435 | {ST77XX_RASET, {0x00, 0x01, 0x00, 0x9F + 0x01}, 4}, 436 | 437 | // Gamma Adjustments (pos. polarity). Not entirely necessary, but provides accurate colors. 438 | {ST7735_GMCTRP1, 439 | {0x02, 0x1c, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2d, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10}, 440 | 16}, 441 | // Gamma Adjustments (neg. polarity). Not entirely necessary, but provides accurate colors. 442 | {ST7735_GMCTRN1, 443 | {0x03, 0x1d, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10}, 444 | 16}, 445 | // Normal Display Mode On 446 | {ST77XX_NORON, {0}, ST_CMD_DELAY}, 447 | // Display On 448 | {ST77XX_DISPON, {0}, ST_CMD_DELAY}, 449 | {0, {0}, 0xFF}, 450 | }; 451 | 452 | const lcd_init_cmd_t st7735_display_direc_cmds[] = 453 | { 454 | // Memory Data Access Control: top-bottom/left-right refresh 455 | {ST77XX_MADCTL, {0xB8}, 1}, 456 | }; 457 | 458 | esp_err_t _lcd_spi_send(spi_device_handle_t spi, spi_transaction_t* t) 459 | { 460 | xSemaphoreTake(_spi_mux, portMAX_DELAY); 461 | esp_err_t res = spi_device_polling_transmit(spi, t);//Transmit! 462 | xSemaphoreGive(_spi_mux); 463 | return res; 464 | } 465 | void lcd_spi_pre_transfer_callback(spi_transaction_t *t) 466 | { 467 | lcd_dc_t *dc = (lcd_dc_t *) t->user; 468 | aw_digitalWrite(dc->dc_io, dc->dc_level); 469 | } 470 | 471 | uint32_t lcd_spi_init(lcd_conf_t* lcd_conf, spi_device_handle_t *spi_wr_dev, lcd_dc_t *dc, int dma_chan) 472 | { 473 | if (_spi_mux == NULL) { 474 | _spi_mux = xSemaphoreCreateMutex(); 475 | } 476 | 477 | if (lcd_conf->init_spi_bus) { 478 | //Initialize SPI Bus for LCD 479 | spi_bus_config_t buscfg = { 480 | .miso_io_num = lcd_conf->pin_num_miso, 481 | .mosi_io_num = lcd_conf->pin_num_mosi, 482 | .sclk_io_num = lcd_conf->pin_num_clk, 483 | .quadwp_io_num = -1, 484 | .quadhd_io_num = -1, 485 | }; 486 | spi_bus_initialize(lcd_conf->spi_host, &buscfg, dma_chan); 487 | } 488 | 489 | spi_device_interface_config_t devcfg = { 490 | // Use low speed to read ID. 491 | .clock_speed_hz = 1 * 1000 * 1000, //Clock out frequency 492 | .mode = 0, //SPI mode 0 493 | .spics_io_num = lcd_conf->pin_num_cs, //CS pin 494 | .queue_size = 7, //We want to be able to queue 7 transactions at a time 495 | .pre_cb = lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line 496 | }; 497 | 498 | // Use high speed to write LCD 499 | devcfg.clock_speed_hz = lcd_conf->clk_freq; 500 | //devcfg.flags = SPI_DEVICE_HALFDUPLEX; 501 | spi_bus_add_device(lcd_conf->spi_host, &devcfg, spi_wr_dev); 502 | 503 | return ESP_OK; 504 | } 505 | void lcd_spi_cmd(spi_device_handle_t spi, const uint8_t cmd, lcd_dc_t *dc) 506 | { 507 | esp_err_t ret; 508 | dc->dc_level = LCD_CMD_LEV; 509 | spi_transaction_t t = { 510 | .length = 8, // Command is 8 bits 511 | .tx_buffer = &cmd, // The data is the cmd itself 512 | .user = (void *) dc, // D/C needs to be set to 0 513 | }; 514 | ret = _lcd_spi_send(spi, &t); // Transmit! 515 | 516 | assert(ret == ESP_OK); // Should have had no issues. 517 | } 518 | 519 | void lcd_spi_send_uint16_r(spi_device_handle_t spi, const uint16_t data, int32_t repeats, lcd_dc_t *dc) 520 | { 521 | uint32_t i; 522 | uint32_t word = data << 16 | data; 523 | uint32_t word_tmp[16]; 524 | spi_transaction_t t; 525 | dc->dc_level = LCD_DATA_LEV; 526 | 527 | while (repeats > 0) { 528 | uint16_t bytes_to_transfer = MIN(repeats * sizeof(uint16_t), SPIFIFOSIZE * sizeof(uint32_t)); 529 | for (i = 0; i < (bytes_to_transfer + 3) / 4; i++) { 530 | word_tmp[i] = word; 531 | } 532 | 533 | memset(&t, 0, sizeof(t)); //Zero out the transaction 534 | t.length = bytes_to_transfer * 8; //Len is in bytes, transaction length is in bits. 535 | t.tx_buffer = word_tmp; //Data 536 | t.user = (void *) dc; //D/C needs to be set to 1 537 | _lcd_spi_send(spi, &t); //Transmit! 538 | repeats -= bytes_to_transfer / sizeof(uint16_t); 539 | } 540 | } 541 | void lcd_spi_data(spi_device_handle_t spi, const uint8_t *data, int len, lcd_dc_t *dc) 542 | { 543 | esp_err_t ret; 544 | if (len == 0) { 545 | return; //no need to send anything 546 | } 547 | dc->dc_level = LCD_DATA_LEV; 548 | 549 | spi_transaction_t t = { 550 | .length = len * 8, // Len is in bytes, transaction length is in bits. 551 | .tx_buffer = data, // Data 552 | .user = (void *) dc, // D/C needs to be set to 1 553 | }; 554 | ret = _lcd_spi_send(spi, &t); // Transmit! 555 | assert(ret == ESP_OK); // Should have had no issues. 556 | } 557 | /****************************************************************************** 558 | DECLARE PRIVATE FUNCTIONS 559 | ******************************************************************************/ 560 | void lcd_config(lcd_conf_t *lcd_conf); 561 | void _fastSendRep(uint16_t val, int rep_num); 562 | void _fastSendBuf(const uint16_t* buf, int point_num, bool swap); 563 | void transmitCmdData(uint8_t cmd, uint32_t data); 564 | void transmitDatas(uint8_t* data, int length); 565 | void transmitCmd(uint8_t cmd); 566 | void transmitDataRepat(uint16_t data, int32_t repeats); 567 | 568 | /****************************************************************************** 569 | DEFINE PUBLIC FUNCTIONS 570 | ******************************************************************************/ 571 | void lcd_init(void) 572 | { 573 | if(lcd_info.spi_mux == NULL) 574 | { 575 | lcd_info.spi_mux = xSemaphoreCreateRecursiveMutex(); 576 | } 577 | 578 | lcd_config(&lcd_info.lcd_conf); 579 | 580 | mb_library_config_t(); 581 | 582 | gpio_config_t io_conf; 583 | io_conf.intr_type = GPIO_PIN_INTR_DISABLE; 584 | io_conf.mode = GPIO_MODE_OUTPUT; 585 | io_conf.pin_bit_mask = ((uint64_t)1 << CONFIG_LIBRARY_CS_GPIO) ;// GPIO_OUTPUT_PIN_SEL; 586 | io_conf.pull_down_en = 0; 587 | io_conf.pull_up_en = 0; 588 | gpio_config(&io_conf); 589 | 590 | gpio_set_level(CONFIG_LIBRARY_CS_GPIO,0); 591 | library_spi_cmd(spi_wr_library, 0x66); 592 | library_spi_cmd(spi_wr_library, 0x99); 593 | gpio_set_level(CONFIG_LIBRARY_CS_GPIO,1); 594 | } 595 | void lcd_write_command(uint8_t cmd, uint8_t *data, uint8_t len, uint8_t databytes); 596 | void lcd_rotate(uint16_t angle) 597 | { 598 | uint8_t data[16]; 599 | 600 | if(angle == 0) 601 | { 602 | data[0] = 0xA8; 603 | lcd_write_command(ST77XX_MADCTL, data, 1, 1); 604 | } 605 | else if(angle == 90) 606 | { 607 | data[0] = 0x08; 608 | lcd_write_command(ST77XX_MADCTL, data, 1, 1); 609 | } 610 | else if(angle == 180) 611 | { 612 | data[0] = 0x68; 613 | lcd_write_command(ST77XX_MADCTL, data, 1, 1); 614 | } 615 | else if(angle == 270) 616 | { 617 | data[0] = 0xC8; 618 | lcd_write_command(ST77XX_MADCTL, data, 1, 1); 619 | } 620 | } 621 | 622 | void lcd_set_bg_brightness(uint16_t percentage) 623 | { 624 | // not implement 625 | } 626 | 627 | void lcd_on(void) 628 | { 629 | aw_pinMode(lcd_info.lcd_conf.pin_num_bckl, AW_GPIO_MODE_OUTPUT); 630 | aw_digitalWrite(lcd_info.lcd_conf.pin_num_bckl, (lcd_info.lcd_conf.bckl_active_level) & 0x01); 631 | } 632 | 633 | 634 | void lcd_off(void) 635 | { 636 | aw_pinMode(lcd_info.lcd_conf.pin_num_bckl, AW_GPIO_MODE_OUTPUT); 637 | aw_digitalWrite(lcd_info.lcd_conf.pin_num_bckl, (lcd_info.lcd_conf.bckl_active_level) & 0x00); 638 | } 639 | 640 | void lcd_write_command(uint8_t cmd, uint8_t *data, uint8_t len, uint8_t databytes) 641 | { 642 | if(len <= 0) 643 | { 644 | return; 645 | } 646 | 647 | lcd_init_cmd_t lcd_cmd; 648 | lcd_cmd.cmd = cmd; 649 | 650 | memcpy(lcd_cmd.data, data, len & 0x0f); 651 | lcd_cmd.databytes = databytes; 652 | 653 | xSemaphoreTakeRecursive(lcd_info.spi_mux, portMAX_DELAY); 654 | if(lcd_cmd.databytes != 0xff) 655 | { 656 | lcd_spi_cmd(lcd_info.spi_wr, lcd_cmd.cmd, &lcd_info.dc); 657 | lcd_spi_data(lcd_info.spi_wr, lcd_cmd.data, lcd_cmd.databytes & 0x1F, &lcd_info.dc); 658 | if(lcd_cmd.databytes & 0x80) 659 | { 660 | vTaskDelay(100 / portTICK_RATE_MS); 661 | } 662 | } 663 | xSemaphoreGiveRecursive(lcd_info.spi_mux); 664 | } 665 | 666 | void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) 667 | { 668 | xSemaphoreTakeRecursive(lcd_info.spi_mux, portMAX_DELAY); 669 | transmitCmdData(LCD_CASET, MAKEWORD(x0 >> 8, ((x0 & 0xFF) + LCD_XSTART), x1 >> 8, ((x1 & 0xFF) + LCD_XSTART))); 670 | transmitCmdData(LCD_PASET, MAKEWORD(y0 >> 8, ((y0 & 0xFF) + LCD_YSTART), y1 >> 8, ((y1 & 0xFF) + LCD_YSTART))); 671 | transmitCmd(LCD_RAMWR); // write to RAM 672 | xSemaphoreGiveRecursive(lcd_info.spi_mux); 673 | } 674 | void lcd_start() 675 | { 676 | xSemaphoreTakeRecursive(lcd_info.spi_mux, portMAX_DELAY); 677 | } 678 | void lcd_stop() 679 | { 680 | xSemaphoreGiveRecursive(lcd_info.spi_mux); 681 | } 682 | void lcd_draw(const uint16_t *bitmap, int16_t w, int16_t h) 683 | { 684 | 685 | lcd_start(); 686 | setAddrWindow(0, 0, w-1, h-1); 687 | _fastSendBuf(bitmap,w*h,false); 688 | lcd_stop(); 689 | } 690 | uint16_t color24to16(uint32_t color888) 691 | { 692 | uint16_t r = (color888 >> 8) & 0xF800; 693 | uint16_t g = (color888 >> 5) & 0x07E0; 694 | uint16_t b = (color888 >> 3) & 0x001F; 695 | 696 | return (r | g | b); 697 | } 698 | /****************************************************************************** 699 | DEFINE PRIVATE FUNCTIONS 700 | ******************************************************************************/ 701 | void lcd_config(lcd_conf_t *lcd_conf) 702 | { 703 | lcd_info.dc.dc_io = lcd_conf->pin_num_dc; 704 | // Initialize non-SPI GPIOs 705 | aw_pinMode(lcd_conf->pin_num_dc, AW_GPIO_MODE_OUTPUT); 706 | aw_pinMode(lcd_conf->pin_num_rst, AW_GPIO_MODE_OUTPUT); 707 | aw_digitalWrite(lcd_conf->pin_num_rst, (lcd_conf->rst_active_level) & 0x1); 708 | vTaskDelay(100 / portTICK_RATE_MS); 709 | aw_digitalWrite(lcd_conf->pin_num_rst, (~(lcd_conf->rst_active_level)) & 0x1); 710 | vTaskDelay(100 / portTICK_RATE_MS); 711 | 712 | lcd_spi_init(lcd_conf, &lcd_info.spi_wr, &lcd_info.dc, lcd_info.dma_chan); 713 | 714 | // Send all the init commands of stt35 715 | int cmd_id = 0; 716 | const lcd_init_cmd_t* lcd_init_cmds = NULL; 717 | lcd_init_cmds = st7735_init_cmds; 718 | assert(lcd_init_cmds != NULL); 719 | while (lcd_init_cmds[cmd_id].databytes != 0xff) 720 | { 721 | lcd_spi_cmd(lcd_info.spi_wr, lcd_init_cmds[cmd_id].cmd, &lcd_info.dc); 722 | lcd_spi_data(lcd_info.spi_wr, lcd_init_cmds[cmd_id].data, lcd_init_cmds[cmd_id].databytes & 0x1F, &lcd_info.dc); 723 | if(lcd_init_cmds[cmd_id].databytes & 0x80) 724 | { 725 | vTaskDelay(100 / portTICK_RATE_MS); 726 | } 727 | cmd_id++; 728 | } 729 | 730 | aw_pinMode(lcd_conf->pin_num_bckl, AW_GPIO_MODE_OUTPUT); 731 | aw_digitalWrite(lcd_conf->pin_num_bckl, (lcd_conf->bckl_active_level) & 0x1); 732 | } 733 | 734 | void _fastSendRep(uint16_t val, int rep_num) 735 | { 736 | int point_num = rep_num; 737 | int gap_point = lcd_info.dma_buf_size; 738 | gap_point = (gap_point > point_num ? point_num : gap_point); 739 | 740 | uint16_t* data_buf = (uint16_t*) malloc(gap_point * sizeof(uint16_t)); 741 | int offset = 0; 742 | while(point_num > 0) 743 | { 744 | for (int i = 0; i < gap_point; i++) 745 | { 746 | data_buf[i] = val; 747 | } 748 | 749 | int trans_points = point_num > gap_point ? gap_point : point_num; 750 | transmitDatas((uint8_t*) (data_buf), sizeof(uint16_t) * trans_points); 751 | offset += trans_points; 752 | point_num -= trans_points; 753 | } 754 | free(data_buf); 755 | data_buf = NULL; 756 | } 757 | 758 | void _fastSendBuf(const uint16_t* buf, int point_num, bool swap) 759 | { 760 | 761 | if((point_num * sizeof(uint16_t)) <= (16 * sizeof(uint32_t))) 762 | { 763 | transmitDatas((uint8_t*) buf, sizeof(uint16_t) * point_num); 764 | } 765 | else 766 | { 767 | int gap_point = lcd_info.dma_buf_size; 768 | int offset = 0; 769 | while(point_num > 0) 770 | { 771 | int trans_points = point_num > gap_point ? gap_point : point_num; 772 | transmitDatas((uint8_t*) (buf + offset), trans_points * sizeof(uint16_t)); 773 | offset += trans_points; 774 | point_num -= trans_points; 775 | } 776 | } 777 | } 778 | 779 | void transmitCmdData(uint8_t cmd, uint32_t data) 780 | { 781 | xSemaphoreTakeRecursive(lcd_info.spi_mux, portMAX_DELAY); 782 | lcd_spi_cmd(lcd_info.spi_wr, cmd, &lcd_info.dc); 783 | lcd_spi_data(lcd_info.spi_wr, (uint8_t *)&data, 4, &lcd_info.dc); 784 | xSemaphoreGiveRecursive(lcd_info.spi_mux); 785 | } 786 | 787 | void transmitDatas(uint8_t* data, int length) 788 | { 789 | xSemaphoreTakeRecursive(lcd_info.spi_mux, portMAX_DELAY); 790 | lcd_spi_data(lcd_info.spi_wr, (uint8_t *)data, length, &lcd_info.dc); 791 | xSemaphoreGiveRecursive(lcd_info.spi_mux); 792 | } 793 | 794 | void transmitCmd(uint8_t cmd) 795 | { 796 | xSemaphoreTakeRecursive(lcd_info.spi_mux, portMAX_DELAY); 797 | lcd_spi_cmd(lcd_info.spi_wr, cmd, &lcd_info.dc); 798 | xSemaphoreGiveRecursive(lcd_info.spi_mux); 799 | } 800 | 801 | void transmitDataRepat(uint16_t data, int32_t repeats) 802 | { 803 | xSemaphoreTakeRecursive(lcd_info.spi_mux, portMAX_DELAY); 804 | lcd_spi_send_uint16_r(lcd_info.spi_wr, data, repeats, &lcd_info.dc); 805 | xSemaphoreGiveRecursive(lcd_info.spi_mux); 806 | } 807 | -------------------------------------------------------------------------------- /lib/cyberpi/src/lcd/lcd.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_H 2 | #define __LCD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "../io/aw9523b.h" 8 | #include "driver/spi_master.h" 9 | #include "freertos/FreeRTOS.h" 10 | #include "freertos/semphr.h" 11 | #include "freertos/task.h" 12 | 13 | 14 | #define ST_CMD_DELAY 0x80 // special signifier for command lists 15 | 16 | #define ST77XX_NOP 0x00 17 | #define ST77XX_SWRESET 0x01 18 | #define ST77XX_RDDID 0x04 19 | #define ST77XX_RDDST 0x09 20 | 21 | #define ST77XX_SLPIN 0x10 22 | #define ST77XX_SLPOUT 0x11 23 | #define ST77XX_PTLON 0x12 24 | #define ST77XX_NORON 0x13 25 | 26 | #define ST77XX_INVOFF 0x20 27 | #define ST77XX_INVON 0x21 28 | #define ST77XX_DISPOFF 0x28 29 | #define ST77XX_DISPON 0x29 30 | #define ST77XX_CASET 0x2A 31 | #define ST77XX_RASET 0x2B 32 | #define ST77XX_RAMWR 0x2C 33 | #define ST77XX_RAMRD 0x2E 34 | 35 | #define ST77XX_PTLAR 0x30 36 | #define ST77XX_TEOFF 0x34 37 | #define ST77XX_TEON 0x35 38 | #define ST77XX_MADCTL 0x36 39 | #define ST77XX_COLMOD 0x3A 40 | 41 | #define ST77XX_MADCTL_MY 0x80 42 | #define ST77XX_MADCTL_MX 0x40 43 | #define ST77XX_MADCTL_MV 0x20 44 | #define ST77XX_MADCTL_ML 0x10 45 | #define ST77XX_MADCTL_RGB 0x00 46 | 47 | #define ST77XX_RDID1 0xDA 48 | #define ST77XX_RDID2 0xDB 49 | #define ST77XX_RDID3 0xDC 50 | #define ST77XX_RDID4 0xDD 51 | 52 | // ST7735 commands 53 | #define ST7735_MADCTL_BGR 0x08 54 | #define ST7735_MADCTL_MH 0x04 55 | 56 | #define ST7735_FRMCTR1 0xB1 57 | #define ST7735_FRMCTR2 0xB2 58 | #define ST7735_FRMCTR3 0xB3 59 | #define ST7735_INVCTR 0xB4 60 | #define ST7735_DISSET5 0xB6 61 | 62 | #define ST7735_PWCTR1 0xC0 63 | #define ST7735_PWCTR2 0xC1 64 | #define ST7735_PWCTR3 0xC2 65 | #define ST7735_PWCTR4 0xC3 66 | #define ST7735_PWCTR5 0xC4 67 | #define ST7735_VMCTR1 0xC5 68 | 69 | #define ST7735_PWCTR6 0xFC 70 | 71 | #define ST7735_GMCTRP1 0xE0 72 | #define ST7735_GMCTRN1 0xE1 73 | 74 | typedef struct { 75 | uint8_t cmd; 76 | uint8_t data[16]; 77 | uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds. 78 | } lcd_init_cmd_t; 79 | 80 | 81 | 82 | /****************************************************************************** 83 | DEFINE MACROS 84 | ******************************************************************************/ 85 | #define TAG ("esp32_lcd") 86 | 87 | #define LCD_TFTHEIGHT 128 88 | #define LCD_TFTWIDTH 128 89 | #define LCD_XSTART (3) 90 | #define LCD_YSTART (2) 91 | 92 | #define LCD_INVOFF 0x20 93 | #define LCD_INVON 0x21 94 | 95 | #define LCD_CASET 0x2A 96 | #define LCD_PASET 0x2B 97 | #define LCD_RAMWR 0x2C 98 | #define LCD_MADCTL 0x36 99 | 100 | // Color definitions 101 | #define COLOR_BLACK 0x0000 /* 0, 0, 0 */ 102 | #define COLOR_NAVY 0x000F /* 0, 0, 128 */ 103 | #define COLOR_DARKGREEN 0x03E0 /* 0, 128, 0 */ 104 | #define COLOR_DARKCYAN 0x03EF /* 0, 128, 128 */ 105 | #define COLOR_MAROON 0x7800 /* 128, 0, 0 */ 106 | #define COLOR_PURPLE 0x780F /* 128, 0, 128 */ 107 | #define COLOR_OLIVE 0x7BE0 /* 128, 128, 0 */ 108 | #define COLOR_LIGHTGREY 0xC618 /* 192, 192, 192 */ 109 | #define COLOR_DARKGREY 0x7BEF /* 128, 128, 128 */ 110 | #define COLOR_BLUE 0x001F /* 0, 0, 255 */ 111 | #define COLOR_GREEN 0x07E0 /* 0, 255, 0 */ 112 | #define COLOR_CYAN 0x07FF /* 0, 255, 255 */ 113 | #define COLOR_RED 0xF800 /* 255, 0, 0 */ 114 | #define COLOR_MAGENTA 0xF81F /* 255, 0, 255 */ 115 | #define COLOR_YELLOW 0xFFE0 /* 255, 255, 0 */ 116 | #define COLOR_WHITE 0xFFFF /* 255, 255, 255 */ 117 | #define COLOR_ORANGE 0xFD20 /* 255, 165, 0 */ 118 | #define COLOR_GREENYELLOW 0xAFE5 /* 173, 255, 47 */ 119 | #define COLOR_PINK 0xF81F 120 | #define COLOR_SILVER 0xC618 121 | #define COLOR_GRAY 0x8410 122 | #define COLOR_LIME 0x07E0 123 | #define COLOR_TEAL 0x0410 124 | #define COLOR_FUCHSIA 0xF81F 125 | #define COLOR_ESP_BKGD 0xD185 126 | 127 | #define LCD_CMD_LEV (0) 128 | #define LCD_DATA_LEV (1) 129 | 130 | #define LCD_MOSI_GPIO (2) 131 | #define LCD_MISO_GPIO (26) // for font library 132 | #define LCD_CLK_GPIO (4) 133 | #define LCD_CS_GPIO (12) 134 | #define LCD_DC_GPIO (AW_P1_4) 135 | #define LCD_RESET_GPIO (AW_P1_5) 136 | #define LCD_BL_GPIO (AW_P1_7) 137 | #define CONFIG_LCD_SPI_NUM (1) 138 | #define CONFIG_LCD_SPI_CLOCK (20000000) 139 | #define CONFIG_LCD_BCKL_ACTIVE_LEVEL (1) 140 | 141 | #define CONFIG_LCD_MOSI_GPIO LCD_MOSI_GPIO 142 | #define CONFIG_LCD_MISO_GPIO LCD_MISO_GPIO 143 | #define CONFIG_LCD_CLK_GPIO LCD_CLK_GPIO 144 | #define CONFIG_LCD_CS_GPIO LCD_CS_GPIO 145 | #define CONFIG_LCD_DC_GPIO LCD_DC_GPIO 146 | #define CONFIG_LCD_RESET_GPIO LCD_RESET_GPIO 147 | #define CONFIG_LCD_BL_GPIO LCD_BL_GPIO 148 | 149 | #define SPIFIFOSIZE 16 150 | #define SPI_DMA_BUFFER_SIZE (1024) 151 | #define SPI_DMA_CHANNEL (1) 152 | 153 | #define SWAPBYTES(i) ((i>>8) | (i<<8)) 154 | #define MAKEWORD(b1, b2, b3, b4) ((uint32_t) ((b1) | ((b2) << 8) | ((b3) << 16) | ((b4) << 24))) 155 | 156 | #ifndef MAX 157 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) 158 | #endif 159 | #ifndef MIN 160 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 161 | #endif 162 | 163 | #define DEFAULT_BACKGROUND_COLOR (COLOR_BLACK) 164 | /****************************************************************************** 165 | DEFINE TYPES & CONSTANTS 166 | ******************************************************************************/ 167 | 168 | typedef struct { 169 | uint8_t dc_io; 170 | uint8_t dc_level; 171 | } lcd_dc_t; 172 | 173 | typedef enum { 174 | LCD_MOD_ST7789 = 1, 175 | LCD_MOD_AUTO_DET = 3, 176 | } lcd_model_t; 177 | 178 | /** 179 | * @brief struct to map GPIO to LCD pins 180 | */ 181 | typedef struct { 182 | lcd_model_t lcd_model; 183 | int8_t pin_num_miso; /*! 2 | #include 3 | #include "es8218e.h" 4 | #include "../i2c/i2c.h" 5 | 6 | static const char *ES_TAG = "ES8218E_DRIVER"; 7 | 8 | #define ES_ASSERT(a, format, b, ...) \ 9 | if ((a) != 0) { \ 10 | ESP_LOGE(ES_TAG, format, ##__VA_ARGS__); \ 11 | return b;\ 12 | } 13 | 14 | void es8218e_read_all() 15 | { 16 | for(int16_t i = 0; i < 50; i++) 17 | { 18 | uint8_t reg = i2c_read(ES8218E_ADDR, i); 19 | } 20 | } 21 | 22 | void es8218e_reset(void) 23 | { 24 | i2c_write(ES8218E_ADDR, ES8218E_RESET, 0x3f); 25 | vTaskDelay(1 / portTICK_RATE_MS); 26 | i2c_write(ES8218E_ADDR, ES8218E_RESET, 0x00); 27 | i2c_write(ES8218E_ADDR, ES8218E_RESET, 0x80); 28 | } 29 | 30 | void es8218e_start(void) 31 | { 32 | i2c_write(ES8218E_ADDR, ES8218E_RESET, 0x3f); 33 | i2c_write(ES8218E_ADDR, ES8218E_RESET, 0x00); 34 | i2c_write(ES8218E_ADDR, ES8218E_CLOCK_MANAGER1, 0x10); 35 | vTaskDelay(1 / portTICK_RATE_MS); 36 | i2c_write(ES8218E_ADDR, ES8218E_CLOCK_MANAGER1, 0x00); 37 | i2c_write(ES8218E_ADDR, ES8218E_CLOCK_MANAGER1, 0x0f); //slave mode 38 | i2c_write(ES8218E_ADDR, ES8218E_CLOCK_MANAGER2, 0x01); //1 39 | i2c_write(ES8218E_ADDR, ES8218E_CLOCK_MANAGER3, 0x20); //4096000/16000/8 = 32 40 | // mb_esp32_i2c_master_write_reg_t(ES8218E_ADDR, 0x06, 0x00); // 41 | i2c_write(ES8218E_ADDR, ES8218E_SERIAL_DATA_PORT, 0x0c); //16 bit data, i2s format(0x0c) //left justify 0x0d 42 | i2c_write(ES8218E_ADDR, ES8218E_ADC_CONTROL2, 0x18); //high pass filter //0x18 open 0x00 close 43 | //0x18(adc soft ramp and high pass filter) //0x10(adc soft ramp) 44 | i2c_write(ES8218E_ADDR, ES8218E_ADC_CONTROL6, 0xA0); //ALCLVL=-1.5db 45 | i2c_write(ES8218E_ADDR, ES8218E_SYSTEM_CONTROL6, 0x30); //POWER-INI time 46 | i2c_write(ES8218E_ADDR, ES8218E_SYSTEM_CONTROL7, 0x20); //POWER-UP time 47 | i2c_write(ES8218E_ADDR, ES8218E_ADC_CONTROL10, 0x04); //HPF slow setting coeff defalut value 48 | i2c_write(ES8218E_ADDR, ES8218E_ADC_CONTROL11, 0x04); //HPF fast setting coeff defalut value 49 | i2c_write(ES8218E_ADDR, ES8218E_ADC_CONTROL1, 0x32); //LIN2/RIN2, PGA=+18db(0x30) PGA = 0db(0x20) //0x20 50 | //低三位,0(0db) 1(3.5db) 2(6db) 3(9db) 4(12db) 5(15db) 6(18db) 51 | i2c_write(ES8218E_ADDR, ES8218E_SYSTEM_CONTROL1, 0x00); //POWER ON 52 | i2c_write(ES8218E_ADDR, ES8218E_RESET, 0x80); //IC start 53 | 54 | uint8_t pga_gain = 0xc0 | (uint8_t)((20.5 + 6.5)/1.5); 55 | i2c_write(ES8218E_ADDR, ES8218E_ADC_CONTROL4, pga_gain); //ALC ON 56 | // mb_esp32_i2c_master_write_reg_t(ES8218E_ADDR, ES8218E_ADC_CONTROL4, 0x1c); //ALC OFF 57 | i2c_write(ES8218E_ADDR, ES8218E_ADCVOLUMEL, 0x00); //0db 58 | } 59 | 60 | void es8218e_stop( ) 61 | { 62 | i2c_write(ES8218E_ADDR, ES8218E_CLOCK_MANAGER1, 0x80); //enable dac 63 | i2c_write(ES8218E_ADDR, ES8218E_CLOCK_MANAGER1, 0x00); // 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2 64 | } 65 | 66 | void es8218e_config_fmt(es_i2s_fmt_t fmt) 67 | { 68 | uint8_t reg = 0; 69 | reg = i2c_read(ES8218E_ADDR, ES8218E_SERIAL_DATA_PORT); 70 | reg = reg & 0xfc; 71 | i2c_write(ES8218E_ADDR, ES8218E_SERIAL_DATA_PORT, reg | fmt); 72 | } -------------------------------------------------------------------------------- /lib/cyberpi/src/microphone/es8218e.h: -------------------------------------------------------------------------------- 1 | #ifndef __ES8218E__ 2 | #define __ES8218E__ 3 | 4 | #define ES8218E_ADDR 0x10 /*!< 0x11:CE=1;0x10:CE=0*/ 5 | 6 | 7 | /* ES8218E register */ 8 | 9 | #define ES8218E_RESET 0x00 10 | 11 | #define ES8218E_CLOCK_MANAGER1 0x01 12 | #define ES8218E_CLOCK_MANAGER2 0x02 13 | #define ES8218E_CLOCK_MANAGER3 0x03 14 | #define ES8218E_CLOCK_MANAGER4 0x04 15 | #define ES8218E_CLOCK_MANAGER5 0x05 16 | #define ES8218E_CLOCK_MANAGER6 0x06 17 | 18 | #define ES8218E_SERIAL_DATA_PORT 0x07 19 | 20 | #define ES8218E_SYSTEM_CONTROL1 0x08 21 | #define ES8218E_SYSTEM_CONTROL2 0x09 22 | #define ES8218E_SYSTEM_CONTROL3 0x0a 23 | #define ES8218E_SYSTEM_CONTROL4 0x0b 24 | #define ES8218E_SYSTEM_CONTROL5 0x0c 25 | #define ES8218E_SYSTEM_CONTROL6 0x0d 26 | #define ES8218E_SYSTEM_CONTROL7 0x0e 27 | 28 | /* ADC */ 29 | #define ES8218E_ADC_CONTROL1 0x0f 30 | #define ES8218E_ADC_CONTROL2 0x10 31 | #define ES8218E_ADCVOLUMEL 0x11 32 | #define ES8218E_ADC_CONTROL4 0x12 33 | #define ES8218E_ADC_CONTROL5 0x13 34 | #define ES8218E_ADC_CONTROL6 0x14 35 | #define ES8218E_ADC_CONTROL7 0x15 36 | #define ES8218E_ADC_CONTROL8 0x16 37 | #define ES8218E_ADC_CONTROL9 0x17 38 | #define ES8218E_ADC_CONTROL10 0x18 39 | #define ES8218E_ADC_CONTROL11 0x19 40 | 41 | /* Equalizer to process ADC data. */ 42 | #define ES8218E_ADC_CONTROL12 0x1a 43 | #define ES8218E_ADC_CONTROL13 0x1b 44 | #define ES8218E_ADC_CONTROL14 0x1c 45 | #define ES8218E_ADC_CONTROL15 0x1d 46 | #define ES8218E_ADC_CONTROL16 0x1e 47 | #define ES8218E_ADC_CONTROL17 0x1f 48 | #define ES8218E_ADC_CONTROL18 0x20 49 | #define ES8218E_ADC_CONTROL19 0x21 50 | #define ES8218E_ADC_CONTROL20 0x22 51 | 52 | typedef enum { 53 | BIT_LENGTH_MIN = -1, 54 | BIT_LENGTH_16BITS = 0x03, 55 | BIT_LENGTH_18BITS = 0x02, 56 | BIT_LENGTH_20BITS = 0x01, 57 | BIT_LENGTH_24BITS = 0x00, 58 | BIT_LENGTH_32BITS = 0x04, 59 | BIT_LENGTH_MAX, 60 | } es_bits_length_t; 61 | 62 | typedef enum { 63 | MCLK_DIV_MIN = -1, 64 | MCLK_DIV_1 = 1, 65 | MCLK_DIV_2 = 2, 66 | MCLK_DIV_3 = 3, 67 | MCLK_DIV_4 = 4, 68 | MCLK_DIV_6 = 5, 69 | MCLK_DIV_8 = 6, 70 | MCLK_DIV_9 = 7, 71 | MCLK_DIV_11 = 8, 72 | MCLK_DIV_12 = 9, 73 | MCLK_DIV_16 = 10, 74 | MCLK_DIV_18 = 11, 75 | MCLK_DIV_22 = 12, 76 | MCLK_DIV_24 = 13, 77 | MCLK_DIV_33 = 14, 78 | MCLK_DIV_36 = 15, 79 | MCLK_DIV_44 = 16, 80 | MCLK_DIV_48 = 17, 81 | MCLK_DIV_66 = 18, 82 | MCLK_DIV_72 = 19, 83 | MCLK_DIV_5 = 20, 84 | MCLK_DIV_10 = 21, 85 | MCLK_DIV_15 = 22, 86 | MCLK_DIV_17 = 23, 87 | MCLK_DIV_20 = 24, 88 | MCLK_DIV_25 = 25, 89 | MCLK_DIV_30 = 26, 90 | MCLK_DIV_32 = 27, 91 | MCLK_DIV_34 = 28, 92 | MCLK_DIV_7 = 29, 93 | MCLK_DIV_13 = 30, 94 | MCLK_DIV_14 = 31, 95 | MCLK_DIV_MAX, 96 | } es_sclk_div_t; 97 | 98 | typedef enum { 99 | LCLK_DIV_MIN = -1, 100 | LCLK_DIV_128 = 0, 101 | LCLK_DIV_192 = 1, 102 | LCLK_DIV_256 = 2, 103 | LCLK_DIV_384 = 3, 104 | LCLK_DIV_512 = 4, 105 | LCLK_DIV_576 = 5, 106 | LCLK_DIV_768 = 6, 107 | LCLK_DIV_1024 = 7, 108 | LCLK_DIV_1152 = 8, 109 | LCLK_DIV_1408 = 9, 110 | LCLK_DIV_1536 = 10, 111 | LCLK_DIV_2112 = 11, 112 | LCLK_DIV_2304 = 12, 113 | 114 | LCLK_DIV_125 = 16, 115 | LCLK_DIV_136 = 17, 116 | LCLK_DIV_250 = 18, 117 | LCLK_DIV_272 = 19, 118 | LCLK_DIV_375 = 20, 119 | LCLK_DIV_500 = 21, 120 | LCLK_DIV_544 = 22, 121 | LCLK_DIV_750 = 23, 122 | LCLK_DIV_1000 = 24, 123 | LCLK_DIV_1088 = 25, 124 | LCLK_DIV_1496 = 26, 125 | LCLK_DIV_1500 = 27, 126 | LCLK_DIV_MAX, 127 | } es_lclk_div_t; 128 | 129 | typedef enum { 130 | D2SE_PGA_GAIN_MIN = -1, 131 | D2SE_PGA_GAIN_DIS = 0, 132 | D2SE_PGA_GAIN_EN = 1, 133 | D2SE_PGA_GAIN_MAX =2, 134 | } es_d2se_pga_t; 135 | 136 | typedef enum { 137 | ADC_INPUT_MIN = -1, 138 | ADC_INPUT_LINPUT1_RINPUT1 = 0x00, 139 | ADC_INPUT_MIC1 = 0x05, 140 | ADC_INPUT_MIC2 = 0x06, 141 | ADC_INPUT_LINPUT2_RINPUT2 = 0x50, 142 | ADC_INPUT_DIFFERENCE = 0xf0, 143 | ADC_INPUT_MAX, 144 | } es_adc_input_t; 145 | 146 | typedef enum { 147 | DAC_OUTPUT_MIN = -1, 148 | DAC_OUTPUT_LOUT1 = 0x04, 149 | DAC_OUTPUT_LOUT2 = 0x08, 150 | DAC_OUTPUT_SPK = 0x09, 151 | DAC_OUTPUT_ROUT1 = 0x10, 152 | DAC_OUTPUT_ROUT2 = 0x20, 153 | DAC_OUTPUT_ALL = 0x3c, 154 | DAC_OUTPUT_MAX, 155 | } es_dac_output_t; 156 | 157 | typedef enum { 158 | MIC_GAIN_MIN = -1, 159 | MIC_GAIN_0DB = 0, 160 | MIC_GAIN_3DB = 3, 161 | MIC_GAIN_6DB = 6, 162 | MIC_GAIN_9DB = 9, 163 | MIC_GAIN_12DB = 12, 164 | MIC_GAIN_15DB = 15, 165 | MIC_GAIN_18DB = 18, 166 | MIC_GAIN_21DB = 21, 167 | MIC_GAIN_24DB = 24, 168 | MIC_GAIN_MAX, 169 | } es_mic_gain_t; 170 | 171 | typedef enum { 172 | ES_MODULE_MIN = -1, 173 | ES_MODULE_ADC = 0x01, 174 | ES_MODULE_DAC = 0x02, 175 | ES_MODULE_ADC_DAC = 0x03, 176 | ES_MODULE_LINE = 0x04, 177 | ES_MODULE_MAX 178 | } es_module_t; 179 | 180 | typedef enum { 181 | ES_MODE_MIN = -1, 182 | ES_MODE_SLAVE = 0x00, 183 | ES_MODE_MASTER = 0x01, 184 | ES_MODE_MAX, 185 | } es_mode_t; 186 | 187 | typedef enum { 188 | ES_I2S_MIN = -1, 189 | ES_I2S_NORMAL = 0, 190 | ES_I2S_LEFT = 1, 191 | ES_I2S_RIGHT = 2, 192 | ES_I2S_DSP = 3, 193 | ES_I2S_MAX 194 | } es_i2s_fmt_t; 195 | 196 | /** 197 | * @brief Configure ES8388 clock 198 | */ 199 | typedef struct { 200 | es_sclk_div_t sclk_div; /*!< bits clock divide */ 201 | es_lclk_div_t lclk_div; /*!< WS clock divide */ 202 | } es_i2s_clock_t; 203 | 204 | void es8218e_config_fmt(es_i2s_fmt_t cfg); 205 | void es8218e_start(void); 206 | void es8218e_stop(void); 207 | void es8218e_read_all(); 208 | #endif -------------------------------------------------------------------------------- /lib/cyberpi/src/sound/synth.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYNTH 2 | #define _SYNTH 3 | //************************************************************************************* 4 | // Arduino synth V4.1 5 | // Optimized audio driver, modulation engine, envelope engine. 6 | // 7 | // Dzl/Illutron 2014 8 | // 9 | //************************************************************************************* 10 | #include "tables.h" 11 | 12 | #define DIFF 1 13 | #define CHA 2 14 | #define CHB 3 15 | #define CHC 4 16 | 17 | #define SINE 0 18 | #define RAMP 1 19 | #define TRIANGLE 2 20 | #define SQUARE 3 21 | #define NOISE 4 22 | #define SAW 5 23 | #define A 6 //waves A-F added by AM 2015 24 | #define B 7 25 | #define C 8 26 | #define D 9 27 | #define E 10 28 | #define F 11 29 | #define G 12 30 | #define H 13 31 | #define I 14 32 | 33 | 34 | #define FSample 20000.0 //-Sample rate (NOTE: must match tables.h) 35 | 36 | volatile unsigned int PCW[16] = { 37 | 0, 0, 0, 0,0, 0, 0, 0, 38 | 0, 0, 0, 0,0, 0, 0, 0}; //-Wave phase accumulators 39 | volatile unsigned int FTW[16] = { 40 | 1000, 200, 300, 400,1000, 200, 300, 400, 41 | 1000, 200, 300, 400,1000, 200, 300, 400}; //-Wave frequency tuning words 42 | volatile unsigned char AMP[16] = { 43 | 255, 255, 255, 255,255, 255, 255, 255, 44 | 255, 255, 255, 255,255, 255, 255, 255}; //-Wave amplitudes [0-255] 45 | volatile unsigned int PITCH[16] = { 46 | 500, 500, 500, 500,500, 500, 500, 500, 47 | 500, 500, 500, 500,500, 500, 500, 500}; //-Voice pitch 48 | volatile int MOD[16] = { 49 | 20, 0, 64, 127,20, 0, 64, 127, 50 | 20, 0, 64, 127,20, 0, 64, 127}; //-Voice envelope modulation [0-127 64=no mod. <64 pitch down >64 pitch up] 51 | volatile unsigned int wavs[16]; //-Wave table selector [address of wave in memory] 52 | volatile unsigned int envs[16]; //-Envelope selector [address of envelope in memory] 53 | volatile unsigned int EPCW[16] = { 54 | 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000}; //-Envelope phase accumulator 55 | volatile unsigned int EFTW[16] = { 56 | 10, 10, 10, 10, 10, 10, 10, 10,10, 10, 10, 10, 10, 10, 10, 10}; //-Envelope speed tuning word 57 | volatile unsigned char divider = 8; //-Sample rate decimator for envelope 58 | volatile unsigned int tim = 0; 59 | volatile unsigned char tik = 0; 60 | volatile unsigned char output_mode; 61 | 62 | //variables added for MintySynth: 63 | unsigned char volume[16]={10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10}; 64 | typedef void (*AudioBack)(uint8_t* audio_buf,uint16_t audio_buf_len); 65 | class MSynth 66 | { 67 | public: 68 | 69 | MSynth() 70 | { 71 | _audioBufLength = 2048; 72 | _audioBufIndex = 0; 73 | _instrumentId = 8; 74 | _trackCount = 16; 75 | _audioBuf = (uint8_t*)malloc(_audioBufLength); 76 | } 77 | ~MSynth() 78 | { 79 | free(_audioBuf); 80 | _audioBufLength = 0; 81 | } 82 | //********************************************************************* 83 | // Startup default 84 | //********************************************************************* 85 | 86 | void begin(AudioBack audioBack) 87 | { 88 | _audioBack = audioBack; 89 | output_mode=CHA; 90 | for(int i=0;i<_trackCount;i++) 91 | { 92 | wavs[i] = (unsigned int)EmptyTable; 93 | volume[i] = 8; 94 | } 95 | } 96 | void setInstrument(uint8_t instrumentId) 97 | { 98 | _instrumentId = instrumentId>14?14:(instrumentId<0?0:instrumentId); 99 | } 100 | void setVolume(unsigned char voice,uint8_t vol) 101 | { 102 | volume[voice] = vol; 103 | } 104 | //********************************************************************* 105 | // Setup all voice parameters in MIDI range 106 | // voice[0-3],wave[0-13],pitch[0-127],envelope[0-4],length[0-127],mod[0-127:64=no mod] 107 | //********************************************************************* 108 | 109 | void setupVoice(unsigned char voice, unsigned char wave, unsigned char pitch, unsigned char env, unsigned char length, unsigned int mod) 110 | { 111 | setWave(voice,wave); 112 | setPitch(voice,pitch); 113 | setEnvelope(voice,env); 114 | setLength(voice,length); 115 | setMod(voice,mod); 116 | } 117 | 118 | //********************************************************************* 119 | // Setup wave [0-6] 120 | //********************************************************************* 121 | 122 | void setWave(unsigned char voice, unsigned char wave) 123 | { 124 | 125 | switch (wave) 126 | { 127 | case SINE: 128 | wavs[voice] = (unsigned int)SinTable; 129 | break; 130 | case TRIANGLE: 131 | wavs[voice] = (unsigned int)TriangleTable; 132 | break; 133 | case SQUARE: 134 | wavs[voice] = (unsigned int)SquareTable; 135 | break; 136 | case SAW: 137 | wavs[voice] = (unsigned int)SawTable; 138 | break; 139 | case RAMP: 140 | wavs[voice] = (unsigned int)RampTable; 141 | break; 142 | case NOISE: 143 | wavs[voice] = (unsigned int)NoiseTable; 144 | break; 145 | case A: 146 | wavs[voice] = (unsigned int)ATable; 147 | break; 148 | case B: 149 | wavs[voice] = (unsigned int)BTable; 150 | break; 151 | case C: 152 | wavs[voice] = (unsigned int)CTable; 153 | break; 154 | case D: 155 | wavs[voice] = (unsigned int)DTable; 156 | break; 157 | case E: 158 | wavs[voice] = (unsigned int)ETable; 159 | break; 160 | case F: 161 | wavs[voice] = (unsigned int)FTable; 162 | break; 163 | case G: 164 | wavs[voice] = (unsigned int)GTable; 165 | break; 166 | case H: 167 | wavs[voice] = (unsigned int)HTable; 168 | break; 169 | default: 170 | wavs[voice] = (unsigned int)ITable; 171 | break; 172 | } 173 | } 174 | //********************************************************************* 175 | // Setup Pitch [0-127] 176 | //********************************************************************* 177 | 178 | void setPitch(unsigned char voice,unsigned char MIDInote) 179 | { 180 | PITCH[voice]=(uint)(PITCHS[MIDInote]); 181 | } 182 | 183 | //********************************************************************* 184 | // Setup Envelope [0-4] 185 | //********************************************************************* 186 | 187 | void setEnvelope(unsigned char voice, unsigned char env) 188 | { 189 | switch (env) 190 | { 191 | case 0: 192 | envs[voice] = (unsigned int)Env0; 193 | break; 194 | case 1: 195 | envs[voice] = (unsigned int)Env1; 196 | break; 197 | case 2: 198 | envs[voice] = (unsigned int)Env2; 199 | break; 200 | case 3: 201 | envs[voice] = (unsigned int)Env3; 202 | break; 203 | case 4: 204 | envs[voice] = (unsigned int)Env4; 205 | break; 206 | default: 207 | envs[voice] = (unsigned int)Env0; 208 | break; 209 | } 210 | } 211 | 212 | //********************************************************************* 213 | // Setup Length [0-128] 214 | //********************************************************************* 215 | 216 | void setLength(unsigned char voice,unsigned char length) 217 | { 218 | EFTW[voice]=(uint)(EFTWS[length]); 219 | } 220 | 221 | //********************************************************************* 222 | // Setup mod 223 | //********************************************************************* 224 | 225 | void setMod(unsigned char voice,unsigned char mod) 226 | { 227 | MOD[voice]=(int)mod-64;//0-127 64 = no mod 228 | } 229 | 230 | //********************************************************************* 231 | // Set frequency direct 232 | //********************************************************************* 233 | 234 | void setFrequency(unsigned char voice,float f) 235 | { 236 | PITCH[voice]=f/(FSample/65535.0); 237 | 238 | } 239 | 240 | //********************************************************************* 241 | // Set time 242 | //********************************************************************* 243 | 244 | void setTime(unsigned char voice,float t) 245 | { 246 | EFTW[voice]=(1.0/t)/(FSample/(32767.5*10.0));//[s]; 247 | } 248 | 249 | //********************************************************************* 250 | // Simple trigger 251 | //********************************************************************* 252 | 253 | void trigger(unsigned char voice) 254 | { 255 | EPCW[voice]=0; 256 | FTW[voice]=PITCH[voice]; 257 | // FTW[voice]=PITCH[voice]+(PITCH[voice]*(EPCW[voice]/(32767.5*128.0 ))*((int)MOD[voice]-512)); 258 | } 259 | 260 | void render() 261 | { 262 | divider++; 263 | if(!(divider%=_trackCount)) 264 | tik=1; 265 | if (!(((uint8_t*)&EPCW[divider])[1]&0x80)) 266 | { 267 | uint8_t*address = (uint8_t*)(envs[divider]); 268 | AMP[divider] = address[((uint8_t*)&(EPCW[divider]+=EFTW[divider]))[1]]; 269 | } 270 | else 271 | AMP[divider] = 0; 272 | 273 | int16_t data = 0; 274 | for(int i=0;i<_trackCount;i++) 275 | { 276 | int8_t*address = (int8_t*)(wavs[i]); 277 | data+=(address[((uint8_t *)&(PCW[i] += FTW[i]))[1]] * AMP[i]) >>volume[i]; 278 | } 279 | data = data/_trackCount; 280 | _audioBuf[_audioBufIndex] = 127+(int8_t)data; 281 | _audioBufIndex++; 282 | if(_audioBufIndex>=_audioBufLength) 283 | { 284 | _audioBufIndex = 0; 285 | (*_audioBack)(_audioBuf,_audioBufLength); 286 | } 287 | FTW[divider] = PITCH[divider] + (int) (((PITCH[divider]>>6)*(EPCW[divider]>>6))/128)*MOD[divider]; 288 | } 289 | void addNote(int track, int note,int8_t time=64){ 290 | track = track%_trackCount; 291 | setupVoice(track, _instrumentId, note, 1, time, 64); 292 | trigger(track); 293 | } 294 | private: 295 | AudioBack _audioBack; 296 | uint8_t *_audioBuf; 297 | uint8_t _trackCount; 298 | int _audioBufIndex; 299 | int _instrumentId; 300 | uint16_t _audioBufLength; 301 | }; 302 | 303 | #endif 304 | -------------------------------------------------------------------------------- /lib/cyberpi/src/sound/tables.h: -------------------------------------------------------------------------------- 1 | // Tables V2 2 | 3 | #ifndef _TABLES 4 | #define _TABLES 5 | 6 | //This table id compatible with 20000.00 Hz. sampling rate 7 | //Envelope frequency tuning word vs. MIDI range value [0-127] 8 | const uint16_t EFTWS[] PROGMEM = { 9 | 0x0371,0x0340,0x0311,0x02E5,0x02BB,0x0294,0x026F,0x024C,0x022B,0x020C,0x01EE,0x01D3,0x01B8,0x01A0,0x0188,0x0172, 10 | 0x015D,0x014A,0x0137,0x0126,0x0115,0x0106,0x00F7,0x00E9,0x00DC,0x00D0,0x00C4,0x00B9,0x00AE,0x00A5,0x009B,0x0093, 11 | 0x008A,0x0083,0x007B,0x0074,0x006E,0x0068,0x0062,0x005C,0x0057,0x0052,0x004D,0x0049,0x0045,0x0041,0x003D,0x003A, 12 | 0x0037,0x0034,0x0031,0x002E,0x002B,0x0029,0x0026,0x0024,0x0022,0x0020,0x001E,0x001D,0x001B,0x001A,0x0018,0x0017, 13 | 0x0015,0x0014,0x0013,0x0012,0x0011,0x0010,0x000F,0x000E,0x000D,0x000D,0x000C,0x000B,0x000A,0x000A,0x0009,0x0009, 14 | 0x0008,0x0008,0x0007,0x0007,0x0006,0x0006,0x0006,0x0005,0x0005,0x0005,0x0004,0x0004,0x0004,0x0004,0x0003,0x0003, 15 | 0x0003,0x0003,0x0003,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001, 16 | 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 17 | }; 18 | 19 | //Voice frequency tuning word vs. MIDI note [0-127] 20 | const uint16_t PITCHS[] PROGMEM = { 21 | 0x001A,0x001C,0x001E,0x001F,0x0021,0x0023,0x0025,0x0028,0x002A,0x002D,0x002F,0x0032,0x0035,0x0038,0x003C,0x003F, 22 | 0x0043,0x0047,0x004B,0x0050,0x0055,0x005A,0x005F,0x0065,0x006B,0x0071,0x0078,0x007F,0x0087,0x008F,0x0097,0x00A0, 23 | 0x00AA,0x00B4,0x00BE,0x00CA,0x00D6,0x00E3,0x00F0,0x00FE,0x010E,0x011E,0x012F,0x0141,0x0154,0x0168,0x017D,0x0194, 24 | 0x01AC,0x01C6,0x01E1,0x01FD,0x021C,0x023C,0x025E,0x0282,0x02A8,0x02D0,0x02FB,0x0329,0x0359,0x038C,0x03C2,0x03FB, 25 | 0x0438,0x0478,0x04BC,0x0504,0x0550,0x05A1,0x05F7,0x0652,0x06B2,0x0718,0x0784,0x07F6,0x0870,0x08F0,0x0978,0x0A08, 26 | 0x0AA1,0x0B43,0x0BEF,0x0CA4,0x0D65,0x0E31,0x0F09,0x0FED,0x10E0,0x11E1,0x12F1,0x1411,0x1543,0x1687,0x17DE,0x1949, 27 | 0x1ACA,0x1C62,0x1E12,0x1FDB,0x21C0,0x23C2,0x25E3,0x2823,0x2A86,0x2D0E,0x2FBC,0x3292,0x3594,0x38C4,0x3C24,0x3FB7, 28 | 0x4381,0x4785,0x4BC6,0x5047,0x550D,0x5A1C,0x5F78,0x6525,0x6B29,0x7188,0x7848,0x7F6F,0x8703,0x8F0A,0x978C,0xA08F, 29 | }; 30 | 31 | 32 | //Arduino synth V4.0 33 | //This table id compatible with 16000.00 Hz. sampling rate 34 | //Envelope frequency tuning word vs. MIDI range value [0-127] 35 | /*const uint16_t EFTWS[] PROGMEM = { 36 | 0x044E,0x0410,0x03D5,0x039E,0x036A,0x0339,0x030B,0x02DF,0x02B6,0x028F,0x026A,0x0247,0x0227,0x0208,0x01EA,0x01CF, 37 | 0x01B5,0x019C,0x0185,0x016F,0x015B,0x0147,0x0135,0x0123,0x0113,0x0104,0x00F5,0x00E7,0x00DA,0x00CE,0x00C2,0x00B7, 38 | 0x00AD,0x00A3,0x009A,0x0091,0x0089,0x0082,0x007A,0x0073,0x006D,0x0067,0x0061,0x005B,0x0056,0x0051,0x004D,0x0048, 39 | 0x0044,0x0041,0x003D,0x0039,0x0036,0x0033,0x0030,0x002D,0x002B,0x0028,0x0026,0x0024,0x0022,0x0020,0x001E,0x001C, 40 | 0x001B,0x0019,0x0018,0x0016,0x0015,0x0014,0x0013,0x0012,0x0011,0x0010,0x000F,0x000E,0x000D,0x000C,0x000C,0x000B, 41 | 0x000A,0x000A,0x0009,0x0009,0x0008,0x0008,0x0007,0x0007,0x0006,0x0006,0x0006,0x0005,0x0005,0x0005,0x0004,0x0004, 42 | 0x0004,0x0004,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0001,0x0001, 43 | 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 44 | }; 45 | //Voice frequency tuning word vs. MIDI note [0-127] 46 | const uint16_t PITCHS[] PROGMEM = { 47 | 0x0021,0x0023,0x0025,0x0027,0x002A,0x002C,0x002F,0x0032,0x0035,0x0038,0x003B,0x003F,0x0042,0x0046,0x004B,0x004F, 48 | 0x0054,0x0059,0x005E,0x0064,0x006A,0x0070,0x0077,0x007E,0x0085,0x008D,0x0096,0x009F,0x00A8,0x00B2,0x00BD,0x00C8, 49 | 0x00D4,0x00E1,0x00EE,0x00FC,0x010B,0x011B,0x012C,0x013E,0x0151,0x0165,0x017A,0x0191,0x01A9,0x01C2,0x01DD,0x01F9, 50 | 0x0217,0x0237,0x0259,0x027D,0x02A3,0x02CB,0x02F5,0x0322,0x0352,0x0385,0x03BA,0x03F3,0x042F,0x046F,0x04B2,0x04FA, 51 | 0x0546,0x0596,0x05EB,0x0645,0x06A5,0x070A,0x0775,0x07E6,0x085F,0x08DE,0x0965,0x09F4,0x0A8C,0x0B2C,0x0BD6,0x0C8B, 52 | 0x0D4A,0x0E14,0x0EEA,0x0FCD,0x10BE,0x11BD,0x12CB,0x13E9,0x1518,0x1659,0x17AD,0x1916,0x1A94,0x1C28,0x1DD5,0x1F9B, 53 | 0x217C,0x237A,0x2596,0x27D2,0x2A31,0x2CB3,0x2F5B,0x322C,0x3528,0x3851,0x3BAB,0x3F37,0x42F9,0x46F5,0x4B2D,0x4FA5, 54 | 0x5462,0x5966,0x5EB7,0x6459,0x6A50,0x70A3,0x7756,0x7E6E,0x85F3,0x8DEA,0x965A,0x9F4B,0xA8C4,0xB2CD,0xBD6F,0xC8B2, 55 | }; 56 | */ 57 | 58 | 59 | const int8_t EmptyTable[] PROGMEM = 60 | { 61 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 62 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 63 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 64 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 65 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 66 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 67 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 68 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 69 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 70 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 71 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 72 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 73 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 74 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 75 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 76 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 77 | }; 78 | const int8_t SinTable[] PROGMEM = 79 | {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,59,62,65,67,70,73,75,78,80,82,85,87,89,91,94,96,98,100,102,103,105,107,108,110,112,113,114,116,117,118,119,120,121,122,123,123,124,125,125,126,126,126,126,126,127,126,126,126,126,126,125,125,124,123,123,122,121,120,119,118,117,116,114,113,112,110,108,107,105,103,102,100,98,96,94,91,89,87,85,82,80,78,75,73,70,67,65,62,59,57,54,51,48,45,42,39,36,33,30,27,24,21,18,15,12,9,6,3,0,-3,-6,-9,-12,-15,-18,-21,-24,-27,-30,-33,-36,-39,-42,-45,-48,-51,-54,-57,-59,-62,-65,-67,-70,-73,-75,-78,-80,-82,-85,-87,-89,-91,-94,-96,-98,-100,-102,-103,-105,-107,-108,-110,-112,-113,-114,-116,-117,-118,-119,-120,-121,-122,-123,-123,-124,-125,-125,-126,-126,-126,-126,-126,-127,-126,-126,-126,-126,-126,-125,-125,-124,-123,-123,-122,-121,-120,-119,-118,-117,-116,-114,-113,-112,-110,-108,-107,-105,-103,-102,-100,-98,-96,-94,-91,-89,-87,-85,-82,-80,-78,-75,-73,-70,-67,-65,-62,-59,-57,-54,-51,-48,-45,-42,-39,-36,-33,-30,-27,-24,-21,-18,-15,-12,-9,-6,-4, 80 | }; 81 | 82 | const int8_t TriangleTable[] PROGMEM = 83 | {0,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,125,123,121,119,117,115,113,111,109,107,105,103,101,99,97,95,93,91,89,87,85,83,81,79,77,75,73,71,69,67,65,63,61,59,57,55,53,51,49,47,45,43,41,39,37,35,33,31,29,27,25,23,21,19,17,15,13,11,9,7,5,3,1,0,-1,-3,-5,-7,-9,-11,-13,-15,-17,-19,-21,-23,-25,-27,-29,-31,-33,-35,-37,-39,-41,-43,-45,-47,-49,-51,-53,-55,-57,-59,-61,-63,-65,-67,-69,-71,-73,-75,-77,-79,-81,-83,-85,-87,-89,-91,-93,-95,-97,-99,-101,-103,-105,-107,-109,-111,-113,-115,-117,-119,-121,-123,-125,-127,-125,-123,-121,-119,-117,-115,-113,-111,-109,-107,-105,-103,-101,-99,-97,-95,-93,-91,-89,-87,-85,-83,-81,-79,-77,-75,-73,-71,-69,-67,-65,-63,-61,-59,-57,-55,-53,-51,-49,-47,-45,-43,-41,-39,-37,-35,-33,-31,-29,-27,-25,-23,-21,-19,-17,-15,-13,-11,-9,-7,-5,-3,-2, 84 | }; 85 | 86 | const int8_t SquareTable[] PROGMEM = 87 | {127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-1, 88 | }; 89 | 90 | const int8_t SawTable[] PROGMEM =//actually guitar 0007 from Adventure Kid (see below) 91 | { 92 | 2,7,13,19,25,30,36,42,48,53,59,64,70,75,81,86,91,96,101,106,110,114,117,120,123,125,126,127,127,127,127,127,127,126,125,123,121,119,117,115,113,110,108,105,102,99,97,94,90,87,84,80,76,72,68,64,60,57,53,49,46,43,40,37,35,33,31,29,27,25,24,21,19,17,15,13,11,9,7,5,4,4,3,3,3,4,5,6,7,8,9,11,12,13,14,16,17,17,18,19,19,19,19,19,19,18,18,17,16,16,15,14,13,12,11,10,9,8,7,5,3,0,-1,-4,-6,-9,-9,-14,-16,-19,-21,-24,-26,-28,-31,-33,-35,-37,-40,-42,-44,-46,-48,-50,-51,-53,-55,-57,-58,-60,-61,-63,-64,-65,-66,-67,-67,-67,-67,-67,-66,-65,-64,-62,-60,-58,-56,-54,-52,-49,-47,-45,-43,-42,-40,-39,-38,-37,-37,-36,-36,-35,-35,-35,-34,-34,-33,-32,-31,-31,-30,-29,-28,-28,-27,-27,-27,-27,-28,-29,-30,-31,-32,-33,-35,-37,-39,-40,-42,-44,-46,-48,-50,-52,-54,-56,-58,-60,-61,-63,-65,-66,-68,-69,-71,-72,-73,-74,-74,-75,-75,-75,-74,-73,-72,-70,-69,-67,-64,-62,-59,-56,-54,-51,-48,-45,-42,-39,-36,-33,-29,-25,-21,-16,-11,-6 93 | 94 | }; 95 | 96 | const int8_t RampTable[] PROGMEM = 97 | {-127,-126,-125,-124,-123,-122,-121,-120,-119,-118,-117,-116,-115,-114,-113,-112,-111,-110,-109,-108,-107,-106,-105,-104,-103,-102,-101,-100,-99,-98,-97,-96,-95,-94,-93,-92,-91,-90,-89,-88,-87,-86,-85,-84,-83,-82,-81,-80,-79,-78,-77,-76,-75,-74,-73,-72,-71,-70,-69,-68,-67,-66,-65,-64,-63,-62,-61,-60,-59,-58,-57,-56,-55,-54,-53,-52,-51,-50,-49,-48,-47,-46,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35,-34,-33,-32,-31,-30,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, 98 | 99 | }; 100 | 101 | const int8_t NoiseTable[] PROGMEM = 102 | {-62,-72,-92,-98,98,-103,96,-89,-29,-55,98,-8,-118,13,11,-1,76,-8,-116,51,33,-85,-43,-16,-114,-47,-63,-113,109,-39,-127,-59,0,118,70,62,54,85,51,122,60,30,-126,-25,71,-82,-11,64,-95,-110,127,37,-14,-57,51,-4,-47,-80,110,7,-117,89,65,-58,50,-21,33,-113,-22,111,-46,108,112,-57,-111,53,-21,-22,-127,-18,-9,95,88,99,-17,-3,74,2,123,-31,53,-7,91,-80,15,-112,114,14,-115,-55,22,95,21,53,-105,-67,-25,25,13,58,-121,-62,103,87,109,38,-79,-60,-16,-68,-91,90,112,-99,118,87,-61,-36,-40,-39,-30,34,83,-100,-43,-114,-54,-8,-36,-52,71,22,-33,116,9,114,24,-91,-48,-106,-2,-31,103,21,117,44,115,-59,53,97,124,66,120,-44,57,-96,-24,46,32,111,-56,-123,46,-11,97,-70,-12,-89,-81,24,-29,-23,77,42,-40,8,-98,-35,-21,116,61,-41,116,66,-88,22,95,-31,40,-51,-78,28,3,124,92,81,-27,78,65,-16,-116,-73,-126,55,-76,78,17,43,66,-24,117,-38,-76,-10,-37,-47,-56,33,94,-40,107,36,-104,-11,-27,-23,105,-96,68,-25,7,67,6,-69,70,-10,10,5,42,120,-71,-122,-86,113,112,119, 103 | }; 104 | 105 | 106 | const int8_t ATable[] PROGMEM =//0094 Tables A-5 plus guitar above are from Adventure Kid's collection of single-cycle waveforms: http://www.adventurekid.se/akrt/waveforms/adventure-kid-waveforms/ I (A.M.) resampled them and reduced them to 8-bit 107 | { 108 | 0,-4,-8,-11,-15,-18,-22,-25,-28,-31,-34,-37,-40,-43,-45,-48,-50,-52,-55,-57,-59,-61,-63,-65,-67,-68,-70,-72,-73,-75,-76,-77,-79,-80,-81,-82,-83,-84,-85,-86,-87,-87,-88,-89,-89,-90,-90,-91,-91,-91,-92,-92,-92,-92,-92,-92,-92,-92,-92,-92,-92,-91,-91,-91,-90,-90,-89,-89,-88,-88,-87,-86,-86,-85,-84,-83,-82,-82,-81,-80,-79,-78,-76,-75,-74,-73,-72,-71,-69,-68,-67,-65,-64,-63,-61,-60,-58,-58,-60,-61,-62,-63,-62,-62,-61,-61,-60,-60,-59,-59,-58,-58,-58,-57,-57,-57,-56,-56,-55,-55,-54,-53,-52,-51,-51,-49,-49,-47,-45,-44,-42,-40,-38,-36,-34,-31,-29,-27,-24,-21,-19,-16,-13,-10,-7,-3,0,3,7,10,14,17,21,25,30,35,39,43,48,52,56,60,61,62,63,65,67,69,72,74,77,79,81,84,86,88,89,91,93,94,95,97,98,99,100,101,102,103,104,105,106,107,108,109,111,113,114,115,117,118,119,119,120,121,122,123,124,125,125,126,127,127,127,127,127,127,127,127,127,127,127,127,127,126,126,125,123,120,115,110,106,103,99,96,93,89,86,82,78,74,70,65,61,56,52,47,43,38,33,29,25,21,18,14,10,6 109 | 110 | }; 111 | 112 | const int8_t BTable[] PROGMEM =//blended0076 113 | { 114 | 0,10,20,30,39,48,57,66,74,82,89,96,102,107,112,117,120,123,126,127,127,127,127,127,126,124,121,119,115,111,107,103,99,94,89,84,79,75,70,65,61,57,53,49,46,43,41,38,37,36,35,34,34,35,35,37,38,40,42,44,47,49,52,55,58,60,63,66,68,70,72,74,75,76,77,77,77,76,75,73,71,68,65,61,57,52,47,42,37,31,24,18,12,5,-2,-9,-15,-22,-28,-34,-40,-46,-51,-56,-60,-64,-68,-71,-73,-74,-75,-76,-76,-75,-73,-71,-68,-65,-61,-57,-52,-46,-41,-35,-28,-22,-22,-8,-1,6,13,20,27,33,39,45,51,56,60,64,68,71,73,75,76,77,77,76,75,73,70,67,63,59,54,49,44,38,32,25,19,12,6,-1,-8,-14,-21,-27,-33,-39,-44,-49,-54,-58,-62,-66,-69,-71,-73,-74,-75,-76,-76,-75,-75,-73,-72,-70,-68,-66,-63,-60,-58,-55,-52,-49,-47,-44,-42,-40,-38,-36,-35,-34,-33,-33,-33,-34,-35,-37,-39,-41,-44,-47,-50,-54,-58,-62,-67,-72,-76,-81,-86,-91,-96,-100,-105,-109,-113,-116,-119,-122,-124,-126,-127,-127,-127,-127,-125,-123,-121,-117,-113,-108,-103,-97,-91,-84,-76,-68,-60,-51,-42,-33,-23,-14 115 | 116 | }; 117 | 118 | const int8_t CTable[] PROGMEM =//0006 119 | { 120 | 121 | 3,9,14,18,22,26,30,34,38,41,45,48,51,54,57,60,63,66,69,71,74,76,79,81,83,85,87,89,90,92,94,95,97,99,102,104,105,107,108,109,111,110,107,105,103,102,101,100,100,99,98,97,96,94,93,92,91,89,88,86,85,83,82,81,80,79,81,82,82,82,82,83,83,83,83,83,83,83,83,84,84,84,85,85,85,85,85,85,85,85,85,85,84,84,84,83,82,81,81,79,78,77,76,74,73,71,69,68,65,63,61,59,56,54,51,49,46,43,40,37,34,31,28,24,21,17,13,8,2,-4,-8,-13,-16,-20,-24,-27,-30,-34,-37,-40,-43,-46,-49,-52,-54,-57,-60,-62,-65,-67,-69,-71,-74,-76,-78,-79,-81,-83,-85,-86,-88,-89,-91,-92,-92,-91,-90,-89,-88,-87,-87,-86,-86,-85,-85,-84,-84,-83,-83,-82,-81,-81,-80,-80,-79,-79,-78,-78,-78,-79,-80,-83,-84,-85,-86,-87,-88,-89,-90,-91,-92,-92,-93,-94,-95,-96,-96,-97,-97,-98,-98,-99,-99,-99,-99,-99,-99,-99,-99,-98,-98,-97,-97,-96,-95,-94,-93,-92,-90,-89,-87,-85,-83,-81,-79,-77,-74,-72,-69,-66,-63,-60,-57,-54,-51,-47,-44,-40,-37,-33,-29,-25,-21,-16,-11,-6, 122 | }; 123 | 124 | const int8_t DTable[] PROGMEM =//altosax0008 125 | { 126 | 127 | 2,9,15,22,29,36,44,51,59,67,74,82,88,93,96,99,103,105,107,110,113,116,119,121,123,125,125,125,126,127,127,127,127,126,124,121,117,114,109,104,98,93,87,82,77,71,67,61,56,52,48,43,37,31,24,19,16,15,12,10,7,4,3,0,-3,-7,-11,-17,-20,-23,-25,-29,-33,-37,-40,-42,-45,-47,-51,-53,-56,-58,-60,-63,-65,-66,-67,-68,-68,-68,-68,-68,-67,-66,-64,-63,-61,-59,-57,-55,-53,-50,-46,-43,-39,-35,-31,-26,-21,-17,-13,-9,-5,-1,3,6,10,13,16,20,23,26,28,30,32,33,33,34,34,33,33,32,30,28,26,24,22,19,17,13,9,5,2,-2,-5,-8,-12,-15,-18,-20,-22,-25,-28,-30,-33,-34,-36,-36,-37,-38,-40,-40,-39,-39,-39,-38,-38,-37,-36,-35,-34,-33,-31,-30,-29,-27,-25,-23,-22,-21,-20,-19,-18,-17,-16,-16,-15,-15,-14,-14,-13,-12,-12,-12,-12,-12,-12,-13,-14,-14,-15,-16,-17,-18,-19,-20,-21,-21,-22,-23,-24,-25,-26,-27,-28,-29,-30,-30,-30,-30,-30,-31,-31,-31,-30,-30,-30,-30,-30,-31,-31,-32,-32,-33,-34,-36,-37,-39,-40,-42,-44,-46,-47,-48,-49,-49,-48,-47,-45,-42,-38,-33,-28,-22,-16,-9 128 | 129 | }; 130 | 131 | const int8_t ETable[] PROGMEM =//98 132 | { 133 | 2,6,10,14,17,21,24,28,31,34,37,41,44,47,50,53,55,58,61,64,66,69,71,74,76,78,80,83,85,87,89,91,92,94,96,98,99,101,102,104,105,106,108,109,110,111,112,113,114,115,116,117,118,119,119,120,121,121,122,123,123,124,124,125,125,125,126,126,126,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,126,126,126,126,125,125,125,124,124,124,123,123,123,122,122,122,121,121,121,119,117,114,109,103,95,86,86,65,53,41,29,16,2,-12,-24,-35,-44,-53,-62,-69,-76,-82,-87,-92,-96,-100,-103,-106,-109,-111,-113,-115,-116,-118,-119,-120,-121,-122,-123,-123,-124,-124,-125,-125,-126,-126,-126,-126,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-126,-126,-126,-126,-125,-125,-125,-124,-124,-123,-123,-122,-122,-121,-121,-120,-119,-119,-118,-117,-116,-116,-115,-114,-113,-112,-111,-109,-108,-107,-106,-104,-103,-102,-100,-99,-97,-95,-94,-92,-90,-88,-86,-84,-82,-80,-77,-75,-73,-70,-68,-65,-63,-60,-57,-54,-51,-49,-46,-42,-39,-36,-33,-30,-26,-23,-19,-16,-12,-8,-4 134 | 135 | }; 136 | 137 | const int8_t FTable[] PROGMEM =//blended0006 138 | { 139 | 7,37,59,74,85,94,100,105,110,113,116,118,120,121,122,123,124,125,126,126,126,127,127,127,127,127,127,127,127,127,127,124,106,94,89,86,84,84,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,84,79,64,67,68,66,64,61,59,57,56,55,55,54,54,54,54,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,54,51,33,20,14,10,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,7,8,7,8,2,-15,-15,-25,-4,10,15,17,16,14,12,10,8,6,4,3,0,0,-1,-2,-2,-3,-4,-4,-4,-5,-5,-5,-5,-6,-6,-6,-6,-6,-6,-8,-25,-39,-45,-49,-50,-51,-51,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-52,-54,-69,-70,-66,-69,-71,-74,-75,-78,-78,-80,-80,-81,-81,-81,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-82,-83,-98,-114,-120,-124,-125,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-127,-124,-109,-89,-59 140 | 141 | }; 142 | 143 | 144 | const int8_t GTable[] PROGMEM =//eguitar_0003 145 | { 146 | 10,40,63,80,91,98,101,102,102,100,97,92,89,86,86,87,90,92,95,96,96,95,93,91,89,88,89,90,91,93,94,94,94,93,91,90,89,89,89,90,91,92,93,93,92,91,90,90,89,89,89,90,91,91,91,91,91,90,90,89,89,89,90,90,90,90,91,90,90,90,89,89,89,89,89,90,90,90,90,90,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,88,88,88,88,88,88,88,89,89,89,89,89,89,89,88,88,87,87,87,88,88,89,89,89,89,88,87,86,86,86,86,88,89,90,91,91,89,86,83,81,81,83,89,96,102,105,101,90,72,48,21,-6,-31,-53,-74,-92,-107,-119,-127,-127,-127,-127,-125,-121,-119,-118,-118,-120,-121,-122,-123,-123,-122,-122,-121,-120,-120,-120,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-121,-120,-120,-120,-120,-120,-120,-120,-121,-121,-121,-121,-120,-120,-119,-119,-119,-119,-119,-120,-121,-121,-121,-121,-120,-119,-119,-118,-118,-118,-119,-120,-121,-121,-121,-121,-120,-118,-117,-116,-117,-117,-119,-121,-122,-123,-122,-120,-117,-114,-113,-113,-116,-123,-125,-125,-125,-122,-103,-74,-40 147 | 148 | }; 149 | 150 | const int8_t HTable[] PROGMEM =//1698 151 | { 152 | 1,3,4,5,7,7,8,8,9,8,20,40,48,51,49,45,40,36,32,27,27,33,41,46,47,44,41,36,32,27,25,20,27,59,76,83,83,77,70,62,73,90,94,91,84,76,67,61,87,111,116,113,104,93,80,77,82,92,95,91,85,78,69,59,50,38,26,25,27,25,23,20,17,14,12,13,14,19,49,83,94,97,89,81,69,73,103,115,113,104,91,78,66,55,46,37,30,27,42,58,61,59,53,46,38,31,24,18,14,9,6,3,1,0,8,35,52,56,55,49,42,35,28,22,16,16,31,38,39,36,31,26,20,16,13,18,24,25,23,21,16,11,-6,-27,-37,-40,-40,-38,-35,-31,-28,-24,-22,-19,-21,-50,-72,-78,-77,-71,-67,-90,-113,-114,-109,-98,-87,-75,-65,-55,-47,-50,-74,-105,-124,-123,-115,-102,-105,-116,-112,-104,-91,-79,-66,-71,-82,-80,-75,-66,-58,-53,-54,-56,-60,-64,-71,-101,-124,-127,-120,-108,-93,-79,-65,-72,-86,-85,-79,-70,-60,-50,-41,-43,-60,-68,-67,-61,-54,-46,-37,-32,-27,-28,-34,-33,-27,-21,-16,-14,-25,-47,-56,-57,-53,-47,-40,-33,-27,-22,-17,-13,-10,-8,-6,-8,-18,-23,-23,-21,-18,-14,-11,-7,-4,-2 153 | 154 | }; 155 | 156 | const int8_t ITable[] PROGMEM =//908 157 | { 158 | 1,2,2,3,4,5,6,7,8,9,9,10,11,12,13,14,15,16,17,18,19,20,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,34,35,37,39,41,43,44,46,47,49,50,52,53,55,56,57,59,60,62,63,65,66,67,69,70,71,73,74,75,77,78,80,81,82,83,85,86,88,89,90,91,93,94,95,96,98,99,100,101,103,104,105,107,108,109,110,112,112,114,114,117,116,120,117,127,105,58,61,57,56,53,51,48,44,41,37,34,29,26,21,18,14,10,6,2,-2,-6,-11,-14,-19,-23,-27,-31,-35,-40,-44,-48,-52,-57,-61,-66,-70,-74,-78,-83,-87,-92,-96,-102,-107,-101,-96,-92,-89,-87,-85,-84,-82,-81,-80,-79,-79,-78,-77,-76,-76,-75,-74,-74,-73,-72,-72,-71,-71,-70,-69,-69,-68,-67,-67,-66,-65,-64,-64,-63,-62,-62,-61,-60,-60,-59,-58,-57,-57,-56,-55,-54,-54,-53,-52,-51,-51,-50,-49,-48,-48,-47,-46,-45,-45,-44,-43,-42,-41,-41,-40,-39,-38,-37,-37,-36,-35,-34,-33,-32,-32,-31,-30,-29,-28,-27,-27,-26,-25,-24,-23,-22,-21,-21,-20,-19,-18,-17,-16,-16,-14,-14,-13,-12,-10,-5,-5,-5,-4,-3,-3,-2,-1,-1 159 | 160 | }; 161 | 162 | 163 | 164 | 165 | const uint8_t Env0[] PROGMEM = 166 | {255,242,229,216,204,191,178,165,153,142,134,125,117,108,100,91,83,74,71,68,65,62,59,56,53,50,48,46,44,42,40,38,36,34,32,31,30,29,28,28,27,26,25,25,24,24,23,23,22,22,21,21,20,20,19,19,19,18,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,10,9,9,8,8,8,7,7,6,6,6,6,6,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,3,3,3,2,2,2,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 167 | }; 168 | 169 | const uint8_t Env1[] PROGMEM = 170 | {255,250,246,242,238,233,229,225,221,217,213,209,206,202,199,195,191,188,183,179,175,170,166,161,157,153,148,144,139,134,130,125,121,116,112,109,105,102,99,96,93,90,87,83,80,77,74,71,68,65,61,58,56,54,51,49,46,44,42,39,37,34,31,28,25,22,19,16,13,12,12,11,11,10,10,10,9,9,8,8,8,7,7,6,6,6,6,6,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,3,3,3,2,2,2,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 171 | }; 172 | 173 | const uint8_t Env2[] PROGMEM = 174 | {255,254,254,254,253,253,253,252,252,252,251,251,251,250,250,250,249,249,247,244,242,240,237,235,233,230,219,200,180,160,141,121,102,82,62,58,53,49,45,40,36,31,27,25,24,24,23,23,22,22,21,21,20,20,19,19,19,18,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,10,9,9,8,8,8,7,7,6,6,6,6,6,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,3,3,3,2,2,2,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 175 | }; 176 | 177 | const uint8_t Env3[] PROGMEM = 178 | {255,254,254,254,253,253,253,252,252,251,251,250,249,248,248,247,246,245,241,237,232,228,223,219,215,210,205,200,195,189,184,179,173,168,163,157,151,145,139,133,127,121,115,110,105,101,96,91,86,82,77,72,69,65,62,58,54,51,47,44,41,38,36,33,31,28,26,23,20,19,18,17,15,14,13,12,10,9,9,9,8,8,7,7,6,6,6,6,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,3,3,3,2,2,2,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 179 | }; 180 | 181 | const uint8_t Env4[] PROGMEM = 182 | {100,101,103,106,110,118,134,166,230,245,249,251,249,248,248,247,246,245,244,242,241,240,239,238,237,236,235,234,233,232,231,230,229,228,227,226,225,224,223,222,220,218,215,211,208,202,195,190,185,178,172,165,160,155,150,145,140,135,130,125,120,115,110,105,100,95,90,85,80,75,70,65,60,55,50,45,41,37,33,30,28,26,24,22,20,18,16,14,12,10,9,8,7,6,5,5,5,4,4,4,4,4,4,3,3,3,2,2,2,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 183 | }; 184 | 185 | /*this one's sort of a vibrato effect, but the vibrato speed changes with duration. 186 | const int8_t Env5[] PROGMEM = 187 | { 188 | 129,145,164,180,195,207,217,223,227,225,222,215,204,191,176,159,141,122,102,84,66,52,39,31,24,21,21,23,28,34,43,52,62,72,82,91,98,103,107,110,110,107,104,99,93,86,78,70,61,52,44,36,29,23,18,13,10,7,5,4,4,4,5,6,7,8,9,10,10,11,12,12,12,12,11,11,9,8,8,8,7,6,5,4,3,3,2,2,1,1,1,1,1,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 189 | }; 190 | */ 191 | 192 | const uint8_t musicNotes1[] PROGMEM = {81,81,173,81,170,81,165,81,81,170,81,81,173,81,81,170,81,81,165,81,81,81,170,81,173,81,81,168,81,81,165,81,81,168,81,81,173,81,81,168,81,81,165,81,81,81,168,81,172,81,81,169,81,81,165,81,81,169,81,81,172,81,81,169,81,81,165,81,81,81,169,81,172,81,81,169,81,81,165,81,81,169,81,81,172,82,81,81,82,169,82,81,81,82,165,82,81,81,82,169,82,81,82,81,225,170,229,222,80,86,99,93,222,86,229,225,82,86,222,229,225,86,80,225,229,222,86,225,229,222,80,86,222,229,225,172,86,82,225,229,222,86,225,229,222,173,86,80,222,229,225,86,225,229,222,82,86,225,229,222,80,86,225,229,222,86,225,229,222,86,80,225,229,222,86,82,225,229,222,86,222,229,225,177,80,86,232,229,225,86,232,229,225,86,82,232,229,225,175,80,86,232,229,225,86,232,229,225,86,80,225,229,232,177,86,82,225,229,232,86,232,229,225,168,86,80,232,229,225,86,225,229,232,82,86,232,229,225,80,86,225,229,232,86,225,229,232,86,80,225,229,232,86,82,232,229,225,86,225,229,232,170,86,80,218,222,225,86,218,222,225,82,86,218,222,225,86,80,225,222,218,86,218,222,225,86,80,225,222,218,172,82,86,218,222,225,86,218,222,225,173,80,86,218,222,225,86,225,222,218,82,86,225,222,218,80,86,218,222,225,172,86,218,222,225,86,80,218,222,225,82,86,225,222,218,86,218,222,225,175,80,86,220,224,227,86,227,224,220,82,86,220,224,227,80,86,227,224,220,177,86,220,224,227,80,86,227,224,220,86,82,227,224,220,86,220,224,227,175,80,86,217,221,224,86,224,221,217,86,82,217,221,224,86,80,217,221,224,173,82,86,217,221,224,82,82,217,80,221,86,224,82,82,224,82,221,86,217,82,82,217,86,221,224,82,99,222,93,229,80,225,86,222,86,229,225,173,86,82,222,229,225,86,80,225,229,222,173,86,222,229,225,80,86,225,229,222,173,86,82,225,229,222,86,225,229,222,177,80,86,225,229,222,86,225,229,222,177,86,82,225,229,222,86,80,225,229,222,175,86,225,229,222,86,80,222,229,225,173,82,86,225,229,222,86,225,229,222,86,80,232,229,225,86,232,229,225,177,82,86,225,229,232,86,80,225,229,232,177,86,225,229,232,80,86,232,229,225,177,86,82,232,229,225,86,225,229,232,175,80,86,225,229,232,86,225,229,232,177,86,82,232,229,225,80,86,225,229,232,175,86,232,229,225,86,80,232,229,225,173,86,82,225,229,232,86,225,229,232,80,86,218,222,225,86,225,222,218,173,86,82,225,222,218,80,86,218,222,225,173,86,225,222,218,86,80,225,222,218,173,82,86,225,222,218,86,218,222,225,177,80,86,218,222,225,86,218,222,225,177,86,82,225,222,218,80,86,225,222,218,175,86,218,222,225,80,86,218,222,225,173,82,86,218,222,225,86,218,222,225,80,86,227,224,220,86,220,224,227,177,86,82,227,224,220,86,80,227,224,220,177,86,227,224,220,80,86,227,224,220,177,86,82,227,224,220,86,227,224,220,86,80,224,221,217,86,217,221,224,181,86,82,224,221,217,86,80,217,221,224,181,82,86,217,221,224,82,82,224,86,221,80,217,82,181,82,217,86,221,82,224,82,82,217,86,221,224,82,99,225,93,229,86,222,80,225,86,229,222,173,86,82,225,229,222,80,86,222,229,225,173,86,225,229,222,86,80,225,229,222,173,82,86,222,229,225,86,222,229,225,177,86,80,225,232,229,86,225,232,229,177,82,86,225,232,229,80,86,229,232,225,175,86,225,232,229,80,86,229,232,225,173,82,86,225,232,229,86,229,232,225,86,80,218,222,225,86,218,222,225,178,86,82,225,222,218,80,86,218,222,225,178,86,225,222,218,86,80,218,222,225,178,86,82,225,222,218,86,225,222,218,177,86,80,227,224,220,86,220,224,227,86,82,220,224,227,80,86,227,224,220,180,86,220,224,227,80,86,227,224,220,86,82,220,224,227,86,220,224,227,177,80,86,217,221,224,86,217,221,224,86,82,217,221,224,80,86,217,221,224,181,82,86,224,221,217,82,82,224,80,221,86,217,82,82,224,82,221,86,217,82,82,217,86,221,224,82,42,99,93,80,45,49,52,41,44,49,52,42,30,80}; 193 | const uint8_t musicNotes2[] PROGMEM = {89,165,169,172,84,160,164,167,86,162,165,169,81,157,160,165,82,158,162,165,77,153,157,160,82,158,162,165,84,160,164,167,181,89,165,169,172,84,179,160,164,167,177,86,162,165,169,176,81,157,160,165,174,82,158,162,165,77,172,153,157,160,174,82,158,162,165,176,84,160,164,167,177,245,89,165,169,172,84,176,243,160,164,167,174,241,86,162,165,169,172,240,81,157,160,165,170,238,82,158,162,165,169,77,236,153,157,160,170,238,82,158,162,165,167,240,84,160,164,167,53,89,165,241,165,169,169,172,84,172,240,51,160,164,170,167,169,238,49,86,162,165,165,169,169,236,48,81,157,160,167,165,165,234,46,82,158,162,162,165,77,165,233,44,153,157,172,160,170,234,46,82,158,162,174,165,172,231,48,84,160,164,170,167,169,49,89,229,165,169,165,233,172,84,167,236,48,160,164,176,234,167,177,233,46,86,162,165,181,229,169,184,233,44,81,157,160,172,231,165,229,42,82,174,158,170,226,162,165,77,172,229,41,153,157,169,236,160,165,234,42,82,158,162,177,238,165,179,236,39,84,177,179,177,160,179,177,179,177,164,234,167,176,89,177,233,37,176,165,169,177,229,41,172,165,84,164,231,44,172,160,167,240,42,164,167,169,165,241,41,86,177,162,176,245,37,165,174,169,176,248,41,81,157,181,184,236,39,160,165,186,82,182,238,37,158,181,162,179,234,34,165,182,77,181,236,37,179,153,157,177,233,44,176,160,174,229,42,82,172,158,162,170,241,46,165,169,243,167,44,84,241,243,241,160,170,243,241,243,241,164,169,42,167,167,240,165,241,41,89,165,167,240,169,169,241,37,170,229,172,84,172,228,39,160,167,236,164,172,231,48,170,167,233,169,229,49,86,162,174,241,172,240,53,165,170,238,169,172,240,56,81,157,170,245,160,169,248,44,165,167,250,165,246,46,82,158,162,245,162,174,243,42,176,246,165,177,245,44,77,153,176,243,174,241,41,157,160,172,240,170,238,37,82,158,169,236,162,167,234,49,165,174,233,51,172,231,84,49,51,49,160,174,234,51,49,51,49,164,172,233,172,172,170,231,48,167,89,169,229,49,165,231,48,181,233,49,169,172,234,37,84,179,236,36,160,231,44,236,39,164,167,234,41,233,37,86,162,238,49,177,165,236,48,169,234,46,181,236,48,81,157,234,53,160,233,56,231,58,165,82,186,229,54,226,53,158,162,238,51,165,240,54,184,241,53,77,240,51,153,238,49,157,160,236,48,186,234,46,82,233,44,158,162,231,42,165,238,41,188,236,39,84,160,238,42,164,236,41,236,236,234,39,167,189,233,37,89,39,165,169,177,245,41,42,172,243,44,84,176,160,39,44,164,167,42,41,86,162,46,174,241,165,44,169,42,177,245,44,81,157,42,160,41,165,39,177,82,250,37,34,158,46,162,165,48,77,248,49,153,48,177,157,46,160,44,177,250,42,82,158,41,162,182,39,165,46,179,252,44,84,160,46,184,44,164,44,44,42,167,184,253,41,89,165,181,182,169,184,241,53,172,181,182,84,184,240,51,172,174,160,176,177,164,179,181,167,182,181,86,177,162,179,238,49,165,181,169,169,170,172,241,53,81,174,172,157,170,172,160,169,165,170,172,241,82,170,58,174,158,172,162,170,169,165,167,169,56,77,167,165,153,167,241,157,169,170,160,172,174,241,170,58,82,174,158,172,162,174,246,176,165,177,172,243,60,84,174,176,160,177,164,179,248,181,167,182,184,248,89,181,61,165,177,245,179,246,169,181,248,49,172,179,245,177,246,84,179,248,48,176,236,160,177,238,179,240,164,181,241,179,243,167,177,245,176,246,177,245,86,174,241,162,176,243,46,165,177,245,165,233,169,167,234,169,236,49,81,170,238,169,236,157,167,234,160,169,236,177,233,165,176,234,177,236,49,174,234,82,158,177,238,176,236,162,174,234,233,165,172,170,231,77,172,233,170,231,153,169,229,170,231,49,157,172,233,174,234,160,176,236,177,238,174,234,49,82,158,177,238,176,236,162,177,238,54,165,176,240,174,241,176,236,51,84,177,238,179,240,160,177,241,164,176,243,56,177,245,174,167,246,176,248,56,89,177,245,165,241,53,243,54,169,245,56,172,243,53,241,54,176,84,243,56,240,44,160,241,46,243,48,164,245,49,243,51,241,53,167,240,54,174,241,53,86,162,238,49,240,51,165,241,53,229,41,169,231,42,177,233,44,81,234,46,233,44,157,231,42,160,233,44,241,41,240,42,165,241,44,165,238,42,82,241,46,158,240,44,162,238,42,41,165,236,234,39,165,77,236,41,234,39,233,37,153,234,39,157,236,41,238,42,240,44,160,241,46,165,238,42,82,158,241,46,240,44,162,241,46,165,240,48,238,49,167,240,44,84,241,46,243,48,160,241,49,164,240,51,241,53,238,167,54,240,56,89,241,53,165,49,51,172,169,53,172,51,49,240,84,51,48,160,49,51,172,164,53,51,49,167,48,238,49,86,46,162,48,169,165,49,37,169,39,241,41,81,42,41,157,39,172,160,41,49,48,165,49,229,46,82,158,49,48,170,162,46,165,44,42,229,44,77,42,41,153,42,169,157,44,46,48,160,49,229,46,82,158,49,48,170,162,49,48,165,46,231,48,84,49,51,160,49,179,164,48,49,167,46,48,181,49,89,165,169,236,169,170,172,169,48,84,167,160,179,181,236,164,167,179,177,46,86,169,162,165,233,165,169,174,172,49,81,157,160,158,236,160,160,165,162,37,82,158,174,176,234,162,174,165,37,77,172,153,160,158,233,157,160,160,37,162,82,158,174,234,162,172,165,174,39,176,84,164,160,243,164,162,167,164,89,165,245,165,177,233,44,169,179,234,177,233,172,176,231,84,160,164,243,165,245,44,164,164,243,167,162,241,86,162,174,233,41,165,172,229,169,174,238,176,236,81,157,164,224,44,160,169,222,165,167,224,82,165,226,158,177,238,42,162,179,240,165,182,238,77,181,236,153,169,224,41,157,172,222,160,181,224,177,226,82,182,238,158,42,162,181,236,165,182,238,179,240,84,172,228,160,51,164,170,226,167,172,228,89,169,229,53,172,241,41,165,172,169,243,42,172,172,241,41,172,240,39,84,172,160,228,51,172,229,53,164,172,167,228,51,169,226,49,86,169,162,238,41,169,236,37,165,169,169,238,46,169,240,44,81,169,157,228,32,172,160,233,30,172,165,231,32,170,229,34,82,170,158,241,46,170,162,243,48,177,165,246,46,177,245,44,77,177,153,233,32,177,157,236,30,177,160,245,32,177,241,34,82,177,158,246,46,174,162,245,44,174,246,46,165,172,243,48,84,172,236,36,160,179,164,234,34,176,167,236,36,172,89,233,37,181,165,236,49,181,236,169,51,181,236,172,49,179,236,84,48,179,236,160,36,179,236,164,37,179,236,167,36,177,233,34,86,177,233,46,162,177,233,165,44,177,233,169,46,184,233,48,81,184,233,157,36,184,236,160,41,184,236,165,39,186,234,37,82,186,234,49,158,186,234,162,51,186,241,165,54,184,241,77,53,184,241,153,41,184,241,157,44,184,241,160,53,186,241,49,82,186,241,158,54,186,238,53,162,186,238,165,54,188,236,51,84,176,236,160,44,176,243,164,42,176,240,167,44,177,236,89,41,165,245,165,44,167,245,44,169,169,245,44,172,165,164,243,44,84,176,243,44,160,177,179,243,44,164,243,44,167,176,241,41,174,86,241,41,162,162,164,241,41,165,165,241,41,169,162,248,41,164,81,172,248,41,157,170,248,44,160,169,248,44,165,167,250,42,165,82,250,42,158,170,169,250,42,162,167,250,49,165,170,248,49,77,169,165,248,49,153,167,248,49,157,169,248,49,160,172,250,49,170,82,174,250,49,158,172,170,250,46,162,169,250,46,165,252,44,167,84,240,44,160,172,170,240,51,164,169,240,48,167,167,241,44,89,169,177,229,53,165,176,231,53,169,177,233,53,172,169,229,172,228,51,84,172,240,51,160,174,241,176,243,51,164,172,240,51,167,49,169,238,86,177,49,162,226,179,228,49,165,181,229,49,169,177,226,56,181,228,81,181,236,56,157,179,234,56,160,177,233,56,165,176,231,58,174,229,82,174,58,158,234,172,233,58,162,174,231,176,234,58,165,56,77,177,233,229,56,153,181,179,231,56,157,177,233,56,160,181,236,234,58,182,82,238,58,158,177,176,236,58,162,174,234,174,58,165,233,172,60,231,84,48,160,167,236,234,48,164,172,233,172,48,167,231,172,49,89,233,37,165,241,240,39,169,241,41,172,233,37,36,84,236,236,48,160,238,49,172,164,240,51,167,236,48,165,233,46,86,241,162,34,243,36,165,245,37,169,241,34,245,36,81,245,44,157,243,42,172,241,41,160,165,240,39,170,238,37,82,238,158,42,236,41,162,238,39,165,240,42,77,172,241,41,37,153,245,243,39,157,241,41,160,245,44,170,42,246,82,241,46,158,240,44,162,165,238,42,238,165,41,167,236,39,84,165,167,165,160,167,231,44,165,167,42,165,164,236,41,236,167,164,39,236,89,165,41,165,49,48,169,177,49,41,172,84,176,44,44,160,46,236,164,48,167,44,174,229,41,86,49,162,51,165,53,49,169,172,53,81,53,157,51,236,160,49,48,165,165,234,46,82,46,158,44,162,46,165,167,48,77,169,236,49,53,153,51,157,49,160,53,174,234,54,82,158,49,48,162,229,46,46,165,167,231,44,84,229,231,229,39,160,231,229,231,229,164,44,167,44,167,228,44,89,169,229,165,169,241,172,181,181,240,84,160,182,44,164,181,179,167,177,238,37,86,162,165,177,169,177,236,81,179,157,177,44,160,165,176,82,174,229,42,158,162,165,231,77,177,233,44,153,157,160,177,238,42,82,158,175,174,37,162,165,175,39,172,231,84,37,39,37,160,39,37,39,37,164,172,231,167,36,172,233,37,89,165,49,169,184,245,172,184,245,84,48,160,186,246,164,184,245,167,182,243,181,241,46,86,162,165,181,241,169,181,241,44,81,157,182,243,160,181,241,165,179,240,177,238,37,82,158,175,162,174,175,39,165,172,77,241,41,153,157,172,160,241,170,46,82,170,158,239,238,162,177,165,239,176,236,39,84,160,164,176,236,39,167,236,89,177,41,165,177,169,172,248,53,248,53,84,250,160,54,164,176,248,53,246,51,167,245,49,86,162,165,174,245,49,169,245,49,81,157,246,51,160,172,245,49,165,243,48,82,241,46,158,239,170,238,162,239,165,77,236,49,153,157,169,236,160,49,234,82,234,47,158,162,46,241,165,167,47,167,240,44,84,160,164,240,44,167,44,89,169,241,165,241,169,181,172,56,56,84,58,160,164,179,240,56,167,54,177,53,86,162,165,189,238,53,169,53,81,157,54,236,53,160,187,165,51,186,49,82,158,47,162,234,46,47,165,77,189,44,153,184,233,157,44,160,42,186,42,82,158,162,49,165,231,231,184,48,84,160,164,48,167,184,89,233,49,165,49,169,245,172,84,172,160,164,243,48,167,170,169,241,86,162,165,253,46,169,181,81,157,44,160,251,179,165,177,250,82,158,162,42,165,77,253,153,177,248,41,157,160,177,250,82,158,162,165,39,39,176,248,84,160,164,167,248,89,177,41,165,165,53,169,172,84,164,236,160,176,51,164,167,234,174,233,49,86,162,165,162,61,169,160,245,81,157,160,172,59,243,165,82,170,241,58,158,162,182,165,77,181,61,153,169,241,56,157,160,241,167,58,82,158,162,174,165,167,240,56,84,160,179,164,167,181,241,56,89,165,169,229,172,228,44,84,160,164,240,167,42,238,41,86,162,226,165,169,224,53,81,157,160,236,165,51,234,49,82,158,162,246,165,245,77,153,233,49,157,160,49,231,82,158,238,162,165,231,48,84,160,164,243,167,245,49,89,165,169,37,172,36,84,160,164,48,167,46,86,162,34,165,169,32,81,157,160,44,165,82,42,158,162,54,165,77,53,153,157,41,160,39,82}; 194 | 195 | const uint8_t musicTicks1[] PROGMEM = {0,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,24,24,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,24,24,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,0,48,0,24,24,0,0,48,0,0,48,0,0,48,0,0,48,0,0,0,24,24,0,0,0,24,24,0,0,0,24,24,0,0,24,0,24,0,0,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,24,24,0,0,0,0,0,24,24,0,0,0,0,0,24,24,0,0,0,0,24,24,0,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,24,24,0,0,0,0,0,24,24,0,0,0,0,0,0,24,24,0,0,0,0,24,24,0,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,48,0,0,0,0,0,48,0,0,0,48,0,0,0,0,48,0,0,0,0,48,0,0,0,0,0,24,24,0,0,0,0,0,24,24,0,0,0,0,0,24,24,0,0,0,0,24,24,0,0,0,48,48,48,48,48,48,48,48,192,0 196 | }; 197 | const uint8_t musicDuring1[] PROGMEM = {16,16,15,7,15,7,15,7,7,15,15,15,15,7,7,15,7,7,15,15,15,7,15,7,15,16,16,15,7,7,15,7,7,15,15,15,15,7,7,15,7,7,15,15,15,7,15,7,15,16,16,15,7,7,15,7,7,15,15,15,15,7,7,15,7,7,15,15,15,7,15,7,15,16,16,15,7,7,15,7,7,15,15,15,15,1,7,7,2,15,4,7,7,6,15,8,15,15,10,15,13,7,14,7,10,15,10,10,15,15,12,12,10,8,10,10,15,15,10,10,10,13,15,10,10,10,15,10,10,10,15,7,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,15,14,10,10,10,15,10,10,10,7,15,10,10,10,15,15,10,10,10,12,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,15,15,13,10,10,10,15,10,10,10,7,15,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,15,14,10,10,10,15,10,10,10,7,15,10,10,10,15,15,10,10,10,12,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,13,15,10,10,10,15,10,10,10,7,15,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,15,14,10,10,10,15,15,10,10,10,7,15,10,10,10,15,15,10,10,10,12,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,15,13,10,10,10,15,15,10,10,10,15,7,10,10,10,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,14,15,10,10,10,15,1,15,10,10,10,2,4,10,15,10,7,10,6,8,10,15,10,15,10,10,13,10,12,10,10,14,12,10,12,10,15,10,15,10,8,10,10,15,15,15,10,10,10,13,15,10,10,10,15,15,10,10,10,15,7,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,14,15,10,10,10,15,15,10,10,10,7,15,10,10,10,15,15,15,10,10,10,12,10,10,10,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,13,15,10,10,10,15,15,10,10,10,15,7,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,15,14,10,10,10,15,15,10,10,10,7,15,10,10,10,15,15,15,10,10,10,12,10,10,10,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,15,13,10,10,10,15,15,10,10,10,7,15,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,15,14,10,10,10,15,15,10,10,10,15,7,10,10,10,15,15,15,10,10,10,12,10,10,10,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,13,15,10,10,10,15,15,10,10,10,15,7,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,14,15,10,10,10,15,1,15,10,10,10,2,4,10,7,10,15,10,6,15,8,10,15,10,15,10,10,13,10,12,10,10,14,12,10,12,10,15,10,15,10,8,10,10,15,15,15,10,10,10,15,13,10,10,10,15,15,10,10,10,7,15,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,15,14,10,10,10,15,15,10,10,10,15,7,10,10,10,15,15,15,10,10,10,12,10,10,10,15,15,10,10,10,8,10,10,10,15,15,15,10,10,10,15,13,10,10,10,15,15,10,10,10,7,15,10,10,10,15,15,15,10,10,10,13,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,15,14,10,10,10,15,15,10,10,10,15,7,10,10,10,15,15,10,10,10,12,10,10,10,15,15,15,10,10,10,8,10,10,10,15,15,10,10,10,15,13,10,10,10,15,1,15,10,10,10,2,4,10,15,10,7,10,6,8,10,15,10,15,10,10,13,10,13,10,10,14,10,15,15,15,10,10,10,10,10,10,10,10,10,12}; 198 | 199 | const uint8_t musicTicks2[] PROGMEM = {0,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,122,118,120,120,120,0,120,120,120,120,0,120,120,120,120,0,120,120,120,120,0,120,120,120,120,0,120,120,120,120,0,120,120,120,120,0,120,120,120,120,2,118,120,120,120,0,0,120,120,120,120,0,0,120,120,120,120,0,0,120,120,120,120,0,0,120,120,120,120,0,0,120,120,120,120,0,0,120,120,120,120,0,0,120,120,120,120,0,2,118,120,120,120,0,0,0,120,120,0,120,120,0,0,0,120,120,0,120,120,0,0,0,120,120,0,120,120,0,0,0,120,120,0,120,120,0,0,0,120,120,0,120,120,0,0,0,120,120,0,120,120,0,0,0,120,120,0,120,120,0,0,2,118,120,0,120,120,0,0,0,120,120,0,0,120,120,0,0,0,120,120,0,0,120,120,0,0,0,120,120,0,0,120,120,0,0,0,120,120,0,0,120,120,0,0,0,120,120,0,0,120,120,0,0,0,120,120,0,0,120,120,0,0,0,120,120,0,0,120,120,0,0,2,28,30,30,30,0,30,30,30,30,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,2,28,30,30,30,0,0,30,30,30,30,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,2,28,30,30,30,0,0,0,30,30,30,30,0,0,0,0,120,0,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,2,118,0,0,120,0,0,0,0,120,0,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,120,0,120,0,120,0,120,0,0,0,120,0,120,0,0,0,120,0,120,0,120,0,120,0,0,0,120,0,120,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,0,120,0,120,0,0,120,0,120,0,0,2,118,0,120,0,0,0,0,120,0,120,0,0,0,120,0,60,60,0,0,0,120,0,60,60,0,0,0,60,60,0,60,60,0,60,60,0,60,60,0,120,0,60,60,0,0,0,120,0,60,60,0,0,0,60,60,0,60,60,0,60,60,0,60,60,0,0,0,120,0,60,60,0,120,0,60,60,0,0,60,60,0,60,60,0,0,60,60,0,60,60,0,0,0,120,0,60,60,0,0,120,0,60,60,0,0,2,58,60,0,60,60,0,0,60,60,0,60,60,0,0,0,120,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,120,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,120,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,0,60,0,60,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,2,58,0,60,0,0,60,0,60,0,0,0,60,0,60,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,120,0,0,60,0,60,0,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,120,0,0,60,0,60,0,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,120,0,0,60,0,60,0,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,0,120,0,0,60,0,60,0,0,120,0,0,60,0,60,0,0,2,58,0,60,0,0,60,0,60,0,0,60,0,60,0,0,60,0,60,0,0,120,0,60,60,0,0,120,0,60,60,0,0,60,60,0,60,60,0,0,60,60,0,60,60,0,0,120,0,60,60,0,0,120,0,60,60,0,0,60,60,0,60,60,0,0,60,60,0,60,60,0,0,120,0,60,60,0,0,120,0,60,60,0,0,60,60,0,60,60,0,0,60,60,0,60,60,0,0,120,0,60,60,0,0,120,0,60,60,0,2,58,60,0,60,60,0,0,60,60,0,60,60,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,2,118,0,120,0,0,120,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,2,118,0,0,120,0,0,0,120,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,2,118,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,2,118,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,2,118,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,0,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,0,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,0,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,0,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,0,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,0,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,0,60,0,60,0,0,0,120,0,0,0,120,0,0,2,118,0,0,0,60,60,0,0,0,120,0,0,0,120,0,0,0,120,0,0,60,0,60,0,0,120,0,0,120,0,0,120,0,0,60,0,60,0,0,0,120,0,0,120,0,0,0,120,0,0,60,0,60,0,0,120,0,0,120,0,0,120,0,0,60,0,60,0,0,0,120,0,0,120,0,0,0,120,0,0,60,0,60,0,0,120,0,0,120,0,0,0,120,0,0,60,0,60,0,0,120,0,0,120,0,0,0,120,0,0,60,0,60,0,0,0,120,0,0,120,0,0,2,28,30,30,30,0,0,0,30,30,0,30,30,0,0,120,0,0,0,120,0,0,0,120,0,60,60,0,0,120,0,120,0,0,120,0,60,60,0,0,120,0,120,0,0,0,120,0,60,60,0,120,0,120,0,0,120,0,60,60,0,0,120,0,120,0,0,0,120,0,60,60,0,120,0,0,120,0,0,0,120,0,60,60,0,120,0,120,0,0,0,120,0,60,60,0,0,120,0,120,0,0,2,28,30,30,30,0,0,30,30,30,30,0,120,0,0,0,120,0,0,0,120,120,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,0,120,120,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,0,120,120,120,0,120,0,0,0,120,120,120,120,0,0,0,120,0,120,0,0,120,0,120,0,0,2,28,30,30,30,0,30,30,30,30,120,0,0,0,120,0,0,0,120,120,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,120,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,120,0,120,0,0,120,0,0,0,120,120,120,0,120,0,0,0,0,120,0,120,0,0,120,0,120,0,0,2,118,120,120,0,0,0,120,0,0,0,120,120,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,120,0,120,0,0,120,0,0,120,0,0,120,0,0,0,120,0,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,120,0,120,0,120,0,0,0,120,0,120,0,0,120,0,0,120,0,0,2,118,120,120,0,0,120,0,0,0,120,120,0,0,120,0,120,0,120,0,120,0,0,0,120,0,120,0,0,120,120,0,0,120,0,120,0,120,0,120,0,0,0,120,0,120,0,0,120,0,120,0,0,120,0,120,0,0,120,120,0,0,120,0,120,0,0,0,120,120,0,120,0,120,0,0,2,118,120,120,0,120,0,0,0,120,120,0,0,120,120,0,120,120,0,0,120,0,120,0,0,120,120,0,0,120,120,0,120,120,0,0,120,0,120,0,0,120,120,0,120,120,0,120,120,0,0,0,120,120,0,0,120,120,120,0,120,0,0,2,118,120,120,120,0,0,0,120,120,0,0,120,120,0,0,120,120,0,0,120,0,120,0,0,0,120,120,0,0,120,120,0,0,120,120,0,0,120,0,120,0,0,0,120,120,0,120,120,0,0,120,120,0,0,0,120,120,0,0,0,120,120,0,120,120,0,0,2,118,120,0,120,120,0,0,0,120,120,0,120,120,0,0,120,120,0,120,0,120,0,0,120,120,0,120,120,0,0,120,120,0,120,0,120,0,0,120,120,0,120,120,0,120,120,0,0,120,120,0,0,120,120,0,120,120,0,2,118,120,0,120,120,0,0,120,120,0,120,120,0,120,120,0,120,120,0,120,120,0,120,120,0,120,120,0,120,120,0,120,120,0,120,120,0,120,120,0,120,120,0 200 | }; 201 | const uint8_t musicDuring2[] PROGMEM = {11,7,12,10,14,10,12,10,14,10,12,10,14,10,12,10,14,10,12,10,14,10,12,10,14,10,12,10,14,10,12,10,12,14,10,12,10,14,16,10,12,10,16,14,10,12,10,16,14,10,12,10,16,14,10,12,10,14,16,10,12,10,16,14,10,12,10,16,14,10,12,10,16,12,14,10,12,10,14,16,16,10,12,10,16,16,14,10,12,10,16,16,14,10,12,10,16,16,14,10,12,10,16,14,16,10,12,10,16,16,14,10,12,10,16,16,14,10,12,10,12,14,16,16,10,12,16,10,14,16,16,16,10,12,16,10,16,16,16,14,10,12,16,10,16,16,16,14,10,12,16,10,16,16,16,14,10,12,16,10,14,16,16,16,10,12,16,10,16,16,16,14,10,12,16,10,16,16,16,14,10,12,16,10,16,16,14,16,10,12,16,16,10,14,16,16,16,10,12,16,16,10,18,16,16,14,10,12,18,16,10,18,16,16,14,10,12,18,16,10,16,16,14,18,10,16,16,12,10,14,16,16,16,10,12,16,16,10,16,16,16,14,10,12,16,16,10,16,16,16,14,16,16,16,10,16,16,16,16,12,16,10,16,14,16,16,16,16,10,12,16,16,16,10,16,14,16,16,16,16,10,16,16,16,12,10,16,16,18,16,14,16,10,16,18,16,12,16,10,16,18,16,14,10,16,18,18,16,12,10,18,14,18,18,16,10,16,12,16,16,16,10,16,14,16,16,16,16,10,12,16,16,16,16,10,16,16,16,14,16,10,12,16,16,16,10,16,16,16,16,14,16,16,16,10,16,16,16,16,16,12,16,16,10,16,16,16,16,16,14,10,16,16,12,16,16,16,16,16,10,14,16,16,16,10,16,16,12,16,16,16,16,10,16,16,16,18,14,10,16,16,16,16,18,12,16,16,10,16,16,18,14,10,16,16,12,16,18,18,10,16,18,16,18,18,14,10,16,16,12,20,16,16,20,16,10,20,16,16,14,10,20,16,20,16,16,12,10,20,16,16,16,16,14,10,16,16,12,16,16,16,10,16,16,16,16,16,14,16,16,16,10,16,16,16,16,16,16,12,16,16,16,16,16,16,16,10,14,16,16,16,10,16,16,20,16,16,12,10,16,16,14,20,16,16,10,16,16,16,16,12,10,16,16,16,16,14,10,16,16,16,12,16,16,10,16,16,20,16,16,14,10,16,16,12,16,18,16,18,10,14,20,16,18,16,16,10,12,20,16,10,20,16,20,20,16,14,20,16,10,20,16,12,10,20,16,20,16,16,14,16,16,10,12,16,16,10,16,16,20,16,16,14,10,16,16,12,16,16,16,16,16,16,10,22,16,16,14,16,10,12,16,20,16,16,10,20,16,14,16,10,16,16,12,10,16,16,14,10,16,16,16,12,16,10,16,16,20,16,14,10,16,12,16,10,16,16,14,20,16,16,10,20,12,10,20,14,20,20,10,20,16,12,20,10,20,16,20,16,14,10,16,12,16,16,10,16,16,20,16,14,10,16,16,16,12,16,16,16,10,20,22,16,14,10,20,20,12,20,16,20,10,20,20,14,20,16,20,16,16,10,16,16,12,16,16,10,16,20,14,16,10,16,16,16,12,20,16,10,16,16,16,20,14,16,16,10,16,16,12,16,10,16,16,16,14,20,20,16,10,16,12,20,16,10,16,16,20,14,16,16,10,16,16,12,16,16,10,16,16,16,20,20,14,16,10,16,12,20,16,16,10,16,16,16,20,14,16,16,10,16,12,16,16,16,10,16,16,20,14,20,22,10,16,20,16,20,12,20,20,16,10,16,20,16,20,14,16,20,16,16,16,10,16,16,16,16,12,16,16,16,16,10,16,16,16,16,20,20,14,16,16,10,16,16,16,12,20,20,16,16,10,16,16,16,16,16,14,16,16,16,16,10,16,16,12,16,16,16,16,10,16,16,16,16,16,20,20,14,10,16,16,16,16,12,20,20,16,10,16,16,16,14,16,16,16,16,10,16,16,16,16,16,12,16,16,16,16,10,16,16,16,16,20,20,16,14,10,16,16,16,16,12,20,20,16,10,16,16,16,16,16,16,16,14,16,16,16,16,10,16,16,12,16,16,16,16,16,16,10,16,16,16,20,14,20,20,10,16,20,16,20,12,20,20,10,16,20,16,20,18,14,16,20,16,16,10,16,16,16,16,12,16,16,16,16,16,16,10,16,16,18,20,20,14,10,16,16,16,16,12,20,20,16,16,10,16,16,18,16,16,14,16,16,16,16,10,16,16,12,16,16,16,16,16,16,10,16,16,18,20,20,14,16,16,10,16,16,12,20,20,16,10,16,16,16,18,14,16,16,16,16,16,16,10,16,16,12,16,16,16,16,16,16,10,16,16,18,20,20,14,10,16,16,16,16,12,20,20,10,16,16,16,16,18,16,16,14,16,16,16,16,10,16,16,12,16,16,16,16,16,10,16,16,16,14,20,20,10,16,16,18,12,20,10,16,16,18,14,16,16,10,16,16,18,12,16,16,16,10,16,18,20,14,16,10,16,18,12,20,16,10,16,18,16,14,16,16,10,16,18,12,16,16,16,10,16,18,20,14,10,16,16,18,12,20,10,16,16,18,16,14,16,16,10,16,18,12,16,16,16,10,16,18,20,14,10,16,16,18,12,20,16,10,16,18,16,14,16,16,10,16,18,12,16,16,10,16,16,16,20,14,10,16,18,12,16,10,16,18,14,16,10,16,16,18,12,10,16,16,18,14,16,10,16,18,12,10,16,16,18,14,10,16,16,18,12,16,10,16,18,14,10,16,16,18,12,16,10,18,14,16,10,16,16,18,12,16,10,18,16,14,10,16,18,12,16,10,16,18,16,14,16,10,18,12,16,10,16,14,16,16,10,16,16,18,12,16,16,16,16,10,16,16,14,10,16,16,16,16,18,12,16,16,10,16,16,14,10,16,16,18,12,16,16,10,16,16,16,16,14,10,16,16,18,12,16,16,10,16,16,14,16,16,10,16,16,18,12,16,16,10,16,16,14,16,16,10,16,16,18,12,16,16,10,16,16,16,16,14,16,16,10,18,12,16,16,10,16,16,16,16,14,16,16,10,18,12,16,16,10,16,16,14,16,16,16,16,16,16,10,16,12,16,16,16,10,16,16,16,16,16,14,16,10,16,16,16,16,16,12,16,10,16,16,16,16,16,14,16,10,16,16,16,16,16,12,16,10,16,16,16,16,16,14,16,10,16,16,16,12,16,16,16,10,16,16,16,16,16,14,16,10,16,16,16,12,16,16,16,10,16,16,16,16,16,14,16,10,16,16,16,12,16,16,16,10,16,16,16,16,16,14,16,10,16,16,16,12,16,16,16,16,16,10,16,16,16,14,16,16,16,10,16,12,16,16,16,10,16,16,16,14,16,16,16,10,16,16,16,16,12,16,16,16,10,16,16,16,14,16,16,16,10,16,16,16,12,16,16,16,10,16,16,16,16,14,16,16,16,10,16,16,12,16,16,16,10,16,19,16,16,14,19,16,10,16,19,16,12,16,19,16,10,16,22,16,16,14,22,16,16,10,22,16,12,16,22,16,10,16,19,16,14,16,19,16,10,16,19,16,12,16,19,16,10,16,22,16,16,14,22,16,10,16,22,16,16,12,22,16,10,16,23,16,16,14,16,16,10,16,16,16,12,16,16,16,10,16,16,16,14,16,16,16,10,16,16,16,16,12,16,16,16,10,16,16,16,16,14,16,16,16,10,16,16,16,16,12,16,16,10,16,16,16,16,14,16,16,10,16,16,16,16,12,16,16,16,10,16,19,16,16,14,16,19,16,10,16,19,16,12,16,19,16,10,16,22,16,16,14,22,16,10,16,16,22,16,12,16,22,16,10,16,19,16,14,16,16,19,16,10,16,19,16,12,16,19,16,10,16,22,16,16,14,16,22,16,10,16,16,22,16,12,16,22,16,10,23,16,16,14,16,16,10,16,16,16,16,12,16,16,16,10,16,16,16,14,16,16,16,16,10,16,16,16,12,16,16,16,10,16,16,16,16,16,14,16,16,16,10,16,16,16,16,16,12,16,16,16,10,16,16,16,14,16,16,10,16,16,16,16,12,16,16,16,10,16,16,19,16,16,14,16,16,19,10,16,16,19,12,16,16,19,10,16,16,22,16,16,14,16,22,10,16,16,16,22,12,16,16,16,16,22,10,19,14,16,16,16,19,10,16,16,16,19,12,17,16,19,10,19,16,16,22,21,14,16,22,10,16,16,16,22,12,16,16,16,22,10,16,16,23,16,14,16,10,16,16,16,16,12,16,16,16,16,10,16,18,16,14,16,16,10,16,16,16,12,16,16,10,16,16,16,14,16,16,16,10,16,16,18,12,16,16,10,16,16,18,16,16,14,16,10,16,16,16,12,16,16,10,16,16,16,16,14,16,16,10,16,16,18,16,16,12,10,16,16,18,16,16,14,16,10,16,16,16,12,16,16,10,16,16,14,18,16,16,16,10,16,16,16,12,17,16,10,19,16,18,16,21,14,16,16,10,16,16,12,18,16,16,16,10,16,18,16,16,14,16,16,16,10,16,16,16,16,16,16,16,12,16,16,16,10,16,16,18,14,16,16,10,16,16,12,16,16,16,10,14,16,16,16,10,16,18,12,16,10,16,16,18,16,14,16,10,16,12,16,16,10,16,16,14,16,10,16,18,12,16,16,10,16,18,16,14,16,10,16,12,16,10,16,16,14,16,18,16,16,10,16,12,17,10,19,16,18,21,14,10,16,16,12,18,16,16,10,16,18,16,14,16,16,16,16,10,16,16,16,16,12,16,16,16,10,16,18,14,16,16,10,12,16,10,20,20,16,14,10,20,18,12,20,20,10,20,16,18,14,10,12,20,10,20,16,14,20,10,20,18,12,10,20,14,20,16,18,10,12,10,16,14,20,16,18,10,12,10,20,16,18,14,10,20,20,18,12,10,20,18,20,16,14,16,16,16,10,16,16,16,16,12,20,16,10,16,20,16,16,14,10,16,12,20,20,10,20,20,14,16,10,20,20,12,20,20,10,20,20,20,20,16,14,10,12,20,20,10,20,20,16,14,10,20,20,12,20,20,10,20,20,20,20,16,14,10,20,12,20,20,16,10,20,14,20,16,10,12,20,10,20,20,16,14,20,10,20,20,12,20,10,20,20,20,16,14,10,12,20,20,16,10,20,14,16,16,10,16,12,10,20,20,20,20,14,20,10,20,12,16,20,20,20,20,10,20,20,14,10,12,16,20,20,10,20,20,14,10,20,20,12,16,20,20,10,20,20,14,20,20,10,20,16,20,12,20,10,14,20,20,10,12,16,20,10,20,20,14,20,20,10,12,20,20,10,16,20,16,20,20,14,10,12,20,20,10,20,14,16,16,10,16,12,16,10,20,20,14,20,10,12,16,16,20,10,20,16,20,14,10,12,24,16,20,10,20,14,10,20,16,20,12,23,10,20,23,20,14,10,20,12,16,20,20,10,14,24,20,10,23,16,12,20,10,20,23,20,14,10,12,20,10,16,16,23,20,14,10,12,20,10,16,14,16,16,10,16,12,16,10,14,16,10,12,16,16,10,16,16,16,14,10,12,24,16,10,20,14,10,16,12,23,20,10,20,23,14,10,12,16,10,14,24,10,18,23,16,12,10,18,23,14,10,12,10,16,16,18,23,14,10,12,10,16,14,18,16,10,18,16,12,10,14,18,16,10,18,16,12,10,16,18,16,16,14,10,12,18,24,10,18,20,14,10,12,18,23,20,10,14,18,20,23,10,12,18,10,14,18,24,10,18,18,23,12,10,18,18,23,14,10,12,18,10,18,18,23,14,10,18,12,10,18,18,16,14,10,12,18,10,18,16,14,10,12,18,10,16,18,16,14,10,18,12,10,18,20,14,10,12,18,10,20,18,20,14,10,12,18,10,18,14,10,18,18,12,10,18,18,14,10,18,12,10,18,18,14,10,12,18,10,18,18,14,10,12,18,10,18,14,10,12,18,10,18,14,10,18,12,10,18,14,10,12,18,10,14,18,10,12,18,10,14,18,10,12,18,10,18,14 202 | }; 203 | const uint8_t sampleScale[9][13]= 204 | 205 | {{60,61,62,63,64,65,66,67,68,69,70,71,72}, 206 | {60,62,64,65,67,69,71,72,0,0,0,0,0}, 207 | {60,62,63,65,67,68,70,72,0,0,0,0,0}, 208 | {60,64,67,72,0,0,0,0,0,0,0,0,0}, 209 | {60,63,67,72,0,0,0,0,0,0,0,0,0}, 210 | {60,62,64,67,69,72,0,0,0,0,0,0,0}, 211 | {60,63,65,67,70,72,0,0,0,0,0,0,0}, 212 | {60,63,65,66,67,70,72,0,0,0,0,0,0}, 213 | {60,62,63,65,67,68,71,72,0,0,0,0,0}}; 214 | 215 | 216 | const uint8_t scale[8][128]= 217 | 218 | //Major 219 | {{0,2,2,4,4,5,5,7,7,9,9,11,12,14,14,16,16,17,17,19,19,21,21,23,24,26,26,28,28,29,29,31,31,33,33,35,36,38,38,40,40,41,41,43,43,45,45,47,48,50,50,52,52,53,53,55,55,57,57,59,60,62,62,64,64,65,65,67,67,69,69,71,72,74,74,76,76,77,77,79,79,81,81,83,84,86,86,88,88,89,89,91,91,93,93,95,96,98,98,100,100,101,101,103,103,105,105,107,108,110,110,112,112,113,113,115,115,117,117,119,120,122,122,124,124,125,125,127}, 220 | 221 | //Natural Minor 222 | {0,2,2,3,3,5,5,7,8,8,10,10,12,14,14,15,15,17,17,19,20,20,22,22,24,26,26,27,27,29,29,31,32,32,34,34,36,38,38,39,39,41,41,43,44,44,46,46,48,50,50,51,51,53,53,55,56,56,58,58,60,62,62,63,63,65,65,67,68,68,70,70,72,74,74,75,75,77,77,79,80,80,82,82,84,86,86,87,87,89,89,91,92,92,94,94,96,98,98,99,99,101,101,103,104,104,106,106,108,110,110,111,111,113,113,115,116,116,118,118,120,122,122,123,123,125,125,127}, 223 | 224 | //Major triad 225 | {0,0,4,4,4,4,7,7,7,7,12,12,12,12,16,16,16,16,19,19,19,19,24,24,24,24,28,28,28,28,31,31,31,31,36,36,36,36,40,40,40,40,43,43,43,43,48,48,48,48,52,52,52,52,55,55,55,55,60,60,60,60,64,64,64,64,67,67,67,67,72,72,72,72,76,76,76,76,79,79,79,79,84,84,84,84,88,88,88,88,91,91,91,91,96,96,96,96,100,100,100,100,103,103,103,103,108,108,108,108,112,112,112,112,115,115,115,115,120,120,120,120,124,124,124,124,127,127}, 226 | 227 | //Minor triad 228 | {0,0,3,3,3,3,7,7,7,7,12,12,12,12,15,15,15,15,19,19,19,19,24,24,24,24,27,27,27,27,31,31,31,31,36,36,36,36,39,39,39,39,43,43,43,43,48,48,48,48,51,51,51,51,55,55,55,55,60,60,60,60,63,63,63,63,67,67,67,67,72,72,72,72,75,75,75,75,79,79,79,79,84,84,84,84,87,87,87,87,91,91,91,91,96,96,96,96,99,99,99,99,103,103,103,103,108,108,108,108,111,111,111,111,115,115,115,115,120,120,120,120,123,123,123,123,127,127}, 229 | 230 | //Major Pent 231 | {0,0,2,2,4,4,7,7,9,9,9,12,12,12,14,14,16,16,19,19,21,21,21,24,24,24,26,26,28,28,31,31,33,33,33,36,36,36,38,38,40,40,43,43,45,45,45,48,48,48,50,50,52,52,55,55,57,57,57,60,60,60,62,62,64,64,67,67,69,69,69,72,72,72,74,74,76,76,79,79,81,81,81,84,84,84,86,86,88,88,91,91,93,93,93,96,96,96,98,98,100,100,103,103,105,105,105,108,108,108,110,110,112,112,115,115,117,117,117,120,120,120,122,122,124,124,127,127}, 232 | 233 | //Minor Pent 234 | {0,0,3,3,5,5,7,7,7,10,10,10,12,12,15,15,17,17,19,19,19,22,22,22,24,24,27,27,29,29,31,31,31,34,34,34,36,36,39,39,41,41,43,43,43,46,46,46,48,48,51,51,53,53,55,55,55,58,58,58,60,60,63,63,65,65,67,67,67,70,70,70,72,72,75,75,77,77,79,79,79,82,82,82,84,84,87,87,89,89,91,91,91,94,94,94,96,96,99,99,101,101,103,103,103,106,106,106,108,108,111,111,113,113,115,115,115,118,118,118,120,120,123,123,125,125,127,127}, 235 | 236 | //Blues Hex 237 | {0,0,3,3,5,5,6,6,7,7,10,10,12,12,15,15,17,17,18,18,19,19,22,22,24,24,27,27,29,29,30,30,31,31,34,34,36,36,39,39,41,41,42,42,43,43,46,46,48,48,51,51,53,53,54,54,55,55,58,58,60,60,63,63,65,65,66,66,67,67,70,70,72,72,75,75,77,77,78,78,79,79,82,82,84,84,87,87,89,89,90,90,91,91,94,94,96,96,99,99,101,101,102,102,103,103,106,106,108,108,111,111,113,113,114,114,115,115,118,118,120,120,123,123,125,125,126,126}, 238 | 239 | //Harmonic Minor 240 | {0,0,2,3,3,5,7,7,8,8,11,11,12,12,14,15,15,17,19,19,20,20,23,23,24,24,26,27,27,29,31,31,32,32,35,35,36,36,38,39,39,41,43,43,44,44,47,47,48,48,50,51,51,53,55,55,56,56,59,59,60,60,62,63,63,65,67,67,68,68,71,71,72,72,74,75,75,77,79,79,80,80,83,83,84,84,86,87,87,89,91,91,92,92,95,95,96,96,98,99,99,101,103,103,104,104,107,107,108,108,110,111,111,113,115,115,116,116,119,119,120,120,122,123,123,125,127,127}}; 241 | 242 | #endif 243 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | [env:esp32dev] 2 | platform = espressif32 3 | board = esp32dev 4 | build_flags = 5 | -DBOARD_HAS_PSRAM 6 | -mfix-esp32-psram-cache-issue 7 | -Llib/cyberpi/src/lcd -lGT30L24A3W 8 | framework = arduino 9 | upload_port = /dev/cu.wchusbserial14120 10 | monitor_speed = 115200 11 | -------------------------------------------------------------------------------- /src/main.ino: -------------------------------------------------------------------------------- 1 | #include "cyberpi.h" 2 | 3 | CyberPi cyber; 4 | void setup() 5 | { 6 | cyber.begin(); 7 | } 8 | float j, f, k; 9 | 10 | void loop() 11 | { 12 | for(uint8_t t = 0; t < 5; t++) 13 | { 14 | uint8_t red = 32 * (1 + sin(t / 2.0 + j / 4.0) ); 15 | uint8_t green = 32 * (1 + sin(t / 1.0 + f / 9.0 + 2.1) ); 16 | uint8_t blue = 32 * (1 + sin(t / 3.0 + k / 14.0 + 4.2) ); 17 | cyber.set_rgb(t, red, green, blue); 18 | } 19 | j += random(1, 6) / 6.0; 20 | f += random(1, 6) / 6.0; 21 | k += random(1, 6) / 6.0; 22 | delay(10); 23 | } --------------------------------------------------------------------------------