├── .gitattributes ├── .gitignore ├── Drivers ├── README.md ├── USBtiny.inf ├── amd64 │ ├── libusb0.dll │ └── libusb0.sys ├── ia64 │ ├── libusb0.dll │ └── libusb0.sys ├── installer_x64.exe ├── installer_x86.exe ├── license │ └── libusb0 │ │ └── installer_license.txt ├── usbtiny.cat └── x86 │ ├── libusb0.sys │ └── libusb0_x86.dll ├── Enclosure ├── avr.STL └── lid.STL ├── Firmware └── pocket-prog │ ├── CHANGELOG │ ├── COPYING │ ├── Makefile │ ├── README │ ├── ir │ ├── Makefile │ ├── crc.o │ ├── int.o │ ├── ir.ps │ ├── ir.py │ ├── ir.sch │ ├── main.c │ ├── main.elf │ ├── main.hex │ ├── main.o │ ├── usb.o │ └── usbtiny.h │ ├── patches │ ├── avrdude-5.1.diff │ └── lirc-0.8.0.diff │ ├── spi │ ├── Makefile │ ├── main.c │ ├── main.hex │ ├── spi.ps │ ├── spi.py │ └── usbtiny.h │ ├── usbtiny │ ├── common.mk │ ├── crc.S │ ├── def.h │ ├── int.S │ ├── usb.c │ └── usb.h │ └── util │ ├── Makefile │ ├── _libusb.so │ ├── check.py │ ├── crc16.py │ ├── libusb.i │ ├── libusb.py │ ├── lsusb.py │ ├── sch2ps │ └── usbtiny.py ├── Hardware ├── AVR-Pocket-Programmer.brd └── AVR-Pocket-Programmer.sch ├── Production ├── AVR-Pocket-Programmer-GiantPanel-v11.brd ├── AVR-Pocket-Programmer-Panel-v11.brd └── AVR-Pocket-Programmer_Panel_v11a.brd └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ############# 33 | ## Eagle 34 | ############# 35 | 36 | # Ignore the board and schematic backup files 37 | *.b#? 38 | *.s#? 39 | 40 | 41 | ################# 42 | ## Visual Studio 43 | ################# 44 | 45 | ## Ignore Visual Studio temporary files, build results, and 46 | ## files generated by popular Visual Studio add-ons. 47 | 48 | # User-specific files 49 | *.suo 50 | *.user 51 | *.sln.docstates 52 | 53 | # Build results 54 | [Dd]ebug/ 55 | [Rr]elease/ 56 | *_i.c 57 | *_p.c 58 | *.ilk 59 | *.meta 60 | *.obj 61 | *.pch 62 | *.pdb 63 | *.pgc 64 | *.pgd 65 | *.rsp 66 | *.sbr 67 | *.tlb 68 | *.tli 69 | *.tlh 70 | *.tmp 71 | *.vspscc 72 | .builds 73 | *.dotCover 74 | 75 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 76 | #packages/ 77 | 78 | # Visual C++ cache files 79 | ipch/ 80 | *.aps 81 | *.ncb 82 | *.opensdf 83 | *.sdf 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | 89 | # ReSharper is a .NET coding add-in 90 | _ReSharper* 91 | 92 | # Installshield output folder 93 | [Ee]xpress 94 | 95 | # DocProject is a documentation generator add-in 96 | DocProject/buildhelp/ 97 | DocProject/Help/*.HxT 98 | DocProject/Help/*.HxC 99 | DocProject/Help/*.hhc 100 | DocProject/Help/*.hhk 101 | DocProject/Help/*.hhp 102 | DocProject/Help/Html2 103 | DocProject/Help/html 104 | 105 | # Click-Once directory 106 | publish 107 | 108 | # Others 109 | [Bb]in 110 | [Oo]bj 111 | sql 112 | TestResults 113 | *.Cache 114 | ClientBin 115 | stylecop.* 116 | ~$* 117 | *.dbmdl 118 | Generated_Code #added for RIA/Silverlight projects 119 | 120 | # Backup & report files from converting an old project file to a newer 121 | # Visual Studio version. Backup files are not needed, because we have git ;-) 122 | _UpgradeReport_Files/ 123 | Backup*/ 124 | UpgradeLog*.XML 125 | 126 | 127 | ############ 128 | ## Windows 129 | ############ 130 | 131 | # Windows image file caches 132 | Thumbs.db 133 | 134 | # Folder config file 135 | Desktop.ini 136 | 137 | 138 | ############# 139 | ## Python 140 | ############# 141 | 142 | *.py[co] 143 | 144 | # Packages 145 | *.egg 146 | *.egg-info 147 | dist 148 | build 149 | eggs 150 | parts 151 | bin 152 | var 153 | sdist 154 | develop-eggs 155 | .installed.cfg 156 | 157 | # Installer logs 158 | pip-log.txt 159 | 160 | # Unit test / coverage reports 161 | .coverage 162 | .tox 163 | 164 | #Translations 165 | *.mo 166 | 167 | #Mr Developer 168 | .mr.developer.cfg 169 | 170 | # Mac crap 171 | .DS_Store 172 | -------------------------------------------------------------------------------- /Drivers/README.md: -------------------------------------------------------------------------------- 1 | 2 | Pocket AVR Programmer Drivers 3 | ============================= 4 | 5 | Folder Contents 6 | ------------------- 7 | Windows 7, 8, 8.1, 10 Driver files for the AVR Pocket Programmer. Original Source of files: http://www.adafruit.com/downloads/usbtiny_signed_8.zip 8 | 9 | Please note you no longer need to verify the security signature for the drivers. 10 | 11 | -------------------------------------------------------------------------------- /Drivers/USBtiny.inf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/USBtiny.inf -------------------------------------------------------------------------------- /Drivers/amd64/libusb0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/amd64/libusb0.dll -------------------------------------------------------------------------------- /Drivers/amd64/libusb0.sys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/amd64/libusb0.sys -------------------------------------------------------------------------------- /Drivers/ia64/libusb0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/ia64/libusb0.dll -------------------------------------------------------------------------------- /Drivers/ia64/libusb0.sys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/ia64/libusb0.sys -------------------------------------------------------------------------------- /Drivers/installer_x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/installer_x64.exe -------------------------------------------------------------------------------- /Drivers/installer_x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/installer_x86.exe -------------------------------------------------------------------------------- /Drivers/usbtiny.cat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/usbtiny.cat -------------------------------------------------------------------------------- /Drivers/x86/libusb0.sys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/x86/libusb0.sys -------------------------------------------------------------------------------- /Drivers/x86/libusb0_x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Drivers/x86/libusb0_x86.dll -------------------------------------------------------------------------------- /Enclosure/avr.STL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Enclosure/avr.STL -------------------------------------------------------------------------------- /Enclosure/lid.STL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Enclosure/lid.STL -------------------------------------------------------------------------------- /Firmware/pocket-prog/CHANGELOG: -------------------------------------------------------------------------------- 1 | 2006-03-12 version 1.0 2 | 3 | o Initial release. 4 | 5 | 6 | 2006-03-31 version 1.1 7 | 8 | o Updated patches/avrdude-5.1.diff. The modifications to Makefile.in 9 | are now included, so that automake1.9 is not needed to build avrdude. 10 | 11 | o Changed the dependencies in utils/Makefile so that it will restart 12 | after a compilation failure. 13 | 14 | o Shaved off a couple of instructions in usbtiny/usb.c. The code now 15 | fits in 2K when compiled with gcc-4.0.2, provided USBTINY_VENDOR_NAME 16 | and USBTINY_DEVICE_NAME are undefined. Gcc-4.0.2 produces about 10% 17 | more code than gcc-3.4.3! 18 | 19 | 20 | 2006-07-12 version 1.2 21 | 22 | o Moved the original SPI application to the spi/ subdirectory, and 23 | added a new IR receiver and LCD controller application in the ir/ 24 | subdirectory. 25 | 26 | o Added an optional additional endpoint (for the ir application). 27 | 28 | o Reduced the size of the spi application by a couple of bytes. 29 | 30 | o Converted the usbtiny.py script to a Python module that defines 31 | a class USBtiny. Added test scripts to both application directories 32 | that use this class. 33 | 34 | o Created a common make include file for the applications, and a global 35 | Makefile that recursively runs make in all subdirectories. 36 | 37 | 38 | 2006-12-15 version 1.3 39 | 40 | o Commented out the USBTINY_VENDOR_NAME/USBTINY_DEVICE_NAME macros, 41 | to make the code fit when compiled with gcc-4.1.0, which seems to 42 | be the standard version in most distributions these days. 43 | 44 | o Added a pull-down resistor in the ir schematic to avoid a hang in 45 | the LCD initialization code when no LCD is attached. The LCD code 46 | can now be disabled by defining LCD_PRESENT as 0. 47 | 48 | o The 1K5 pullup of the ir application is now controlled by an I/O pin, 49 | so that the device disappears from the USB bus when it is flashed 50 | in-circuit, and is automatically recognized when it comes out of RESET 51 | (idea from Reinhard Max). 52 | 53 | o Updated lirc patch with a gap calculation fix from Reinhard Max. 54 | 55 | o Fixed some build problems of the libusb python wrapper, and added 56 | proper error reporting. 57 | 58 | o Made the flash and SRAM sizes configurable in the Makefile. 59 | 60 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/Makefile: -------------------------------------------------------------------------------- 1 | # ====================================================================== 2 | # USBtiny global Makefile 3 | # 4 | # Copyright (C) 2006 Dick Streefland 5 | # 6 | # This is free software, licensed under the terms of the GNU General 7 | # Public License as published by the Free Software Foundation. 8 | # ====================================================================== 9 | 10 | DIR = spi ir util 11 | 12 | all clean clobber: 13 | @for i in $(DIR); do $(MAKE) $(MFLAGS) -C $$i $@; done 14 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/README: -------------------------------------------------------------------------------- 1 | USBtiny 2 | ======= 3 | 4 | USBtiny is a software implementation of the USB low-speed protocol for 5 | the Atmel ATtiny microcontrollers. Of course, it will also work on the 6 | ATmega series. The software is written for an AVR clocked at 12 MHz. 7 | At this frequency, each bit on the USB bus takes 8 clock cycles, and 8 | with a lot of trickery, it is possible to decode and encode the USB 9 | waveforms by software. The USB driver needs between 1300 and 1400 10 | bytes of flash space (excluding the optional identification strings), 11 | depending on the configuration and compiler version, and 46 bytes RAM 12 | (excluding stack space). The C interface consists of 3 to 5 functions, 13 | depending on the configuration. 14 | 15 | 16 | Implementation 17 | ============== 18 | 19 | USB uses two differential data signals, D+ and D-, which are normally 20 | complementary. However, the end of a packet is signalled by pulling 21 | both signals low. Data is not transmitted directly on the USB bus, it 22 | is NRZI encoded first. This means that a "0" bit is encoded as a bit 23 | change, and a "1" bit is encoded as no bit change. After 6 "1" bits, 24 | "bit stuffing" takes place to force a change on the USB signal lines. 25 | 26 | The software is interrupt driven: the start of a USB packet triggers 27 | an interrupt. The interrupt handler synchronizes with the sync byte, 28 | removes the NRZI encoding and bit stuffing, and stores the packed in 29 | one of the two RAM buffers. Two buffers are used so that the next 30 | packet can be received while the current one is being processed. 31 | Depending on the packet type, a reply packed may be sent back 32 | immediately in the interrupt handler. 33 | 34 | The rest of the USB driver is written in C. A usb_poll() function 35 | must to be called periodically to poll for incoming packets. Only a 36 | single endpoint is supported at the moment. Standard control requests 37 | are directly handled by the USB driver. Other SETUP requests are 38 | forwarded to a user-supplied function usb_setup(). Support for large 39 | replies and OUT control requests is optional, see usbtiny.h. 40 | 41 | To use the USB driver in your own application, you need to configure 42 | the macros in usbtiny.h, and provide a function usb_setup() to handle 43 | SETUP control packets. Optionally, you need to provide the functions 44 | usb_in() and usb_out(). Your code needs to call the initialization 45 | function usb_init() at program startup, and usb_poll() at regular 46 | intervals. The AVR device type and the upload command should be 47 | configured at the top of the Makefile. 48 | 49 | 50 | Other USB projects 51 | ================== 52 | 53 | This software was inspired by two similar USB projects for the AVR: 54 | 55 | http://www.cesko.host.sk/IgorPlugUSB/IgorPlug-USB%20(AVR)_eng.htm 56 | http://www.obdev.at/products/avrusb/index.html 57 | 58 | My version has the advantage that you have more freedom over which I/O 59 | pins to use for the D+ and D- USB signals. You don't need to use bit 0 60 | for the D+ signal. The only restriction is that both signals should be 61 | on the same I/O port. When you select a pin for D+ that can also 62 | generate an interrupt, only two I/O pins are required. The pin-change 63 | interrupt is deliberately not used, so that it remains available for 64 | other uses. 65 | 66 | Another improvement is that the CRC calculation is faster, because it 67 | uses a lookup table. A bit-wise calculation turned out to be too slow 68 | for the USB controller in my laptop. For instance, the obdev code 69 | worked fine on my desktop computer, but not on my laptop. 70 | 71 | Apart from these advantages, I think that my code is more readable and 72 | easier to configure, but that impression may be caused by a mild form 73 | of the NIH syndrome that I'm suffering from. In any case, I learned a 74 | lot about the USB protocol, and writing the interrupt handler was a 75 | nice puzzle. 76 | 77 | 78 | Hardware 79 | ======== 80 | 81 | The AVR must be clocked with an external 12 MHz crystal. For an 82 | ATtiny2313, this means that the low fuse byte must be reprogrammed, 83 | for instance to 0xff. I also recommend to enable the BOD circuit, 84 | when available. For the ATtiny2313, this means programming the high 85 | fuse byte to 0xdb (BOD level is 2.7V). 86 | 87 | The USB data signals are specified at 3.3V. The easiest way to 88 | accomplish this is to use a 3.3V power supply for the AVR. However, 89 | driving the USB signals with 5V seems to work as well in most cases, 90 | which may be more convenient when you need to interface to 5V 91 | peripherals. According to the USB specification, a device should not 92 | be damaged by 5V signals. I've been running the AVR and USB bus at 5V, 93 | and haven't encounter any problems so far, but I have some reports 94 | of Viao laptops that do not work with 5V signals. In that case, you 95 | can reduce the voltage of the USB data signals by adding 3V6 zener 96 | diodes from the data signals to ground. 97 | 98 | 99 | USBtiny SPI converter 100 | ===================== 101 | 102 | My first USBtiny application is a USB to SPI (Serial Programming 103 | Interface) converter. The SPI signals are connected to a female DB-25 104 | connecter, so that the converter can be plugged onto my AVR parallel 105 | port programmer. Because the most important parallel port signals are 106 | connected to the DB-25 connecter, the same hardware (with different 107 | firmware) could be used to control other parallel port devices. That 108 | is also the reason why I connected the ACK signal to the INT1 pin. 109 | I didn't bother to put capacitors on the crystal, but they are 110 | recommended for reliable operation. The software, the schematic and 111 | a Python test script can be found in the "spi" subdirectory. 112 | 113 | The circuit may be powered via the diode at pin 14 of the DB-25 114 | connector to enable reprograming the ATtiny2313 in-system. This 115 | requires an adaptor cable between another SPI programmer and a DB-25 116 | male connector with the following connections: 117 | 118 | SPI DB25 119 | --- ---- 120 | GND 25 121 | VCC 14 122 | RESET 13 123 | SCK 9 124 | MISO 8 125 | MOSI 7 126 | 127 | Bit-banging the SPI signals via USB turned out to be very slow. To get 128 | reasonable programming speeds, I've moved the SPI algorithm into the 129 | AVR. This means that you can send a 32-bit SPI command in a single USB 130 | packet. In addition, you can read or write up to 255 bytes from/to 131 | flash or EEPROM in a single control transfer. 132 | 133 | The subdirectory "patches" contains a patch for avrdude-5.1 that adds 134 | support for controlling this SPI converter. The programmer name is 135 | "usbtiny". You can use the -B option or the "sck" command to specify 136 | the minimum SCK period in microseconds (range: 1..250, default: 10). 137 | 138 | 139 | USBtiny LIRC compatible IR receiver and LCD controller 140 | ====================================================== 141 | 142 | A second USBtiny application is a receiver for infrared remote 143 | controls that can be used with the LIRC package (http://www.lirc.org/). 144 | The firmware stores the mark/space timings from a TSOP1738 IR decoder 145 | in a buffer that is polled by a LIRC device driver. As a visual 146 | feedback, a LED is flashed when a signal is being received. As an 147 | additional (optional) feature, a 2x16 LCD display is attached to PORTB. 148 | You can control the display via the USB bus. The software, the schematic 149 | and a Python test script can be found in the "ir" subdirectory. 150 | A pull-down resistor at PB3 prevents a hang in the LCD initialization 151 | code when no LCD is attached to PORTB. You can disable the LCD code by 152 | setting the LCD_PRESENT macro in main.c to 0. 153 | 154 | I adopted the "IgorPlug-USB" protocol, so that the existing LIRC 155 | device driver "igorplugusb" could be used without modifications. 156 | Nevertheless, a patch for lirc-0.8.0 is included in the "patches" 157 | subdirectory, with the following modifications: 158 | 1) An increase of the sample rate from 10 to 100 times per second. 159 | This is not required, but improves the responsiveness and repeat 160 | behavior for some remote controls. 161 | 2) A fix from Reinhard Max to get correct gap timings. 162 | 3) A compilation fix for the latest 2.6 Linux kernels. 163 | 164 | 165 | Tools 166 | ===== 167 | 168 | The software was developed on a Linux system. In addition to standard 169 | tools like GNU make, you need the AVR versions of gcc, binutils and 170 | glibc to build the code: On a Debian/Ubuntu system, you can apt-get 171 | the following packages: 172 | 173 | gcc-avr 174 | binutils-avr 175 | avr-libc 176 | 177 | To upload the code to an AVR, I use avrdude with a parallel port 178 | programmer. 179 | 180 | I initially used gcc-3.4.3 with the -Os option, which generates 181 | reasonable compact code. Unfortunately, newer versions like gcc-4.1.0 182 | generate about 10% more code, and as a result, the application code 183 | did not fit in 2K anymore. To make it fit, I had to remove the optional 184 | vendor and device strings, by undefining the USBTINY_VENDOR_NAME and 185 | USBTINY_DEVICE_NAME macros. 186 | 187 | The schematics were created with gschem, which is part of the gEDA 188 | package. The conversion to Postscript is done with a script that 189 | invokes gschem non-interactively. 190 | 191 | The "util" and application code subdirectories each contain their own 192 | Makefile. In addition, there is a global Makefile that recursively 193 | invokes all other Makefiles. 194 | 195 | 196 | Host software 197 | ============= 198 | 199 | The subdirectory "utils" contains a Python module "usbtiny.py" that 200 | defines a class USBtiny that can be used to communicate with the 201 | USBtiny firmware. This class is used by the test scripts. 202 | 203 | The usbtiny.py module uses a Python wrapper around libusb that is 204 | generated by "swig". Type "make" to build the wrapper. Of course, you 205 | need to have swig, libusb and libusb-dev installed on your system. 206 | 207 | Libusb needs appropriate permissions to open a USB device. This means 208 | that you either have to run the scripts as "root", or you should 209 | configure the hotplug or udev system to relax the permissions of the 210 | device file created under /proc/bus/usb/ when the device is plugged 211 | in. With udev, you can change the permissions by adding a rule like 212 | 213 | SUBSYSTEM=="usb_device", MODE="0666" 214 | 215 | to the udev rules in /etc/udev/rules.d/ 216 | 217 | 218 | License 219 | ======= 220 | 221 | The USBtiny software is licensed under the terms of the GNU General 222 | Public License as published by the Free Software Foundation, either 223 | version 2 of the license, or (at your option) any later version. A 224 | copy of the GPL version 2 license can be found in the file COPYING. 225 | 226 | 227 | Author & website 228 | ================ 229 | 230 | Dick Streefland 231 | 232 | http://www.google.com/search?btnI&q=webtag_net_streefland_avr_usbtiny 233 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/Makefile: -------------------------------------------------------------------------------- 1 | # ====================================================================== 2 | # Makefile for USB IR receiver 3 | # 4 | # Copyright (C) 2006 Dick Streefland 5 | # 6 | # This is free software, licensed under the terms of the GNU General 7 | # Public License as published by the Free Software Foundation. 8 | # ====================================================================== 9 | 10 | USBTINY = ../usbtiny 11 | TARGET_ARCH = -mmcu=attiny2313 12 | OBJECTS = main.o 13 | FLASH_CMD = avrdude -pt2313 -U flash:w:main.hex 14 | STACK = 39 15 | FLASH = 2048 16 | SRAM = 128 17 | SCHEM = ir.ps 18 | 19 | include $(USBTINY)/common.mk 20 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/crc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Firmware/pocket-prog/ir/crc.o -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/int.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Firmware/pocket-prog/ir/int.o -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/ir.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # ====================================================================== 3 | # ir.py - USBtiny/ir test program 4 | # ====================================================================== 5 | 6 | import sys, os.path 7 | sys.path[0] = os.path.join(sys.path[0], '../util') 8 | import usbtiny 9 | 10 | vendor = 0x03eb 11 | product = 0x0002 12 | 13 | IGORPLUG_CLEAR = 1 # clear IR data 14 | IGORPLUG_READ = 2 # read IR data (wValue: offset) 15 | LCD_INSTR = 20 # write instructions to LCD (via OUT) 16 | LCD_DATA = 21 # write data to LCD (via OUT) 17 | 18 | usage = """Available commands: 19 | t - perform USB echo test 20 | c - clear IR data 21 | r - read current IR data 22 | i ... - send instruction bytes to LCD 23 | d ... - send data bytes to LCD 24 | s ... - send strings to LCD""" 25 | 26 | dev = usbtiny.USBtiny(vendor, product) 27 | 28 | cmd = '?' 29 | if len(sys.argv) > 1: 30 | cmd = sys.argv[1] 31 | arg = sys.argv[2:] 32 | if cmd == 'r': 33 | data = dev.control_in(IGORPLUG_READ, 0, 0, 3 + 36) 34 | usbtiny.dump(0, data) 35 | elif cmd == 'c': 36 | dev.control_in(IGORPLUG_CLEAR, 0, 0, 0) 37 | elif cmd == 't': 38 | dev.echo_test() 39 | elif cmd == 'i': 40 | s = ''.join([chr(int(x,16)) for x in arg]) 41 | dev.control_out(LCD_INSTR, 0, 0, s) 42 | elif cmd == 'd': 43 | s = ''.join([chr(int(x,16)) for x in arg]) 44 | dev.control_out(LCD_DATA, 0, 0, s) 45 | elif cmd == 's': 46 | dev.control_out(LCD_DATA, 0, 0, ' '.join(arg)) 47 | else: 48 | print >> sys.stderr, usage 49 | sys.exit(1) 50 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/ir.sch: -------------------------------------------------------------------------------- 1 | v 20060906 1 2 | T 63600 57350 5 10 0 0 0 0 1 3 | device=AT90S2313 4 | T 63600 57550 5 10 0 0 0 0 1 5 | footprint=DIP20 6 | T 63600 57750 5 10 0 0 0 0 1 7 | net=GND:10 8 | T 63600 57950 5 10 0 0 0 0 1 9 | net=Vcc:20 10 | T 63600 58150 5 10 0 0 0 0 1 11 | description=8-bit RISC micro controller (Atmel) 12 | T 63600 58350 5 10 0 0 0 0 1 13 | numslots=0 14 | T 63600 58550 5 10 0 0 0 0 1 15 | author=Werner Hoch 16 | T 63500 57500 5 10 0 1 0 0 1 17 | device=HEADER10 18 | T 63500 55500 8 10 0 1 0 0 1 19 | pins=10 20 | T 63500 55500 8 10 0 1 0 0 1 21 | class=IO 22 | T 67500 57850 5 10 0 0 0 0 1 23 | device=DB25 24 | C 56900 56100 1 0 0 resistor-2.sym 25 | { 26 | T 57075 56350 5 10 1 1 0 0 1 27 | refdes=68 28 | } 29 | C 56900 55300 1 0 0 resistor-2.sym 30 | { 31 | T 57075 55550 5 10 1 1 0 0 1 32 | refdes=68 33 | } 34 | C 57800 55900 1 180 0 resistor-2.sym 35 | { 36 | T 57050 55950 5 10 1 1 0 0 1 37 | refdes=1K5 38 | } 39 | T 65500 55650 5 10 0 0 0 0 1 40 | device=AT90S2313 41 | T 65500 55850 5 10 0 0 0 0 1 42 | footprint=DIP20 43 | T 65500 56050 5 10 0 0 0 0 1 44 | net=GND:10 45 | T 65500 56250 5 10 0 0 0 0 1 46 | net=Vcc:20 47 | P 60000 53500 60000 53700 1 0 0 48 | { 49 | T 60050 53600 5 8 1 1 0 0 1 50 | pinnumber=1 51 | T 60050 53600 5 8 0 1 0 2 1 52 | pinseq=1 53 | T 60000 53850 9 8 1 1 0 3 1 54 | pinlabel=Reset 55 | T 60000 54000 5 8 0 1 0 3 1 56 | pintype=in 57 | } 58 | L 59808 53974 60192 53974 3 0 0 0 -1 -1 59 | V 60000 53750 50 6 0 0 0 -1 -1 0 -1 -1 -1 -1 -1 60 | P 59300 53500 59300 53800 1 0 0 61 | { 62 | T 59350 53600 5 8 1 1 0 0 1 63 | pinnumber=4 64 | T 59350 53600 5 8 0 1 0 2 1 65 | pinseq=2 66 | T 59300 53850 9 8 1 1 0 3 1 67 | pinlabel=XTAL2 68 | T 59300 54000 5 8 0 1 0 3 1 69 | pintype=out 70 | } 71 | P 58600 53500 58600 53800 1 0 0 72 | { 73 | T 58650 53600 5 8 1 1 0 0 1 74 | pinnumber=5 75 | T 58650 53600 5 8 0 1 0 2 1 76 | pinseq=3 77 | T 58600 53850 9 8 1 1 0 3 1 78 | pinlabel=XTAL1 79 | T 58600 54000 5 8 0 1 0 3 1 80 | pintype=in 81 | } 82 | P 58000 54600 58300 54600 1 0 0 83 | { 84 | T 58200 54650 5 8 1 1 0 6 1 85 | pinnumber=11 86 | T 58200 54550 5 8 0 1 0 8 1 87 | pinseq=4 88 | T 58350 54600 9 8 1 1 0 0 1 89 | pinlabel=PD6 (ICP) 90 | T 58350 54600 5 8 0 1 0 2 1 91 | pintype=io 92 | } 93 | P 58000 55000 58300 55000 1 0 0 94 | { 95 | T 58200 55050 5 8 1 1 0 6 1 96 | pinnumber=9 97 | T 58200 54950 5 8 0 1 0 8 1 98 | pinseq=5 99 | T 58350 55000 9 8 1 1 0 0 1 100 | pinlabel=PD5 (T1) 101 | T 58350 55000 5 8 0 1 0 2 1 102 | pintype=io 103 | } 104 | P 58000 55400 58300 55400 1 0 0 105 | { 106 | T 58200 55450 5 8 1 1 0 6 1 107 | pinnumber=8 108 | T 58200 55350 5 8 0 1 0 8 1 109 | pinseq=6 110 | T 58350 55400 9 8 1 1 0 0 1 111 | pinlabel=PD4 (T0) 112 | T 58350 55400 5 8 0 1 0 2 1 113 | pintype=io 114 | } 115 | P 58000 55800 58300 55800 1 0 0 116 | { 117 | T 58200 55850 5 8 1 1 0 6 1 118 | pinnumber=7 119 | T 58200 55750 5 8 0 1 0 8 1 120 | pinseq=7 121 | T 58350 55800 9 8 1 1 0 0 1 122 | pinlabel=PD3 (INT1) 123 | T 58350 55800 5 8 0 1 0 2 1 124 | pintype=io 125 | } 126 | P 58000 56200 58300 56200 1 0 0 127 | { 128 | T 58200 56250 5 8 1 1 0 6 1 129 | pinnumber=6 130 | T 58200 56150 5 8 0 1 0 8 1 131 | pinseq=8 132 | T 58350 56200 9 8 1 1 0 0 1 133 | pinlabel=PD2 (INT0) 134 | T 58350 56200 5 8 0 1 0 2 1 135 | pintype=io 136 | } 137 | P 58000 56600 58300 56600 1 0 0 138 | { 139 | T 58200 56650 5 8 1 1 0 6 1 140 | pinnumber=3 141 | T 58200 56550 5 8 0 1 0 8 1 142 | pinseq=9 143 | T 58350 56600 9 8 1 1 0 0 1 144 | pinlabel=PD1 (TXD) 145 | T 58350 56600 5 8 0 1 0 2 1 146 | pintype=io 147 | } 148 | P 58000 57000 58300 57000 1 0 0 149 | { 150 | T 58200 57050 5 8 1 1 0 6 1 151 | pinnumber=2 152 | T 58200 56950 5 8 0 1 0 8 1 153 | pinseq=10 154 | T 58350 57000 9 8 1 1 0 0 1 155 | pinlabel=PD0 (RXD) 156 | T 58350 57000 5 8 0 1 0 2 1 157 | pintype=io 158 | } 159 | P 60600 54200 60300 54200 1 0 0 160 | { 161 | T 60400 54250 5 8 1 1 0 0 1 162 | pinnumber=19 163 | T 60400 54150 5 8 0 1 0 2 1 164 | pinseq=11 165 | T 60250 54200 9 8 1 1 0 6 1 166 | pinlabel=(SCK) PB7 167 | T 60250 54200 5 8 0 1 0 8 1 168 | pintype=io 169 | } 170 | P 60600 54600 60300 54600 1 0 0 171 | { 172 | T 60400 54650 5 8 1 1 0 0 1 173 | pinnumber=18 174 | T 60400 54550 5 8 0 1 0 2 1 175 | pinseq=12 176 | T 60250 54600 9 8 1 1 0 6 1 177 | pinlabel=(MISO) PB6 178 | T 60250 54600 5 8 0 1 0 8 1 179 | pintype=io 180 | } 181 | P 60600 55000 60300 55000 1 0 0 182 | { 183 | T 60400 55050 5 8 1 1 0 0 1 184 | pinnumber=17 185 | T 60400 54950 5 8 0 1 0 2 1 186 | pinseq=13 187 | T 60250 55000 9 8 1 1 0 6 1 188 | pinlabel=(MOSI) PB5 189 | T 60250 55000 5 8 0 1 0 8 1 190 | pintype=io 191 | } 192 | P 60600 55400 60300 55400 1 0 0 193 | { 194 | T 60400 55450 5 8 1 1 0 0 1 195 | pinnumber=16 196 | T 60400 55350 5 8 0 1 0 2 1 197 | pinseq=14 198 | T 60250 55400 9 8 1 1 0 6 1 199 | pinlabel=PB4 200 | T 60250 55400 5 8 0 1 0 8 1 201 | pintype=io 202 | } 203 | P 60600 55800 60300 55800 1 0 0 204 | { 205 | T 60400 55850 5 8 1 1 0 0 1 206 | pinnumber=15 207 | T 60400 55750 5 8 0 1 0 2 1 208 | pinseq=15 209 | T 60250 55800 9 8 1 1 0 6 1 210 | pinlabel=(OC1) PB3 211 | T 60250 55800 5 8 0 1 0 8 1 212 | pintype=io 213 | } 214 | P 60600 56200 60300 56200 1 0 0 215 | { 216 | T 60400 56250 5 8 1 1 0 0 1 217 | pinnumber=14 218 | T 60400 56150 5 8 0 1 0 2 1 219 | pinseq=16 220 | T 60250 56200 9 8 1 1 0 6 1 221 | pinlabel=PB2 222 | T 60250 56200 5 8 0 1 0 8 1 223 | pintype=io 224 | } 225 | P 60600 56600 60300 56600 1 0 0 226 | { 227 | T 60400 56650 5 8 1 1 0 0 1 228 | pinnumber=13 229 | T 60400 56550 5 8 0 1 0 2 1 230 | pinseq=17 231 | T 60250 56600 9 8 1 1 0 6 1 232 | pinlabel=(AIN1) PB1 233 | T 60250 56600 5 8 0 1 0 8 1 234 | pintype=io 235 | } 236 | P 60600 57000 60300 57000 1 0 0 237 | { 238 | T 60400 57050 5 8 1 1 0 0 1 239 | pinnumber=12 240 | T 60400 56950 5 8 0 1 0 2 1 241 | pinseq=18 242 | T 60250 57000 9 8 1 1 0 6 1 243 | pinlabel=(AIN0) PB0 244 | T 60250 57000 5 8 0 1 0 8 1 245 | pintype=io 246 | } 247 | B 58300 53800 2000 3600 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1 248 | T 65500 56450 5 10 0 0 0 0 1 249 | description=8-bit RISC micro controller (Atmel) 250 | T 65500 56650 5 10 0 0 0 0 1 251 | numslots=0 252 | T 65500 56850 5 10 0 0 0 0 1 253 | author=Werner Hoch 254 | T 58300 57450 9 10 1 0 0 0 1 255 | ATtiny2313 256 | C 54500 54600 1 0 0 connector4-1.sym 257 | { 258 | T 54500 56000 5 10 1 1 0 0 1 259 | refdes=USB 260 | } 261 | N 56200 55100 56600 55100 4 262 | N 56600 55100 56600 56200 4 263 | N 56600 56200 56900 56200 4 264 | N 58600 53500 58600 53400 4 265 | N 59300 53500 59300 53400 4 266 | N 57800 56200 58000 56200 4 267 | N 57800 55400 58000 55400 4 268 | N 56200 54800 56200 52500 4 269 | T 60700 52200 9 10 1 0 0 0 1 270 | IR receiver and LCD controller with USB interface 271 | T 55100 55800 9 10 1 0 0 0 1 272 | Vcc 273 | T 55100 55500 9 10 1 0 0 0 1 274 | D- 275 | T 55100 55200 9 10 1 0 0 0 1 276 | D+ 277 | T 55100 54900 9 10 1 0 0 0 1 278 | GND 279 | C 58600 53300 1 0 0 crystal-1.sym 280 | { 281 | T 58650 53100 5 10 1 1 0 0 1 282 | refdes=12MHz 283 | T 58800 54000 5 10 0 0 0 0 1 284 | symversion=0.1 285 | } 286 | C 60200 53400 1 90 1 capacitor-4.sym 287 | { 288 | T 60300 52700 5 10 1 1 0 6 1 289 | refdes=1uF 290 | T 59500 53200 5 10 0 0 270 2 1 291 | symversion=0.1 292 | } 293 | C 56100 52200 1 0 0 EMBEDDEDgnd-1.sym 294 | [ 295 | P 56200 52300 56200 52500 1 0 1 296 | { 297 | T 56258 52361 5 4 0 1 0 0 1 298 | pinnumber=1 299 | T 56258 52361 5 4 0 0 0 0 1 300 | pinseq=1 301 | T 56258 52361 5 4 0 1 0 0 1 302 | pinlabel=1 303 | T 56258 52361 5 4 0 1 0 0 1 304 | pintype=pwr 305 | } 306 | L 56100 52300 56300 52300 3 0 0 0 -1 -1 307 | L 56155 52250 56245 52250 3 0 0 0 -1 -1 308 | L 56180 52210 56220 52210 3 0 0 0 -1 -1 309 | T 56400 52250 8 10 0 0 0 0 1 310 | net=GND:1 311 | ] 312 | C 59500 52500 1 90 0 capacitor-1.sym 313 | { 314 | T 59800 52800 5 10 1 1 180 0 1 315 | refdes=27pF 316 | T 58600 52700 5 10 0 0 90 0 1 317 | symversion=0.1 318 | } 319 | C 58800 52500 1 90 0 capacitor-1.sym 320 | { 321 | T 59100 52800 5 10 1 1 180 0 1 322 | refdes=27pF 323 | T 57900 52700 5 10 0 0 90 0 1 324 | symversion=0.1 325 | } 326 | C 56500 53400 1 270 0 led-2.sym 327 | C 56500 54300 1 270 0 resistor-2.sym 328 | { 329 | T 56600 54300 5 10 1 1 180 0 1 330 | refdes=330 331 | } 332 | T 62150 54650 5 10 0 0 0 0 1 333 | device=AOP-Standard 334 | T 62150 55250 5 10 0 0 0 0 1 335 | footprint=DIP8 336 | T 62150 55450 5 10 0 0 0 0 1 337 | description=single opamp 338 | T 62150 55050 5 10 0 0 0 0 1 339 | numslots=0 340 | T 62150 54850 5 10 0 0 0 0 1 341 | symversion=0.1 342 | T 62150 55650 5 10 0 0 0 0 1 343 | comment=NC-PINS:1,5,8 344 | C 60300 53400 1 0 0 vcc-2.sym 345 | L 56800 54200 57800 54200 3 0 0 0 -1 -1 346 | L 57800 54200 57800 54800 3 0 0 0 -1 -1 347 | L 56800 54800 56800 54200 3 0 0 0 -1 -1 348 | P 57700 54200 57700 53900 1 0 1 349 | { 350 | T 57750 54050 5 8 1 1 0 0 1 351 | pinnumber=3 352 | T 57650 54050 5 8 0 1 270 2 1 353 | pinseq=6 354 | T 57700 54100 9 8 0 1 270 6 1 355 | pinlabel=OUT 356 | T 57700 54100 5 8 0 1 270 8 1 357 | pintype=out 358 | } 359 | P 57200 54200 57200 53900 1 0 1 360 | { 361 | T 57250 54050 5 8 1 1 0 0 1 362 | pinnumber=2 363 | T 57150 54200 5 8 0 1 180 2 1 364 | pinseq=7 365 | T 57200 54200 9 8 0 1 180 5 1 366 | pinlabel=V+ 367 | T 57200 54250 5 8 0 1 180 5 1 368 | pintype=pwr 369 | } 370 | P 56900 54200 56900 53900 1 0 1 371 | { 372 | T 56950 54050 5 8 1 1 0 0 1 373 | pinnumber=1 374 | T 56950 54000 5 8 0 1 0 2 1 375 | pinseq=4 376 | T 56900 54100 9 8 0 1 0 3 1 377 | pinlabel=V- 378 | T 56900 54200 5 8 0 1 0 3 1 379 | pintype=pwr 380 | } 381 | T 56925 54450 9 8 1 0 0 0 1 382 | TSOP1738 383 | L 56800 54800 57800 54800 3 0 0 0 -1 -1 384 | C 57300 53400 1 0 0 vcc-2.sym 385 | N 56900 53900 56900 52500 4 386 | N 58000 54600 58000 53900 4 387 | N 58000 53900 57700 53900 4 388 | N 60600 57000 61400 57000 4 389 | N 61400 57000 61400 54400 4 390 | N 61400 54400 62400 54400 4 391 | N 60600 56600 61200 56600 4 392 | N 61200 56600 61200 54100 4 393 | N 61200 54100 62400 54100 4 394 | N 60600 56200 61000 56200 4 395 | N 61000 56200 61000 53800 4 396 | N 61000 53800 62400 53800 4 397 | N 60600 55800 60800 55800 4 398 | N 60800 53500 62400 53500 4 399 | N 62400 56500 61600 56500 4 400 | N 61600 56500 61600 55400 4 401 | N 61600 55400 60600 55400 4 402 | N 62400 56200 61800 56200 4 403 | N 61800 56200 61800 55000 4 404 | N 61800 55000 60600 55000 4 405 | N 60600 54600 62000 54600 4 406 | N 62000 54600 62000 55900 4 407 | N 62000 55900 62400 55900 4 408 | C 62300 57500 1 180 0 resistor-variable-2.sym 409 | { 410 | T 61650 57600 5 10 1 1 0 0 1 411 | refdes=10K 412 | } 413 | C 62200 57100 1 0 0 EMBEDDEDgnd-1.sym 414 | [ 415 | P 62300 57200 62300 57400 1 0 1 416 | { 417 | T 62358 57261 5 4 0 1 0 0 1 418 | pinnumber=1 419 | T 62358 57261 5 4 0 0 0 0 1 420 | pinseq=1 421 | T 62358 57261 5 4 0 1 0 0 1 422 | pinlabel=1 423 | T 62358 57261 5 4 0 1 0 0 1 424 | pintype=pwr 425 | } 426 | L 62200 57200 62400 57200 3 0 0 0 -1 -1 427 | L 62255 57150 62345 57150 3 0 0 0 -1 -1 428 | L 62280 57110 62320 57110 3 0 0 0 -1 -1 429 | T 62500 57150 8 10 0 0 0 0 1 430 | net=GND:1 431 | ] 432 | N 62400 56800 61800 56800 4 433 | N 61800 56800 61800 56900 4 434 | N 62300 57400 62400 57400 4 435 | C 61200 57400 1 0 0 vcc-2.sym 436 | N 62400 57100 61400 57100 4 437 | N 61400 57100 61400 57400 4 438 | N 56200 55400 56900 55400 4 439 | N 60000 53500 60000 53400 4 440 | B 62700 52600 2200 5100 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1 441 | { 442 | T 63400 58175 8 10 0 0 0 0 1 443 | device=LCD 444 | } 445 | T 62775 57400 3 8 1 0 0 0 1 446 | VSS (GND) 447 | P 62700 57400 62400 57400 1 0 1 448 | { 449 | T 62536 57450 5 8 1 1 0 0 1 450 | pinnumber=1 451 | T 62536 57450 5 8 0 0 0 0 1 452 | pinseq=1 453 | } 454 | T 62775 57100 3 8 1 0 0 0 1 455 | VDD (VCC) 456 | P 62700 57100 62400 57100 1 0 1 457 | { 458 | T 62496 57150 5 8 1 1 0 0 1 459 | pinnumber=2 460 | T 62496 57150 5 8 0 0 0 0 1 461 | pinseq=2 462 | } 463 | T 62775 56800 3 8 1 0 0 0 1 464 | V0 465 | P 62700 56800 62400 56800 1 0 1 466 | { 467 | T 62520 56850 5 8 1 1 0 0 1 468 | pinnumber=3 469 | T 62520 56850 5 8 0 0 0 0 1 470 | pinseq=3 471 | } 472 | T 62775 56500 3 8 1 0 0 0 1 473 | RS 474 | P 62700 56500 62400 56500 1 0 1 475 | { 476 | T 62496 56550 5 8 1 1 0 0 1 477 | pinnumber=4 478 | T 62496 56550 5 8 0 0 0 0 1 479 | pinseq=4 480 | } 481 | T 62775 56200 3 8 1 0 0 0 1 482 | R/W 483 | P 62700 56200 62400 56200 1 0 1 484 | { 485 | T 62520 56250 5 8 1 1 0 0 1 486 | pinnumber=5 487 | T 62520 56250 5 8 0 0 0 0 1 488 | pinseq=5 489 | } 490 | T 62775 55900 3 8 1 0 0 0 1 491 | E 492 | P 62700 55900 62400 55900 1 0 1 493 | { 494 | T 62504 55950 5 8 1 1 0 0 1 495 | pinnumber=6 496 | T 62504 55950 5 8 0 0 0 0 1 497 | pinseq=6 498 | } 499 | T 62750 55600 3 8 1 0 0 0 1 500 | DB0 501 | P 62700 55600 62400 55600 1 0 1 502 | { 503 | T 62520 55650 5 8 1 1 0 0 1 504 | pinnumber=7 505 | T 62520 55650 5 8 0 0 0 0 1 506 | pinseq=7 507 | } 508 | T 62750 55300 3 8 1 0 0 0 1 509 | DB1 510 | P 62700 55300 62400 55300 1 0 1 511 | { 512 | T 62512 55350 5 8 1 1 0 0 1 513 | pinnumber=8 514 | T 62512 55350 5 8 0 0 0 0 1 515 | pinseq=8 516 | } 517 | T 62750 55000 3 8 1 0 0 0 1 518 | DB2 519 | P 62700 55000 62400 55000 1 0 1 520 | { 521 | T 62496 55050 5 8 1 1 0 0 1 522 | pinnumber=9 523 | T 62496 55050 5 8 0 0 0 0 1 524 | pinseq=9 525 | } 526 | T 62750 54700 3 8 1 0 0 0 1 527 | DB3 528 | P 62400 54700 62700 54700 1 0 0 529 | { 530 | T 62500 54750 5 8 1 1 0 0 1 531 | pinnumber=10 532 | T 62500 54750 5 8 0 0 0 0 1 533 | pinseq=10 534 | } 535 | T 62750 54400 3 8 1 0 0 0 1 536 | DB4 537 | P 62400 54400 62700 54400 1 0 0 538 | { 539 | T 62500 54450 5 8 1 1 0 0 1 540 | pinnumber=11 541 | T 62500 54450 5 8 0 0 0 0 1 542 | pinseq=11 543 | } 544 | T 62750 54100 3 8 1 0 0 0 1 545 | DB5 546 | P 62400 54100 62700 54100 1 0 0 547 | { 548 | T 62500 54150 5 8 1 1 0 0 1 549 | pinnumber=12 550 | T 62500 54150 5 8 0 0 0 0 1 551 | pinseq=12 552 | } 553 | T 62750 53800 3 8 1 0 0 0 1 554 | DB6 555 | P 62400 53800 62700 53800 1 0 0 556 | { 557 | T 62500 53850 5 8 1 1 0 0 1 558 | pinnumber=13 559 | T 62500 53850 5 8 0 0 0 0 1 560 | pinseq=13 561 | } 562 | T 62750 53500 3 8 1 0 0 0 1 563 | DB7 564 | P 62400 53500 62700 53500 1 0 0 565 | { 566 | T 62500 53550 5 8 1 1 0 0 1 567 | pinnumber=14 568 | T 62500 53550 5 8 0 0 0 0 1 569 | pinseq=14 570 | } 571 | T 62750 53200 3 8 1 0 0 0 1 572 | A 573 | P 62400 53200 62700 53200 1 0 0 574 | { 575 | T 62500 53250 5 8 1 1 0 0 1 576 | pinnumber=15 577 | T 62500 53250 5 8 0 0 0 0 1 578 | pinseq=15 579 | } 580 | T 62750 52900 3 8 1 0 0 0 1 581 | K 582 | P 62400 52900 62700 52900 1 0 0 583 | { 584 | T 62500 52950 5 8 1 1 0 0 1 585 | pinnumber=16 586 | T 62500 52950 5 8 0 0 0 0 1 587 | pinseq=16 588 | } 589 | B 63700 52800 1000 4700 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1 590 | L 62900 56350 63100 56350 3 0 0 0 -1 -1 591 | T 63900 55200 9 15 1 0 0 0 1 592 | LCD 593 | C 57400 53400 1 90 1 capacitor-4.sym 594 | { 595 | T 57500 52700 5 10 1 1 0 6 1 596 | refdes=1uF 597 | T 56700 53200 5 10 0 0 270 2 1 598 | symversion=0.1 599 | } 600 | N 56600 54300 56600 55000 4 601 | N 56600 55000 58000 55000 4 602 | N 57800 55800 58000 55800 4 603 | C 56000 55700 1 0 0 vcc-2.sym 604 | N 56900 55800 56800 55800 4 605 | N 56800 55800 56800 55400 4 606 | N 57200 53900 57200 53400 4 607 | C 60900 53400 1 90 1 resistor-2.sym 608 | { 609 | T 60300 53000 5 10 1 1 180 6 1 610 | refdes=22K 611 | } 612 | N 57200 53400 57500 53400 4 613 | N 60000 53400 60500 53400 4 614 | N 56200 52500 60800 52500 4 615 | N 60800 53400 60800 55800 4 616 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/main.c: -------------------------------------------------------------------------------- 1 | // ====================================================================== 2 | // IR receiver and LCD controller with USB interface. 3 | // 4 | // Read IR mark/space patterns from a TSOP1738 on the ICP input pin. 5 | // Mark and space periods are measured in units of 12Mhz/1024, which is 6 | // 85.33 us. Up to 35 periods are stored in a buffer, where they can 7 | // be read via a USB request. The buffer layout and USB requests are 8 | // compatible with the "IgorPlug-USB" device, which is supported by LIRC 9 | // through the "igorplugusb" driver. This implementation should also 10 | // work with that driver. If IgorPlug-USB compatibility is not required, 11 | // the resolution could be improved by reducing SCALING to 9, and you 12 | // could also get rid of the additional endpoint (USBTINY_ENDPOINT). 13 | // 14 | // There are some IR protocols with very long packets length, such as 15 | // the "NEC" protocol (http://www.xs4all.nl/~sbp/knowledge/ir/nec.htm). 16 | // This protocol uses 67 mark/space periods, which is too much for the 17 | // limited amount of RAM in the ATtiny2313. Simply truncating the 18 | // packet to the amount of available buffer space is not an option, 19 | // because the significant bits are at the end of the packet. Instead, 20 | // a buffer of 35 bytes (IR_MAX) is used, of which the last 16 bytes 21 | // (IR_WRAP) are used as a circular buffer. Because both the address 22 | // (16 periods) and the command code (16 periods) are sent twice (normal 23 | // and inverted), the wrapping will result in a buffer with both the 24 | // device address and the inverted command code. Other IR protocols are 25 | // typically shorter than 35 periods. 26 | // 27 | // 16-bit Timer1 is initialized in normal mode with a clock of 12MHz/8. 28 | // Both the positive and negative edges of the IR input signal on the 29 | // ICP input pin trigger an input capture interrupt, because the edge 30 | // selection is toggled on every interrupt. Output compare register A 31 | // is used for a timeout to detect the end of an IR transmission. 32 | // The timeout value is updated on every edge. When at least 4 edges 33 | // were detected when a timeout occurs, the packet count ir.count is 34 | // incremented and the ir.length byte is set to the packed length. This 35 | // byte is checked when a read request is received via USB to see if a 36 | // packet is available 37 | // 38 | // The two interrupt handlers in this file run for more than 28 cycles, 39 | // so they need to reenable interrupts to allow USB interrupts to be 40 | // handled in time. To avoid nested IR interrupts, the input capture and 41 | // output compare interrupts are disabled before the global interrupt 42 | // flag is set. In the input capture interrupt handler, the interrupts 43 | // are disabled for a maximum of 26, 27 and 21 cycles, and in the output 44 | // compare interrupt handler for 21, 23 and 21 cycles. Unfortunately, 45 | // it was not possible to meet the 28 cycle maximum for the input 46 | // capture interrupt handler without replacing the compiler generated 47 | // prolog and epilog code by inline assembly, which makes the code a 48 | // little fragile. 49 | // 50 | // The IR receiver is disabled during an IR buffer read, so that a 51 | // packet that is being tranmitted to the host, is not overwritten by 52 | // the next packet. When a transfer is in progress, 'inpos' has a value 53 | // other than 0xff. When the buffer is read completely, the IR receiver 54 | // is reenabled again, but when the next IR packet has already started, 55 | // this packed is discarded by setting 'edges' to 0xff. 56 | // 57 | // There are two USB request codes to control the LCD, one to write 58 | // instructions, and one to write data to the display. OUT transfers 59 | // are used to transfer up to 255 bytes for a single request. 60 | // 61 | // Stack space calculations for gcc-3.4.3 and gcc-4.1.0: 62 | // 63 | // 3.4.3 4.1.0 64 | // ----- ----- 65 | // 0 0 main 66 | // 0 0 lcd_init (inlined) 67 | // 2 2 usb_init 68 | // 0 0 ir_init (inlined) 69 | // 6 5 usb_poll 70 | // 0 0 usb_receive (inlined) 71 | // 2 2 usb_setup 72 | // 5 5 usb_out 73 | // 4 4 lcd_write 74 | // 2 2 lcd_read4 75 | // 2 2 lcd_write4 76 | // 0 0 usb_transmit (inlined) 77 | // 2 4 usb_int 78 | // 2 2 crc 79 | // 80 | // Maximum stack space is 6+5+4+2=17 for gcc-3.4.3 and 5+5+4+2=16 for 81 | // gcc-4.1.0. Total stack usage: 82 | // - USB interrupt: 11 bytes 83 | // - IR input capture interrupt: 11 bytes 84 | // - IR output compare interrupt: 7 bytes 85 | // - main(): 17 bytes 86 | // The two IR interrupt handler cannot be active simultaneously, so the 87 | // maximum stack space is 17+11+11=39 bytes. 88 | // 89 | // NOTE: The above cycle and stack size figures were obtained by 90 | // inspecting the code generated by gcc-3.4.3 and gcc-4.1.0. 91 | // Other compiler versions may generate different code, leading 92 | // to different figures. Likewise, the replacement prolog and 93 | // epilog code may have to be adapted when a different compiler 94 | // version allocates different registers. 95 | // 96 | // Copyright (C) 2006 Dick Streefland 97 | // 98 | // This is free software, licensed under the terms of the GNU General 99 | // Public License as published by the Free Software Foundation. 100 | // ====================================================================== 101 | 102 | #include 103 | #include 104 | #include "usb.h" 105 | 106 | // ---------------------------------------------------------------------- 107 | // IR receiver definitions 108 | // ---------------------------------------------------------------------- 109 | 110 | #define TIMEOUT 10500 // IR transmission timeout in us 111 | #define IR_MAX 35 // maximum number of IR data bytes 112 | #define IR_WRAP 16 // wrap area at end (for 67 byte NEC protocol) 113 | #define SCALING 10 // 9: 42.67 us period, 10: 85.33 us period 114 | #define LED 5 // PORTD bit number for LED 115 | #define PULLUP 3 // PORTD bit number for D- pullup 116 | 117 | enum 118 | { 119 | // Generic requests 120 | USBTINY_ECHO, // echo test 121 | // IgorPlug-USB requests 122 | IGORPLUG_CLEAR, // clear IR data 123 | IGORPLUG_READ, // read IR data (wValue: offset) 124 | // LCD requests 125 | LCD_INSTR = 20, // write instructions to LCD (via OUT) 126 | LCD_DATA, // write data to LCD (via OUT) 127 | }; 128 | 129 | static byte_t inpos = 0xff; // read position for usb_in(), or 0xff 130 | static byte_t edges; // incremented for each edge 131 | static struct // IgorPlug-USB compatible data layout 132 | { 133 | byte_t length; // length of data[] 134 | byte_t count; // incremented for each IR packet 135 | byte_t offset; // not used 136 | byte_t data[IR_MAX]; // mark/space periods 137 | } ir; 138 | 139 | // ---------------------------------------------------------------------- 140 | // LCD definitions 141 | // ---------------------------------------------------------------------- 142 | 143 | #define LCD_PRESENT 1 // set to 0 to remove LCD support 144 | 145 | #define DDR DDRB 146 | #define PORT PORTB 147 | #define PIN PINB 148 | 149 | #define D4 0 150 | #define RS 4 151 | #define RW 5 152 | #define E 6 153 | 154 | #define MASK_D4 (0xf << D4) 155 | #define MASK_RS (1 << RS) 156 | #define MASK_RW (1 << RW) 157 | #define MASK_E (1 << E) 158 | 159 | // ---------------------------------------------------------------------- 160 | // Handler for timer1 input capture interrupt: edge on IR input 161 | // ---------------------------------------------------------------------- 162 | __attribute__((signal,naked)) // interrupts are DISABLED 163 | extern void SIG_TIMER1_CAPT ( void ) 164 | { 165 | static uint_t prev; 166 | uint_t stamp; 167 | byte_t delta; 168 | byte_t e; 169 | 170 | asm volatile( 171 | "push r23\n" 172 | "in r23,__SREG__\n" 173 | "push r18\n" 174 | "push r19\n" 175 | "push r24\n" 176 | "push r25\n" 177 | :: ); 178 | stamp = ICR1; // get time stamp 179 | TIMSK = 0; // disable both IR interrupts 180 | TCCR1B ^= _BV(ICES1); // toggle edge detector 181 | sei(); // allow USB interrupt 182 | PORTD |= _BV(LED); // switch LED on 183 | asm volatile( 184 | "push r20\n" 185 | "push r21\n" 186 | "push r30\n" 187 | "push r31\n" 188 | :: ); 189 | delta = (stamp - prev + (1 << (SCALING-3-1))) >> (SCALING-3); 190 | asm volatile("" : : "r"(delta) ); // calculate delta (gcc-4.1.0) 191 | prev = stamp; 192 | OCR1A = stamp + 12L * TIMEOUT / 8; // update timeout value 193 | cli(); // enter critical region 194 | e = edges; 195 | if ( e != 0xff ) // packet should not be ignored? 196 | { 197 | if ( e > IR_MAX ) // packet too long for buffer? 198 | { 199 | e -= IR_WRAP; // wrap, don't truncate 200 | } 201 | if ( inpos == 0xff ) // update ir only when USB idle 202 | { 203 | ir.length = 0; // discard previous packet 204 | if ( e > 0 ) 205 | { 206 | ir.data[e - 1] = delta; 207 | } 208 | } 209 | edges = e + 1; 210 | } 211 | sei(); // allow USB interrupt 212 | asm volatile("nop"); // reduce latency to 1 cycle 213 | asm volatile( 214 | "pop r31\n" 215 | "pop r30\n" 216 | "pop r21\n" 217 | "pop r20\n" 218 | :: ); 219 | cli(); 220 | TIMSK = _BV(OCIE1A) | _BV(ICIE1); // reenable IR interrupts 221 | asm volatile( 222 | "pop r25\n" 223 | "pop r24\n" 224 | "pop r19\n" 225 | "pop r18\n" 226 | "out __SREG__,r23\n" 227 | "pop r23\n" 228 | "reti\n" 229 | :: ); 230 | } 231 | 232 | // ---------------------------------------------------------------------- 233 | // Handler for timer1 output compare A interrupt: IR transmission timeout 234 | // ---------------------------------------------------------------------- 235 | __attribute__((signal)) // interrupts are DISABLED 236 | extern void SIG_TIMER1_COMPA ( void ) 237 | { 238 | TIMSK = 0; // disable both IR interrupts 239 | sei(); // allow USB interrupt 240 | PORTD &= ~_BV(LED); // switch LED off 241 | cli(); // enter critical region 242 | if ( edges >= 4 // at least two pulses (NEC) 243 | && edges != 0xff // packet should not be ignored 244 | && inpos == 0xff // update ir only when USB idle 245 | ) 246 | { 247 | ir.count++; 248 | ir.length = edges - 1; // new packet is complete 249 | } 250 | edges = 0; 251 | sei(); // allow USB interrupt 252 | TCCR1B &= ~_BV(ICES1); // reset to negative edge 253 | cli(); 254 | TIMSK = _BV(OCIE1A) | _BV(ICIE1); // reenable IR interrupts 255 | } 256 | 257 | // ---------------------------------------------------------------------- 258 | // Initialize the IR receiver. 259 | // ---------------------------------------------------------------------- 260 | static void ir_init ( void ) 261 | { 262 | DDRD |= _BV(LED); 263 | TCCR1B = _BV(ICNC1) // noise canceler, trigger on negative edge 264 | | _BV(CS11); // clock source clk/8 265 | TIMSK = _BV(OCIE1A) // output compare 1A match interrupt enable 266 | | _BV(ICIE1); // input capture 1 interrupt enable 267 | } 268 | 269 | #if LCD_PRESENT 270 | // ---------------------------------------------------------------------- 271 | // Delay times 100 microseconds. 272 | // ---------------------------------------------------------------------- 273 | static void lcd_delay100u ( byte_t count ) 274 | { 275 | asm volatile( 276 | "0: ldi r25, 240\n" 277 | "1: rjmp 2f\n" 278 | "2: dec r25\n" 279 | " brne 1b\n" // 240 * 5 cycles = 100us 280 | " dec r24\n" 281 | " brne 0b\n" 282 | ); 283 | } 284 | 285 | // ---------------------------------------------------------------------- 286 | // Write 4 bits to the LCD. 287 | // ---------------------------------------------------------------------- 288 | static void lcd_write4 ( byte_t data ) 289 | { 290 | PORT = (PORT & ~ MASK_D4) | (data << D4); 291 | PORT |= MASK_E; // E high period: > 230ns 292 | DDR = MASK_RS | MASK_RW | MASK_E | MASK_D4; // Dx setup time: > 80ns 293 | PORT &= ~ MASK_E; // hold time: > 10ns 294 | DDR = MASK_RS | MASK_RW | MASK_E; 295 | } 296 | 297 | // ---------------------------------------------------------------------- 298 | // Read 4 bits from the LCD. 299 | // ---------------------------------------------------------------------- 300 | static byte_t lcd_read4 ( void ) 301 | { 302 | byte_t save; 303 | byte_t data; 304 | 305 | save = PORT; 306 | PORT = MASK_RW; // address setup time: > 40ns 307 | PORT |= MASK_E; // E high period: > 230ns 308 | asm volatile("rjmp 0f\n0:"); 309 | data = (PIN & MASK_D4) >> D4; // data access time: > 160ns 310 | PORT = save; 311 | return data; 312 | } 313 | 314 | // ---------------------------------------------------------------------- 315 | // Write a byte to the LCD. 316 | // ---------------------------------------------------------------------- 317 | static void lcd_write ( byte_t b ) 318 | { 319 | byte_t h; 320 | 321 | do 322 | { 323 | h = lcd_read4(); 324 | (void) lcd_read4(); 325 | } while ( h & 0x08 ); 326 | lcd_write4( b >> 4 ); 327 | lcd_write4( b & 15 ); 328 | } 329 | 330 | // ---------------------------------------------------------------------- 331 | // Initialize the LCD. 332 | // ---------------------------------------------------------------------- 333 | static void lcd_init ( void ) 334 | { 335 | DDR = MASK_RS | MASK_RW | MASK_E; 336 | PORT = 0; 337 | //lcd_delay100u( 150 ); -- skipped because of RESET delay 338 | lcd_write4( 3 ); 339 | lcd_delay100u( 41 ); 340 | lcd_write4( 3 ); 341 | lcd_delay100u( 1 ); 342 | lcd_write( 0x32 ); // switch to 4-bit mode 343 | lcd_write( 0x28 ); // function set: 4-bit mode, two lines 344 | lcd_write( 0x01 ); // clear display 345 | lcd_write( 0x06 ); // entry mode: increment, no shift 346 | lcd_write( 0x0c ); // display control: on, no cursor 347 | } 348 | #endif /* LCD_PRESENT */ 349 | 350 | // ---------------------------------------------------------------------- 351 | // Handle a non-standard SETUP packet. 352 | // ---------------------------------------------------------------------- 353 | extern byte_t usb_setup ( byte_t data[8] ) 354 | { 355 | byte_t req; 356 | byte_t r; 357 | 358 | r = 0; 359 | 360 | // Generic requests 361 | req = data[1]; 362 | if ( req == USBTINY_ECHO ) 363 | { 364 | r = 8; 365 | } 366 | 367 | // IgorPlug-USB requests 368 | if ( req == IGORPLUG_CLEAR ) 369 | { 370 | ir.length = 0; 371 | inpos = 0xff; 372 | } 373 | if ( req == IGORPLUG_READ ) 374 | { 375 | cli(); 376 | if ( ir.length > 0 ) 377 | { 378 | inpos = data[4]; 379 | r = 0xff; // call usb_in() to get the data 380 | } 381 | else 382 | { 383 | data[0] = 0; 384 | r = 1; 385 | } 386 | sei(); 387 | } 388 | 389 | // LCD requests 390 | if ( req == LCD_INSTR ) 391 | { 392 | PORT &= ~ MASK_RS; // data will be received by usb_out() 393 | } 394 | if ( req == LCD_DATA ) 395 | { 396 | PORT |= MASK_RS; // data will be received by usb_out() 397 | } 398 | 399 | return r; 400 | } 401 | 402 | // ---------------------------------------------------------------------- 403 | // Handle an IN packet. 404 | // ---------------------------------------------------------------------- 405 | extern byte_t usb_in ( byte_t* data, byte_t len ) 406 | { 407 | byte_t n; 408 | byte_t max; 409 | 410 | max = ir.length + 3; 411 | n = 0; 412 | while ( n < len ) 413 | { 414 | if ( inpos >= max ) // end of packet? 415 | { 416 | cli(); 417 | if ( edges ) // next packet already started? 418 | { 419 | edges = 0xff; // ignore remainder of packet 420 | } 421 | inpos = 0xff; // reenable receiver 422 | sei(); 423 | break; 424 | } 425 | data[n++] = (& ir.length)[inpos++]; 426 | } 427 | return n; 428 | } 429 | 430 | // ---------------------------------------------------------------------- 431 | // Handle an OUT packet. 432 | // ---------------------------------------------------------------------- 433 | extern void usb_out ( byte_t* data, byte_t len ) 434 | { 435 | #if LCD_PRESENT 436 | while ( len ) 437 | { 438 | lcd_write( *data++ ); 439 | len--; 440 | } 441 | #endif /* LCD_PRESENT */ 442 | } 443 | 444 | // ---------------------------------------------------------------------- 445 | // Main 446 | // ---------------------------------------------------------------------- 447 | __attribute__((naked)) // suppress redundant SP initialization 448 | extern int main ( void ) 449 | { 450 | PORTD |= _BV(PULLUP); 451 | DDRD |= _BV(PULLUP); // enable pullup on D- 452 | #if LCD_PRESENT 453 | lcd_init(); 454 | #endif /* LCD_PRESENT */ 455 | usb_init(); 456 | ir_init(); 457 | for ( ;; ) 458 | { 459 | usb_poll(); 460 | } 461 | return 0; 462 | } 463 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/main.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Firmware/pocket-prog/ir/main.elf -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/main.hex: -------------------------------------------------------------------------------- 1 | :1000000039C073C050C0B0C204C34DC04CC04BC057 2 | :100010004AC049C048C047C046C045C044C043C0AC 3 | :1000200042C041C040C000CDD914F13C28E5A16CCC 4 | :1000300078B5509D89440E03490052002F004C00B2 5 | :10004000430044000403090409021900010100806F 6 | :10005000280904000001FF000000070581000800D6 7 | :100060000012010101FF000008EB03020003010080 8 | :100070000200010011241FBECFEDCDBF10E0A0E6AD 9 | :10008000B0E0E0EDF7E003C0C89531960D92A436DC 10 | :10009000B107D1F710E0A4E6B0E001C01D92A93B82 11 | :1000A000B107E1F776C3ACCFDC019FEF8FEF660FAE 12 | :1000B000B9F046E2F0E0229560FF2D91E82FE227AB 13 | :1000C000EF70929582958F70392F307F832B9F70C0 14 | :1000D000E40F359193273170932783276A9559F759 15 | :1000E000809590958D939D9308950F931F932F93D3 16 | :1000F000DF93CF930FB70F938299FECF82990BC0F6 17 | :10010000829909C0829907C0829905C0829903C06B 18 | :1001100000E40ABFA8C0C091A100DD27CE55DF4F83 19 | :100120000BE014E124E0829BE9CF3F934F936F9360 20 | :1001300060B330E803C060B3432B49934427647134 21 | :100140002627215020B32471A9F137953C3FA0F513 22 | :100150006227615060B3647137953C3F98F526275C 23 | :100160002150379520B324713C3F90F562276150B0 24 | :1001700037953C3F60B36471A0F526272150379531 25 | :100180003C3FC8F520B324716227615037953C3F4E 26 | :10019000B0F50A9560B37AF064712627215037953F 27 | :1001A0003C3F88F520B324716227615037953C3F6E 28 | :1001B00010F22DC031C048C0612720B324713F77B1 29 | :1001C0004160C6CF3F77426060B364712127C7CFDB 30 | :1001D0003F774460612720B32471622761503795CF 31 | :1001E000C8CF3F7748602127316060B3647126270C 32 | :1001F00021503795C6CF3F7740616127C1CF3F7708 33 | :1002000040622127C4CF3F7740646127C9CF3F7741 34 | :100210004068212700C08FCF30E43ABF0B500195D2 35 | :10022000033090F0C01B2881233C91F12B3481F1E5 36 | :1002300019811F774091B800141731F42936D9F08D 37 | :100240002D3249F0213E39F04427409364006F91EC 38 | :100250004F913F9108C0209364006F914F913F915F 39 | :100260000AB706FD49CF0F910FBFCF91DF912F91B4 40 | :100270001F910F911895009193000023F1F0409188 41 | :10028000A0004423D1F440939300C4E9D0E018C007 42 | :10029000209164002223C1F24091A000442369F41C 43 | :1002A0000093A00020939F000091A1004BE0401B11 44 | :1002B0004093A100C0E6D0E002C0C1E6D0E001E07A 45 | :1002C00022B32B7E206111B3146122BB11BB14E158 46 | :1002D00030E830FF212722BB379547954C3FC0F5CA 47 | :1002E00030FF2127379522BB47954C3FA8F530FFBB 48 | :1002F00021273795000022BB47954C3F78F530FF0A 49 | :1003000021273795000022BB47954C3F48F530FF29 50 | :100310002127699122BB379547954C3F18F530FF4F 51 | :100320002127379522BB47954C3F00F530FF212709 52 | :100330003795479522BB4C3FD8F430FF212737959E 53 | :10034000362F479522BB4C3FA8F40A9512F614C0ED 54 | :100350002127442722BBC2CF2127C5CF2127CBCFBE 55 | :100360002127D1CF2127442722BBD7CF2127DACF7E 56 | :100370002127DFCF2127E5CF2B7E22BB6F914F9125 57 | :100380003F9100E40ABFDF91CF9111B3022F2061AA 58 | :1003900022BB1B7EDFBFDF912F91000011BB02BB90 59 | :1003A0001F910F91189585B7836085BF8BB78064C7 60 | :1003B0008BBF789408950F931F93CF93DF93609131 61 | :1003C000A000662309F46FC08091A1009927CC2773 62 | :1003D000DD27C81BD90BC255DF4F635091E09093C6 63 | :1003E000650010E080919F008D3209F04EC00E81B3 64 | :1003F0008F8181110FEF88818076B1F58981882303 65 | :1004000019F412E0888339C0853021F48A81809301 66 | :10041000690036C08630F9F482E0809365008B81F4 67 | :10042000813021F4C1E6D0E012E127C0823021F40E 68 | :10043000C8E4D0E019E121C0833011F58A81882316 69 | :1004400021F4C4E4D0E014E018C08230C9F4C6E35B 70 | :10045000D0E01EE012C0883011F4988303C08A30C7 71 | :1004600079F41883192F09C08C2F9D2F2DD1182FA7 72 | :100470008F3F19F483E080936500011708F4102F73 73 | :10048000D0936800C093670005C0662319F08C2FD5 74 | :100490009D2F6BD11093660083EC80939400109293 75 | :1004A00093001092A00030919300332309F04CC0C8 76 | :1004B00020916500222309F443C08091940098E8BC 77 | :1004C000892780939400C0916600C93008F0C8E085 78 | :1004D000A5E9B0E0CC2339F1233031F46C2F8A2F19 79 | :1004E0009B2F1CD1C82F1AC0E0916700F0916800C3 80 | :1004F000213039F4932F9C1768F481918D939F5F7D 81 | :10050000FACF932F9C1730F4C895802D31968D9398 82 | :100510009F5FF8CFF0936800E093670080916600DA 83 | :100520008C1B809366006C2F85E990E0BDDDCD5F6C 84 | :10053000C0939300C350C83038F41092650004C0D3 85 | :10054000809169008093B8008AE0849908C0815046 86 | :1005500011F0849BFCCF882311F480936900DF9114 87 | :10056000CF911F910F9108957F937FB72F933F9362 88 | :100570008F939F9324B535B519BE8EB590E4892726 89 | :100580008EBD7894959A4F935F93EF93FF938091EC 90 | :100590006A0090916B00532F422F481B590B952FE7 91 | :1005A000842F805C9F4F880F892F881F990B91950E 92 | :1005B000982F30936B0020936A002A57324C3BBD32 93 | :1005C0002ABDF89420916C002F3F99F0243208F056 94 | :1005D0002051809162008F3F49F410926D002223D8 95 | :1005E00029F0E22FFF27E359FF4F92832F5F2093DB 96 | :1005F0006C0078940000FF91EF915F914F91F89417 97 | :1006000088E489BF9F918F913F912F917FBF7F9108 98 | :1006100018951F920F920FB60F9211248F939F93EC 99 | :1006200019BE78949598F89490916C00943070F07D 100 | :100630009F3F61F0809162008F3F41F480916E0096 101 | :100640008F5F80936E00915090936D0010926C00BC 102 | :1006500078948EB58F7B8EBDF89488E489BF9F9186 103 | :100660008F910F900FBE0F901F90189590EF00C0C4 104 | :100670009A95E9F78A95D1F7089598B3907F982BCA 105 | :1006800098BBC69A8FE787BBC69880E787BB08955B 106 | :1006900098B380E288BBC69A00C086B38F7098BBBF 107 | :1006A000992708951F93CF93C82FF2DF182FF0DFFB 108 | :1006B00013FDFBCF8C2F82958F70DFDF8C2F8F7017 109 | :1006C000DCDFCF911F910895F92FE82F90E0818111 110 | :1006D000882311F498E01FC0813031F490936D00AD 111 | :1006E0008FEF8093620017C0823071F4F89480918C 112 | :1006F0006D00882329F08481809362009FEF02C0FF 113 | :10070000808391E0789407C0843111F4C49803C0C9 114 | :10071000853109F4C49A892F9927089520916D0095 115 | :100720002D5F30E03617F0F44FEFB92FA82F8091EE 116 | :100730006200821758F0F89480916C00882311F0C1 117 | :1007400040936C004093620078940CC0E82FFF2720 118 | :10075000E359FF4F8F5F8093620080818D933F5FED 119 | :10076000361728F3832F992708950F931F93CF935C 120 | :10077000082F192FC62F662341F0F12FE02F81910A 121 | :100780000E2F1F2F8FDFC150C1F7CF911F910F91F7 122 | :100790000895939A8B9A80E787BB18BA83E06DDF40 123 | :1007A00089E264DF83E069DF81E060DF82E37ADF92 124 | :1007B00088E278DF81E076DF86E074DF8CE072DF4C 125 | :1007C000F2DD8D9A82E88EBD88E489BFF4DDFECF2C 126 | :0407D000D25AFF00FA 127 | :00000001FF 128 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Firmware/pocket-prog/ir/main.o -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/usb.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Firmware/pocket-prog/ir/usb.o -------------------------------------------------------------------------------- /Firmware/pocket-prog/ir/usbtiny.h: -------------------------------------------------------------------------------- 1 | // ====================================================================== 2 | // USBtiny Configuration 3 | // 4 | // Copyright (C) 2006 Dick Streefland 5 | // 6 | // This is free software, licensed under the terms of the GNU General 7 | // Public License as published by the Free Software Foundation. 8 | // ====================================================================== 9 | 10 | // The D+ and D- USB signals should be connected to two pins of the same 11 | // I/O port. The following macros define the port letter and the input 12 | // bit numbers: 13 | #define USBTINY_PORT D 14 | #define USBTINY_DPLUS 2 15 | #define USBTINY_DMINUS 4 16 | 17 | // The D+ signal should be connected to an interrupt input to trigger an 18 | // interrupt at the start of a packet. When you use the same pin for the 19 | // D+ USB signal and the interrupt input, only two I/O pins are needed 20 | // for the USB interface. The following macro defines the interrupt 21 | // number: 22 | #define USBTINY_INT 0 23 | 24 | // The power requirement of the USB device in mA, or 0 when the device 25 | // is not bus powered: 26 | #define USBTINY_MAX_POWER 80 27 | 28 | // The USB vendor and device IDs. These values should be unique for 29 | // every distinct device. You can get your own vendor ID from the USB 30 | // Implementers Forum (www.usb.org) if you have a spare $1500 to kill. 31 | // Alternatively, you can buy a small range of device IDs from 32 | // www.voti.nl or www.mecanique.co.uk, or be naughty and use something 33 | // else, like for instance product ID 0x6666, which is registered as 34 | // "Prototype product Vendor ID". 35 | #define USBTINY_VENDOR_ID 0x03eb // IgorPlug-USB 36 | #define USBTINY_DEVICE_ID 0x0002 // IgorPlug-USB 37 | 38 | // The version of the device as a 16-bit number: 256*major + minor. 39 | #define USBTINY_DEVICE_VERSION 0x103 40 | 41 | // The following optional macros may be used as an identification of 42 | // your device. Undefine them when you run out of flash space. 43 | //#define USBTINY_VENDOR_NAME "Dick Streefland" 44 | //#define USBTINY_DEVICE_NAME "USBtiny IR/LCD" 45 | #define USBTINY_DEVICE_NAME "IR/LCD" 46 | #undef USBTINY_SERIAL 47 | 48 | // Define the device class, subclass and protocol. Device class 0xff 49 | // is "vendor specific". 50 | #define USBTINY_DEVICE_CLASS 0xff 51 | #define USBTINY_DEVICE_SUBCLASS 0 52 | #define USBTINY_DEVICE_PROTOCOL 0 53 | 54 | // Define the interface class, subclass and protocol. Interface class 55 | // 0xff is "vendor specific". 56 | #define USBTINY_INTERFACE_CLASS 0xff 57 | #define USBTINY_INTERFACE_SUBCLASS 0 58 | #define USBTINY_INTERFACE_PROTOCOL 0 59 | 60 | // Normally, usb_setup() should write the reply of up to 8 bytes into the 61 | // packet buffer, and return the reply length. When this macro is defined 62 | // as 1, you have the option of returning 0xff instead. In that case, the 63 | // USB driver will call a function usb_in() to obtain the data to send 64 | // back to the host. This can be used to generate the data on-the-fly. 65 | #define USBTINY_CALLBACK_IN 1 66 | 67 | // When this macro is defined as 0, OUT packets are simply ignored. 68 | // When defined as 1, the function usb_out() is called for OUT packets. 69 | // You need this option to send data from the host to the device in 70 | // a control transfer. 71 | #define USBTINY_CALLBACK_OUT 1 72 | 73 | // Set the macro USBTINY_ENDPOINT to 1 to add an additional endpoint, 74 | // according to the values of the three other macros. 75 | #define USBTINY_ENDPOINT 1 76 | #define USBTINY_ENDPOINT_ADDRESS 0x81 // IN endpoint #1 77 | #define USBTINY_ENDPOINT_TYPE 0x00 // control transfer type 78 | #define USBTINY_ENDPOINT_INTERVAL 0 // ignored 79 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/patches/avrdude-5.1.diff: -------------------------------------------------------------------------------- 1 | diff -pu avrdude-5.1/Makefile.am.orig avrdude-5.1/Makefile.am 2 | --- avrdude-5.1/Makefile.am.orig 2006-01-13 00:13:50.000000000 +0100 3 | +++ avrdude-5.1/Makefile.am 2006-02-11 22:09:53.000000000 +0100 4 | @@ -62,6 +62,8 @@ avrdude_SOURCES = \ 5 | bitbang.h \ 6 | butterfly.c \ 7 | butterfly.h \ 8 | + usbtiny.c \ 9 | + usbtiny.h \ 10 | config.c \ 11 | config.h \ 12 | confwin.c \ 13 | diff -pu avrdude-5.1/Makefile.in.orig avrdude-5.1/Makefile.in 14 | --- avrdude-5.1/Makefile.in.orig 2006-01-23 22:45:25.000000000 +0100 15 | +++ avrdude-5.1/Makefile.in 2006-03-25 23:05:12.000000000 +0100 16 | @@ -88,17 +88,17 @@ am_avrdude_OBJECTS = avrdude-config_gram 17 | avrdude-lexer.$(OBJEXT) avrdude-avr.$(OBJEXT) \ 18 | avrdude-avr910.$(OBJEXT) avrdude-avrpart.$(OBJEXT) \ 19 | avrdude-bitbang.$(OBJEXT) avrdude-butterfly.$(OBJEXT) \ 20 | - avrdude-config.$(OBJEXT) avrdude-confwin.$(OBJEXT) \ 21 | - avrdude-crc16.$(OBJEXT) avrdude-fileio.$(OBJEXT) \ 22 | - avrdude-jtagmkI.$(OBJEXT) avrdude-jtagmkII.$(OBJEXT) \ 23 | - avrdude-lists.$(OBJEXT) avrdude-main.$(OBJEXT) \ 24 | - avrdude-par.$(OBJEXT) avrdude-pgm.$(OBJEXT) \ 25 | - avrdude-ppi.$(OBJEXT) avrdude-ppiwin.$(OBJEXT) \ 26 | - avrdude-safemode.$(OBJEXT) avrdude-serbb_posix.$(OBJEXT) \ 27 | - avrdude-serbb_win32.$(OBJEXT) avrdude-ser_posix.$(OBJEXT) \ 28 | - avrdude-ser_win32.$(OBJEXT) avrdude-stk500.$(OBJEXT) \ 29 | - avrdude-stk500v2.$(OBJEXT) avrdude-term.$(OBJEXT) \ 30 | - avrdude-usb_libusb.$(OBJEXT) 31 | + avrdude-usbtiny.$(OBJEXT) avrdude-config.$(OBJEXT) \ 32 | + avrdude-confwin.$(OBJEXT) avrdude-crc16.$(OBJEXT) \ 33 | + avrdude-fileio.$(OBJEXT) avrdude-jtagmkI.$(OBJEXT) \ 34 | + avrdude-jtagmkII.$(OBJEXT) avrdude-lists.$(OBJEXT) \ 35 | + avrdude-main.$(OBJEXT) avrdude-par.$(OBJEXT) \ 36 | + avrdude-pgm.$(OBJEXT) avrdude-ppi.$(OBJEXT) \ 37 | + avrdude-ppiwin.$(OBJEXT) avrdude-safemode.$(OBJEXT) \ 38 | + avrdude-serbb_posix.$(OBJEXT) avrdude-serbb_win32.$(OBJEXT) \ 39 | + avrdude-ser_posix.$(OBJEXT) avrdude-ser_win32.$(OBJEXT) \ 40 | + avrdude-stk500.$(OBJEXT) avrdude-stk500v2.$(OBJEXT) \ 41 | + avrdude-term.$(OBJEXT) avrdude-usb_libusb.$(OBJEXT) 42 | avrdude_OBJECTS = $(am_avrdude_OBJECTS) 43 | avrdude_LDADD = $(LDADD) 44 | DEFAULT_INCLUDES = -I. -I$(srcdir) -I. 45 | @@ -271,6 +271,8 @@ avrdude_SOURCES = \ 46 | bitbang.h \ 47 | butterfly.c \ 48 | butterfly.h \ 49 | + usbtiny.c \ 50 | + usbtiny.h \ 51 | config.c \ 52 | config.h \ 53 | confwin.c \ 54 | @@ -445,6 +447,7 @@ distclean-compile: 55 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/avrdude-stk500v2.Po@am__quote@ 56 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/avrdude-term.Po@am__quote@ 57 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/avrdude-usb_libusb.Po@am__quote@ 58 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/avrdude-usbtiny.Po@am__quote@ 59 | 60 | .c.o: 61 | @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ 62 | @@ -558,6 +561,20 @@ avrdude-butterfly.obj: butterfly.c 63 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 64 | @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(avrdude_CPPFLAGS) $(CPPFLAGS) $(avrdude_CFLAGS) $(CFLAGS) -c -o avrdude-butterfly.obj `if test -f 'butterfly.c'; then $(CYGPATH_W) 'butterfly.c'; else $(CYGPATH_W) '$(srcdir)/butterfly.c'; fi` 65 | 66 | +avrdude-usbtiny.o: usbtiny.c 67 | +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(avrdude_CPPFLAGS) $(CPPFLAGS) $(avrdude_CFLAGS) $(CFLAGS) -MT avrdude-usbtiny.o -MD -MP -MF "$(DEPDIR)/avrdude-usbtiny.Tpo" -c -o avrdude-usbtiny.o `test -f 'usbtiny.c' || echo '$(srcdir)/'`usbtiny.c; \ 68 | +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/avrdude-usbtiny.Tpo" "$(DEPDIR)/avrdude-usbtiny.Po"; else rm -f "$(DEPDIR)/avrdude-usbtiny.Tpo"; exit 1; fi 69 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='usbtiny.c' object='avrdude-usbtiny.o' libtool=no @AMDEPBACKSLASH@ 70 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 71 | +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(avrdude_CPPFLAGS) $(CPPFLAGS) $(avrdude_CFLAGS) $(CFLAGS) -c -o avrdude-usbtiny.o `test -f 'usbtiny.c' || echo '$(srcdir)/'`usbtiny.c 72 | + 73 | +avrdude-usbtiny.obj: usbtiny.c 74 | +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(avrdude_CPPFLAGS) $(CPPFLAGS) $(avrdude_CFLAGS) $(CFLAGS) -MT avrdude-usbtiny.obj -MD -MP -MF "$(DEPDIR)/avrdude-usbtiny.Tpo" -c -o avrdude-usbtiny.obj `if test -f 'usbtiny.c'; then $(CYGPATH_W) 'usbtiny.c'; else $(CYGPATH_W) '$(srcdir)/usbtiny.c'; fi`; \ 75 | +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/avrdude-usbtiny.Tpo" "$(DEPDIR)/avrdude-usbtiny.Po"; else rm -f "$(DEPDIR)/avrdude-usbtiny.Tpo"; exit 1; fi 76 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='usbtiny.c' object='avrdude-usbtiny.obj' libtool=no @AMDEPBACKSLASH@ 77 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 78 | +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(avrdude_CPPFLAGS) $(CPPFLAGS) $(avrdude_CFLAGS) $(CFLAGS) -c -o avrdude-usbtiny.obj `if test -f 'usbtiny.c'; then $(CYGPATH_W) 'usbtiny.c'; else $(CYGPATH_W) '$(srcdir)/usbtiny.c'; fi` 79 | + 80 | avrdude-config.o: config.c 81 | @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(avrdude_CPPFLAGS) $(CPPFLAGS) $(avrdude_CFLAGS) $(CFLAGS) -MT avrdude-config.o -MD -MP -MF "$(DEPDIR)/avrdude-config.Tpo" -c -o avrdude-config.o `test -f 'config.c' || echo '$(srcdir)/'`config.c; \ 82 | @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/avrdude-config.Tpo" "$(DEPDIR)/avrdude-config.Po"; else rm -f "$(DEPDIR)/avrdude-config.Tpo"; exit 1; fi 83 | diff -pu avrdude-5.1/avrdude.conf.in.orig avrdude-5.1/avrdude.conf.in 84 | --- avrdude-5.1/avrdude.conf.in.orig 2006-01-17 22:01:25.000000000 +0100 85 | +++ avrdude-5.1/avrdude.conf.in 2006-02-11 22:09:53.000000000 +0100 86 | @@ -537,6 +537,12 @@ programmer 87 | miso = 7; 88 | ; 89 | 90 | +programmer 91 | + id = "usbtiny"; 92 | + desc = "USB programmer built with ATtiny2313"; 93 | + type = usbtiny; 94 | +; 95 | + 96 | # 97 | # PART DEFINITIONS 98 | # 99 | diff -pu avrdude-5.1/config_gram.y.orig avrdude-5.1/config_gram.y 100 | --- avrdude-5.1/config_gram.y.orig 2005-11-25 07:14:06.000000000 +0100 101 | +++ avrdude-5.1/config_gram.y 2006-02-11 22:09:53.000000000 +0100 102 | @@ -40,6 +40,7 @@ 103 | #include "avr.h" 104 | #include "jtagmkI.h" 105 | #include "jtagmkII.h" 106 | +#include "usbtiny.h" 107 | 108 | #if defined(WIN32NATIVE) 109 | #define strtok_r( _s, _sep, _lasts ) \ 110 | @@ -125,6 +126,7 @@ static int parse_cmdbits(OPCODE * op); 111 | %token K_VCC 112 | %token K_VFYLED 113 | %token K_WRITEPAGE 114 | +%token K_USBTINY 115 | 116 | %token K_NO 117 | %token K_YES 118 | @@ -372,6 +374,12 @@ prog_parm : 119 | } 120 | } | 121 | 122 | + K_TYPE TKN_EQUAL K_USBTINY { 123 | + { 124 | + usbtiny_initpgm(current_prog); 125 | + } 126 | + } | 127 | + 128 | K_DESC TKN_EQUAL TKN_STRING { 129 | strncpy(current_prog->desc, $3->value.string, PGM_DESCLEN); 130 | current_prog->desc[PGM_DESCLEN-1] = 0; 131 | diff -pu avrdude-5.1/lexer.l.orig avrdude-5.1/lexer.l 132 | --- avrdude-5.1/lexer.l.orig 2005-11-25 07:14:06.000000000 +0100 133 | +++ avrdude-5.1/lexer.l 2006-02-11 22:09:53.000000000 +0100 134 | @@ -172,6 +172,7 @@ stk500 { yylval=NULL; return K 135 | stk500v2 { yylval=NULL; return K_STK500V2; } 136 | stk500_devcode { yylval=NULL; return K_STK500_DEVCODE; } 137 | type { yylval=NULL; return K_TYPE; } 138 | +usbtiny { yylval=NULL; return K_USBTINY; } 139 | vcc { yylval=NULL; return K_VCC; } 140 | vfyled { yylval=NULL; return K_VFYLED; } 141 | 142 | diff -pu /dev/null avrdude-5.1/usbtiny.c 143 | --- /dev/null 2006-01-16 00:01:55.000000000 +0100 144 | +++ avrdude-5.1/usbtiny.c 2006-02-25 20:51:32.000000000 +0100 145 | @@ -0,0 +1,414 @@ 146 | +// ---------------------------------------------------------------------- 147 | +// Driver for the "usbtiny" programmer. 148 | +// 149 | +// Copyright (C) 2006 Dick Streefland 150 | +// 151 | +// This is free software, licensed under the terms of the GNU General 152 | +// Public License as published by the Free Software Foundation. 153 | +// ---------------------------------------------------------------------- 154 | + 155 | +#include 156 | +#include 157 | +#include "pgm.h" 158 | +#include "avr.h" 159 | + 160 | +#define USBDEV_VENDOR 0x1964 161 | +#define USBDEV_PRODUCT 0x0001 162 | + 163 | +enum 164 | +{ 165 | + // Generic requests 166 | + USBTINY_ECHO, // echo test 167 | + USBTINY_READ, // read byte (wIndex:address) 168 | + USBTINY_WRITE, // write byte (wIndex:address, wValue:value) 169 | + USBTINY_CLR, // clear bit (wIndex:address, wValue:bitno) 170 | + USBTINY_SET, // set bit (wIndex:address, wValue:bitno) 171 | + // Programming requests 172 | + USBTINY_POWERUP, // apply power (wValue:SCK-period, wIndex:RESET) 173 | + USBTINY_POWERDOWN, // remove power from chip 174 | + USBTINY_SPI, // issue SPI command (wValue:c1c0, wIndex:c3c2) 175 | + USBTINY_POLL_BYTES, // set poll bytes for write (wValue:p1p2) 176 | + USBTINY_FLASH_READ, // read flash (wIndex:address) 177 | + USBTINY_FLASH_WRITE, // write flash (wIndex:address, wValue:timeout) 178 | + USBTINY_EEPROM_READ, // read eeprom (wIndex:address) 179 | + USBTINY_EEPROM_WRITE, // write eeprom (wIndex:address, wValue:timeout) 180 | +}; 181 | + 182 | +enum 183 | +{ 184 | + RESET_LOW = 0, 185 | + RESET_HIGH = 1, 186 | + SCK_MIN = 1, // usec (target clock >= 4 MHz) 187 | + SCK_MAX = 250, // usec (target clock >= 16 KHz) 188 | + SCK_DEFAULT = 10, // usec (target clock >= 0.4 MHz) 189 | + CHUNK_SIZE = 128, // must be power of 2 less than 256 190 | + USB_TIMEOUT = 500, // msec 191 | +}; 192 | + 193 | +typedef unsigned char byte_t; 194 | +typedef unsigned int uint_t; 195 | +typedef unsigned long ulong_t; 196 | + 197 | +extern int avr_write_byte_default ( PROGRAMMER* pgm, AVRPART* p, 198 | + AVRMEM* mem, ulong_t addr, 199 | + byte_t data ); 200 | +extern int verbose; 201 | +extern char* progname; 202 | + 203 | +static usb_dev_handle* usb_handle; 204 | +static int sck_period; 205 | +static int chunk_size; 206 | +static AVRMEM* cache_mem; 207 | +static ulong_t cache_base; 208 | +static byte_t cache_buf[CHUNK_SIZE]; 209 | +static int cache_disable; 210 | + 211 | +// ---------------------------------------------------------------------- 212 | + 213 | +static void usb_control ( int req, int val, int index ) 214 | +{ 215 | + usb_control_msg( usb_handle, 216 | + USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 217 | + req, val, index, NULL, 0, USB_TIMEOUT ); 218 | +} 219 | + 220 | +static int usb_in ( int req, int val, int index, byte_t* buf, int buflen, int umax ) 221 | +{ 222 | + int n; 223 | + int timeout; 224 | + 225 | + timeout = USB_TIMEOUT + (buflen * umax) / 1000; 226 | + n = usb_control_msg( usb_handle, 227 | + USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 228 | + req, val, index, (char*) buf, buflen, timeout ); 229 | + if ( n != buflen ) 230 | + { 231 | + fprintf( stderr, "USB read error: expected %d, got %d\n", buflen, n ); 232 | + return -1; 233 | + } 234 | + return 0; 235 | +} 236 | + 237 | +static int usb_out ( int req, int val, int index, byte_t* buf, int buflen, int umax ) 238 | +{ 239 | + int n; 240 | + int timeout; 241 | + 242 | + timeout = USB_TIMEOUT + (buflen * umax) / 1000; 243 | + n = usb_control_msg( usb_handle, 244 | + USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 245 | + req, val, index, (char*) buf, buflen, timeout ); 246 | + if ( n != buflen ) 247 | + { 248 | + fprintf( stderr, "USB write error: expected %d, got %d\n", buflen, n ); 249 | + return -1; 250 | + } 251 | + return 0; 252 | +} 253 | + 254 | +static int usbtiny_avr_op ( PROGRAMMER* pgm, AVRPART* p, int op, byte_t res[4] ) 255 | +{ 256 | + byte_t cmd[4]; 257 | + 258 | + if ( ! p->op[op] ) 259 | + { 260 | + fprintf( stderr, "Operation %d not defined\n", op ); 261 | + return -1; 262 | + } 263 | + memset( cmd, 0, sizeof(cmd) ); 264 | + avr_set_bits( p->op[op], cmd ); 265 | + return pgm->cmd( pgm, cmd, res ); 266 | +} 267 | + 268 | +// ---------------------------------------------------------------------- 269 | + 270 | +static int usbtiny_open ( PROGRAMMER* pgm, char* name ) 271 | +{ 272 | + struct usb_bus* bus; 273 | + struct usb_device* dev = 0; 274 | + 275 | + usb_init(); 276 | + usb_find_busses(); 277 | + usb_find_devices(); 278 | + for ( bus = usb_busses; bus; bus = bus->next ) 279 | + { 280 | + for ( dev = bus->devices; dev; dev = dev->next ) 281 | + { 282 | + if ( dev->descriptor.idVendor == USBDEV_VENDOR 283 | + && dev->descriptor.idProduct == USBDEV_PRODUCT 284 | + ) 285 | + { 286 | + usb_handle = usb_open( dev ); 287 | + if ( ! usb_handle ) 288 | + { 289 | + fprintf( stderr, 290 | + "Cannot open USB device: %s\n", 291 | + usb_strerror() ); 292 | + return -1; 293 | + } 294 | + return 0; 295 | + } 296 | + } 297 | + } 298 | + fprintf( stderr, "Could not find USB device 0x%x/0x%x\n", 299 | + USBDEV_VENDOR, USBDEV_PRODUCT ); 300 | + return -1; 301 | +} 302 | + 303 | +static void usbtiny_close ( PROGRAMMER* pgm ) 304 | +{ 305 | + if ( ! usb_handle ) 306 | + { 307 | + return; 308 | + } 309 | + usb_close( usb_handle ); 310 | + usb_handle = NULL; 311 | +} 312 | + 313 | +static void usbtiny_set_chunk_size ( int period ) 314 | +{ 315 | + chunk_size = CHUNK_SIZE; 316 | + while ( chunk_size > 8 && period > 16 ) 317 | + { // Reduce the chunk size for a slow SCK to reduce 318 | + // the maximum time of a single USB transfer. 319 | + chunk_size >>= 1; 320 | + period >>= 1; 321 | + } 322 | +} 323 | + 324 | +static int usbtiny_set_sck_period ( PROGRAMMER* pgm, double v ) 325 | +{ 326 | + sck_period = (int) (v * 1e6 + 0.5); 327 | + if ( sck_period < SCK_MIN ) 328 | + { 329 | + sck_period = SCK_MIN; 330 | + } 331 | + if ( sck_period > SCK_MAX ) 332 | + { 333 | + sck_period = SCK_MAX; 334 | + } 335 | + printf( "%s: Setting SCK period to %d usec\n", progname, sck_period ); 336 | + usb_control( USBTINY_POWERUP, sck_period, RESET_LOW ); 337 | + usbtiny_set_chunk_size( sck_period ); 338 | + return 0; 339 | +} 340 | + 341 | +static int usbtiny_initialize ( PROGRAMMER* pgm, AVRPART* p ) 342 | +{ 343 | + byte_t res[4]; 344 | + 345 | + if ( pgm->bitclock > 0.0 ) 346 | + { // -B option specified: convert to valid range for sck_period 347 | + usbtiny_set_sck_period( pgm, pgm->bitclock ); 348 | + } 349 | + else 350 | + { // -B option not specified: use default 351 | + sck_period = SCK_DEFAULT; 352 | + if ( verbose ) 353 | + { 354 | + printf( "%s: Using SCK period of %d usec\n", 355 | + progname, sck_period ); 356 | + } 357 | + usb_control( USBTINY_POWERUP, sck_period, RESET_LOW ); 358 | + usbtiny_set_chunk_size( sck_period ); 359 | + } 360 | + usleep( 50000 ); 361 | + if ( ! usbtiny_avr_op( pgm, p, AVR_OP_PGM_ENABLE, res ) ) 362 | + { // no response, RESET and try again 363 | + usb_control( USBTINY_POWERUP, sck_period, RESET_HIGH ); 364 | + usb_control( USBTINY_POWERUP, sck_period, RESET_LOW ); 365 | + usleep( 20000 ); 366 | + if ( ! usbtiny_avr_op( pgm, p, AVR_OP_PGM_ENABLE, res ) ) 367 | + { // give up 368 | + return -1; 369 | + } 370 | + } 371 | + return 0; 372 | +} 373 | + 374 | +static void usbtiny_powerdown ( PROGRAMMER* pgm ) 375 | +{ 376 | + if ( ! usb_handle ) 377 | + { 378 | + return; 379 | + } 380 | + usb_control( USBTINY_POWERDOWN, 0, 0 ); 381 | +} 382 | + 383 | +static int usbtiny_cmd ( PROGRAMMER* pgm, byte_t cmd[4], byte_t res[4] ) 384 | +{ 385 | + int r; 386 | + 387 | + cache_mem = NULL; 388 | + memset( res, '\0', sizeof(res) ); 389 | + r = usb_in( USBTINY_SPI, (cmd[1] << 8) | cmd[0], (cmd[3] << 8) | cmd[2], 390 | + (char*) res, sizeof(res), 8 * sck_period ); 391 | + if ( verbose > 1 ) 392 | + { 393 | + printf( "CMD: [%02x %02x %02x %02x] [%02x %02x %02x %02x]\n", 394 | + cmd[0], cmd[1], cmd[2], cmd[3], 395 | + res[0], res[1], res[2], res[3] ); 396 | + } 397 | + return (r == 0 && res[2] == cmd[1]); 398 | +} 399 | + 400 | +static int usbtiny_chip_erase ( PROGRAMMER* pgm, AVRPART* p ) 401 | +{ 402 | + byte_t res[4]; 403 | + int r; 404 | + 405 | + r = usbtiny_avr_op( pgm, p, AVR_OP_CHIP_ERASE, res ); 406 | + usleep( p->chip_erase_delay ); 407 | + usb_control( USBTINY_POWERUP, sck_period, RESET_HIGH ); 408 | + pgm->initialize( pgm, p ); 409 | + return r; 410 | +} 411 | + 412 | +static void usbtiny_display ( PROGRAMMER* pgm, char* p ) 413 | +{ 414 | +} 415 | + 416 | +static void usbtiny_enable ( PROGRAMMER* pgm ) 417 | +{ 418 | +} 419 | + 420 | +static void usbtiny_disable ( PROGRAMMER* pgm ) 421 | +{ 422 | +} 423 | + 424 | +static int usbtiny_paged_load ( PROGRAMMER* pgm, AVRPART* p, AVRMEM* m, 425 | + int page_size, int n_bytes ) 426 | +{ 427 | + int i; 428 | + int chunk; 429 | + int req; 430 | + 431 | + req = ( strcmp( m->desc, "flash" ) == 0 432 | + ? USBTINY_FLASH_READ 433 | + : USBTINY_EEPROM_READ 434 | + ); 435 | + for ( i = 0; i < n_bytes; i += chunk ) 436 | + { 437 | + chunk = chunk_size; 438 | + if ( chunk > n_bytes - i ) 439 | + { 440 | + chunk = n_bytes - i; 441 | + } 442 | + usb_in( req, 0, i, m->buf + i, chunk, 32 * sck_period ); 443 | + report_progress( i + chunk, n_bytes, NULL ); 444 | + } 445 | + return n_bytes; 446 | +} 447 | + 448 | +static int usbtiny_paged_write ( PROGRAMMER* pgm, AVRPART* p, AVRMEM* m, 449 | + int page_size, int n_bytes ) 450 | +{ 451 | + int i; 452 | + int chunk; 453 | + int next; 454 | + int req; 455 | + int delay; 456 | + 457 | + req = ( strcmp( m->desc, "flash" ) == 0 458 | + ? USBTINY_FLASH_WRITE 459 | + : USBTINY_EEPROM_WRITE 460 | + ); 461 | + delay = 0; 462 | + if ( ! m->paged ) 463 | + { 464 | + i = (m->readback[1] << 8) | m->readback[0]; 465 | + usb_control( USBTINY_POLL_BYTES, i, 0 ); 466 | + delay = m->max_write_delay; 467 | + } 468 | + for ( i = 0; i < n_bytes; i = next ) 469 | + { 470 | + chunk = chunk_size; 471 | + if ( m->paged && chunk > page_size ) 472 | + { 473 | + chunk = page_size; 474 | + } 475 | + if ( chunk > n_bytes - i ) 476 | + { 477 | + chunk = n_bytes - i; 478 | + } 479 | + usb_out( req, delay, i, m->buf + i, chunk, 32 * sck_period + delay ); 480 | + next = i + chunk; 481 | + if ( m->paged 482 | + && ((next % page_size) == 0 || next == n_bytes) 483 | + ) 484 | + { 485 | + avr_write_page( pgm, p, m, (unsigned long) i ); 486 | + } 487 | + report_progress( next, n_bytes, NULL ); 488 | + } 489 | + return n_bytes; 490 | +} 491 | + 492 | +static int usbtiny_read_byte ( PROGRAMMER* pgm, AVRPART* p, AVRMEM* m, 493 | + ulong_t addr, byte_t* value ) 494 | +{ 495 | + ulong_t base; 496 | + int req; 497 | + int size; 498 | + 499 | + if ( cache_disable > 0 ) 500 | + { 501 | + return -1; // fall back to avr_read_byte_default() 502 | + } 503 | + if ( strcmp( m->desc, "flash" ) != 0 504 | + && strcmp( m->desc, "eeprom" ) != 0 505 | + ) 506 | + { 507 | + return -1; // fall back to avr_read_byte_default() 508 | + } 509 | + base = addr & ~ (chunk_size - 1); 510 | + if ( cache_mem != m || cache_base != base ) 511 | + { 512 | + req = ( strcmp( m->desc, "flash" ) == 0 513 | + ? USBTINY_FLASH_READ 514 | + : USBTINY_EEPROM_READ 515 | + ); 516 | + size = (m->size < chunk_size ? m->size : chunk_size); 517 | + if ( usb_in( req, 0, (int) base, cache_buf, size, 32 * sck_period ) != 0 ) 518 | + { 519 | + cache_mem = NULL; 520 | + return -1; 521 | + } 522 | + cache_mem = m; 523 | + cache_base = base; 524 | + } 525 | + *value = cache_buf[addr - base]; 526 | + return 0; 527 | +} 528 | + 529 | +static int usbtiny_write_byte ( PROGRAMMER* pgm, AVRPART* p, AVRMEM* m, 530 | + ulong_t addr, byte_t value ) 531 | +{ 532 | + int r; 533 | + 534 | + cache_disable++; 535 | + r = avr_write_byte_default( pgm, p, m, addr, value ); 536 | + cache_disable--; 537 | + return r; 538 | +} 539 | + 540 | +extern void usbtiny_initpgm ( PROGRAMMER* pgm ) 541 | +{ 542 | + strcpy( pgm->type, "USBTINY" ); 543 | + pgm->initialize = usbtiny_initialize; 544 | + pgm->display = usbtiny_display; 545 | + pgm->enable = usbtiny_enable; 546 | + pgm->disable = usbtiny_disable; 547 | + pgm->powerup = NULL; 548 | + pgm->powerdown = usbtiny_powerdown; 549 | + pgm->program_enable = NULL; 550 | + pgm->chip_erase = usbtiny_chip_erase; 551 | + pgm->cmd = usbtiny_cmd; 552 | + pgm->open = usbtiny_open; 553 | + pgm->close = usbtiny_close; 554 | + pgm->paged_load = usbtiny_paged_load; 555 | + pgm->paged_write = usbtiny_paged_write; 556 | + pgm->read_byte = usbtiny_read_byte; 557 | + pgm->write_byte = usbtiny_write_byte; 558 | + pgm->set_sck_period = usbtiny_set_sck_period; 559 | +} 560 | diff -pu /dev/null avrdude-5.1/usbtiny.h 561 | --- /dev/null 2006-01-16 00:01:55.000000000 +0100 562 | +++ avrdude-5.1/usbtiny.h 2006-02-11 22:09:53.000000000 +0100 563 | @@ -0,0 +1 @@ 564 | +extern void usbtiny_initpgm ( PROGRAMMER* pgm ); 565 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/patches/lirc-0.8.0.diff: -------------------------------------------------------------------------------- 1 | diff -pu lirc-0.8.0/drivers/lirc_igorplugusb/lirc_igorplugusb.c.orig lirc-0.8.0/drivers/lirc_igorplugusb/lirc_igorplugusb.c 2 | --- lirc-0.8.0/drivers/lirc_igorplugusb/lirc_igorplugusb.c.orig 2005-03-21 15:39:38.000000000 +0100 3 | +++ lirc-0.8.0/drivers/lirc_igorplugusb/lirc_igorplugusb.c 2006-12-13 00:44:23.000000000 +0100 4 | @@ -110,7 +110,7 @@ 5 | #define ADDITIONAL_LIRC_BYTES 2 6 | 7 | /* times to poll per second */ 8 | -#define SAMPLE_RATE 10 9 | +#define SAMPLE_RATE 100 10 | 11 | 12 | /**** Igor's USB Request Codes */ 13 | @@ -373,6 +373,7 @@ static int usb_remote_poll(void* data, s 14 | /* 1 Igor-tick = 85.333333 us */ 15 | code = (unsigned int)ir->buf_in[i] * 85 16 | + (unsigned int)ir->buf_in[i]/3; 17 | + ir->last_time.tv_usec += code; 18 | if(ir->in_space) 19 | code |= PULSE_BIT; 20 | lirc_buffer_write_n(buf, (unsigned char*)&code, 1); 21 | @@ -615,7 +616,7 @@ static struct usb_device_id usb_remote_i 22 | }; 23 | 24 | static struct usb_driver usb_remote_driver = { 25 | - .owner = THIS_MODULE, 26 | + /* .owner = THIS_MODULE, */ 27 | .name = DRIVER_NAME, 28 | .probe = usb_remote_probe, 29 | .disconnect = usb_remote_disconnect, 30 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/spi/Makefile: -------------------------------------------------------------------------------- 1 | # ====================================================================== 2 | # Makefile for USB SPI interface 3 | # 4 | # Copyright (C) 2006 Dick Streefland 5 | # 6 | # This is free software, licensed under the terms of the GNU General 7 | # Public License as published by the Free Software Foundation. 8 | # ====================================================================== 9 | 10 | USBTINY = ../usbtiny 11 | TARGET_ARCH = -mmcu=attiny2313 12 | OBJECTS = main.o 13 | FLASH_CMD = avrdude -c usbtiny -B 1 -pt2313 -U flash:w:main.hex 14 | #FUSE_CMD = avrdude -c usbtiny -B 10 -pt2313 -U hfuse:w:0xd9:m -U lfuse:w:0xef:m 15 | FUSE_CMD = avrdude -c usbtiny -pt2313 -U hfuse:w:0xdf:m -U lfuse:w:0xef:m 16 | STACK = 32 17 | FLASH = 2048 18 | SRAM = 128 19 | SCHEM = spi.ps 20 | 21 | include $(USBTINY)/common.mk 22 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/spi/main.c: -------------------------------------------------------------------------------- 1 | // ====================================================================== 2 | // Control a parallel port AVR programmer (avrdude type "bsd") via USB. 3 | // 4 | // Copyright (C) 2006 Dick Streefland 5 | // 6 | // This is free software, licensed under the terms of the GNU General 7 | // Public License as published by the Free Software Foundation. 8 | // 9 | // ====================================================================== 10 | 11 | #include 12 | #include "usb.h" 13 | 14 | enum 15 | { 16 | // Generic requests 17 | USBTINY_ECHO, // echo test 18 | USBTINY_READ, // read byte 19 | USBTINY_WRITE, // write byte 20 | USBTINY_CLR, // clear bit 21 | USBTINY_SET, // set bit 22 | // Programming requests 23 | USBTINY_POWERUP, // apply power (wValue:SCK-period, wIndex:RESET) 24 | USBTINY_POWERDOWN, // remove power from chip 25 | USBTINY_SPI, // issue SPI command (wValue:c1c0, wIndex:c3c2) 26 | USBTINY_POLL_BYTES, // set poll bytes for write (wValue:p1p2) 27 | USBTINY_FLASH_READ, // read flash (wIndex:address) 28 | USBTINY_FLASH_WRITE, // write flash (wIndex:address, wValue:timeout) 29 | USBTINY_EEPROM_READ, // read eeprom (wIndex:address) 30 | USBTINY_EEPROM_WRITE, // write eeprom (wIndex:address, wValue:timeout) 31 | USBTINY_DDRWRITE, // set port direction 32 | USBTINY_SPI1 // a single SPI command 33 | }; 34 | 35 | // ---------------------------------------------------------------------- 36 | // Programmer output pins: 37 | // LED PB0 (D0) 38 | #define LED PB0 39 | // VCC PB1 (D1) 40 | // VCC PB2 (D2) 41 | // VCC PB3 (D3) 42 | // RESET PB5 (D4) 43 | #define RESET PB4 44 | // MOSI PB5 (D5) 45 | #define MOSI PB5 46 | // SCK PB7 (D7) 47 | #define SCK PB7 48 | 49 | // ---------------------------------------------------------------------- 50 | #define PORT PORTB 51 | #define DDR DDRB 52 | #define POWER_MASK _BV(LED) 53 | #define RESET_MASK _BV(RESET) 54 | #define SCK_MASK _BV(SCK) 55 | #define MOSI_MASK _BV(MOSI) 56 | #define LED_MASK _BV(LED) 57 | 58 | // ---------------------------------------------------------------------- 59 | // Programmer input pins: 60 | // MISO PB6 61 | #define MISO 6 62 | // ---------------------------------------------------------------------- 63 | #define PIN PINB 64 | #define MISO_MASK _BV(MISO) 65 | 66 | // ---------------------------------------------------------------------- 67 | // Local data 68 | // ---------------------------------------------------------------------- 69 | static byte_t sck_period; // SCK period in microseconds (1..250) 70 | static byte_t poll1; // first poll byte for write 71 | static byte_t poll2; // second poll byte for write 72 | static uint_t address; // read/write address 73 | static uint_t timeout; // write timeout in usec 74 | static byte_t cmd0; // current read/write command byte 75 | static byte_t cmd[4]; // SPI command buffer 76 | static byte_t res[4]; // SPI result buffer 77 | 78 | // ---------------------------------------------------------------------- 79 | // Delay exactly times 0.5 microseconds (6 cycles). 80 | // ---------------------------------------------------------------------- 81 | __attribute__((always_inline)) 82 | static void delay ( void ) 83 | { 84 | asm volatile( 85 | " mov __tmp_reg__,%0 \n" 86 | "0: rjmp 1f \n" 87 | "1: nop \n" 88 | " dec __tmp_reg__ \n" 89 | " brne 0b \n" 90 | : : "r" (sck_period) ); 91 | } 92 | 93 | // ---------------------------------------------------------------------- 94 | // Issue one SPI command. 95 | // ---------------------------------------------------------------------- 96 | static void spi ( byte_t* cmd, byte_t* res, int i ) 97 | { 98 | byte_t c; 99 | byte_t r; 100 | byte_t mask; 101 | 102 | while (i != 0) 103 | { 104 | i--; 105 | c = *cmd++; 106 | r = 0; 107 | for ( mask = 0x80; mask; mask >>= 1 ) 108 | { 109 | if ( c & mask ) 110 | { 111 | PORT |= MOSI_MASK; 112 | } 113 | delay(); 114 | PORT |= SCK_MASK; 115 | delay(); 116 | r <<= 1; 117 | if ( PIN & MISO_MASK ) 118 | { 119 | r++; 120 | } 121 | PORT &= ~ MOSI_MASK; 122 | PORT &= ~ SCK_MASK; 123 | } 124 | *res++ = r; 125 | } 126 | } 127 | 128 | // ---------------------------------------------------------------------- 129 | // Create and issue a read or write SPI command. 130 | // ---------------------------------------------------------------------- 131 | static void spi_rw ( void ) 132 | { 133 | uint_t a; 134 | 135 | a = address++; 136 | if ( cmd0 & 0x80 ) 137 | { // eeprom 138 | a <<= 1; 139 | } 140 | cmd[0] = cmd0; 141 | if ( a & 1 ) 142 | { 143 | cmd[0] |= 0x08; 144 | } 145 | cmd[1] = a >> 9; 146 | cmd[2] = a >> 1; 147 | spi( cmd, res, 4 ); 148 | } 149 | 150 | // ---------------------------------------------------------------------- 151 | // Handle a non-standard SETUP packet. 152 | // ---------------------------------------------------------------------- 153 | extern byte_t usb_setup ( byte_t data[8] ) 154 | { 155 | byte_t bit; 156 | byte_t mask; 157 | byte_t* addr; 158 | byte_t req; 159 | 160 | // Generic requests 161 | req = data[1]; 162 | if ( req == USBTINY_ECHO ) 163 | { 164 | return 8; 165 | } 166 | addr = (byte_t*) (int) data[4]; 167 | bit = data[2] & 7; 168 | mask = 1 << bit; 169 | if (req == USBTINY_SET) { 170 | PORT |= mask; 171 | return 0; 172 | } 173 | if (req == USBTINY_CLR) { 174 | PORT &= ~ mask; 175 | return 0; 176 | } 177 | if (req == USBTINY_WRITE) { 178 | PORT = data[2]; 179 | return 0; 180 | } 181 | if (req == USBTINY_READ) { 182 | data[0] = PIN; 183 | return 1; 184 | } 185 | if (req == USBTINY_DDRWRITE) { 186 | DDR = data[2]; 187 | } 188 | // Programming requests 189 | if ( req == USBTINY_POWERUP ) 190 | { 191 | sck_period = data[2]; 192 | mask = POWER_MASK; 193 | if ( data[4] ) 194 | { 195 | mask |= RESET_MASK; 196 | } 197 | PORTD &= ~_BV(4); 198 | DDR = POWER_MASK | RESET_MASK | SCK_MASK | MOSI_MASK; 199 | PORT = mask; 200 | return 0; 201 | } 202 | if ( req == USBTINY_POWERDOWN ) 203 | { 204 | //PORT |= RESET_MASK; 205 | DDR = 0x00; 206 | PORT = 0x00; 207 | PORTD |= _BV(4); 208 | return 0; 209 | } 210 | if ( ! PORT ) 211 | { 212 | return 0; 213 | } 214 | if ( req == USBTINY_SPI ) 215 | { 216 | spi( data + 2, data + 0, 4 ); 217 | return 4; 218 | } 219 | if ( req == USBTINY_SPI1 ) 220 | { 221 | spi( data + 2, data + 0, 1 ); 222 | return 1; 223 | } 224 | if ( req == USBTINY_POLL_BYTES ) 225 | { 226 | poll1 = data[2]; 227 | poll2 = data[3]; 228 | return 0; 229 | } 230 | address = * (uint_t*) & data[4]; 231 | if ( req == USBTINY_FLASH_READ ) 232 | { 233 | cmd0 = 0x20; 234 | return 0xff; // usb_in() will be called to get the data 235 | } 236 | if ( req == USBTINY_EEPROM_READ ) 237 | { 238 | cmd0 = 0xa0; 239 | return 0xff; // usb_in() will be called to get the data 240 | } 241 | timeout = * (uint_t*) & data[2]; 242 | if ( req == USBTINY_FLASH_WRITE ) 243 | { 244 | cmd0 = 0x40; 245 | return 0; // data will be received by usb_out() 246 | } 247 | if ( req == USBTINY_EEPROM_WRITE ) 248 | { 249 | cmd0 = 0xc0; 250 | return 0; // data will be received by usb_out() 251 | } 252 | return 0; 253 | } 254 | 255 | // ---------------------------------------------------------------------- 256 | // Handle an IN packet. 257 | // ---------------------------------------------------------------------- 258 | extern byte_t usb_in ( byte_t* data, byte_t len ) 259 | { 260 | byte_t i; 261 | 262 | for ( i = 0; i < len; i++ ) 263 | { 264 | spi_rw(); 265 | data[i] = res[3]; 266 | } 267 | return len; 268 | } 269 | 270 | // ---------------------------------------------------------------------- 271 | // Handle an OUT packet. 272 | // ---------------------------------------------------------------------- 273 | extern void usb_out ( byte_t* data, byte_t len ) 274 | { 275 | byte_t i; 276 | uint_t usec; 277 | byte_t r; 278 | 279 | for ( i = 0; i < len; i++ ) 280 | { 281 | cmd[3] = data[i]; 282 | spi_rw(); 283 | cmd[0] ^= 0x60; // turn write into read 284 | for ( usec = 0; usec < timeout; usec += 32 * sck_period ) 285 | { // when timeout > 0, poll until byte is written 286 | spi( cmd, res, 4 ); 287 | r = res[3]; 288 | if ( r == cmd[3] && r != poll1 && r != poll2 ) 289 | { 290 | break; 291 | } 292 | } 293 | } 294 | } 295 | 296 | // ---------------------------------------------------------------------- 297 | // Main 298 | // ---------------------------------------------------------------------- 299 | __attribute__((naked)) // suppress redundant SP initialization 300 | extern int main ( void ) 301 | { 302 | PORTD |= _BV(4); 303 | DDRD = _BV(6) | _BV(5) | _BV(4); // setup USB pullup, LED pin and buffer select pins to output 304 | usb_init(); 305 | PORTD = _BV(6) | _BV(4); // pull pull-up and buffer disable high 306 | 307 | for ( ;; ) 308 | { 309 | usb_poll(); 310 | } 311 | return 0; 312 | } 313 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/spi/main.hex: -------------------------------------------------------------------------------- 1 | :100000002CC05BC038C037C036C035C034C033C028 2 | :1000100032C031C030C02FC02EC02DC02CC02BC06C 3 | :100020002AC029C028C000CDD914F13C28E5A16C14 4 | :1000300078B5509D894412010101FF000008811725 5 | :100040009F0C040100000001090212000101008060 6 | :10005000320904000000FF00000011241FBECFED94 7 | :10006000CDBF10E0A2E6B0E001C01D92AE39B107ED 8 | :10007000E1F7A1D3A8C3C4CFDC019FEF8FEF660FD8 9 | :10008000B9F046E2F0E0229560FF2D91E82FE227DB 10 | :10009000EF70929582958F70392F307F832B9F70F0 11 | :1000A000E40F359193273170932783276A9559F789 12 | :1000B000809590958D939D9308950F931F932F9303 13 | :1000C000DF93CF930FB70F938299FECF82990BC026 14 | :1000D000829909C0829907C0829905C0829903C09C 15 | :1000E00000E40ABFA8C0C0918600DD27C957DF4FD2 16 | :1000F0000BE01CE024E0829BE9CF3F934F936F938A 17 | :1001000060B330E803C060B3432B499344276C705D 18 | :100110002627215020B32C70A9F137953C3FA0F53C 19 | :100120006227615060B36C7037953C3F98F5262785 20 | :100130002150379520B32C703C3F90F562276150D9 21 | :1001400037953C3F60B36C70A0F52627215037955A 22 | :100150003C3FC8F520B32C706227615037953C3F77 23 | :10016000B0F50A9560B37AF06C7026272150379568 24 | :100170003C3F88F520B32C706227615037953C3F97 25 | :1001800010F22DC031C048C0612720B32C703F77DA 26 | :100190004160C6CF3F77426060B36C702127C7CF04 27 | :1001A0003F774460612720B32C70622761503795F8 28 | :1001B000C8CF3F7748602127316060B36C70262735 29 | :1001C00021503795C6CF3F7740616127C1CF3F7738 30 | :1001D00040622127C4CF3F7740646127C9CF3F7772 31 | :1001E0004068212700C08FCF30E43ABF0B50019503 32 | :1001F000033090F0C01B2881233C91F12B3481F116 33 | :1002000019811F7740919D00141731F42936D9F0D8 34 | :100210002D3249F0213E39F04427409362006F911E 35 | :100220004F913F9108C0209362006F914F913F9191 36 | :100230000AB706FD49CF0F910FBFCF91DF912F91E4 37 | :100240001F910F911895009178000023F1F04091D3 38 | :1002500085004423D1F440937800C9E7D0E018C06A 39 | :10026000209162002223C1F240918500442369F469 40 | :100270000093850020938400009186004BE0401B92 41 | :1002800040938600C0E6D0E002C0C1E6D0E001E0C5 42 | :1002900022B3237F286011B31C6022BB11BB1CE07A 43 | :1002A00030E830FF212722BB379547954C3FC0F5FA 44 | :1002B00030FF2127379522BB47954C3FA8F530FFEB 45 | :1002C00021273795000022BB47954C3F78F530FF3A 46 | :1002D00021273795000022BB47954C3F48F530FF5A 47 | :1002E0002127699122BB379547954C3F18F530FF80 48 | :1002F0002127379522BB47954C3F00F530FF21273A 49 | :100300003795479522BB4C3FD8F430FF21273795CE 50 | :10031000362F479522BB4C3FA8F40A9512F614C01D 51 | :100320002127442722BBC2CF2127C5CF2127CBCFEE 52 | :100330002127D1CF2127442722BBD7CF2127DACFAE 53 | :100340002127DFCF2127E5CF237F22BB6F914F915C 54 | :100350003F9100E40ABFDF91CF9111B3022F2860D3 55 | :1003600022BB137FDFBFDF912F91000011BB02BBC7 56 | :100370001F910F91189585B7836085BF8BB78064F7 57 | :100380008BBF789408951F93CF93DF93609185007E 58 | :10039000662309F461C080918600CCE0D0E0C81BE0 59 | :1003A000D109C957DF4F81E08093630080918400B9 60 | :1003B0008D3209F043C01E818F8181111FEF88812A 61 | :1003C000807661F58981882321F41882198292E070 62 | :1003D0002DC0853021F48A81809367009FC08630CC 63 | :1003E00091F482E0809363008B81813021F492E16B 64 | :1003F000C6E3D0E01BC0823009F090C0959A92E12C 65 | :10040000C8E4D0E013C0883019F481E0888304C0C8 66 | :100410008A3009F083C0188291E008C0CE01DBD099 67 | :10042000982F8F3F19F483E080936300191708F029 68 | :10043000192FD0936600C093650005C0635011F07A 69 | :10044000CE015FD110E01093640083EC80937900BB 70 | :10045000109278001092850080917800882309F02E 71 | :1004600053C020916300222309F44AC0809179008F 72 | :1004700098E889278093790010916400193010F072 73 | :1004800018E002C0112379F1233031F48AE790E0BB 74 | :10049000612F22D1182F22C0309165004091660053 75 | :1004A000213061F4832F942FFC01AAE7B0E0819101 76 | :1004B0008D938E2F831B8117D0F30CC0832F942F25 77 | :1004C000FC01AAE7B0E0849131968D938E2F831BB7 78 | :1004D0008117C8F3F0936600E09365008091640093 79 | :1004E000811B809364008AE790E0612FC5DD1D5F6A 80 | :1004F000109378001350183038F41092630004C041 81 | :100500008091670080939D008AE002C0815019F0BD 82 | :10051000839BFCCF05C01092670002C090E088CF9B 83 | :10052000DF91CF911F9108951F93FC01DB01709122 84 | :10053000680023C0108190E060E820E030E0862F62 85 | :10054000812309F0C59A072E00C000000A94E1F744 86 | :10055000C79A072E00C000000A94E1F7990FB699D8 87 | :100560009F5FC598C79866952F5F3F4F283031052C 88 | :1005700031F74150504031969D9341155105D1F6C8 89 | :100580001F91089520916B0030916C002F5F3F4FB9 90 | :1005900030936C0020936B002150304080916F00AD 91 | :1005A00087FF02C0220F331F8093700020FF03C01B 92 | :1005B000886080937000832F8695809371003695B4 93 | :1005C00027952093720080E790E064E770E044E0B4 94 | :1005D00050E0AADF0895FC013181332311F488E053 95 | :1005E0000895BC016E5F7F4F4281242F277081E008 96 | :1005F00090E0982F01C0990F2A95EAF7343019F44A 97 | :1006000088B3982B20C0333021F488B39095982379 98 | :100610001AC0323011F448BB5BC0313019F486B3D4 99 | :1006200080832CC03D3011F447BB15C0353069F4D0 100 | :10063000409368008481882311F091E101C091E02A 101 | :10064000949881EB87BB98BB43C0363021F417BA2E 102 | :1006500018BA949A3DC088B38823E1F1373039F451 103 | :10066000CB01BF0144E050E05FDF84E008953E30FD 104 | :1006700039F4CB01BF0141E050E056DF81E008953D 105 | :10068000383031F440936900838180936A0020C040 106 | :100690008481958190936C0080936B00393011F4C4 107 | :1006A00080E203C03B3029F480EA80936F008FEF33 108 | :1006B00008958281938190936E0080936D003A300B 109 | :1006C00011F480E403C03C3029F480EC80936F0087 110 | :1006D00080E0089580E008950F931F93CF93DF93F8 111 | :1006E000062FEC0110E005C04DDF80917700899363 112 | :1006F0001F5F1017C8F3802FDF91CF911F910F91CB 113 | :1007000008957F928F929F92AF92BF92CF92DF9285 114 | :10071000EF92FF920F931F93CF93DF93862EA090BB 115 | :100720006D00B0906E0090906900C0906A002091BA 116 | :100730006800E22EFF2435E0EE0CFF1C3A95E1F74D 117 | :100740008C01DD2420E6722E26C0F8018081809382 118 | :10075000730018DF80917000872580937000C0E0DF 119 | :10076000D0E013C080E790E064E770E044E050E040 120 | :10077000DBDE9091770080917300981721F4991532 121 | :1007800011F09C1529F4CE0DDF1DCA15DB0550F3C1 122 | :10079000D3940F5F1F4FD814C0F2DF91CF911F91F8 123 | :1007A0000F91FF90EF90DF90CF90BF90AF909F9010 124 | :1007B0008F907F900895949A80E781BBDCDD80E57F 125 | :0A07C00082BBE1DDFECFF894FFCF0D 126 | :0207CA00D25A01 127 | :00000001FF 128 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/spi/spi.ps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 2 | %%Creator: gEDA gschem 20060906 3 | %%CreationDate: Fri Dec 15 00:29:55 2006 4 | %%Title: /tmp/release8440/usbtiny-1.3/spi/spi.sch 5 | %%Author: (null) 6 | %%BoundingBox: 0 0 612 792 7 | %%Pages: 1 8 | %%Endcomments 9 | %%BeginProlog 10 | % Prolog for gEDA, define all the functions needed for rendering 11 | % schematics on Postscript devices 12 | 13 | 14 | % Draw a line from the second coordinate to the first 15 | % x2 y2 x1 y1 width line - 16 | /line { 17 | setlinewidth 18 | % pop off first element and moveto 19 | moveto 20 | % pop off remaining elements and draw a line segment 21 | lineto 22 | % draw it 23 | stroke 24 | } bind def 25 | 26 | 27 | % Draw a dot 28 | % x y r dot - 29 | /dot { 30 | 0 360 arc fill 31 | } bind def 32 | 33 | % Draw a dot-dashed line, a bunch of lined segments, 34 | % if the array element only has length two, draw a dot. 35 | % [ [x2 y2 x1 y1] [x4 y4 x3 y3] [x5 y5] ... ] width dashed - 36 | /width 0 def 37 | /dashed { 38 | dup 2.0 div /width exch def 39 | setlinewidth 40 | % pop off each line segment and draw it as a dot or as a line 41 | { 42 | aload length 2 gt 43 | { moveto lineto stroke} 44 | { width dot } ifelse 45 | } forall 46 | } bind def 47 | 48 | % Draw an arc segment 49 | % x y r ang1 ang2 width darc - 50 | /darc { 51 | setlinewidth 52 | arc stroke 53 | } bind def 54 | 55 | % Draw a series of arc segment bits, if the array element only has a single 56 | % element in it, draw a dot. 57 | % [ [sa1 ea1] [sa2 ea2] ... ] x y r width dashedarc - 58 | /x 0 def 59 | /y 0 def 60 | /dashedarc { 61 | dup /width exch def 62 | setlinewidth 63 | /r exch def 64 | /y exch def 65 | /x exch def 66 | { aload length 1 gt 67 | { 68 | % this element had two angles in it 69 | % extract start and stop angles 70 | x y r % drop x y and r onto stack 71 | % at this point we have: sa ea x y r 72 | % we need x y r sa ea 73 | % so.. 74 | 5 -2 roll 75 | % and add it to the current path, and draw it 76 | arc stroke 77 | } { 78 | % this element only had one angle in it, place a 79 | % filled dot at the appropriate place 80 | % compute center point of the arc using the angle 81 | % that is on the top of the stack 82 | dup % angle angle 83 | cos r mul x add % angle x 84 | exch % x angle 85 | sin r mul y add % x y 86 | width % x y width/2 87 | dot % draw the dot 88 | } ifelse 89 | } forall 90 | 91 | % Now draw it 92 | stroke 93 | } bind def 94 | 95 | % Draw a box 96 | % width height x y linethickness box - 97 | /box { 98 | setlinewidth 99 | moveto 100 | exch dup 0 rlineto % w h, h w w 0 -- Draw bottom line 101 | exch 0 exch rlineto % h w, w h 0, w 0 h -- Draw right line 102 | neg 0 rlineto % w, -w 0 -- Draw Top line 103 | closepath % finish and draw it 104 | stroke 105 | } bind def 106 | 107 | % Draw a filled box 108 | % width height x y fbox - 109 | /fbox { 110 | moveto 111 | exch dup 0 rlineto 112 | exch 0 exch rlineto 113 | neg 0 rlineto 114 | closepath 115 | fill 116 | } bind def 117 | 118 | % Font reincoding utilities 119 | 120 | % ISOLatin1Encoding, extended with remaining uncoded glyphs 121 | /ISOLatin1Extended [ 122 | /.notdef /Lslash /lslash /OE /oe /Scaron /scaron /Zcaron /zcaron 123 | /Ydieresis /trademark /bullet /dagger /daggerdbl /ellipsis /emdash 124 | /endash /fi /fl /florin /fraction /guilsinglleft /guilsinglright 125 | /perthousand /quotedblbase /quotedblleft /quotedblright 126 | /quotesinglbase /quotesingle /.notdef /.notdef /.notdef /space 127 | /exclam /quotedbl /numbersign /dollar /percent /ampersand 128 | /quoteright /parenleft /parenright /asterisk /plus /comma /minus 129 | /period /slash /zero /one /two /three /four /five /six /seven /eight 130 | /nine /colon /semicolon /less /equal /greater /question /at /A /B /C 131 | /D /E /F /G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z 132 | /bracketleft /backslash /bracketright /asciicircum /underscore 133 | /quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s 134 | /t /u /v /w /x /y /z /braceleft /bar /braceright /asciitilde 135 | /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef 136 | /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef 137 | /.notdef /.notdef /.notdef /dotlessi /grave /acute /circumflex 138 | /tilde /macron /breve /dotaccent /dieresis /.notdef /ring /cedilla 139 | /.notdef /hungarumlaut /ogonek /caron /space /exclamdown /cent 140 | /sterling /currency /yen /brokenbar /section /dieresis /copyright 141 | /ordfeminine /guillemotleft /logicalnot /hyphen /registered /macron 142 | /degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph 143 | /periodcentered /cedilla /onesuperior /ordmasculine /guillemotright 144 | /onequarter /onehalf /threequarters /questiondown /Agrave /Aacute 145 | /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute 146 | /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth 147 | /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply 148 | /Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn 149 | /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring 150 | /ae /ccedilla /egrave /eacute /ecircumflex /edieresis /igrave 151 | /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute 152 | /ocircumflex /otilde /odieresis /divide /oslash /ugrave /uacute 153 | /ucircumflex /udieresis /yacute /thorn /ydieresis 154 | ] def 155 | 156 | % `new-font-name' `encoding-vector' `old-font-name' RE - 157 | /RE { 158 | findfont 159 | dup maxlength dict begin { 160 | 1 index /FID ne { def } { pop pop } ifelse 161 | } forall 162 | /Encoding exch def 163 | dup /FontName exch def 164 | currentdict end definefont pop 165 | } bind def 166 | 167 | % Text handling functions, select the font and scale it, then we need 168 | % only to apply the appropriate transformations to get the text 169 | % justified into the right spots. The bad thing here is that we don't 170 | % do any kerning, so the output may look a bit strange. 171 | 172 | % compute the height of one character and return lly and ury 173 | % (char) charheight lly ury 174 | /charheight { 175 | gsave % push graphics state 176 | newpath % clear current path 177 | 0 0 moveto % Set current point 178 | false charpath % get path 179 | flattenpath % flatten path 180 | pathbbox % stack = llx lly urx ury 181 | exch pop % stack = llx lly ury 182 | 3 -1 roll pop % stack = lly ury 183 | grestore % pop graphics state 184 | } bind def 185 | 186 | % compute the height of a string, one character at a time 187 | % (string) stringheight lly ury 188 | /lly 0.0 def 189 | /ury 0.0 def 190 | 191 | /stringheight { 192 | /lly 0.0 def % initial value of heightmin 193 | /ury 0.0 def % initial value of heightmax 194 | { % work through string 195 | ( ) dup 0 4 -1 roll put % create one character string 196 | charheight % measure it's height 197 | dup ury gt { % if ury gt heightmax 198 | /ury exch def % update with new value 199 | } { 200 | pop % else discard ury 201 | } ifelse 202 | dup lly lt { % if lly lt heightmin 203 | /lly exch def % update with new value 204 | } { 205 | pop % else discard lly 206 | } ifelse 207 | } forall 208 | lly ury % Return the results 209 | } bind def 210 | 211 | % calculate the string width taking into account the escapes. 212 | /mystrx 0.0 def 213 | /mystry 0.0 def 214 | /mystresc false def 215 | 216 | /mystringwidth { 217 | /mystrx 0.0 def 218 | /mystry 0.0 def 219 | /mystresc false def 220 | { % work through string 221 | % did we process the escape character last? 222 | mystresc { 223 | % last character was escape 224 | % handle the escape 225 | % is it an _ = 95? 226 | dup 95 eq { 227 | pop % we don't need the character anymore 228 | % toggle drawing overbars 229 | 0.0 0.0 % make it like it never happened... 230 | } { 231 | % otherwise measure the character 232 | (\\ ) dup 1 4 -1 roll put % count a \ and the character 233 | stringwidth 234 | } ifelse 235 | % and reset the flag 236 | /mystresc false def 237 | } { 238 | % last character was not escape 239 | % is this escape 240 | dup 92 eq { 241 | % yes, escape character, set flag 242 | /mystresc true def 243 | pop % drop character 244 | 0.0 0.0 % make like this character has no width and height 245 | } { 246 | ( ) dup 0 4 -1 roll put % create one character string 247 | stringwidth % measure it's height/width 248 | } ifelse 249 | } ifelse 250 | % accumulate x and y movements 251 | mystry add /mystry exch def 252 | mystrx add /mystrx exch def 253 | } forall 254 | mystrx mystry % drop results on stack 255 | } bind def 256 | 257 | % Render a string with overbars 258 | % 259 | /escaped false def 260 | /drawoverbar false def 261 | /fontsize 0.0 def 262 | 263 | % Show a string, with an overbar over it 264 | % string charshow - 265 | /charshow { 266 | drawoverbar { 267 | % draw an overbar for the character 268 | gsave 269 | fontsize 10.0 div setlinewidth 270 | 0 fontsize rmoveto % move to (0,overbarheight) 271 | dup stringwidth pop 0 rlineto % draw line to 272 | stroke 273 | grestore 274 | } if 275 | show 276 | } bind def 277 | 278 | /overbarshow { 279 | /drawoverbar false def % start by not drawing overbars 280 | { % work through string 281 | escaped { 282 | % the last character was the escape 283 | % handle the escape 284 | % is it an _ = 95? 285 | dup 95 eq { 286 | pop % we don't need the character anymore 287 | % toggle drawing overbars 288 | /drawoverbar drawoverbar not def 289 | } { 290 | % otherwise render the character 291 | (\\ ) dup 1 4 -1 roll put % draw a \ and the character 292 | charshow % render the string 293 | } ifelse 294 | % and reset the flag 295 | /escaped false def 296 | } { 297 | % check for escape character \ = 92 298 | dup 92 eq { 299 | % yes, escape character, set flag 300 | /escaped true def 301 | pop % drop character 302 | } { 303 | % no, reset flag and draw character 304 | ( ) dup 0 4 -1 roll put % create one character string 305 | charshow 306 | } ifelse 307 | } ifelse 308 | } forall 309 | } bind def 310 | % 311 | % hcenter rjustify vcenter vjustify spacing [(line1) (line2) ... ] rot x y size text - 312 | /stringw 0.0 def 313 | /stringh 0.0 def 314 | /spacing 0.0 def 315 | /strings [ ] def 316 | /stringtxt ( ) def 317 | /stringcount 0 def 318 | /rot 0.0 def 319 | 320 | /text { 321 | gsave % save state for later 322 | 323 | dup /fontsize exch def % save font size for corrections later 324 | % do font selection 325 | /gEDAFont findfont 326 | exch scalefont 327 | setfont 328 | 329 | % set up coordinates 330 | translate % move origin to given point 331 | rotate % rotate so that text is drawn 332 | 0 0 moveto 333 | dup length /stringcount exch def % Get number of strings 334 | /strings exch def % save strings 335 | /spacing exch def 336 | % do we have more than 1 string to render? 337 | stringcount 1 eq { 338 | /stringtxt strings aload pop def % get the string 339 | /stringw stringtxt mystringwidth pop neg def % get the -width 340 | /stringh stringtxt stringheight exch pop neg def% get the -height 341 | 342 | % First do vertical calculations 343 | % hcenter rjustify vcenter vjustify 344 | % vertical justification 345 | { 0 stringh rmoveto } if 346 | % vertical center 347 | { 0 stringh 0.3571425 mul rmoveto } if % not 0.5, so that 348 | % it looks nicer 349 | % Then do horizontal calculations 350 | % right justify 351 | { stringw 0 rmoveto } if 352 | % center 353 | { stringw 2.0 div 0 rmoveto } if 354 | % Draw the text 355 | stringtxt overbarshow 356 | } { 357 | % More than one line, compute bounding box for the text 358 | 359 | % vertical height, don't use the actual hieght of the characters 360 | % assume that the user wants to make the baselines line up with two 361 | % text boxes placed side by side 362 | /stringh stringcount spacing mul neg def 363 | % Now figure out horizontal size, this amounts to keeping track 364 | % of the longest string 365 | /stringw 0.0 def 366 | strings { 367 | mystringwidth pop 368 | dup stringw gt { 369 | /stringw exch def 370 | } { 371 | pop 372 | } ifelse 373 | } forall 374 | /stringw stringw neg def % get the -width 375 | 376 | % First do vertical calculations 377 | % hcenter rjustify vcenter vjustify 378 | % vertical justification 379 | { 0 stringh fontsize add rmoveto } if 380 | % vertical center 381 | { 0 stringh 0.5 mul rmoveto } if 382 | % Then do horizontal calculations 383 | % right justify 384 | { stringw 0 rmoveto } if 385 | % center 386 | { stringw 2.0 div 0 rmoveto } if 387 | % now move up to the first line and begin rendering 388 | 0 stringcount 1 sub spacing mul rmoveto 389 | strings { 390 | gsave % Save starting point 391 | overbarshow % render the text 392 | grestore 393 | 0 spacing neg rmoveto 394 | } forall 395 | } ifelse 396 | grestore % Restore old state 397 | } bind def 398 | 399 | 400 | %%EndProlog 401 | %%Page: 1 1 402 | /gEDAFont ISOLatin1Extended /Helvetica RE 403 | 2 setlinecap 404 | 0.072000 0.072000 scale 405 | 386 2713 translate 406 | 0.732443 0.732443 scale 407 | -53400 -51170 translate 408 | gsave 409 | 62450 57590 150 70 180 2 darc 410 | 63125 57400 75 0 60 2 darc 411 | 62600 52600 50 0 360 2 darc 412 | 62550 52600 62000 52600 10 line 413 | gsave 414 | false true false false 208.000000 [(13) ] 0 62200 52650 111.111115 text 415 | grestore 416 | gsave 417 | false true false false 104.000000 [(SLCT) ] 0 62700 52450 55.555557 text 418 | grestore 419 | 62900 52800 50 0 360 2 darc 420 | 62600 53000 50 0 360 2 darc 421 | 62550 53000 62000 53000 10 line 422 | gsave 423 | false true false false 208.000000 [(12) ] 0 62200 53050 111.111115 text 424 | grestore 425 | gsave 426 | false true false false 104.000000 [(PE) ] 0 62700 52850 55.555557 text 427 | grestore 428 | 62900 53200 50 0 360 2 darc 429 | 62600 53400 50 0 360 2 darc 430 | 62550 53400 62000 53400 10 line 431 | gsave 432 | false true false false 208.000000 [(11) ] 0 62200 53450 111.111115 text 433 | grestore 434 | gsave 435 | false true false false 104.000000 [(BUSY) ] 0 62700 53250 55.555557 text 436 | grestore 437 | 62900 53600 50 0 360 2 darc 438 | 62600 53800 50 0 360 2 darc 439 | 62550 53800 62000 53800 10 line 440 | gsave 441 | false true false false 208.000000 [(10) ] 0 62200 53850 111.111115 text 442 | grestore 443 | gsave 444 | false true false false 104.000000 [(/ACK) ] 0 62700 53650 55.555557 text 445 | grestore 446 | 62900 54000 50 0 360 2 darc 447 | 62600 54200 50 0 360 2 darc 448 | 62550 54200 62000 54200 10 line 449 | gsave 450 | false true false false 208.000000 [(9) ] 0 62200 54250 111.111115 text 451 | grestore 452 | gsave 453 | false true false false 104.000000 [(DATA7) ] 0 62700 54050 55.555557 text 454 | grestore 455 | 62900 54400 50 0 360 2 darc 456 | 62600 54600 50 0 360 2 darc 457 | 62550 54600 62000 54600 10 line 458 | gsave 459 | false true false false 208.000000 [(8) ] 0 62200 54650 111.111115 text 460 | grestore 461 | gsave 462 | false true false false 104.000000 [(DATA6) ] 0 62700 54450 55.555557 text 463 | grestore 464 | 62900 54800 50 0 360 2 darc 465 | 62600 55000 50 0 360 2 darc 466 | 62550 55000 62000 55000 10 line 467 | gsave 468 | false true false false 208.000000 [(7) ] 0 62200 55050 111.111115 text 469 | grestore 470 | gsave 471 | false true false false 104.000000 [(DATA5) ] 0 62700 54850 55.555557 text 472 | grestore 473 | 62900 55200 50 0 360 2 darc 474 | 62600 55400 50 0 360 2 darc 475 | 62550 55400 62000 55400 10 line 476 | gsave 477 | false true false false 208.000000 [(6) ] 0 62200 55450 111.111115 text 478 | grestore 479 | gsave 480 | false true false false 104.000000 [(DATA4) ] 0 62700 55250 55.555557 text 481 | grestore 482 | 62900 55600 50 0 360 2 darc 483 | 62600 55800 50 0 360 2 darc 484 | 62550 55800 62000 55800 10 line 485 | gsave 486 | false true false false 208.000000 [(5) ] 0 62200 55850 111.111115 text 487 | grestore 488 | gsave 489 | false true false false 104.000000 [(DATA3) ] 0 62700 55650 55.555557 text 490 | grestore 491 | 62900 56000 50 0 360 2 darc 492 | 62600 56200 50 0 360 2 darc 493 | 62550 56200 62000 56200 10 line 494 | gsave 495 | false true false false 208.000000 [(4) ] 0 62200 56250 111.111115 text 496 | grestore 497 | gsave 498 | false true false false 104.000000 [(DATA2) ] 0 62700 56050 55.555557 text 499 | grestore 500 | 62900 56400 50 0 360 2 darc 501 | 62600 56600 50 0 360 2 darc 502 | 62550 56600 62000 56600 10 line 503 | gsave 504 | false true false false 208.000000 [(3) ] 0 62200 56650 111.111115 text 505 | grestore 506 | gsave 507 | false true false false 104.000000 [(DATA1) ] 0 62700 56450 55.555557 text 508 | grestore 509 | 62900 56800 50 0 360 2 darc 510 | 62600 57000 50 0 360 2 darc 511 | 62550 57000 62000 57000 10 line 512 | gsave 513 | false true false false 208.000000 [(2) ] 0 62200 57050 111.111115 text 514 | grestore 515 | gsave 516 | false true false false 104.000000 [(DATA0) ] 0 62700 56850 55.555557 text 517 | grestore 518 | 62900 57200 50 0 360 2 darc 519 | 62600 57400 50 0 360 2 darc 520 | 62550 57400 62000 57400 10 line 521 | gsave 522 | false true false false 208.000000 [(1) ] 0 62200 57450 111.111115 text 523 | grestore 524 | gsave 525 | false true false false 104.000000 [(/STROBE) ] 0 62700 57250 55.555557 text 526 | grestore 527 | 62499 57732 63162 57466 2 line 528 | 62950 52800 63500 52800 10 line 529 | gsave 530 | false true false false 208.000000 [(25) ] 0 63450 52850 111.111115 text 531 | grestore 532 | gsave 533 | false true false false 104.000000 [(GND) ] 0 62950 52650 55.555557 text 534 | grestore 535 | 62950 53600 63500 53600 10 line 536 | gsave 537 | false true false false 208.000000 [(23) ] 0 63450 53650 111.111115 text 538 | grestore 539 | gsave 540 | false true false false 104.000000 [(GND) ] 0 62950 53450 55.555557 text 541 | grestore 542 | 62950 53200 63500 53200 10 line 543 | gsave 544 | false true false false 208.000000 [(24) ] 0 63450 53250 111.111115 text 545 | grestore 546 | gsave 547 | false true false false 104.000000 [(GND) ] 0 62950 53050 55.555557 text 548 | grestore 549 | 62950 54000 63500 54000 10 line 550 | gsave 551 | false true false false 208.000000 [(22) ] 0 63450 54050 111.111115 text 552 | grestore 553 | gsave 554 | false true false false 104.000000 [(GND) ] 0 62950 53850 55.555557 text 555 | grestore 556 | 62950 54400 63500 54400 10 line 557 | gsave 558 | false true false false 208.000000 [(21) ] 0 63450 54450 111.111115 text 559 | grestore 560 | gsave 561 | false true false false 104.000000 [(GND) ] 0 62950 54250 55.555557 text 562 | grestore 563 | 62950 54800 63500 54800 10 line 564 | gsave 565 | false true false false 208.000000 [(20) ] 0 63450 54850 111.111115 text 566 | grestore 567 | gsave 568 | false true false false 104.000000 [(GND) ] 0 62950 54650 55.555557 text 569 | grestore 570 | 62950 55200 63500 55200 10 line 571 | gsave 572 | false true false false 208.000000 [(19) ] 0 63450 55250 111.111115 text 573 | grestore 574 | gsave 575 | false true false false 104.000000 [(GND) ] 0 62950 55050 55.555557 text 576 | grestore 577 | 62950 55600 63500 55600 10 line 578 | gsave 579 | false true false false 208.000000 [(18) ] 0 63450 55650 111.111115 text 580 | grestore 581 | gsave 582 | false true false false 104.000000 [(GND) ] 0 62950 55450 55.555557 text 583 | grestore 584 | 62950 56000 63500 56000 10 line 585 | gsave 586 | false true false false 208.000000 [(17) ] 0 63450 56050 111.111115 text 587 | grestore 588 | gsave 589 | false true false false 104.000000 [(/SLCTIN) ] 0 63100 55850 55.555557 text 590 | grestore 591 | 62950 56400 63500 56400 10 line 592 | gsave 593 | false true false false 208.000000 [(16) ] 0 63450 56450 111.111115 text 594 | grestore 595 | gsave 596 | false true false false 104.000000 [(/INIT) ] 0 62950 56250 55.555557 text 597 | grestore 598 | 62950 56800 63500 56800 10 line 599 | gsave 600 | false true false false 208.000000 [(15) ] 0 63450 56850 111.111115 text 601 | grestore 602 | gsave 603 | false true false false 104.000000 [(/ERROR) ] 0 63100 56650 55.555557 text 604 | grestore 605 | 62950 57200 63500 57200 10 line 606 | gsave 607 | false true false false 208.000000 [(14) ] 0 63450 57250 111.111115 text 608 | grestore 609 | gsave 610 | false true false false 104.000000 [(/AUTOF) ] 0 63100 57050 55.555557 text 611 | grestore 612 | 62450 52350 150 180 290 2 darc 613 | 63125 52500 75 -60 0 2 darc 614 | 63161 52434 62497 52208 2 line 615 | 62300 52350 62300 57590 2 line 616 | 63200 57400 63200 52500 2 line 617 | grestore 618 | gsave 619 | false true false false 260.000000 [(DB25 female) ] 0 63300 57900 138.888885 text 620 | grestore 621 | gsave 622 | 57700 56200 57550 56200 10 line 623 | 56800 56200 56952 56200 10 line 624 | 56950 56100 57550 56100 2 line 625 | 57550 56100 57550 56300 2 line 626 | 57550 56300 56950 56300 2 line 627 | 56950 56300 56950 56100 2 line 628 | grestore 629 | gsave 630 | false false false false 260.000000 [(68) ] 0 57000 56400 138.888885 text 631 | grestore 632 | gsave 633 | 57700 55400 57550 55400 10 line 634 | 56800 55400 56952 55400 10 line 635 | 56950 55300 57550 55300 2 line 636 | 57550 55300 57550 55500 2 line 637 | 57550 55500 56950 55500 2 line 638 | 56950 55500 56950 55300 2 line 639 | grestore 640 | gsave 641 | false false false false 260.000000 [(68) ] 0 57000 55600 138.888885 text 642 | grestore 643 | gsave 644 | 56400 55400 56250 55400 10 line 645 | 55500 55400 55652 55400 10 line 646 | 55650 55300 56250 55300 2 line 647 | 56250 55300 56250 55500 2 line 648 | 56250 55500 55650 55500 2 line 649 | 55650 55500 55650 55300 2 line 650 | grestore 651 | gsave 652 | false false false false 260.000000 [(1K5) ] 0 55700 55600 138.888885 text 653 | grestore 654 | gsave 655 | 55500 52600 55650 52600 10 line 656 | 56400 52600 56248 52600 10 line 657 | 55650 52500 56250 52500 2 line 658 | 56250 52500 56250 52700 2 line 659 | 56250 52700 55650 52700 2 line 660 | 55650 52700 55650 52500 2 line 661 | grestore 662 | gsave 663 | false true false false 260.000000 [(22K) ] 0 56100 52800 138.888885 text 664 | grestore 665 | gsave 666 | 56100 58000 56100 57600 2 line 667 | 56100 58000 55800 57800 2 line 668 | 55800 57800 56100 57600 2 line 669 | 55800 58000 55800 57600 2 line 670 | 56400 57800 56200 57800 10 line 671 | 55500 57800 55700 57800 10 line 672 | 55700 57800 55800 57800 2 line 673 | 56100 57800 56200 57800 2 line 674 | grestore 675 | gsave 676 | false true false false 260.000000 [(1N4148) ] 0 56300 58000 138.888885 text 677 | grestore 678 | 63500 55600 63900 55600 10 line 679 | 63500 55200 63900 55200 10 line 680 | 63500 54800 63900 54800 10 line 681 | 63500 54400 63900 54400 10 line 682 | 63500 54000 63900 54000 10 line 683 | 63500 53600 63900 53600 10 line 684 | 63500 53200 63900 53200 10 line 685 | 63500 52800 63900 52800 10 line 686 | gsave 687 | 55400 58550 50 0 360 2 darc 688 | 55400 58500 55400 58200 10 line 689 | gsave 690 | false false false false 260.000000 [(Vcc) ] 0 55200 58650 138.888885 text 691 | grestore 692 | grestore 693 | 60000 53500 60000 53700 10 line 694 | gsave 695 | false false false false 208.000000 [(1) ] 0 60050 53600 111.111115 text 696 | grestore 697 | gsave 698 | true false false false 208.000000 [(Reset) ] 0 60000 53850 111.111115 text 699 | grestore 700 | 59808 53974 60192 53974 2 line 701 | 60000 53750 50 0 360 2 darc 702 | 59300 53500 59300 53800 10 line 703 | gsave 704 | false false false false 208.000000 [(4) ] 0 59350 53600 111.111115 text 705 | grestore 706 | gsave 707 | true false false false 208.000000 [(XTAL2) ] 0 59300 53850 111.111115 text 708 | grestore 709 | 58600 53500 58600 53800 10 line 710 | gsave 711 | false false false false 208.000000 [(5) ] 0 58650 53600 111.111115 text 712 | grestore 713 | gsave 714 | true false false false 208.000000 [(XTAL1) ] 0 58600 53850 111.111115 text 715 | grestore 716 | 58000 54600 58300 54600 10 line 717 | gsave 718 | false true false false 208.000000 [(11) ] 0 58200 54650 111.111115 text 719 | grestore 720 | gsave 721 | false false false false 208.000000 [(PD6 \(ICP\)) ] 0 58350 54600 111.111115 text 722 | grestore 723 | 58000 55000 58300 55000 10 line 724 | gsave 725 | false true false false 208.000000 [(9) ] 0 58200 55050 111.111115 text 726 | grestore 727 | gsave 728 | false false false false 208.000000 [(PD5 \(T1\)) ] 0 58350 55000 111.111115 text 729 | grestore 730 | 58000 55400 58300 55400 10 line 731 | gsave 732 | false true false false 208.000000 [(8) ] 0 58200 55450 111.111115 text 733 | grestore 734 | gsave 735 | false false false false 208.000000 [(PD4 \(T0\)) ] 0 58350 55400 111.111115 text 736 | grestore 737 | 58000 55800 58300 55800 10 line 738 | gsave 739 | false true false false 208.000000 [(7) ] 0 58200 55850 111.111115 text 740 | grestore 741 | gsave 742 | false false false false 208.000000 [(PD3 \(INT1\)) ] 0 58350 55800 111.111115 text 743 | grestore 744 | 58000 56200 58300 56200 10 line 745 | gsave 746 | false true false false 208.000000 [(6) ] 0 58200 56250 111.111115 text 747 | grestore 748 | gsave 749 | false false false false 208.000000 [(PD2 \(INT0\)) ] 0 58350 56200 111.111115 text 750 | grestore 751 | 58000 56600 58300 56600 10 line 752 | gsave 753 | false true false false 208.000000 [(3) ] 0 58200 56650 111.111115 text 754 | grestore 755 | gsave 756 | false false false false 208.000000 [(PD1 \(TXD\)) ] 0 58350 56600 111.111115 text 757 | grestore 758 | 58000 57000 58300 57000 10 line 759 | gsave 760 | false true false false 208.000000 [(2) ] 0 58200 57050 111.111115 text 761 | grestore 762 | gsave 763 | false false false false 208.000000 [(PD0 \(RXD\)) ] 0 58350 57000 111.111115 text 764 | grestore 765 | 60600 54200 60300 54200 10 line 766 | gsave 767 | false false false false 208.000000 [(19) ] 0 60400 54250 111.111115 text 768 | grestore 769 | gsave 770 | false true false false 208.000000 [(\(SCK\) PB7) ] 0 60250 54200 111.111115 text 771 | grestore 772 | 60600 54600 60300 54600 10 line 773 | gsave 774 | false false false false 208.000000 [(18) ] 0 60400 54650 111.111115 text 775 | grestore 776 | gsave 777 | false true false false 208.000000 [(\(MISO\) PB6) ] 0 60250 54600 111.111115 text 778 | grestore 779 | 60600 55000 60300 55000 10 line 780 | gsave 781 | false false false false 208.000000 [(17) ] 0 60400 55050 111.111115 text 782 | grestore 783 | gsave 784 | false true false false 208.000000 [(\(MOSI\) PB5) ] 0 60250 55000 111.111115 text 785 | grestore 786 | 60600 55400 60300 55400 10 line 787 | gsave 788 | false false false false 208.000000 [(16) ] 0 60400 55450 111.111115 text 789 | grestore 790 | gsave 791 | false true false false 208.000000 [(PB4) ] 0 60250 55400 111.111115 text 792 | grestore 793 | 60600 55800 60300 55800 10 line 794 | gsave 795 | false false false false 208.000000 [(15) ] 0 60400 55850 111.111115 text 796 | grestore 797 | gsave 798 | false true false false 208.000000 [(\(OC1\) PB3) ] 0 60250 55800 111.111115 text 799 | grestore 800 | 60600 56200 60300 56200 10 line 801 | gsave 802 | false false false false 208.000000 [(14) ] 0 60400 56250 111.111115 text 803 | grestore 804 | gsave 805 | false true false false 208.000000 [(PB2) ] 0 60250 56200 111.111115 text 806 | grestore 807 | 60600 56600 60300 56600 10 line 808 | gsave 809 | false false false false 208.000000 [(13) ] 0 60400 56650 111.111115 text 810 | grestore 811 | gsave 812 | false true false false 208.000000 [(\(AIN1\) PB1) ] 0 60250 56600 111.111115 text 813 | grestore 814 | 60600 57000 60300 57000 10 line 815 | gsave 816 | false false false false 208.000000 [(12) ] 0 60400 57050 111.111115 text 817 | grestore 818 | gsave 819 | false true false false 208.000000 [(\(AIN0\) PB0) ] 0 60250 57000 111.111115 text 820 | grestore 821 | 58300 53800 60300 53800 2 line 822 | 60300 53800 60300 57400 2 line 823 | 60300 57400 58300 57400 2 line 824 | 58300 57400 58300 53800 2 line 825 | gsave 826 | false false false false 260.000000 [(ATtiny2313) ] 0 58300 57450 138.888885 text 827 | grestore 828 | 60600 57000 62000 57000 10 line 829 | 60600 56600 62000 56600 10 line 830 | 60600 56200 62000 56200 10 line 831 | 60600 55800 62000 55800 10 line 832 | 60600 55400 62000 55400 10 line 833 | 60600 55000 62000 55000 10 line 834 | 60600 54600 62000 54600 10 line 835 | 60600 54200 62000 54200 10 line 836 | gsave 837 | 54800 54800 55100 54800 10 line 838 | gsave 839 | false false false false 208.000000 [(3) ] 0 53650 54750 111.111115 text 840 | grestore 841 | 54800 55100 55100 55100 10 line 842 | gsave 843 | false false false false 208.000000 [(2) ] 0 53650 55050 111.111115 text 844 | grestore 845 | 54800 54500 55100 54500 10 line 846 | gsave 847 | false false false false 208.000000 [(4) ] 0 53650 54450 111.111115 text 848 | grestore 849 | 54800 55100 53900 55100 2 line 850 | 54800 54800 53900 54800 2 line 851 | 54800 54500 53900 54500 2 line 852 | 54800 55400 55100 55400 10 line 853 | gsave 854 | false false false false 208.000000 [(1) ] 0 53650 55350 111.111115 text 855 | grestore 856 | 54800 55400 53900 55400 2 line 857 | 53400 54300 53900 54300 2 line 858 | 53900 54300 53900 55600 2 line 859 | 53900 55600 53400 55600 2 line 860 | 53400 55600 53400 54300 2 line 861 | grestore 862 | gsave 863 | false false false false 260.000000 [(USB) ] 0 53400 55700 138.888885 text 864 | grestore 865 | 55100 54800 56700 54800 10 line 866 | 56700 54800 56700 56200 10 line 867 | 56700 56200 56800 56200 10 line 868 | 56400 55400 56800 55400 10 line 869 | 56500 55400 56500 55100 10 line 870 | 56500 55100 55100 55100 10 line 871 | 60000 53500 60000 52600 10 line 872 | 58600 53500 58600 53400 10 line 873 | 59300 53500 59300 53400 10 line 874 | 58000 57000 57800 57000 10 line 875 | 57800 57000 57800 58400 10 line 876 | 57800 58400 63700 58400 10 line 877 | 63700 58400 63700 56400 10 line 878 | 63700 56400 63500 56400 10 line 879 | 58000 56600 57600 56600 10 line 880 | 57600 56600 57600 58600 10 line 881 | 57600 58600 63900 58600 10 line 882 | 63900 58600 63900 56000 10 line 883 | 63900 56000 63500 56000 10 line 884 | 57700 56200 58000 56200 10 line 885 | 58000 55800 57800 55800 10 line 886 | 57800 55800 57800 53000 10 line 887 | 57800 53000 61500 53000 10 line 888 | 61500 53000 61500 53800 10 line 889 | 61500 53800 62000 53800 10 line 890 | 57700 55400 58000 55400 10 line 891 | 58000 55000 57600 55000 10 line 892 | 57600 55000 57600 52800 10 line 893 | 57600 52800 61700 52800 10 line 894 | 61700 52800 61700 53400 10 line 895 | 61700 53400 62000 53400 10 line 896 | 58000 54600 58000 53200 10 line 897 | 58000 53200 61300 53200 10 line 898 | 61300 53200 61300 57400 10 line 899 | 61300 57400 62000 57400 10 line 900 | 56400 57800 63500 57800 10 line 901 | 63500 57800 63500 57200 10 line 902 | 63900 55600 63900 51700 10 line 903 | 55100 55400 55500 55400 10 line 904 | 55500 57800 55400 57800 10 line 905 | 55400 55400 55400 58200 10 line 906 | 55400 55400 55400 52600 10 line 907 | 55100 54500 55100 51700 10 line 908 | 55100 51700 63900 51700 10 line 909 | 55400 52600 55500 52600 10 line 910 | 56400 52600 62000 52600 10 line 911 | gsave 912 | false false false false 260.000000 [(USB to parallel port converter) ] 0 61400 51200 138.888885 text 913 | grestore 914 | gsave 915 | false false false false 260.000000 [(Vcc) ] 0 54000 55500 138.888885 text 916 | grestore 917 | gsave 918 | false false false false 260.000000 [(D-) ] 0 54000 55200 138.888885 text 919 | grestore 920 | gsave 921 | false false false false 260.000000 [(D+) ] 0 54000 54900 138.888885 text 922 | grestore 923 | gsave 924 | false false false false 260.000000 [(GND) ] 0 54000 54600 138.888885 text 925 | grestore 926 | gsave 927 | 55400 51700 55400 51500 10 line 928 | 55550 51500 55250 51500 2 line 929 | gsave 930 | false true false true 208.000000 [(Vss) ] 0 55525 51450 111.111115 text 931 | grestore 932 | newpath 933 | 55400 51700 934 | 30 935 | 0 360 arc 936 | fill 937 | newpath 938 | 55400 51700 939 | 30 940 | 0 360 arc 941 | fill 942 | grestore 943 | gsave 944 | 58600 53400 58800 53400 10 line 945 | 59100 53400 59300 53400 10 line 946 | 58850 53300 59050 53300 2 line 947 | 59050 53300 59050 53500 2 line 948 | 59050 53500 58850 53500 2 line 949 | 58850 53500 58850 53300 2 line 950 | 58800 53540 58800 53260 2 line 951 | 59100 53540 59100 53260 2 line 952 | grestore 953 | gsave 954 | false false false false 260.000000 [(12MHz) ] 0 58100 53300 138.888885 text 955 | grestore 956 | gsave 957 | 55400 52600 55400 52400 10 line 958 | gsave 959 | false true false false 208.000000 [(1) ] 270 55450 52450 111.111115 text 960 | grestore 961 | 55400 51700 55400 51900 10 line 962 | gsave 963 | false false false false 208.000000 [(2) ] 270 55450 51850 111.111115 text 964 | grestore 965 | 55600 52050 55200 52050 2 line 966 | 55400 51900 55400 52050 2 line 967 | 55400 52250 55400 52400 2 line 968 | 55600 52361 55500 52361 2 line 969 | 55549 52310 55549 52410 2 line 970 | 55200 52150 55600 52150 2 line 971 | 55600 52150 55600 52250 2 line 972 | 55600 52250 55200 52250 2 line 973 | 55200 52250 55200 52150 2 line 974 | newpath 975 | 55400 51700 976 | 30 977 | 0 360 arc 978 | fill 979 | newpath 980 | 55400 51700 981 | 30 982 | 0 360 arc 983 | fill 984 | grestore 985 | gsave 986 | false false false false 260.000000 [(1uF) ] 270 55700 52400 138.888885 text 987 | grestore 988 | newpath 989 | 63900 55200 990 | 30 991 | 0 360 arc 992 | fill 993 | newpath 994 | 63900 55200 995 | 30 996 | 0 360 arc 997 | fill 998 | newpath 999 | 63900 54800 1000 | 30 1001 | 0 360 arc 1002 | fill 1003 | newpath 1004 | 63900 54800 1005 | 30 1006 | 0 360 arc 1007 | fill 1008 | newpath 1009 | 63900 54400 1010 | 30 1011 | 0 360 arc 1012 | fill 1013 | newpath 1014 | 63900 54400 1015 | 30 1016 | 0 360 arc 1017 | fill 1018 | newpath 1019 | 63900 54000 1020 | 30 1021 | 0 360 arc 1022 | fill 1023 | newpath 1024 | 63900 54000 1025 | 30 1026 | 0 360 arc 1027 | fill 1028 | newpath 1029 | 63900 53600 1030 | 30 1031 | 0 360 arc 1032 | fill 1033 | newpath 1034 | 63900 53600 1035 | 30 1036 | 0 360 arc 1037 | fill 1038 | newpath 1039 | 63900 53200 1040 | 30 1041 | 0 360 arc 1042 | fill 1043 | newpath 1044 | 63900 53200 1045 | 30 1046 | 0 360 arc 1047 | fill 1048 | newpath 1049 | 63900 52800 1050 | 30 1051 | 0 360 arc 1052 | fill 1053 | newpath 1054 | 63900 52800 1055 | 30 1056 | 0 360 arc 1057 | fill 1058 | newpath 1059 | 56500 55400 1060 | 30 1061 | 0 360 arc 1062 | fill 1063 | newpath 1064 | 56500 55400 1065 | 30 1066 | 0 360 arc 1067 | fill 1068 | newpath 1069 | 56500 55400 1070 | 30 1071 | 0 360 arc 1072 | fill 1073 | newpath 1074 | 60000 52600 1075 | 30 1076 | 0 360 arc 1077 | fill 1078 | newpath 1079 | 60000 52600 1080 | 30 1081 | 0 360 arc 1082 | fill 1083 | newpath 1084 | 63900 54400 1085 | 30 1086 | 0 360 arc 1087 | fill 1088 | newpath 1089 | 63900 54000 1090 | 30 1091 | 0 360 arc 1092 | fill 1093 | newpath 1094 | 63900 53600 1095 | 30 1096 | 0 360 arc 1097 | fill 1098 | newpath 1099 | 63900 53200 1100 | 30 1101 | 0 360 arc 1102 | fill 1103 | newpath 1104 | 63900 52800 1105 | 30 1106 | 0 360 arc 1107 | fill 1108 | newpath 1109 | 63900 55200 1110 | 30 1111 | 0 360 arc 1112 | fill 1113 | newpath 1114 | 63900 54800 1115 | 30 1116 | 0 360 arc 1117 | fill 1118 | newpath 1119 | 55400 55400 1120 | 30 1121 | 0 360 arc 1122 | fill 1123 | newpath 1124 | 55400 55400 1125 | 30 1126 | 0 360 arc 1127 | fill 1128 | newpath 1129 | 55400 57800 1130 | 30 1131 | 0 360 arc 1132 | fill 1133 | newpath 1134 | 55400 57800 1135 | 30 1136 | 0 360 arc 1137 | fill 1138 | newpath 1139 | 55400 55400 1140 | 30 1141 | 0 360 arc 1142 | fill 1143 | newpath 1144 | 55400 55400 1145 | 30 1146 | 0 360 arc 1147 | fill 1148 | newpath 1149 | 55400 57800 1150 | 30 1151 | 0 360 arc 1152 | fill 1153 | newpath 1154 | 55400 55400 1155 | 30 1156 | 0 360 arc 1157 | fill 1158 | newpath 1159 | 55400 52600 1160 | 30 1161 | 0 360 arc 1162 | fill 1163 | newpath 1164 | 55400 55400 1165 | 30 1166 | 0 360 arc 1167 | fill 1168 | newpath 1169 | 55400 51700 1170 | 30 1171 | 0 360 arc 1172 | fill 1173 | newpath 1174 | 55400 51700 1175 | 30 1176 | 0 360 arc 1177 | fill 1178 | newpath 1179 | 55400 52600 1180 | 30 1181 | 0 360 arc 1182 | fill 1183 | newpath 1184 | 60000 52600 1185 | 30 1186 | 0 360 arc 1187 | fill 1188 | newpath 1189 | 55400 51700 1190 | 30 1191 | 0 360 arc 1192 | fill 1193 | newpath 1194 | 55400 51700 1195 | 30 1196 | 0 360 arc 1197 | fill 1198 | newpath 1199 | 55400 51700 1200 | 30 1201 | 0 360 arc 1202 | fill 1203 | newpath 1204 | 55400 51700 1205 | 30 1206 | 0 360 arc 1207 | fill 1208 | showpage 1209 | %%End 1210 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/spi/spi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # ====================================================================== 3 | # spi.py - USBtiny/spi test program 4 | # ====================================================================== 5 | 6 | import sys, os.path 7 | sys.path[0] = os.path.join(sys.path[0], '../util') 8 | import usbtiny 9 | 10 | vendor = 0x1964 11 | product = 0x0001 12 | 13 | # Generic requests 14 | USBTINY_ECHO = 0 # echo test 15 | USBTINY_READ = 1 # read byte (wIndex:address) 16 | USBTINY_WRITE = 2 # write byte (wIndex:address, wValue:value) 17 | USBTINY_CLR = 3 # clear bit (wIndex:address, wValue:bitno) 18 | USBTINY_SET = 4 # set bit (wIndex:address, wValue:bitno) 19 | # Programming requests 20 | USBTINY_POWERUP = 5 # apply power (wValue:SCK-period, wIndex:RESET) 21 | USBTINY_POWERDOWN = 6 # remove power from chip 22 | USBTINY_SPI = 7 # issue SPI command (wValue:c1c0, wIndex:c3c2) 23 | USBTINY_POLL_BYTES = 8 # set poll bytes for write (wValue:p1p2) 24 | USBTINY_FLASH_READ = 9 # read flash (wIndex:address) 25 | USBTINY_FLASH_WRITE = 10 # write flash (wIndex:address, wValue:timeout) 26 | USBTINY_EEPROM_READ = 11 # read eeprom (wIndex:address) 27 | USBTINY_EEPROM_WRITE = 12 # write eeprom (wIndex:address, wValue:timeout) 28 | 29 | usage = """Available commands: 30 | t - echo test 31 | r - read byte at 32 | w - write byte at 33 | c - clear bit at 34 | s - set bit at 35 | U - powerup; set RESET to 36 | D - powerdown 37 | C - issue SPI command 38 | P - set poll bytes 39 | f - read from flash 40 | e - read from EEPROM 41 | F - write byte to flash 42 | E - write byte to EEPROM""" 43 | 44 | # --- check arguments 45 | cmd = None 46 | addr = 0x00 47 | byte = 0x00 48 | c3 = 0x00 49 | c4 = 0x00 50 | argc = len(sys.argv) 51 | if argc > 1: 52 | cmd = sys.argv[1][0] 53 | if argc > 2 and cmd != 't': 54 | byte = int(sys.argv[2], 16) 55 | if argc > 3: 56 | addr = byte 57 | byte = int(sys.argv[3], 16) 58 | if argc > 4: 59 | c3 = int(sys.argv[4], 16) 60 | if argc > 5: 61 | c4 = int(sys.argv[5], 16) 62 | if not (argc == 2 and cmd in "tD")\ 63 | and not (argc == 3 and cmd in "rU")\ 64 | and not (argc == 4 and cmd in "wcsPfe")\ 65 | and not (argc == 5 and cmd in "FE")\ 66 | and not (argc == 6 and cmd in "C"): 67 | print >> sys.stderr, usage 68 | sys.exit(1) 69 | 70 | # --- open USB device 71 | dev = usbtiny.USBtiny(vendor, product) 72 | 73 | # --- dispatch command 74 | if cmd == 't': 75 | dev.echo_test() 76 | elif cmd == 'r': 77 | addr = byte 78 | byte = dev.control_in(USBTINY_READ, 0, addr, 1) 79 | print "%02x: %02x" % (addr, ord(byte)) 80 | elif cmd == 'w': 81 | dev.control_in(USBTINY_WRITE, byte, addr, 0) 82 | elif cmd == 'c': 83 | dev.control_in(USBTINY_CLR, byte, addr, 0) 84 | elif cmd == 's': 85 | dev.control_in(USBTINY_SET, byte, addr, 0) 86 | elif cmd == 'U': 87 | dev.control_in(USBTINY_POWERUP, 20, byte, 0) 88 | elif cmd == 'D': 89 | dev.control_in(USBTINY_POWERDOWN, 0, 0, 0) 90 | elif cmd == 'C': 91 | r = dev.control_in(USBTINY_SPI, addr + (byte << 8), c3 + (c4 << 8), 4) 92 | if len(r) == 4: 93 | print "%02x %02x %02x %02x" % tuple([ord(i) for i in r]) 94 | else: 95 | print "No power" 96 | elif cmd == 'P': 97 | dev.control_in(USBTINY_POLL_BYTES, addr + (byte << 8), 0, 0) 98 | elif cmd == 'f': 99 | r = dev.control_in(USBTINY_FLASH_READ, 0, addr, byte) 100 | usbtiny.dump(addr, r) 101 | elif cmd == 'e': 102 | r = dev.control_in(USBTINY_EEPROM_READ, 0, addr, byte) 103 | usbtiny.dump(addr, r) 104 | elif cmd == 'F': 105 | buf = chr(c3) 106 | dev.control_out(USBTINY_FLASH_WRITE, byte, addr, buf) 107 | elif cmd == 'E': 108 | buf = chr(c3) 109 | dev.control_out(USBTINY_EEPROM_WRITE, byte, addr, buf) 110 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/spi/usbtiny.h: -------------------------------------------------------------------------------- 1 | // ====================================================================== 2 | // USBtiny Configuration 3 | // 4 | // Copyright (C) 2006 Dick Streefland 5 | // 6 | // This is free software, licensed under the terms of the GNU General 7 | // Public License as published by the Free Software Foundation. 8 | // ====================================================================== 9 | 10 | // The D+ and D- USB signals should be connected to two pins of the same 11 | // I/O port. The following macros define the port letter and the input 12 | // bit numbers: 13 | #define USBTINY_PORT D 14 | #define USBTINY_DPLUS 2 15 | #define USBTINY_DMINUS 3 16 | 17 | // The D+ signal should be connected to an interrupt input to trigger an 18 | // interrupt at the start of a packet. When you use the same pin for the 19 | // D+ USB signal and the interrupt input, only two I/O pins are needed 20 | // for the USB interface. The following macro defines the interrupt 21 | // number: 22 | #define USBTINY_INT 0 23 | 24 | // The power requirement of the USB device in mA, or 0 when the device 25 | // is not bus powered: 26 | #define USBTINY_MAX_POWER 100 27 | 28 | // The USB vendor and device IDs. These values should be unique for 29 | // every distinct device. You can get your own vendor ID from the USB 30 | // Implementers Forum (www.usb.org) if you have a spare $1500 to kill. 31 | // Alternatively, you can buy a small range of device IDs from 32 | // www.voti.nl or www.mecanique.co.uk, or be naughty and use something 33 | // else, like for instance product ID 0x6666, which is registered as 34 | // "Prototype product Vendor ID". 35 | //#define USBTINY_VENDOR_ID 0x1B4F // SparkFun VendorID 36 | //#define USBTINY_DEVICE_ID 0x0003 // SparkFun Product ID #3 37 | #define USBTINY_VENDOR_ID 0x1781 // SparkFun Licensed VendorID 38 | #define USBTINY_DEVICE_ID 0x0C9F // SparkFun Licensed ProductID 39 | 40 | // The version of the device as a 16-bit number: 256*major + minor. 41 | #define USBTINY_DEVICE_VERSION 0x104 42 | 43 | // The following optional macros may be used as an identification of 44 | // your device. Undefine them when you run out of flash space. 45 | //#define USBTINY_VENDOR_NAME "Dick Streefland" 46 | //#define USBTINY_DEVICE_NAME "USBtiny" 47 | #undef USBTINY_SERIAL 48 | 49 | // Define the device class, subclass and protocol. Device class 0xff 50 | // is "vendor specific". 51 | #define USBTINY_DEVICE_CLASS 0xff 52 | #define USBTINY_DEVICE_SUBCLASS 0 53 | #define USBTINY_DEVICE_PROTOCOL 0 54 | 55 | // Define the interface class, subclass and protocol. Interface class 56 | // 0xff is "vendor specific". 57 | #define USBTINY_INTERFACE_CLASS 0xff 58 | #define USBTINY_INTERFACE_SUBCLASS 0 59 | #define USBTINY_INTERFACE_PROTOCOL 0 60 | 61 | // Normally, usb_setup() should write the reply of up to 8 bytes into the 62 | // packet buffer, and return the reply length. When this macro is defined 63 | // as 1, you have the option of returning 0xff instead. In that case, the 64 | // USB driver will call a function usb_in() to obtain the data to send 65 | // back to the host. This can be used to generate the data on-the-fly. 66 | #define USBTINY_CALLBACK_IN 1 67 | 68 | // When this macro is defined as 0, OUT packets are simply ignored. 69 | // When defined as 1, the function usb_out() is called for OUT packets. 70 | // You need this option to send data from the host to the device in 71 | // a control transfer. 72 | #define USBTINY_CALLBACK_OUT 1 73 | 74 | // Set the macro USBTINY_ENDPOINT to 1 to add an additional endpoint, 75 | // according to the values of the three other macros. 76 | #define USBTINY_ENDPOINT 0 77 | #define USBTINY_ENDPOINT_ADDRESS 0x81 // IN endpoint #1 78 | #define USBTINY_ENDPOINT_TYPE 0x00 // control transfer type 79 | #define USBTINY_ENDPOINT_INTERVAL 0 // ignored 80 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/usbtiny/common.mk: -------------------------------------------------------------------------------- 1 | # ====================================================================== 2 | # Common Makefile for USBtiny applications 3 | # 4 | # Macros to be defined before including this file: 5 | # 6 | # USBTINY - the location of this directory 7 | # TARGET_ARCH - gcc -mmcu= option with AVR device type 8 | # OBJECTS - the objects in addition to the USBtiny objects 9 | # FLASH_CMD - command to upload main.hex to flash 10 | # STACK - maximum stack size (optional) 11 | # FLASH - flash size (optional) 12 | # SRAM - SRAM size (optional) 13 | # SCHEM - Postscript version of the schematic to be generated 14 | # 15 | # Copyright (C) 2006 Dick Streefland 16 | # 17 | # This is free software, licensed under the terms of the GNU General 18 | # Public License as published by the Free Software Foundation. 19 | # ====================================================================== 20 | 21 | CC = avr-gcc 22 | CFLAGS = -Os -g -Wall -I. -I$(USBTINY) 23 | ASFLAGS = -Os -g -Wall -I. 24 | #CFLAGS = -Os -g -Wall -I. -I$(USBTINY) 25 | #ASFLAGS = -Os -g -Wall -I. 26 | LDFLAGS = -g 27 | MODULES = crc.o int.o usb.o $(OBJECTS) 28 | UTIL = $(USBTINY)/../util 29 | 30 | main.hex: 31 | 32 | all: main.hex $(SCHEM) 33 | 34 | clean: 35 | rm -f main.elf *.o tags *.sch~ gschem.log 36 | 37 | clobber: clean 38 | rm -f main.hex $(SCHEM) 39 | 40 | main.elf: $(MODULES) 41 | $(LINK.o) -o $@ $(MODULES) 42 | 43 | main.hex: main.elf $(UTIL)/check.py 44 | @python $(UTIL)/check.py main.elf $(STACK) $(FLASH) $(SRAM) 45 | avr-objcopy -j .text -j .data -O ihex main.elf main.hex 46 | 47 | disasm: main.elf 48 | avr-objdump -S main.elf 49 | 50 | flash: main.hex 51 | $(FLASH_CMD) 52 | fuse: 53 | $(FUSE_CMD) 54 | 55 | crc.o: $(USBTINY)/crc.S $(USBTINY)/def.h usbtiny.h 56 | $(COMPILE.c) $(USBTINY)/crc.S 57 | int.o: $(USBTINY)/int.S $(USBTINY)/def.h usbtiny.h 58 | $(COMPILE.c) $(USBTINY)/int.S 59 | usb.o: $(USBTINY)/usb.c $(USBTINY)/def.h $(USBTINY)/usb.h usbtiny.h 60 | $(COMPILE.c) $(USBTINY)/usb.c 61 | 62 | main.o: $(USBTINY)/usb.h 63 | 64 | %.ps: %.sch $(UTIL)/sch2ps 65 | $(UTIL)/sch2ps $< 66 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/usbtiny/crc.S: -------------------------------------------------------------------------------- 1 | ; ====================================================================== 2 | ; Calculate and append CRC 3 | ; 4 | ; The CRC is calculated 4 bits at a time, using a precomputed table of 5 | ; 16 values. Each value is 16 bits, but only the 8 significant bits are 6 | ; stored. The table should not cross a 256-byte page. The check.py script 7 | ; will check for this. 8 | ; 9 | ; A bitwise algorithm would be a little smaller, but takes more time. 10 | ; In fact, it takes too much time for the USB controller in my laptop. 11 | ; The poll frequently is so high, that a lot of time is spent in the 12 | ; interrupt handler, sending NAK packets, leaving little time for the 13 | ; actual checksum calculation. An 8 bit algoritm would be even faster, 14 | ; but requires a lookup table of 512 bytes. 15 | ; 16 | ; Copyright (C) 2006 Dick Streefland 17 | ; 18 | ; This is free software, licensed under the terms of the GNU General 19 | ; Public License as published by the Free Software Foundation. 20 | ; ====================================================================== 21 | 22 | #include "def.h" 23 | 24 | ; ---------------------------------------------------------------------- 25 | ; void crc(unsigned char *data, unsigned char len); 26 | ; ---------------------------------------------------------------------- 27 | #define data r24 28 | #define len r22 29 | 30 | #define b r18 31 | #define tmp r19 32 | #define zl r20 33 | #define crc_l r24 34 | #define crc_h r25 35 | 36 | .text 37 | .global crc 38 | .type crc, @function 39 | crc: 40 | ; crc = 0xffff 41 | movw XL, r24 42 | ldi crc_h, 0xff 43 | ldi crc_l, 0xff 44 | lsl len 45 | breq done 46 | ldi zl, lo8(crc4tab) 47 | ldi ZH, hi8(crc4tab) 48 | 49 | next_nibble: 50 | ; b = (len & 1 ? b >> 4 : *data++) 51 | swap b 52 | sbrs len, 0 53 | ld b, X+ 54 | 55 | ; index = (crc ^ b) & 0x0f 56 | mov ZL, crc_l 57 | eor ZL, b 58 | andi ZL, 0x0f 59 | 60 | ; crc >>= 4 61 | swap crc_h 62 | swap crc_l 63 | andi crc_l, 0x0f 64 | mov tmp, crc_h 65 | andi tmp, 0xf0 66 | or crc_l, tmp 67 | andi crc_h, 0x0f 68 | 69 | ; crc ^= crc4tab[index] 70 | add ZL, zl 71 | lpm tmp, Z+ 72 | eor crc_h, tmp 73 | andi tmp, 1 74 | eor crc_h, tmp 75 | eor crc_l, tmp 76 | 77 | ; next nibble 78 | dec len 79 | brne next_nibble 80 | 81 | done: 82 | ; crc ^= 0xffff 83 | com crc_l 84 | com crc_h 85 | 86 | ; append crc to buffer 87 | st X+, crc_l 88 | st X+, crc_h 89 | 90 | ret 91 | 92 | ; ---------------------------------------------------------------------- 93 | ; CRC table. As bits 1..8 are always zero, omit them. 94 | ; ---------------------------------------------------------------------- 95 | .section .progmem.crc,"a",@progbits 96 | ;;; .align 4 ; avoid crossing a page boundary 97 | crc4tab: 98 | .byte 0x00+0x00 99 | .byte 0xcc+0x01 100 | .byte 0xd8+0x01 101 | .byte 0x14+0x00 102 | .byte 0xf0+0x01 103 | .byte 0x3c+0x00 104 | .byte 0x28+0x00 105 | .byte 0xe4+0x01 106 | .byte 0xa0+0x01 107 | .byte 0x6c+0x00 108 | .byte 0x78+0x00 109 | .byte 0xb4+0x01 110 | .byte 0x50+0x00 111 | .byte 0x9c+0x01 112 | .byte 0x88+0x01 113 | .byte 0x44+0x00 114 | /* ---------------------------------------------------------------------- *\ 115 | #!/usr/bin/python 116 | for crc in range(16): 117 | for bit in range(4): 118 | xor = crc & 1 119 | crc >>= 1 120 | if xor: 121 | crc ^= 0xA001 # X^16 + X^15 + X^2 + 1 (reversed) 122 | print "\t.byte\t0x%02x+0x%02x" % (crc >> 8, crc & 0xff) 123 | \* ---------------------------------------------------------------------- */ 124 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/usbtiny/def.h: -------------------------------------------------------------------------------- 1 | // ====================================================================== 2 | // Common definitions for the USB driver 3 | // 4 | // Copyright (C) 2006 Dick Streefland 5 | // 6 | // This is free software, licensed under the terms of the GNU General 7 | // Public License as published by the Free Software Foundation. 8 | // ====================================================================== 9 | 10 | #ifdef __ASSEMBLER__ 11 | #define __SFR_OFFSET 0 12 | #endif 13 | #include 14 | #include "usbtiny.h" 15 | 16 | // Preprocessor magic 17 | #define CAT2(a,b) CAT2EXP(a, b) 18 | #define CAT2EXP(a,b) a ## b 19 | #define CAT3(a,b,c) CAT3EXP(a, b, c) 20 | #define CAT3EXP(a,b,c) a ## b ## c 21 | 22 | // I/O Ports 23 | #define USB_IN CAT2(PIN, USBTINY_PORT) 24 | #define USB_OUT CAT2(PORT, USBTINY_PORT) 25 | #define USB_DDR CAT2(DDR, USBTINY_PORT) 26 | 27 | // I/O bit masks 28 | #define USB_MASK_DMINUS (1 << (USBTINY_DMINUS)) 29 | #define USB_MASK_DPLUS (1 << (USBTINY_DPLUS)) 30 | #define USB_MASK (USB_MASK_DMINUS | USB_MASK_DPLUS) 31 | 32 | // Interrupt configuration 33 | #if defined EICRA 34 | # define USB_INT_CONFIG EICRA 35 | #else 36 | # define USB_INT_CONFIG MCUCR 37 | #endif 38 | #define USB_INT_CONFIG_SET ((1 << CAT3(ISC,USBTINY_INT,1)) | (1 << CAT3(ISC,USBTINY_INT,0))) 39 | #if defined SIG_INT0 40 | # define USB_INT_VECTOR CAT2(SIG_INT, USBTINY_INT) 41 | #else 42 | # define USB_INT_VECTOR CAT2(SIG_INTERRUPT, USBTINY_INT) 43 | #endif 44 | 45 | // Interrupt enable 46 | #if defined GIMSK 47 | # define USB_INT_ENABLE GIMSK 48 | #elif defined EIMSK 49 | # define USB_INT_ENABLE EIMSK 50 | #else 51 | # define USB_INT_ENABLE GICR 52 | #endif 53 | #define USB_INT_ENABLE_BIT CAT2(INT,USBTINY_INT) 54 | 55 | // Interrupt pending bit 56 | #if defined EIFR 57 | # define USB_INT_PENDING EIFR 58 | #else 59 | # define USB_INT_PENDING GIFR 60 | #endif 61 | #define USB_INT_PENDING_BIT CAT2(INTF,USBTINY_INT) 62 | 63 | // USB PID values 64 | #define USB_PID_SETUP 0x2d 65 | #define USB_PID_OUT 0xe1 66 | #define USB_PID_IN 0x69 67 | #define USB_PID_DATA0 0xc3 68 | #define USB_PID_DATA1 0x4b 69 | #define USB_PID_ACK 0xd2 70 | #define USB_PID_NAK 0x5a 71 | #define USB_PID_STALL 0x1e 72 | 73 | // Various constants 74 | #define USB_BUFSIZE 11 // PID + data + CRC 75 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/usbtiny/int.S: -------------------------------------------------------------------------------- 1 | ; ====================================================================== 2 | ; USB interrupt handler 3 | ; 4 | ; This is the handler for the interrupt caused by the initial rising edge 5 | ; on the D+ USB signal. The NRZI encoding and bit stuffing are removed, 6 | ; and the packet is saved in one of the two input buffers. In some cases, 7 | ; a reply packet is sent right away. 8 | ; 9 | ; When a DATA0/DATA1 packet directly follows a SETUP or OUT packet, while 10 | ; this interrupt handler is not yet finished, there would be no time to 11 | ; return and take another interrupt. In that case, the second packet is 12 | ; decoded directly in the same invocation. 13 | ; 14 | ; This code is *extremely* time critical. For instance, there is not a 15 | ; single spare cycle in the receiver loop, and only two in the transmitter 16 | ; loop. In addition, the various code paths are laid out in such a way that 17 | ; the various USB timeouts are not violated, in particular the maximum time 18 | ; between the reception of a packet and the reply, which is 6.5 bit times 19 | ; for a detachable cable (TRSPIPD1), and 7.5 bit times for a captive cable 20 | ; (TRSPIPD2). The worst-case delay here is 51 cycles, which is just below 21 | ; the 52 cycles for a detachable cable. 22 | ; 23 | ; The interrupt handler must be reached within 34 cycles after D+ goes high 24 | ; for the first time, so the interrupts should not be disabled for longer 25 | ; than 34-4-2=28 cycles. 26 | ; 27 | ; The end-of-packet (EOP) is sampled in the second bit, because the USB 28 | ; standard allows the EOP to be delayed by up to one bit. As the EOP 29 | ; duration is two bits, this is not a problem. 30 | ; 31 | ; Stack usage including the return address: 11 bytes. 32 | ; 33 | ; Copyright (C) 2006 Dick Streefland 34 | ; 35 | ; This is free software, licensed under the terms of the GNU General 36 | ; Public License as published by the Free Software Foundation. 37 | ; ====================================================================== 38 | 39 | #include "def.h" 40 | 41 | ; ---------------------------------------------------------------------- 42 | ; local data 43 | ; ---------------------------------------------------------------------- 44 | .data 45 | tx_ack: .byte USB_PID_ACK ; ACK packet 46 | tx_nak: .byte USB_PID_NAK ; NAK packet 47 | .lcomm token_pid, 1 ; PID of most recent token packet 48 | 49 | ; ---------------------------------------------------------------------- 50 | ; register definitions 51 | ; ---------------------------------------------------------------------- 52 | // receiver: 53 | #define count r16 54 | #define usbmask r17 55 | #define odd r18 56 | #define byte r19 57 | #define fixup r20 58 | #define even r22 59 | 60 | // transmitter: 61 | #define output odd 62 | #define done fixup 63 | #define next even 64 | 65 | // control: 66 | #define pid odd 67 | #define addr usbmask 68 | #define tmp fixup 69 | 70 | #define nop2 rjmp .+0 // not .+2 for some strange reason 71 | 72 | ; ---------------------------------------------------------------------- 73 | ; interrupt handler 74 | ; ---------------------------------------------------------------------- 75 | .text 76 | .global USB_INT_VECTOR 77 | .type USB_INT_VECTOR, @function 78 | ; ---------------------------------------------------------------------- 79 | ; This handler must be reached no later than 34 cycles after D+ goes high 80 | ; for the first time. 81 | ; ---------------------------------------------------------------------- 82 | USB_INT_VECTOR: 83 | ; save registers 84 | push count 85 | push usbmask 86 | push odd 87 | push YH 88 | push YL 89 | in count, SREG 90 | push count 91 | 92 | ; ---------------------------------------------------------------------- 93 | ; Synchronize to the pattern 10101011 on D+. This code must be reached 94 | ; no later than 47 cycles after D+ goes high for the first time. 95 | ; ---------------------------------------------------------------------- 96 | sync: 97 | ; wait until D+ == 0 98 | sbic USB_IN, USBTINY_DPLUS 99 | rjmp sync ; jump if D+ == 1 100 | resync: 101 | ; sync on 0-->1 transition on D+ with a 2 cycle resolution 102 | sbic USB_IN, USBTINY_DPLUS 103 | rjmp sync6 ; jump if D+ == 1 104 | sbic USB_IN, USBTINY_DPLUS 105 | rjmp sync6 ; jump if D+ == 1 106 | sbic USB_IN, USBTINY_DPLUS 107 | rjmp sync6 ; jump if D+ == 1 108 | sbic USB_IN, USBTINY_DPLUS 109 | rjmp sync6 ; jump if D+ == 1 110 | sbic USB_IN, USBTINY_DPLUS 111 | rjmp sync6 ; jump if D+ == 1 112 | ldi count, 1< false start, bail out 115 | 116 | sync6: 117 | ; we are now between -1 and +1 cycle from the center of the bit 118 | ; following the 0-->1 transition 119 | lds YL, usb_rx_off 120 | clr YH 121 | subi YL, lo8(-(usb_rx_buf)) ; Y = & usb_rx_buf[usb_rx_off] 122 | sbci YH, hi8(-(usb_rx_buf)) 123 | ldi count, USB_BUFSIZE ; limit on number of bytes to receive 124 | ldi usbmask, USB_MASK ; why is there no eori instruction? 125 | ldi odd, USB_MASK_DPLUS 126 | 127 | sync7: 128 | ; the last sync bit should also be 1 129 | sbis USB_IN, USBTINY_DPLUS ; bit 7 of sync byte? 130 | rjmp resync ; no, wait for next transition 131 | push byte 132 | push fixup 133 | push even 134 | 135 | ; ---------------------------------------------------------------------- 136 | ; receiver loop 137 | ; ---------------------------------------------------------------------- 138 | in even, USB_IN ; sample bit 0 139 | ldi byte, 0x80 ; load sync byte for correct unstuffing 140 | rjmp rxentry ; 2 cycles 141 | 142 | rxloop: 143 | in even, USB_IN ; sample bit 0 144 | or fixup, byte 145 | st Y+, fixup ; 2 cycles 146 | rxentry: 147 | clr fixup 148 | andi even, USB_MASK 149 | eor odd, even 150 | subi odd, 1 151 | in odd, USB_IN ; sample bit 1 152 | andi odd, USB_MASK 153 | breq eop ; ==> EOP detected 154 | ror byte 155 | cpi byte, 0xfc 156 | brcc skip0 157 | skipped0: 158 | eor even, odd 159 | subi even, 1 160 | in even, USB_IN ; sample bit 2 161 | andi even, USB_MASK 162 | ror byte 163 | cpi byte, 0xfc 164 | brcc skip1 165 | skipped1: 166 | eor odd, even 167 | subi odd, 1 168 | ror byte 169 | in odd, USB_IN ; sample bit 3 170 | andi odd, USB_MASK 171 | cpi byte, 0xfc 172 | brcc skip2 173 | eor even, odd 174 | subi even, 1 175 | ror byte 176 | skipped2: 177 | cpi byte, 0xfc 178 | in even, USB_IN ; sample bit 4 179 | andi even, USB_MASK 180 | brcc skip3 181 | eor odd, even 182 | subi odd, 1 183 | ror byte 184 | skipped4: 185 | cpi byte, 0xfc 186 | skipped3: 187 | brcc skip4 188 | in odd, USB_IN ; sample bit 5 189 | andi odd, USB_MASK 190 | eor even, odd 191 | subi even, 1 192 | ror byte 193 | skipped5: 194 | cpi byte, 0xfc 195 | brcc skip5 196 | dec count 197 | in even, USB_IN ; sample bit 6 198 | brmi overflow ; ==> overflow 199 | andi even, USB_MASK 200 | eor odd, even 201 | subi odd, 1 202 | ror byte 203 | skipped6: 204 | cpi byte, 0xfc 205 | brcc skip6 206 | in odd, USB_IN ; sample bit 7 207 | andi odd, USB_MASK 208 | eor even, odd 209 | subi even, 1 210 | ror byte 211 | cpi byte, 0xfc 212 | brcs rxloop ; 2 cycles 213 | rjmp skip7 214 | 215 | eop: 216 | rjmp eop2 217 | overflow: 218 | rjmp ignore 219 | 220 | ; ---------------------------------------------------------------------- 221 | ; out-of-line code to skip stuffing bits 222 | ; ---------------------------------------------------------------------- 223 | skip0: ; 1+6 cycles 224 | eor even, usbmask 225 | in odd, USB_IN ; resample bit 1 226 | andi odd, USB_MASK 227 | cbr byte, (1<<7) 228 | sbr fixup, (1<<0) 229 | rjmp skipped0 230 | 231 | skip1: ; 2+5 cycles 232 | cbr byte, (1<<7) 233 | sbr fixup, (1<<1) 234 | in even, USB_IN ; resample bit 2 235 | andi even, USB_MASK 236 | eor odd, usbmask 237 | rjmp skipped1 238 | 239 | skip2: ; 3+7 cycles 240 | cbr byte, (1<<7) 241 | sbr fixup, (1<<2) 242 | eor even, usbmask 243 | in odd, USB_IN ; resample bit 3 244 | andi odd, USB_MASK 245 | eor even, odd 246 | subi even, 1 247 | ror byte 248 | rjmp skipped2 249 | 250 | skip3: ; 4+7 cycles 251 | cbr byte, (1<<7) 252 | sbr fixup, (1<<3) 253 | eor odd, usbmask 254 | ori byte, 1 255 | in even, USB_IN ; resample bit 4 256 | andi even, USB_MASK 257 | eor odd, even 258 | subi odd, 1 259 | ror byte 260 | rjmp skipped3 261 | 262 | skip4: ; 5 cycles 263 | cbr byte, (1<<7) 264 | sbr fixup, (1<<4) 265 | eor even, usbmask 266 | rjmp skipped4 267 | 268 | skip5: ; 5 cycles 269 | cbr byte, (1<<7) 270 | sbr fixup, (1<<5) 271 | eor odd, usbmask 272 | rjmp skipped5 273 | 274 | skip6: ; 5 cycles 275 | cbr byte, (1<<7) 276 | sbr fixup, (1<<6) 277 | eor even, usbmask 278 | rjmp skipped6 279 | 280 | skip7: ; 7 cycles 281 | cbr byte, (1<<7) 282 | sbr fixup, (1<<7) 283 | eor odd, usbmask 284 | nop2 285 | rjmp rxloop 286 | 287 | ; ---------------------------------------------------------------------- 288 | ; end-of-packet detected (worst-case: 3 cycles after end of SE0) 289 | ; ---------------------------------------------------------------------- 290 | eop2: 291 | ; clear pending interrupt (SE0+3) 292 | ldi byte, 1< SOP <= 51 371 | 372 | ; ---------------------------------------------------------------------- 373 | ; Handle DATA0/DATA1 (SE0+17) 374 | ; ---------------------------------------------------------------------- 375 | is_data: 376 | lds pid, token_pid 377 | tst pid ; data following our SETUP/OUT 378 | breq ignore ; no, ignore 379 | lds tmp, usb_rx_len 380 | tst tmp ; buffer free? 381 | brne nak ; no, reply with NAK 382 | sts usb_rx_len, count ; pass buffer length 383 | sts usb_rx_token, pid ; pass PID of token (SETUP or OUT) 384 | lds count, usb_rx_off ; switch to other input buffer 385 | ldi tmp, USB_BUFSIZE 386 | sub tmp, count 387 | sts usb_rx_off, tmp 388 | 389 | ; ---------------------------------------------------------------------- 390 | ; send ACK packet (SE0+35) 391 | ; ---------------------------------------------------------------------- 392 | ack: 393 | ldi YL, lo8(tx_ack) 394 | ldi YH, hi8(tx_ack) 395 | rjmp send_token 396 | 397 | ; ---------------------------------------------------------------------- 398 | ; send NAK packet (SE0+36) 399 | ; ---------------------------------------------------------------------- 400 | nak: 401 | ldi YL, lo8(tx_nak) 402 | ldi YH, hi8(tx_nak) 403 | send_token: 404 | ldi count, 1 ; SE0+40, SE0 --> SOP <= 51 405 | 406 | ; ---------------------------------------------------------------------- 407 | ; acquire the bus and send a packet (11 cycles to SOP) 408 | ; ---------------------------------------------------------------------- 409 | send_packet: 410 | in output, USB_OUT 411 | cbr output, USB_MASK 412 | ori output, USB_MASK_DMINUS 413 | in usbmask, USB_DDR 414 | ori usbmask, USB_MASK 415 | out USB_OUT, output ; idle state 416 | out USB_DDR, usbmask ; acquire bus 417 | ldi usbmask, USB_MASK 418 | ldi byte, 0x80 ; start with sync byte 419 | 420 | ; ---------------------------------------------------------------------- 421 | ; transmitter loop 422 | ; ---------------------------------------------------------------------- 423 | txloop: 424 | sbrs byte, 0 425 | eor output, usbmask 426 | out USB_OUT, output ; output bit 0 427 | ror byte 428 | ror done 429 | stuffed0: 430 | cpi done, 0xfc 431 | brcc stuff0 432 | sbrs byte, 0 433 | eor output, usbmask 434 | ror byte 435 | stuffed1: 436 | out USB_OUT, output ; output bit 1 437 | ror done 438 | cpi done, 0xfc 439 | brcc stuff1 440 | sbrs byte, 0 441 | eor output, usbmask 442 | ror byte 443 | nop 444 | stuffed2: 445 | out USB_OUT, output ; output bit 2 446 | ror done 447 | cpi done, 0xfc 448 | brcc stuff2 449 | sbrs byte, 0 450 | eor output, usbmask 451 | ror byte 452 | nop 453 | stuffed3: 454 | out USB_OUT, output ; output bit 3 455 | ror done 456 | cpi done, 0xfc 457 | brcc stuff3 458 | sbrs byte, 0 459 | eor output, usbmask 460 | ld next, Y+ ; 2 cycles 461 | out USB_OUT, output ; output bit 4 462 | ror byte 463 | ror done 464 | stuffed4: 465 | cpi done, 0xfc 466 | brcc stuff4 467 | sbrs byte, 0 468 | eor output, usbmask 469 | ror byte 470 | stuffed5: 471 | out USB_OUT, output ; output bit 5 472 | ror done 473 | cpi done, 0xfc 474 | brcc stuff5 475 | sbrs byte, 0 476 | eor output, usbmask 477 | ror byte 478 | stuffed6: 479 | ror done 480 | out USB_OUT, output ; output bit 6 481 | cpi done, 0xfc 482 | brcc stuff6 483 | sbrs byte, 0 484 | eor output, usbmask 485 | ror byte 486 | mov byte, next 487 | stuffed7: 488 | ror done 489 | out USB_OUT, output ; output bit 7 490 | cpi done, 0xfc 491 | brcc stuff7 492 | dec count 493 | brpl txloop ; 2 cycles 494 | 495 | rjmp gen_eop 496 | 497 | ; ---------------------------------------------------------------------- 498 | ; out-of-line code to insert stuffing bits 499 | ; ---------------------------------------------------------------------- 500 | stuff0: ; 2+3 501 | eor output, usbmask 502 | clr done 503 | out USB_OUT, output 504 | rjmp stuffed0 505 | 506 | stuff1: ; 3 507 | eor output, usbmask 508 | rjmp stuffed1 509 | 510 | stuff2: ; 3 511 | eor output, usbmask 512 | rjmp stuffed2 513 | 514 | stuff3: ; 3 515 | eor output, usbmask 516 | rjmp stuffed3 517 | 518 | stuff4: ; 2+3 519 | eor output, usbmask 520 | clr done 521 | out USB_OUT, output 522 | rjmp stuffed4 523 | 524 | stuff5: ; 3 525 | eor output, usbmask 526 | rjmp stuffed5 527 | 528 | stuff6: ; 3 529 | eor output, usbmask 530 | rjmp stuffed6 531 | 532 | stuff7: ; 3 533 | eor output, usbmask 534 | rjmp stuffed7 535 | 536 | ; ---------------------------------------------------------------------- 537 | ; generate EOP, release the bus, and return from interrupt 538 | ; ---------------------------------------------------------------------- 539 | gen_eop: 540 | cbr output, USB_MASK 541 | out USB_OUT, output ; output SE0 for 2 bit times 542 | pop even 543 | pop fixup 544 | pop byte 545 | ldi count, 1< 30 | #include 31 | #include "def.h" 32 | #include "usb.h" 33 | 34 | #define LE(word) (word) & 0xff, (word) >> 8 35 | 36 | // ---------------------------------------------------------------------- 37 | // USB constants 38 | // ---------------------------------------------------------------------- 39 | 40 | enum 41 | { 42 | DESCRIPTOR_TYPE_DEVICE = 1, 43 | DESCRIPTOR_TYPE_CONFIGURATION, 44 | DESCRIPTOR_TYPE_STRING, 45 | DESCRIPTOR_TYPE_INTERFACE, 46 | DESCRIPTOR_TYPE_ENDPOINT, 47 | }; 48 | 49 | // ---------------------------------------------------------------------- 50 | // Interrupt handler interface 51 | // ---------------------------------------------------------------------- 52 | 53 | byte_t usb_rx_buf[2*USB_BUFSIZE]; // two input buffers 54 | byte_t usb_rx_off; // buffer offset: 0 or USB_BUFSIZE 55 | byte_t usb_rx_len; // buffer size, 0 means empty 56 | byte_t usb_rx_token; // PID of token packet: SETUP or OUT 57 | 58 | byte_t usb_tx_buf[USB_BUFSIZE]; // output buffer 59 | byte_t usb_tx_len; // output buffer size, 0 means empty 60 | 61 | byte_t usb_address; // assigned USB address 62 | 63 | // ---------------------------------------------------------------------- 64 | // Local data 65 | // ---------------------------------------------------------------------- 66 | 67 | enum 68 | { 69 | TX_STATE_IDLE = 0, // transmitter idle 70 | TX_STATE_RAM, // usb_tx_data is a RAM address 71 | TX_STATE_ROM, // usb_tx_data is a ROM address 72 | TX_STATE_CALLBACK, // call usb_in() to obtain transmit data 73 | }; 74 | 75 | static byte_t usb_tx_state; // TX_STATE_*, see enum above 76 | static byte_t usb_tx_total; // total transmit size 77 | static byte_t* usb_tx_data; // pointer to data to transmit 78 | static byte_t new_address; // new device address 79 | 80 | #if defined USBTINY_VENDOR_NAME 81 | struct 82 | { 83 | byte_t length; 84 | byte_t type; 85 | int string[sizeof(USBTINY_VENDOR_NAME)-1]; 86 | } string_vendor PROGMEM = 87 | { 88 | 2 * sizeof(USBTINY_VENDOR_NAME), 89 | DESCRIPTOR_TYPE_STRING, 90 | { CAT2(L, USBTINY_VENDOR_NAME) } 91 | }; 92 | # define VENDOR_NAME_ID 1 93 | #else 94 | # define VENDOR_NAME_ID 0 95 | #endif 96 | 97 | #if defined USBTINY_DEVICE_NAME 98 | struct 99 | { 100 | byte_t length; 101 | byte_t type; 102 | int string[sizeof(USBTINY_DEVICE_NAME)-1]; 103 | } string_device PROGMEM = 104 | { 105 | 2 * sizeof(USBTINY_DEVICE_NAME), 106 | DESCRIPTOR_TYPE_STRING, 107 | { CAT2(L, USBTINY_DEVICE_NAME) } 108 | }; 109 | # define DEVICE_NAME_ID 2 110 | #else 111 | # define DEVICE_NAME_ID 0 112 | #endif 113 | 114 | #if defined USBTINY_SERIAL 115 | struct 116 | { 117 | byte_t length; 118 | byte_t type; 119 | int string[sizeof(USBTINY_SERIAL)-1]; 120 | } string_serial PROGMEM = 121 | { 122 | 2 * sizeof(USBTINY_SERIAL), 123 | DESCRIPTOR_TYPE_STRING, 124 | { CAT2(L, USBTINY_SERIAL) } 125 | }; 126 | # define SERIAL_ID 3 127 | #else 128 | # define SERIAL_ID 0 129 | #endif 130 | 131 | #if VENDOR_NAME_ID || DEVICE_NAME_ID || SERIAL_ID 132 | static byte_t string_langid [] PROGMEM = 133 | { 134 | 4, // bLength 135 | DESCRIPTOR_TYPE_STRING, // bDescriptorType (string) 136 | LE(0x0409), // wLANGID[0] (American English) 137 | }; 138 | #endif 139 | 140 | // Device Descriptor 141 | static byte_t descr_device [18] PROGMEM = 142 | { 143 | 18, // bLength 144 | DESCRIPTOR_TYPE_DEVICE, // bDescriptorType 145 | LE(0x0101), // bcdUSB 146 | USBTINY_DEVICE_CLASS, // bDeviceClass 147 | USBTINY_DEVICE_SUBCLASS, // bDeviceSubClass 148 | USBTINY_DEVICE_PROTOCOL, // bDeviceProtocol 149 | 8, // bMaxPacketSize0 150 | LE(USBTINY_VENDOR_ID), // idVendor 151 | LE(USBTINY_DEVICE_ID), // idProduct 152 | LE(USBTINY_DEVICE_VERSION), // bcdDevice 153 | VENDOR_NAME_ID, // iManufacturer 154 | DEVICE_NAME_ID, // iProduct 155 | SERIAL_ID, // iSerialNumber 156 | 1, // bNumConfigurations 157 | }; 158 | 159 | // Configuration Descriptor 160 | static byte_t descr_config [] PROGMEM = 161 | { 162 | 9, // bLength 163 | DESCRIPTOR_TYPE_CONFIGURATION, // bDescriptorType 164 | LE(9+9+7*USBTINY_ENDPOINT), // wTotalLength 165 | 1, // bNumInterfaces 166 | 1, // bConfigurationValue 167 | 0, // iConfiguration 168 | (USBTINY_MAX_POWER ? 0x80 : 0xc0), // bmAttributes 169 | (USBTINY_MAX_POWER + 1) / 2, // MaxPower 170 | 171 | // Standard Interface Descriptor 172 | 9, // bLength 173 | DESCRIPTOR_TYPE_INTERFACE, // bDescriptorType 174 | 0, // bInterfaceNumber 175 | 0, // bAlternateSetting 176 | USBTINY_ENDPOINT, // bNumEndpoints 177 | USBTINY_INTERFACE_CLASS, // bInterfaceClass 178 | USBTINY_INTERFACE_SUBCLASS, // bInterfaceSubClass 179 | USBTINY_INTERFACE_PROTOCOL, // bInterfaceProtocol 180 | 0, // iInterface 181 | 182 | #if USBTINY_ENDPOINT 183 | // Additional Endpoint 184 | 7, // bLength 185 | DESCRIPTOR_TYPE_ENDPOINT, // bDescriptorType 186 | USBTINY_ENDPOINT_ADDRESS, // bEndpointAddress 187 | USBTINY_ENDPOINT_TYPE, // bmAttributes 188 | LE(8), // wMaxPacketSize 189 | USBTINY_ENDPOINT_INTERVAL, // bInterval 190 | #endif 191 | }; 192 | 193 | // ---------------------------------------------------------------------- 194 | // Inspect an incoming packet. 195 | // ---------------------------------------------------------------------- 196 | static void usb_receive ( byte_t* data, byte_t rx_len ) 197 | { 198 | byte_t len; 199 | byte_t type; 200 | byte_t limit; 201 | 202 | usb_tx_state = TX_STATE_RAM; 203 | len = 0; 204 | if ( usb_rx_token == USB_PID_SETUP ) 205 | { 206 | limit = data[6]; 207 | if ( data[7] ) 208 | { 209 | limit = 255; 210 | } 211 | type = data[0] & 0x60; 212 | if ( type == 0x00 ) 213 | { // Standard request 214 | if ( data[1] == 0 ) // GET_STATUS 215 | { 216 | len = 2; 217 | #if USBTINY_MAX_POWER == 0 218 | data[0] = (data[0] == 0x80); 219 | #else 220 | data[0] = 0; 221 | #endif 222 | data[1] = 0; 223 | } 224 | else if ( data[1] == 5 ) // SET_ADDRESS 225 | { 226 | new_address = data[2]; 227 | } 228 | else if ( data[1] == 6 ) // GET_DESCRIPTOR 229 | { 230 | usb_tx_state = TX_STATE_ROM; 231 | if ( data[3] == 1 ) 232 | { // DEVICE 233 | data = (byte_t*) &descr_device; 234 | len = sizeof(descr_device); 235 | } 236 | else if ( data[3] == 2 ) 237 | { // CONFIGURATION 238 | data = (byte_t*) &descr_config; 239 | len = sizeof(descr_config); 240 | // If we got this far, there's a good chance everything is OK with enumeration so turn on the OK led 241 | PORTD |= _BV(5); 242 | 243 | } 244 | #if VENDOR_NAME_ID || DEVICE_NAME_ID || SERIAL_ID 245 | else if ( data[3] == 3 ) 246 | { // STRING 247 | if ( data[2] == 0 ) 248 | { 249 | data = (byte_t*) &string_langid; 250 | len = sizeof(string_langid); 251 | } 252 | #if VENDOR_NAME_ID 253 | else if ( data[2] == VENDOR_NAME_ID ) 254 | { 255 | data = (byte_t*) &string_vendor; 256 | len = sizeof(string_vendor); 257 | } 258 | #endif 259 | #if DEVICE_NAME_ID 260 | else if ( data[2] == DEVICE_NAME_ID ) 261 | { 262 | data = (byte_t*) &string_device; 263 | len = sizeof(string_device); 264 | } 265 | #endif 266 | #if SERIAL_ID 267 | else if ( data[2] == SERIAL_ID ) 268 | { 269 | data = (byte_t*) &string_serial; 270 | len = sizeof(string_serial); 271 | } 272 | #endif 273 | } 274 | #endif 275 | } 276 | else if ( data[1] == 8 ) // GET_CONFIGURATION 277 | { 278 | data[0] = 1; // return bConfigurationValue 279 | len = 1; 280 | } 281 | else if ( data[1] == 10 ) // GET_INTERFACE 282 | { 283 | data[0] = 0; 284 | len = 1; 285 | } 286 | } 287 | else 288 | { // Class or Vendor request 289 | len = usb_setup( data ); 290 | #if USBTINY_CALLBACK_IN 291 | if ( len == 0xff ) 292 | { 293 | usb_tx_state = TX_STATE_CALLBACK; 294 | } 295 | #endif 296 | } 297 | if ( len > limit ) 298 | { 299 | len = limit; 300 | } 301 | usb_tx_data = data; 302 | } 303 | #if USBTINY_CALLBACK_OUT 304 | else if ( rx_len > 0 ) 305 | { // usb_rx_token == USB_PID_OUT 306 | usb_out( data, rx_len ); 307 | } 308 | #endif 309 | usb_tx_total = len; 310 | usb_tx_buf[0] = USB_PID_DATA0; // next data packet will be DATA1 311 | } 312 | 313 | // ---------------------------------------------------------------------- 314 | // Load the transmit buffer with the next packet. 315 | // ---------------------------------------------------------------------- 316 | static void usb_transmit ( void ) 317 | { 318 | byte_t len; 319 | byte_t* src; 320 | byte_t* dst; 321 | byte_t i; 322 | byte_t b; 323 | 324 | usb_tx_buf[0] ^= (USB_PID_DATA0 ^ USB_PID_DATA1); 325 | len = usb_tx_total; 326 | if ( len > 8 ) 327 | { 328 | len = 8; 329 | } 330 | dst = usb_tx_buf + 1; 331 | if ( len > 0 ) 332 | { 333 | #if USBTINY_CALLBACK_IN 334 | if ( usb_tx_state == TX_STATE_CALLBACK ) 335 | { 336 | len = usb_in( dst, len ); 337 | } 338 | else 339 | #endif 340 | { 341 | src = usb_tx_data; 342 | if ( usb_tx_state == TX_STATE_RAM ) 343 | { 344 | for ( i = 0; i < len; i++ ) 345 | { 346 | *dst++ = *src++; 347 | } 348 | } 349 | else // usb_tx_state == TX_STATE_ROM 350 | { 351 | for ( i = 0; i < len; i++ ) 352 | { 353 | b = pgm_read_byte( src ); 354 | src++; 355 | *dst++ = b; 356 | } 357 | } 358 | usb_tx_data = src; 359 | } 360 | usb_tx_total -= len; 361 | } 362 | crc( usb_tx_buf + 1, len ); 363 | usb_tx_len = len + 3; 364 | if ( len < 8 ) 365 | { // this is the last packet 366 | usb_tx_state = TX_STATE_IDLE; 367 | } 368 | } 369 | 370 | // ---------------------------------------------------------------------- 371 | // Initialize the low-level USB driver. 372 | // ---------------------------------------------------------------------- 373 | extern void usb_init ( void ) 374 | { 375 | USB_INT_CONFIG |= USB_INT_CONFIG_SET; 376 | USB_INT_ENABLE |= (1 << USB_INT_ENABLE_BIT); 377 | sei(); 378 | } 379 | 380 | // ---------------------------------------------------------------------- 381 | // Poll USB driver: 382 | // - check for incoming USB packets 383 | // - refill an empty transmit buffer 384 | // - check for USB bus reset 385 | // ---------------------------------------------------------------------- 386 | extern void usb_poll ( void ) 387 | { 388 | byte_t i; 389 | 390 | // check for incoming USB packets 391 | if ( usb_rx_len != 0 ) 392 | { 393 | usb_receive( usb_rx_buf + USB_BUFSIZE - usb_rx_off + 1, usb_rx_len - 3 ); 394 | usb_tx_len = 0; // abort pending transmission 395 | usb_rx_len = 0; // accept next packet 396 | } 397 | // refill an empty transmit buffer, when the transmitter is active 398 | if ( usb_tx_len == 0 ) 399 | { 400 | if ( usb_tx_state != TX_STATE_IDLE ) 401 | { 402 | usb_transmit(); 403 | } 404 | else 405 | { // change the USB address at the end of a transfer 406 | usb_address = new_address; 407 | } 408 | } 409 | // check for USB bus reset 410 | for ( i = 10; i > 0 && ! (USB_IN & USB_MASK_DMINUS); i-- ) 411 | { 412 | } 413 | if ( i == 0 ) 414 | { // SE0 for more than 2.5uS is a reset 415 | new_address = 0; 416 | } 417 | } 418 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/usbtiny/usb.h: -------------------------------------------------------------------------------- 1 | // ====================================================================== 2 | // Public interface of the USB driver 3 | // 4 | // Copyright (C) 2006 Dick Streefland 5 | // 6 | // This is free software, licensed under the terms of the GNU General 7 | // Public License as published by the Free Software Foundation. 8 | // ====================================================================== 9 | 10 | #ifndef USB_H 11 | #define USB_H 12 | 13 | typedef unsigned char byte_t; 14 | typedef unsigned int uint_t; 15 | 16 | // usb.c 17 | extern void usb_init ( void ); 18 | extern void usb_poll ( void ); 19 | 20 | // crc.S 21 | extern void crc ( byte_t* data, byte_t len ); 22 | 23 | // application callback functions 24 | extern byte_t usb_setup ( byte_t data[8] ); 25 | extern void usb_out ( byte_t* data, byte_t len ); 26 | extern byte_t usb_in ( byte_t* data, byte_t len ); 27 | 28 | #endif // USB_H 29 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/util/Makefile: -------------------------------------------------------------------------------- 1 | # ====================================================================== 2 | # Build a Python wrapper for libusb. 3 | # 4 | # Copyright (C) 2006 Dick Streefland 5 | # 6 | # This is free software, licensed under the terms of the GNU General 7 | # Public License as published by the Free Software Foundation. 8 | # ====================================================================== 9 | 10 | PYTHONINC=$(shell python -c "import distutils.sysconfig; print distutils.sysconfig.get_python_inc()") 11 | 12 | all: _libusb.so 13 | 14 | clean: 15 | rm -f libusb.pyc libusb_wrap.c usbtiny.pyc 16 | 17 | clobber: clean 18 | rm -f _libusb.so libusb.py 19 | 20 | _libusb.so: libusb.i 21 | swig -python -D'__attribute__(x)=' -w302,454 -I/usr/include $< 22 | gcc -s -shared -I$(PYTHONINC) -o _libusb.so libusb_wrap.c -lusb 23 | @rm -f libusb_wrap.c 24 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/util/_libusb.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Pocket_AVR_Programmer/47a9ec210194901e5e74139c7de51876e11df963/Firmware/pocket-prog/util/_libusb.so -------------------------------------------------------------------------------- /Firmware/pocket-prog/util/check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # ====================================================================== 3 | # check.py - Check section sizes and other constraints 4 | # 5 | # Copyright (C) 2006 Dick Streefland 6 | # 7 | # This is free software, licensed under the terms of the GNU General 8 | # Public License as published by the Free Software Foundation. 9 | # ====================================================================== 10 | 11 | import os, sys 12 | 13 | stacksize = 32 14 | flashsize = 2048 15 | ramsize = 128 16 | 17 | if len(sys.argv) > 2: 18 | stacksize = int(sys.argv[2]) 19 | if len(sys.argv) > 3: 20 | flashsize = int(sys.argv[3]) 21 | if len(sys.argv) > 4: 22 | ramsize = int(sys.argv[4]) 23 | 24 | max_sram = ramsize - stacksize 25 | 26 | for line in os.popen('avr-objdump -ht ' + sys.argv[1]).readlines(): 27 | a = line.split() 28 | if len(a) == 7: 29 | if a[1] == '.text': 30 | text = int(a[2], 16) 31 | if a[1] == '.data': 32 | data = int(a[2], 16) 33 | if a[1] == '.bss': 34 | bss = int(a[2], 16) 35 | if len(a) == 5 and a[4] == 'crc4tab': 36 | crc4tab = int(a[0], 16) 37 | print 'text: %d, data: %d, bss: %d' % (text, data, bss) 38 | 39 | status = 0 40 | overflow = text + data - flashsize 41 | if overflow > 0: 42 | print 'ERROR: Flash size limit exceeded by %d bytes.' % overflow 43 | status = 1 44 | overflow = bss + data - max_sram 45 | if overflow > 0: 46 | print 'ERROR: SRAM size limit exceeded by %d bytes.' % overflow 47 | status = 1 48 | if (crc4tab & 0xff) > 0xf0: 49 | print 'ERROR: The table crc4tab should not cross a page boundary.' 50 | status = 1 51 | sys.exit(status) 52 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/util/crc16.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # ====================================================================== 3 | # crc16.py - Prototype implementations of CRC16 calculation 4 | # 5 | # Copyright (C) 2006 Dick Streefland 6 | # 7 | # This is free software, licensed under the terms of the GNU General 8 | # Public License as published by the Free Software Foundation. 9 | # ====================================================================== 10 | 11 | import sys 12 | 13 | polynomial = 0xA001 # X^16 + X^15 + X^2 + 1 - lower 16 bits, reversed 14 | 15 | def crc_update(crc, value, bits): 16 | for bit in range(bits): 17 | xor = (crc ^ (value >> bit)) & 1 18 | crc >>= 1 19 | if xor: 20 | crc ^= polynomial 21 | return crc 22 | 23 | def crc1(crc, byte): 24 | return crc_update(crc, byte, 8) 25 | 26 | def crc4(crc, byte): 27 | crc = (crc >> 4) ^ tab4[(crc ^ byte) & 0xf] 28 | crc = (crc >> 4) ^ tab4[(crc ^ (byte >> 4)) & 0xf] 29 | return crc 30 | 31 | def crc8(crc, byte): 32 | return (crc >> 8) ^ tab8[(crc ^ byte) & 0xff] 33 | 34 | def crc_file(file, crcfunc): 35 | crc = 0xffff 36 | for byte in open(file).read(): 37 | crc = crcfunc(crc, ord(byte)) 38 | crc ^= 0xffff 39 | print "%02x %02x %s" % (crc & 0xff, crc >> 8, file) 40 | 41 | tab4 = [crc_update(i, 0, 4) for i in range(2**4)] 42 | tab8 = [crc_update(i, 0, 8) for i in range(2**8)] 43 | for file in sys.argv[1:]: 44 | crc_file(file, crc1) 45 | crc_file(file, crc4) 46 | crc_file(file, crc8) 47 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/util/libusb.i: -------------------------------------------------------------------------------- 1 | // ====================================================================== 2 | // SWIG interface description for libusb 3 | // 4 | // Copyright (C) 2006 Dick Streefland 5 | // 6 | // This is free software, licensed under the terms of the GNU General 7 | // Public License as published by the Free Software Foundation. 8 | // ====================================================================== 9 | 10 | %module libusb 11 | 12 | %{ 13 | 14 | #include "usb.h" 15 | #include 16 | 17 | static void check_status ( int status ) 18 | { 19 | if ( status < 0 ) 20 | { 21 | fprintf( stderr, "libusb: %s\n", strerror( errno ) ); 22 | exit( 1 ); 23 | } 24 | } 25 | 26 | static void usb_control_in ( usb_dev_handle* dev, int requesttype, 27 | int request, int value, int index, 28 | char* inbuf, int* psize, int timeout ) 29 | { 30 | int r; 31 | 32 | Py_BEGIN_ALLOW_THREADS 33 | r = usb_control_msg( dev, USB_ENDPOINT_IN | requesttype, request, 34 | value, index, inbuf, *psize, timeout ); 35 | Py_END_ALLOW_THREADS 36 | check_status( r ); 37 | *psize = r; 38 | } 39 | 40 | static int usb_control_out ( usb_dev_handle* dev, int requesttype, 41 | int request, int value, int index, 42 | char* outbuf, int bufsize, int timeout ) 43 | { 44 | int r; 45 | 46 | Py_BEGIN_ALLOW_THREADS 47 | r = usb_control_msg( dev, USB_ENDPOINT_OUT | requesttype, request, 48 | value, index, outbuf, bufsize, timeout ); 49 | Py_END_ALLOW_THREADS 50 | check_status( r ); 51 | return r; 52 | } 53 | 54 | static void usb_string ( usb_dev_handle* dev, int index, char* strbuf ) 55 | { 56 | int r; 57 | 58 | Py_BEGIN_ALLOW_THREADS 59 | r = usb_get_string_simple( dev, index, strbuf, 255 ); 60 | Py_END_ALLOW_THREADS 61 | if ( r < 0 ) 62 | { 63 | r = 0; 64 | } 65 | strbuf[r] = '\0'; 66 | } 67 | 68 | %} 69 | 70 | %include cstring.i 71 | 72 | %cstring_output_withsize( char* inbuf, int* psize ); 73 | static void usb_control_in ( usb_dev_handle *dev, int requesttype, 74 | int request, int value, int index, 75 | char* inbuf, int* psize, int timeout ); 76 | 77 | %cstring_input_binary( char* outbuf, int bufsize ) 78 | static int usb_control_out ( usb_dev_handle *dev, int requesttype, 79 | int request, int value, int index, 80 | char* outbuf, int bufsize, int timeout ); 81 | 82 | %cstring_bounded_output( char* strbuf, 255 ); 83 | static void usb_string ( usb_dev_handle* dev, int index, char* strbuf ); 84 | 85 | typedef unsigned short u_int16_t; 86 | typedef unsigned char u_int8_t; 87 | 88 | %include usb.h 89 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/util/lsusb.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # ====================================================================== 3 | # lsusb.py - Python version of the lsusb command 4 | # 5 | # Copyright (C) 2006 Dick Streefland 6 | # 7 | # This is free software, licensed under the terms of the GNU General 8 | # Public License as published by the Free Software Foundation. 9 | # ====================================================================== 10 | 11 | from libusb import * 12 | 13 | usb_init() 14 | usb_find_busses() 15 | usb_find_devices() 16 | bus = usb_get_busses() 17 | while bus: 18 | dev = bus.devices 19 | while dev: 20 | d = dev.descriptor 21 | print "Bus %s" % dev.bus.dirname, 22 | print "Device %s:" % dev.filename, 23 | print "ID %04x:%04x" % (d.idVendor, d.idProduct), 24 | h = usb_open(dev) 25 | str = [] 26 | for i in [d.iManufacturer, d.iProduct, d.iSerialNumber]: 27 | s = usb_string(h, i) 28 | if s: 29 | str.append(s) 30 | if str: 31 | print "[%s]" % ', '.join(str), 32 | usb_close(h) 33 | print 34 | dev = dev.next 35 | bus = bus.next 36 | -------------------------------------------------------------------------------- /Firmware/pocket-prog/util/sch2ps: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ====================================================================== 3 | # sch2ps - Convert gschem schematic to Postscript 4 | # 5 | # Copyright (C) 2006 Dick Streefland 6 | # 7 | # This is free software, licensed under the terms of the GNU General 8 | # Public License as published by the Free Software Foundation. 9 | # ====================================================================== 10 | 11 | tmp=/tmp/tmp$$.scm 12 | trap "rm -f $tmp gschem.log" 0 1 2 3 15 13 | 14 | cat < $tmp 15 | ; Script to generate a Postscript file. 16 | ; Usage: gschem -q -s