├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE ├── README.md ├── packs ├── LICENSE ├── README.md ├── atmega │ ├── AT90CAN128.atdf │ ├── AT90CAN32.atdf │ ├── AT90CAN64.atdf │ ├── AT90PWM1.atdf │ ├── AT90PWM161.atdf │ ├── AT90PWM216.atdf │ ├── AT90PWM2B.atdf │ ├── AT90PWM316.atdf │ ├── AT90PWM3B.atdf │ ├── AT90PWM81.atdf │ ├── AT90USB1286.atdf │ ├── AT90USB1287.atdf │ ├── AT90USB162.atdf │ ├── AT90USB646.atdf │ ├── AT90USB647.atdf │ ├── AT90USB82.atdf │ ├── ATmega128.atdf │ ├── ATmega1280.atdf │ ├── ATmega1281.atdf │ ├── ATmega1284.atdf │ ├── ATmega1284P.atdf │ ├── ATmega1284RFR2.atdf │ ├── ATmega128A.atdf │ ├── ATmega128RFA1.atdf │ ├── ATmega128RFR2.atdf │ ├── ATmega16.atdf │ ├── ATmega1608.atdf │ ├── ATmega1609.atdf │ ├── ATmega162.atdf │ ├── ATmega164A.atdf │ ├── ATmega164P.atdf │ ├── ATmega164PA.atdf │ ├── ATmega165A.atdf │ ├── ATmega165P.atdf │ ├── ATmega165PA.atdf │ ├── ATmega168.atdf │ ├── ATmega168A.atdf │ ├── ATmega168P.atdf │ ├── ATmega168PA.atdf │ ├── ATmega168PB.atdf │ ├── ATmega169A.atdf │ ├── ATmega169P.atdf │ ├── ATmega169PA.atdf │ ├── ATmega16A.atdf │ ├── ATmega16HVA.atdf │ ├── ATmega16HVB.atdf │ ├── ATmega16HVBrevB.atdf │ ├── ATmega16M1.atdf │ ├── ATmega16U2.atdf │ ├── ATmega16U4.atdf │ ├── ATmega2560.atdf │ ├── ATmega2561.atdf │ ├── ATmega2564RFR2.atdf │ ├── ATmega256RFR2.atdf │ ├── ATmega32.atdf │ ├── ATmega3208.atdf │ ├── ATmega3209.atdf │ ├── ATmega324A.atdf │ ├── ATmega324P.atdf │ ├── ATmega324PA.atdf │ ├── ATmega324PB.atdf │ ├── ATmega325.atdf │ ├── ATmega3250.atdf │ ├── ATmega3250A.atdf │ ├── ATmega3250P.atdf │ ├── ATmega3250PA.atdf │ ├── ATmega325A.atdf │ ├── ATmega325P.atdf │ ├── ATmega325PA.atdf │ ├── ATmega328.atdf │ ├── ATmega328P.atdf │ ├── ATmega328PB.atdf │ ├── ATmega329.atdf │ ├── ATmega3290.atdf │ ├── ATmega3290A.atdf │ ├── ATmega3290P.atdf │ ├── ATmega3290PA.atdf │ ├── ATmega329A.atdf │ ├── ATmega329P.atdf │ ├── ATmega329PA.atdf │ ├── ATmega32A.atdf │ ├── ATmega32C1.atdf │ ├── ATmega32HVB.atdf │ ├── ATmega32HVBrevB.atdf │ ├── ATmega32M1.atdf │ ├── ATmega32U2.atdf │ ├── ATmega32U4.atdf │ ├── ATmega406.atdf │ ├── ATmega48.atdf │ ├── ATmega4808.atdf │ ├── ATmega4809.atdf │ ├── ATmega48A.atdf │ ├── ATmega48P.atdf │ ├── ATmega48PA.atdf │ ├── ATmega48PB.atdf │ ├── ATmega64.atdf │ ├── ATmega640.atdf │ ├── ATmega644.atdf │ ├── ATmega644A.atdf │ ├── ATmega644P.atdf │ ├── ATmega644PA.atdf │ ├── ATmega644RFR2.atdf │ ├── ATmega645.atdf │ ├── ATmega6450.atdf │ ├── ATmega6450A.atdf │ ├── ATmega6450P.atdf │ ├── ATmega645A.atdf │ ├── ATmega645P.atdf │ ├── ATmega649.atdf │ ├── ATmega6490.atdf │ ├── ATmega6490A.atdf │ ├── ATmega6490P.atdf │ ├── ATmega649A.atdf │ ├── ATmega649P.atdf │ ├── ATmega64A.atdf │ ├── ATmega64C1.atdf │ ├── ATmega64HVE2.atdf │ ├── ATmega64M1.atdf │ ├── ATmega64RFR2.atdf │ ├── ATmega8.atdf │ ├── ATmega808.atdf │ ├── ATmega809.atdf │ ├── ATmega8515.atdf │ ├── ATmega8535.atdf │ ├── ATmega88.atdf │ ├── ATmega88A.atdf │ ├── ATmega88P.atdf │ ├── ATmega88PA.atdf │ ├── ATmega88PB.atdf │ ├── ATmega8A.atdf │ ├── ATmega8HVA.atdf │ ├── ATmega8U2.atdf │ ├── Atmel.ATmega_DFP.pdsc │ └── VERSION ├── automotive │ ├── ATA5272.atdf │ ├── ATA5505.atdf │ ├── ATA5700M322.atdf │ ├── ATA5702M322.atdf │ ├── ATA5781.atdf │ ├── ATA5782.atdf │ ├── ATA5783.atdf │ ├── ATA5787.atdf │ ├── ATA5790.atdf │ ├── ATA5790N.atdf │ ├── ATA5791.atdf │ ├── ATA5795.atdf │ ├── ATA5831.atdf │ ├── ATA5832.atdf │ ├── ATA5833.atdf │ ├── ATA5835.atdf │ ├── ATA6285.atdf │ ├── ATA6286.atdf │ ├── ATA6612C.atdf │ ├── ATA6613C.atdf │ ├── ATA6614Q.atdf │ ├── ATA6616C.atdf │ ├── ATA6617C.atdf │ ├── ATA664251.atdf │ ├── ATA8210.atdf │ ├── ATA8215.atdf │ ├── ATA8510.atdf │ ├── ATA8515.atdf │ └── VERSION ├── tiny │ ├── ATtiny10.atdf │ ├── ATtiny102.atdf │ ├── ATtiny104.atdf │ ├── ATtiny11.atdf │ ├── ATtiny12.atdf │ ├── ATtiny13.atdf │ ├── ATtiny13A.atdf │ ├── ATtiny15.atdf │ ├── ATtiny1614.atdf │ ├── ATtiny1616.atdf │ ├── ATtiny1617.atdf │ ├── ATtiny1634.atdf │ ├── ATtiny167.atdf │ ├── ATtiny20.atdf │ ├── ATtiny212.atdf │ ├── ATtiny214.atdf │ ├── ATtiny2313.atdf │ ├── ATtiny2313A.atdf │ ├── ATtiny24.atdf │ ├── ATtiny24A.atdf │ ├── ATtiny25.atdf │ ├── ATtiny26.atdf │ ├── ATtiny261.atdf │ ├── ATtiny261A.atdf │ ├── ATtiny3214.atdf │ ├── ATtiny3216.atdf │ ├── ATtiny3217.atdf │ ├── ATtiny4.atdf │ ├── ATtiny40.atdf │ ├── ATtiny412.atdf │ ├── ATtiny414.atdf │ ├── ATtiny416.atdf │ ├── ATtiny417.atdf │ ├── ATtiny4313.atdf │ ├── ATtiny43U.atdf │ ├── ATtiny44.atdf │ ├── ATtiny441.atdf │ ├── ATtiny44A.atdf │ ├── ATtiny45.atdf │ ├── ATtiny461.atdf │ ├── ATtiny461A.atdf │ ├── ATtiny48.atdf │ ├── ATtiny5.atdf │ ├── ATtiny80.atdf │ ├── ATtiny814.atdf │ ├── ATtiny816.atdf │ ├── ATtiny817.atdf │ ├── ATtiny828.atdf │ ├── ATtiny84.atdf │ ├── ATtiny840.atdf │ ├── ATtiny841.atdf │ ├── ATtiny84A.atdf │ ├── ATtiny85.atdf │ ├── ATtiny861.atdf │ ├── ATtiny861A.atdf │ ├── ATtiny87.atdf │ ├── ATtiny88.atdf │ ├── ATtiny9.atdf │ └── VERSION ├── xmegaa │ ├── ATxmega128A1.atdf │ ├── ATxmega128A1U.atdf │ ├── ATxmega128A3.atdf │ ├── ATxmega128A3U.atdf │ ├── ATxmega128A4U.atdf │ ├── ATxmega16A4.atdf │ ├── ATxmega16A4U.atdf │ ├── ATxmega192A3.atdf │ ├── ATxmega192A3U.atdf │ ├── ATxmega256A3.atdf │ ├── ATxmega256A3B.atdf │ ├── ATxmega256A3BU.atdf │ ├── ATxmega256A3U.atdf │ ├── ATxmega32A4.atdf │ ├── ATxmega32A4U.atdf │ ├── ATxmega64A1.atdf │ ├── ATxmega64A1U.atdf │ ├── ATxmega64A3.atdf │ ├── ATxmega64A3U.atdf │ ├── ATxmega64A4U.atdf │ └── VERSION ├── xmegab │ ├── ATxmega128B1.atdf │ ├── ATxmega128B3.atdf │ ├── ATxmega64B1.atdf │ ├── ATxmega64B3.atdf │ └── VERSION ├── xmegac │ ├── ATxmega128C3.atdf │ ├── ATxmega16C4.atdf │ ├── ATxmega192C3.atdf │ ├── ATxmega256C3.atdf │ ├── ATxmega32C3.atdf │ ├── ATxmega32C4.atdf │ ├── ATxmega384C3.atdf │ ├── ATxmega64C3.atdf │ └── VERSION ├── xmegad │ ├── ATxmega128D3.atdf │ ├── ATxmega128D4.atdf │ ├── ATxmega16D4.atdf │ ├── ATxmega192D3.atdf │ ├── ATxmega256D3.atdf │ ├── ATxmega32D3.atdf │ ├── ATxmega32D4.atdf │ ├── ATxmega384D3.atdf │ ├── ATxmega64D3.atdf │ ├── ATxmega64D4.atdf │ └── VERSION └── xmegae │ ├── ATxmega16E5.atdf │ ├── ATxmega32E5.atdf │ ├── ATxmega8E5.atdf │ └── VERSION ├── rustfmt.toml └── src ├── current.rs ├── extra_info.rs ├── lib.rs ├── load.rs ├── model.rs └── pack.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | **/*.rs.bk 3 | Cargo.lock 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | 3 | rust: 4 | - nightly 5 | 6 | script: 7 | - cargo test --verbose --release 8 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "avr-mcu" 3 | version = "0.3.5" 4 | authors = ["Dylan McKay "] 5 | 6 | description = """ 7 | Pragmatic structures for all AVR microcontrollers 8 | """ 9 | 10 | license = "MIT" 11 | repository = "https://github.com/avr-rust/avr-mcu" 12 | documentation = "https://docs.rs/avr-mcu" 13 | 14 | keywords = ["avr", "mcu", "io", "constants", "pins"] 15 | categories = ["embedded"] 16 | 17 | 18 | [dependencies] 19 | json = "0.12" 20 | lazy_static = "1.4" 21 | target-cpu-fetch = "0.1" 22 | xmltree = "0.10" 23 | 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2017 Dylan McKay 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # avr-mcu 2 | 3 | [![Crates.io](https://img.shields.io/crates/v/avr-mcu.svg)](https://crates.io/crates/avr-mcu) 4 | [![Build Status](https://travis-ci.org/avr-rust/avr-mcu.svg?branch=master)](https://travis-ci.org/avr-rust/avr-mcu) 5 | [![license](https://img.shields.io/github/license/avr-rust/avr-mcu.svg)]() 6 | 7 | Pragmatic access to AVR chip information. 8 | 9 | [Documentation](https://docs.rs/avr-mcu/) 10 | 11 | ## Purpose 12 | 13 | This library has been written to be used by other AVR libraries to 14 | generate code (such as IO-related compile time constants). 15 | 16 | This crate can be compiled an run on all architectures, including x86 and AVR. 17 | 18 | -------------------------------------------------------------------------------- /packs/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Atmel Corporation, 2 | a wholly owned subsidiary of Microchip Technology Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the Licence at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | -------------------------------------------------------------------------------- /packs/README.md: -------------------------------------------------------------------------------- 1 | These pack files are downloaded from Atmel's website 2 | 3 | http://packs.download.atmel.com/ 4 | 5 | -------------------------------------------------------------------------------- /packs/atmega/VERSION: -------------------------------------------------------------------------------- 1 | 1.2.132 2 | -------------------------------------------------------------------------------- /packs/automotive/VERSION: -------------------------------------------------------------------------------- 1 | 1.2.102 2 | -------------------------------------------------------------------------------- /packs/tiny/ATtiny10.atdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | -------------------------------------------------------------------------------- /packs/tiny/ATtiny11.atdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | -------------------------------------------------------------------------------- /packs/tiny/ATtiny12.atdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | -------------------------------------------------------------------------------- /packs/tiny/ATtiny15.atdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | -------------------------------------------------------------------------------- /packs/tiny/ATtiny4.atdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | -------------------------------------------------------------------------------- /packs/tiny/ATtiny5.atdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | -------------------------------------------------------------------------------- /packs/tiny/ATtiny9.atdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | -------------------------------------------------------------------------------- /packs/tiny/VERSION: -------------------------------------------------------------------------------- 1 | 1.3.132 2 | -------------------------------------------------------------------------------- /packs/xmegaa/VERSION: -------------------------------------------------------------------------------- 1 | 1.1.68 2 | -------------------------------------------------------------------------------- /packs/xmegab/VERSION: -------------------------------------------------------------------------------- 1 | 1.1.55 2 | -------------------------------------------------------------------------------- /packs/xmegac/VERSION: -------------------------------------------------------------------------------- 1 | 1.1.50 2 | -------------------------------------------------------------------------------- /packs/xmegad/VERSION: -------------------------------------------------------------------------------- 1 | 1.1.57 2 | -------------------------------------------------------------------------------- /packs/xmegae/VERSION: -------------------------------------------------------------------------------- 1 | 1.2.51 2 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | fn_args_layout = "Compressed" 2 | use_small_heuristics = "Max" 3 | -------------------------------------------------------------------------------- /src/current.rs: -------------------------------------------------------------------------------- 1 | //! Utilities for querying information about the microcontroller being targeted. 2 | 3 | use load; 4 | use std::env; 5 | use Mcu; 6 | 7 | /// Gets information about the current microcontroller. 8 | /// 9 | /// Returns `None` if the target architecture is not AVR. 10 | /// 11 | /// When targeting AVR, this function will always return `Some(mcu)`. 12 | pub fn mcu() -> Option { 13 | mcu_name().map(|mcu_name| load::microcontroller(&mcu_name)) 14 | } 15 | 16 | /// Gets the name of the microcontroller being targeted. 17 | /// 18 | /// Returns `None` if the target architecture is not AVR. 19 | /// 20 | /// When targeting AVR, this function will always return `Some(mcu_name)`. 21 | /// 22 | /// # Example results 23 | /// 24 | /// * `Some("atmega328")` 25 | /// * `Some("attiny85")` 26 | /// * `None` 27 | pub fn mcu_name() -> Option { 28 | target_cpu_fetch::target_cpu().ok().and_then(|o| o) 29 | } 30 | 31 | /// Checks if the current cargo target architecture is AVR. 32 | pub fn is_compiling_for_avr() -> bool { 33 | env::var("CARGO_CFG_TARGET_ARCH") == Ok("avr".to_string()) 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/extra_info.rs: -------------------------------------------------------------------------------- 1 | //! Extra MCU information that does not exist in packfiles. 2 | 3 | use Architecture; 4 | 5 | /// Information about a MCU. 6 | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 7 | pub struct Info { 8 | /// The architecture. 9 | pub arch: Architecture, 10 | pub c_preprocessor_name: String, 11 | } 12 | 13 | fn mmcu_from_mcu_name(mcu_name: &str) -> Architecture { 14 | use Architecture::*; 15 | 16 | match mcu_name.to_lowercase().as_ref() { 17 | "at90s1200" | "attiny11" | "attiny12" | "attiny15" | "attiny28" => Avr1, 18 | 19 | "at90s2313" | "at90s2323" | "at90s2333" | "at90s2343" | "attiny22" | "attiny26" 20 | | "at90s4414" | "at90s4433" | "at90s4434" | "at90s8515" | "at90s8534" | "at90s8535" => Avr2, 21 | 22 | "ata5272" | "ata6616c" | "attiny13" | "attiny13a" | "attiny2313" | "attiny2313a" 23 | | "attiny24" | "attiny24a" | "attiny4313" | "attiny44" | "attiny44a" | "attiny441" 24 | | "attiny84" | "attiny84a" | "attiny25" | "attiny45" | "attiny85" | "attiny261" 25 | | "attiny261a" | "attiny461" | "attiny461a" | "attiny861" | "attiny861a" | "attiny43u" 26 | | "attiny87" | "attiny48" | "attiny88" | "attiny828" | "attiny841" | "at86rf401" => Avr25, 27 | 28 | "at43usb355" | "at76c711" => Avr3, 29 | 30 | "atmega103" | "at43usb320" => Avr31, 31 | 32 | "ata5505" | "ata6617c" | "ata664251" | "at90usb82" | "at90usb162" | "atmega8u2" 33 | | "atmega16u2" | "atmega32u2" | "attiny167" | "attiny1634" => Avr35, 34 | 35 | "ata6285" | "ata6286" | "ata6289" | "ata6612c" | "atmega8" | "atmega8a" | "atmega48" 36 | | "atmega48a" | "atmega48p" | "atmega48pa" | "atmega48pb" | "atmega88" | "atmega88a" 37 | | "atmega88p" | "atmega88pa" | "atmega88pb" | "atmega8515" | "atmega8535" 38 | | "atmega8hva" | "at90pwm1" | "at90pwm2" | "at90pwm2b" | "at90pwm3" | "at90pwm3b" 39 | | "at90pwm81" => Avr4, 40 | 41 | "ata5700m322" | "ata5702m322" | "ata5782" | "ata5790" | "ata5790n" | "ata5791" 42 | | "ata5795" | "ata5831" | "ata6613c" | "ata6614q" | "ata8210" | "ata8215" | "ata8510" 43 | | "atmega16" | "atmega16a" | "atmega161" | "atmega162" | "atmega163" | "atmega164a" 44 | | "atmega164p" | "atmega164pa" | "atmega165" | "atmega165a" | "atmega165p" 45 | | "atmega165pa" | "atmega168" | "atmega168a" | "atmega168p" | "atmega168pa" 46 | | "atmega168pb" | "atmega169" | "atmega169a" | "atmega169p" | "atmega169pa" 47 | | "atmega16hvb" | "atmega16hvbrevb" | "atmega16m1" | "atmega16u4" | "atmega32a" 48 | | "atmega32" | "atmega323" | "atmega324a" | "atmega324p" | "atmega324pa" | "atmega325" 49 | | "atmega325a" | "atmega325p" | "atmega325pa" | "atmega3250" | "atmega3250a" 50 | | "atmega3250p" | "atmega3250pa" | "atmega328" | "atmega328p" | "atmega328pb" 51 | | "atmega329" | "atmega329a" | "atmega329p" | "atmega329pa" | "atmega3290" 52 | | "atmega3290a" | "atmega3290p" | "atmega3290pa" | "atmega32c1" | "atmega32m1" 53 | | "atmega32u4" | "atmega32u6" | "atmega406" | "atmega64" | "atmega64a" | "atmega640" 54 | | "atmega644" | "atmega644a" | "atmega644p" | "atmega644pa" | "atmega645" 55 | | "atmega645a" | "atmega645p" | "atmega6450" | "atmega6450a" | "atmega6450p" 56 | | "atmega649" | "atmega649a" | "atmega649p" | "atmega6490" | "atmega16hva" 57 | | "atmega16hva2" | "atmega32hvb" | "atmega6490a" | "atmega6490p" | "atmega64c1" 58 | | "atmega64m1" | "atmega64hve" | "atmega64hve2" | "atmega64rfr2" | "atmega644rfr2" 59 | | "atmega32hvbrevb" | "at90can32" | "at90can64" | "at90pwm161" | "at90pwm216" 60 | | "at90pwm316" | "at90scr100" | "at90usb646" | "at90usb647" | "at94k" | "m3000" => Avr5, 61 | 62 | "atmega128" | "atmega128a" | "atmega1280" | "atmega1281" | "atmega1284" | "atmega1284p" 63 | | "atmega128rfa1" | "atmega128rfr2" | "atmega1284rfr2" | "at90can128" | "at90usb1286" 64 | | "at90usb1287" => Avr51, 65 | 66 | "atmega2560" | "atmega2561" | "atmega256rfr2" | "atmega2564rfr2" => Avr6, 67 | 68 | "atxmega8e5" | "atxmega16a4" | "atxmega16d4" | "atxmega16e5" | "atxmega32a4" 69 | | "atxmega32c3" | "atxmega32d3" | "atxmega32d4" | "atxmega16a4u" | "atxmega16c4" 70 | | "atxmega32a4u" | "atxmega32c4" | "atxmega32e5" => Xmega2, 71 | 72 | "attiny202" | "attiny204" | "attiny212" | "attiny214" | "attiny402" | "attiny404" 73 | | "attiny406" | "attiny412" | "attiny414" | "attiny416" | "attiny417" | "attiny804" 74 | | "attiny806" | "attiny807" | "attiny814" | "attiny816" | "attiny817" | "attiny1604" 75 | | "attiny1606" | "attiny1607" | "attiny1614" | "attiny1616" | "attiny1617" | "attiny3214" 76 | | "attiny3216" | "attiny3217" | "atmega808" | "atmega809" | "atmega1608" | "atmega1609" 77 | | "atmega3208" | "atmega3209" | "atmega4808" | "atmega4809" => Xmega3, 78 | 79 | "atxmega64a3" | "atxmega64d3" | "atxmega64a3u" | "atxmega64a4u" | "atxmega64b1" 80 | | "atxmega64b3" | "atxmega64c3" | "atxmega64d4" => Xmega4, 81 | 82 | "atxmega64a1" | "atxmega64a1u" => Xmega5, 83 | 84 | "atxmega128a3" | "atxmega128d3" | "atxmega192a3" | "atxmega192d3" | "atxmega256a3" 85 | | "atxmega256a3b" | "atxmega256a3bu" | "atxmega256d3" | "atxmega128a3u" 86 | | "atxmega128b1" | "atxmega128b3" | "atxmega128c3" | "atxmega128d4" | "atxmega192a3u" 87 | | "atxmega192c3" | "atxmega256a3u" | "atxmega256c3" | "atxmega384c3" | "atxmega384d3" => { 88 | Xmega6 89 | } 90 | 91 | "atxmega128a1" | "atxmega128a1u" | "atxmega128a4u" => Xmega7, 92 | 93 | "attiny4" | "attiny5" | "attiny9" | "attiny10" | "attiny102" | "attiny20" | "attiny40" => { 94 | Tiny 95 | } 96 | 97 | "ata8515" | "ata5781" | "ata5783" | "ata5787" | "ata5832" | "ata5833" | "ata5835" 98 | | "atmega324pb" | "attiny104" | "attiny80" | "attiny840" => Unknown, 99 | 100 | mcu_name => panic!("the AVR architecture name for MCU '{}' is unknown", mcu_name), 101 | } 102 | } 103 | 104 | fn c_preprocessor_name_from_mcu_name(mcu_name: &str) -> String { 105 | let proper_mcu_name = mcu_name 106 | .to_uppercase() 107 | .replace("XMEGA", "xmega") 108 | .replace("MEGA", "mega") 109 | .replace("TINY", "tiny"); 110 | format!("__AVR_{}__", proper_mcu_name) 111 | } 112 | 113 | /// Looks up extra information about a microcontroller. 114 | pub fn lookup>(mcu_name: T) -> Info { 115 | Info { 116 | arch: mmcu_from_mcu_name(mcu_name.as_ref()), 117 | c_preprocessor_name: c_preprocessor_name_from_mcu_name(mcu_name.as_ref()), 118 | } 119 | } 120 | 121 | #[cfg(test)] 122 | mod test { 123 | use super::*; 124 | 125 | use microcontroller_names; 126 | 127 | #[test] 128 | fn atmega328_makes_sense() { 129 | assert_eq!( 130 | Info { arch: Architecture::Avr5, c_preprocessor_name: "__AVR_ATmega328__".to_string() }, 131 | lookup("ATmega328") 132 | ); 133 | } 134 | 135 | #[test] 136 | fn matches_upper_and_lowercase() { 137 | assert_eq!(lookup("ATtiny85"), lookup("ATtiny85")); 138 | } 139 | 140 | #[test] 141 | fn there_is_a_mapping_for_every_packfile() { 142 | for mcu_name in microcontroller_names() { 143 | let info = lookup(mcu_name); 144 | assert!(info.c_preprocessor_name.len() > 0); 145 | } 146 | } 147 | 148 | // This test exists so that we can always see when 149 | // new unknown architectures are added. 150 | #[test] 151 | fn there_is_a_constant_number_of_unknown_architectures() { 152 | const EXPECTED_UNKOWNS: usize = 11; 153 | 154 | let unknown_count = microcontroller_names() 155 | .iter() 156 | .map(self::lookup) 157 | .filter(|info| info.arch == Architecture::Unknown) 158 | .count(); 159 | assert_eq!(EXPECTED_UNKOWNS, unknown_count); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Information about every AVR microcontroller. 2 | //! 3 | //! # Device representation 4 | //! 5 | //! The API consists of a set of types that represent information about each 6 | //! microcontroller. The top-level type is [`Mcu`](struct.Mcu.html), modelling 7 | //! a single microcontroller. 8 | //! 9 | //! # Retrieving microcontroller information 10 | //! 11 | //! It is possible to look up information for a specific MCU, or all of them at once. 12 | //! 13 | //! ## Getting information for the current target 14 | //! 15 | //! In a lot of cases, we only care about the target microcontroller. 16 | //! 17 | //! ```nodoc 18 | //! let mcu = avr_mcu::current::mcu().unwrap(); 19 | //! println!("Device: {}", mcu.device.name); 20 | //! ``` 21 | //! 22 | //! # Behind-the-hood 23 | //! 24 | //! This crate embeds a set of "packfiles" released by Atmel. These are XML 25 | //! specifications containing all of the information exposed by this crate. 26 | //! 27 | //! You can see a list of all packfiles [here](https://github.com/avr-rust/avr-mcu/tree/master/packs). 28 | //! 29 | //! A build script takes these packfiles and persists them as data structures in Rust. 30 | //! 31 | //! # Examples 32 | //! 33 | //! ```nodoc 34 | //! for mcu in avr_mcu::microcontrollers() { 35 | //! println!("Device: {}", mcu.device.name); 36 | //! } 37 | //! ``` 38 | 39 | extern crate xmltree; 40 | #[macro_use] 41 | extern crate lazy_static; 42 | 43 | pub use self::load::{microcontroller, microcontroller_names, microcontrollers}; 44 | pub use self::model::*; 45 | 46 | mod extra_info; 47 | mod load; 48 | mod model; 49 | mod pack; 50 | 51 | pub mod current; 52 | -------------------------------------------------------------------------------- /src/load.rs: -------------------------------------------------------------------------------- 1 | use model::Mcu; 2 | use pack; 3 | 4 | use std::path::{Path, PathBuf}; 5 | use std::{fs, io}; 6 | 7 | /// The extension on the pack files. 8 | const PACK_FILE_EXT: &str = "atdf"; 9 | 10 | /// All pack collections inside the 'packs' folder 11 | /// of this repository. 12 | const PACK_COLLECTIONS: &[&str] = 13 | &["atmega", "tiny", "xmegaa", "xmegab", "xmegac", "xmegad", "xmegae", "automotive"]; 14 | 15 | /// The on-disk path of the crate root. 16 | const CRATE_ROOT: &str = env!("CARGO_MANIFEST_DIR"); 17 | 18 | lazy_static! { 19 | static ref MCUS: Vec = 20 | self::load_microcontrollers().expect("failed to load microcontrollers"); 21 | static ref MCU_NAMES: Vec = pack_informations() 22 | .expect("could not find packfiles") 23 | .into_iter() 24 | .map(|pack| pack.mcu_name) 25 | .collect(); 26 | } 27 | 28 | struct PackInfo { 29 | pub mcu_name: String, 30 | pub path: PathBuf, 31 | } 32 | 33 | /// Retrieves a list of `Mcu` objects for all microcontrollers. 34 | pub fn microcontrollers() -> &'static [Mcu] { 35 | &MCUS[..] 36 | } 37 | 38 | /// Retrieves a list of all microcontroller names. 39 | /// 40 | /// # Examples 41 | /// 42 | /// * `atmega328p` 43 | /// * `attiny85` 44 | pub fn microcontroller_names() -> &'static [String] { 45 | &MCU_NAMES[..] 46 | } 47 | 48 | /// Retrieves information for a specific microcontroller. 49 | pub fn microcontroller(name: &str) -> Mcu { 50 | let pack_info = pack_informations() 51 | .unwrap() 52 | .into_iter() 53 | .find(|pack_info| pack_info.mcu_name == name) 54 | .expect(&format!("no microcontroller with the name '{}' found", name)); 55 | pack::load(&pack_info.path).expect("could not parse microcontroller pack") 56 | } 57 | 58 | /// Retrieves a list of `Mcu` objects in a directory containg `PACK_COLLECTIONS`. 59 | fn load_microcontrollers() -> Result, io::Error> { 60 | let microcontrollers = pack_informations()? 61 | .into_iter() 62 | .map(|pack_info| pack::load(&pack_info.path).unwrap()) 63 | .collect(); 64 | 65 | Ok(microcontrollers) 66 | } 67 | 68 | fn pack_informations() -> Result, io::Error> { 69 | let path = Path::new(CRATE_ROOT).join("packs"); 70 | pack_informations_from(&path) 71 | } 72 | 73 | fn pack_informations_from(path: &Path) -> Result, io::Error> { 74 | let mut pack_paths = Vec::new(); 75 | 76 | for pack_name in PACK_COLLECTIONS { 77 | pack_paths.extend(find_packs(&path.join(pack_name)).unwrap()); 78 | } 79 | 80 | Ok(pack_paths 81 | .into_iter() 82 | .map(|path| PackInfo { 83 | mcu_name: path.file_stem().unwrap().to_str().unwrap().to_lowercase().to_owned(), 84 | path: path.to_owned(), 85 | }) 86 | .collect()) 87 | } 88 | 89 | /// Finds all pack files in a directory. 90 | fn find_packs(in_dir: &Path) -> Result, io::Error> { 91 | let mut paths = Vec::new(); 92 | 93 | for entry in fs::read_dir(in_dir)? { 94 | let entry = entry?; 95 | if let Some(PACK_FILE_EXT) = entry.path().extension().map(|s| s.to_str().unwrap()) { 96 | paths.push(entry.path()); 97 | } 98 | } 99 | Ok(paths) 100 | } 101 | 102 | #[cfg(test)] 103 | mod test { 104 | #[test] 105 | fn there_are_at_least_100_microcontrollers() { 106 | let mcus = super::microcontrollers(); 107 | assert!(mcus.len() > 100, "there should be at least 100 microcontrollers"); 108 | } 109 | 110 | #[test] 111 | fn can_get_atmega328p_by_name() { 112 | let mcu = super::microcontroller("atmega328p"); 113 | assert_eq!("ATmega328P", mcu.device.name); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/model.rs: -------------------------------------------------------------------------------- 1 | /// A microcontroller with one or more variants. 2 | #[derive(Clone, Debug, PartialOrd, PartialEq)] 3 | pub struct Mcu { 4 | /// Information about the microcontroller itself. 5 | pub device: Device, 6 | /// The different variants the mcu can come in. 7 | pub variants: Vec, 8 | /// The modules built into the mcu package. 9 | pub modules: Vec, 10 | /// The family that the mcu belongs to. 11 | pub architecture: Architecture, 12 | /// The C preprocessor name. 13 | pub c_preprocessor_name: String, 14 | } 15 | 16 | /// Information fore a specific device. 17 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 18 | pub struct Device { 19 | /// The name of the device. 20 | pub name: String, 21 | /// A list of all address spaces the device has. 22 | pub address_spaces: Vec, 23 | /// A list of supported peripherals. 24 | pub peripherals: Vec, 25 | /// A list of supported interrupts 26 | pub interrupts: Vec, 27 | } 28 | 29 | /// A variation of a specific microcontroller. 30 | #[derive(Clone, Debug, PartialOrd, PartialEq)] 31 | pub struct Variant { 32 | /// The name of the variant. 33 | pub name: String, 34 | /// What pinout is used. 35 | pub pinout: Option, 36 | /// The package format. 37 | pub package: String, 38 | /// The minimum temperate in celsius. 39 | pub temperature_min: i32, 40 | /// The maximum temperature in celsius. 41 | pub temperature_max: i32, 42 | /// The minimum voltage. 43 | pub voltage_min: f32, 44 | /// The maximum voltate. 45 | pub voltage_max: f32, 46 | /// The max clock speed in Hz. 47 | pub speed_max_hz: u64, 48 | } 49 | 50 | /// An address space. 51 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 52 | pub struct AddressSpace { 53 | /// The identifier. 54 | pub id: String, 55 | /// The name. 56 | pub name: String, 57 | /// The starting memory address of the address space. 58 | pub start_address: u32, 59 | /// The number of bytes in the address space. 60 | pub size: u32, 61 | /// What segments are in the address space. 62 | pub segments: Vec, 63 | } 64 | 65 | /// A segment of memory in a particular address space. 66 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 67 | pub struct MemorySegment { 68 | /// The name of the segment. 69 | pub name: String, 70 | /// A pointer to the first byte in the segment. 71 | pub start_address: u32, 72 | /// The number of bytes in the segment. 73 | pub size: u32, 74 | /// The segment type. 75 | pub ty: String, 76 | /// Whether the segment can be read from. 77 | pub readable: bool, 78 | /// Whether the segment can be written to. 79 | pub writable: bool, 80 | /// Whether the segment can be executed. 81 | pub executable: bool, 82 | /// How large pages are in this segment. 83 | pub page_size: Option, 84 | } 85 | 86 | /// An on-board peripheral, such as an IO port. 87 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 88 | pub struct Peripheral { 89 | /// The name of the peripheral, for example, `PORT`. 90 | pub name: String, 91 | /// A list of instances where the peripheral is used. 92 | /// 93 | /// As an example, if the peripheral is an IO port, then the 94 | /// instance list would list all PORT instances, such as `PORTA` 95 | /// and `PORTB`. 96 | pub instances: Vec, 97 | } 98 | 99 | /// An interrupt supported by a device. 100 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 101 | pub struct Interrupt { 102 | /// The name of the interrupt, for example `TIMER1_COMPA`. 103 | pub name: String, 104 | /// A brief description of the interrupt 105 | pub caption: String, 106 | /// The interrupt vector table index 107 | pub index: u32, 108 | } 109 | 110 | /// A module built into the silicon. 111 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 112 | pub struct Module { 113 | /// The name of the module, for example, `PORT`. 114 | pub name: String, 115 | /// Registers associated with the module. 116 | pub register_groups: Vec, 117 | /// Value groups associated with the module. 118 | pub value_groups: Vec, 119 | } 120 | 121 | /// An instance of a peripheral. 122 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 123 | pub struct Instance { 124 | /// The name of the peripheral instance, for example, `PORTB`. 125 | pub name: String, 126 | /// What signals are used in the peripheral. 127 | pub signals: Vec, 128 | } 129 | 130 | /// A group of registers. 131 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 132 | pub struct RegisterGroup { 133 | /// The name of the group. 134 | pub name: String, 135 | pub caption: String, 136 | /// The registers that make up the group. 137 | pub registers: Vec, 138 | } 139 | 140 | /// A group of values. 141 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 142 | pub struct ValueGroup { 143 | pub name: String, 144 | pub caption: String, 145 | pub values: Vec, 146 | } 147 | 148 | /// A values for a register/mask. 149 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 150 | pub struct Value { 151 | pub name: String, 152 | pub caption: String, 153 | pub value: u32, 154 | } 155 | 156 | /// Specifies the mutability of a register. 157 | #[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 158 | pub enum ReadWrite { 159 | /// The register is readable and writable. 160 | ReadAndWrite, 161 | /// The register is read-only. 162 | ReadOnly, 163 | /// The register is write-only. 164 | WriteOnly, 165 | } 166 | 167 | /// An CPU or IO register. 168 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 169 | pub struct Register { 170 | /// The name of the register, such as `TCCR0A`. 171 | pub name: String, 172 | /// The register description. 173 | pub caption: String, 174 | /// The offset of the register in IO space. 175 | pub offset: u32, 176 | /// The number of bytes that make up the bitfield. 177 | pub size: u32, 178 | pub mask: Option, 179 | /// The mutability of the register. 180 | pub rw: ReadWrite, 181 | /// The bitfields supported by the register. 182 | pub bitfields: Vec, 183 | } 184 | 185 | /// A bitfield within a register. 186 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 187 | pub struct Bitfield { 188 | /// The name of the bitfield, such as `U2X0` for the USART register `UCSR0A`. 189 | pub name: String, 190 | /// A description of the bitfield. 191 | pub caption: String, 192 | /// The mask that makes up the bitfield. 193 | /// 194 | /// This will always match up to the parent register. A 16-bit register has 195 | /// 16-but masks. 196 | pub mask: u32, 197 | /// The number of bytes that make up the bitfield. 198 | pub size: u32, 199 | /// reference into value_groups on the container 200 | pub values: Option, 201 | } 202 | 203 | /// A signal that is exposed on the outside of the package. 204 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 205 | pub struct Signal { 206 | /// The external pin name that exposes the signal. 207 | pub pad: String, 208 | pub group: Option, 209 | pub index: Option, 210 | } 211 | 212 | /// An AVR architecture (mcu family) name. 213 | /// 214 | /// Architecture is a misnomer - 'mcu family' would make sense. 215 | /// Cores with the same instruction sets share an architecture name. 216 | #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 217 | pub enum Architecture { 218 | Unknown, 219 | 220 | Avr0, 221 | Avr1, 222 | Avr2, 223 | Avr25, 224 | Avr3, 225 | Avr31, 226 | Avr35, 227 | Avr4, 228 | Avr5, 229 | Avr51, 230 | Avr6, 231 | Xmega2, 232 | Xmega3, 233 | Xmega4, 234 | Xmega5, 235 | Xmega6, 236 | Xmega7, 237 | Tiny, 238 | } 239 | 240 | /// A port, such as `PORTB`. 241 | #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] 242 | pub struct Port<'a> { 243 | /// The port peripheral instance. 244 | instance: &'a Instance, 245 | /// The register group associated with the port. 246 | register_group: &'a RegisterGroup, 247 | } 248 | 249 | impl Mcu { 250 | /// Gets a peripheral module by name. 251 | pub fn peripheral(&self, name: &str) -> Option<&Peripheral> { 252 | self.device.peripherals.iter().find(|p| p.name == name) 253 | } 254 | 255 | /// Gets a module by name. 256 | pub fn module(&self, name: &str) -> Option<&Module> { 257 | self.modules.iter().find(|p| p.name == name) 258 | } 259 | 260 | /// Gets an iterator over all register groups. 261 | pub fn register_groups<'a>(&'a self) -> impl Iterator { 262 | self.modules.iter().flat_map(|m| m.register_groups.iter()) 263 | } 264 | 265 | /// Gets an iterator over all registers. 266 | pub fn registers<'a>(&'a self) -> impl Iterator { 267 | self.register_groups().flat_map(|rg| rg.registers.iter()) 268 | } 269 | 270 | /// Gets a port by letter. 271 | pub fn port(&self, letter: char) -> Port { 272 | let port_name = format!("PORT{}", letter); 273 | let instance = self 274 | .port_peripheral() 275 | .instance(&port_name) 276 | .expect("no port instance with that letter found"); 277 | let register_group = self 278 | .port_module() 279 | .register_group(&port_name) 280 | .expect("no port register group with that letter found"); 281 | Port { instance, register_group } 282 | } 283 | 284 | /// Gets the port peripheral. 285 | pub fn port_peripheral(&self) -> &Peripheral { 286 | self.peripheral("PORT").expect("mcu does not have a port peripheral") 287 | } 288 | 289 | /// Gets the port module. 290 | pub fn port_module(&self) -> &Module { 291 | self.module("PORT").expect("mcu does not have a port module") 292 | } 293 | } 294 | 295 | impl Peripheral { 296 | /// Gets an instance by name. 297 | pub fn instance(&self, name: &str) -> Option<&Instance> { 298 | self.instances.iter().find(|i| i.name == name) 299 | } 300 | 301 | /// Gets an iterator over all signals that the peripheral uses. 302 | pub fn signals<'a>(&'a self) -> impl Iterator { 303 | self.instances.iter().flat_map(|i| i.signals.iter()) 304 | } 305 | 306 | pub fn instance_signal_with_pad(&self, pad: &str) -> Option<(&Instance, &Signal)> { 307 | self.instance_signals_on_pad(pad).next() 308 | } 309 | 310 | /// Gets a tuple of `(instance, signal)` pairs that use a pad by its name. 311 | fn instance_signals_on_pad<'a>( 312 | &'a self, 313 | pad: &str, 314 | ) -> impl Iterator { 315 | let mut instance_signals = Vec::new(); 316 | 317 | for instance in self.instances.iter() { 318 | for signal in instance.signals.iter() { 319 | if signal.pad == pad { 320 | instance_signals.push((instance, signal)); 321 | } 322 | } 323 | } 324 | instance_signals.into_iter() 325 | } 326 | } 327 | 328 | impl Module { 329 | /// Gets a register group by name. 330 | pub fn register_group(&self, name: &str) -> Option<&RegisterGroup> { 331 | self.register_groups.iter().find(|rg| rg.name == name) 332 | } 333 | 334 | /// Gets an iterator over all registers in the module. 335 | pub fn registers<'a>(&'a self) -> impl Iterator { 336 | self.register_groups.iter().flat_map(|rg| rg.registers.iter()) 337 | } 338 | } 339 | 340 | impl Register { 341 | /// Get the union between two descriptions of the same register. 342 | pub fn union(&self, with: &Self) -> Self { 343 | assert_eq!( 344 | self.name, with.name, 345 | "can only take the union between different descriptions of the same register" 346 | ); 347 | 348 | let mut result = self.clone(); 349 | 350 | match (result.mask, with.mask) { 351 | (None, Some(v)) => result.mask = Some(v), // rhs is more specific 352 | _ => (), 353 | } 354 | 355 | result 356 | } 357 | } 358 | 359 | impl<'a> Port<'a> { 360 | /// Gets all associated registers. 361 | pub fn registers(&'a self) -> impl Iterator { 362 | self.register_group.registers.iter() 363 | } 364 | 365 | /// Gets all associated signals. 366 | pub fn signals(&'a self) -> impl Iterator { 367 | self.instance.signals.iter() 368 | } 369 | 370 | /// Gets the signal associated with a pad. 371 | pub fn signal_with_pad(&'a self, pad: &str) -> Option<&'a Signal> { 372 | self.signals().find(|s| s.pad == pad) 373 | } 374 | 375 | /// Gets the data direction register. 376 | pub fn ddr_register(&self) -> &Register { 377 | self.registers() 378 | .find(|r| r.name.starts_with("DDR")) 379 | .expect("port does not have ddr register") 380 | } 381 | 382 | /// Gets the port register. 383 | pub fn port_register(&self) -> &Register { 384 | self.registers() 385 | .find(|r| r.name.starts_with("PORT")) 386 | .expect("port does not have port register") 387 | } 388 | 389 | /// Gets the pin register. 390 | pub fn pin_register(&self) -> &Register { 391 | self.registers() 392 | .find(|r| r.name.starts_with("PIN")) 393 | .expect("port does not have pin register") 394 | } 395 | } 396 | 397 | impl Architecture { 398 | pub fn name(&self) -> &'static str { 399 | use Architecture::*; 400 | 401 | match self { 402 | Unknown => "", 403 | Avr0 => "avr0", 404 | Avr1 => "avr1", 405 | Avr2 => "avr2", 406 | Avr25 => "avr25", 407 | Avr3 => "avr3", 408 | Avr31 => "avr31", 409 | Avr35 => "avr35", 410 | Avr4 => "avr4", 411 | Avr5 => "avr5", 412 | Avr51 => "avr51", 413 | Avr6 => "avr6", 414 | Xmega2 => "xmega2", 415 | Xmega3 => "xmega3", 416 | Xmega4 => "xmega4", 417 | Xmega5 => "xmega5", 418 | Xmega6 => "xmega6", 419 | Xmega7 => "xmega7", 420 | Tiny => "tiny", 421 | } 422 | } 423 | } 424 | -------------------------------------------------------------------------------- /src/pack.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | use std::fs::File; 4 | use std::io; 5 | use std::io::prelude::*; 6 | use std::path::Path; 7 | 8 | use xmltree::{Element, XMLNode}; 9 | 10 | pub fn load(path: &Path) -> Result { 11 | let mut file = File::open(path)?; 12 | let mut body = String::new(); 13 | file.read_to_string(&mut body)?; 14 | 15 | println!("loading pack '{}'", path.display()); 16 | let root = Element::parse(body.as_bytes()).unwrap(); 17 | 18 | Ok(self::read_pack(&root)) 19 | } 20 | 21 | fn read_pack(root: &Element) -> Mcu { 22 | let device_element = root.get_child("devices").unwrap().get_child("device").unwrap(); 23 | 24 | let device = self::read_device(&device_element); 25 | let variants = root 26 | .get_child("variants") 27 | .unwrap() 28 | .children 29 | .iter() 30 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 31 | .map(self::read_variant) 32 | .collect(); 33 | let modules = root 34 | .get_child("modules") 35 | .unwrap() 36 | .children 37 | .iter() 38 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 39 | .map(self::read_module); 40 | 41 | // Not all desired information is available in pack files. 42 | // Grab the remaining bits from a lookup table. 43 | let extra_info = super::extra_info::lookup(&device.name); 44 | 45 | Mcu { 46 | device: device, 47 | variants: variants, 48 | modules: modules.collect(), 49 | architecture: extra_info.arch, 50 | c_preprocessor_name: extra_info.c_preprocessor_name, 51 | } 52 | } 53 | 54 | fn read_device(device: &Element) -> Device { 55 | let device_name = device.attributes.get("name").unwrap().clone(); 56 | 57 | let peripherals = device 58 | .get_child("peripherals") 59 | .unwrap() 60 | .children 61 | .iter() 62 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 63 | .map(self::read_peripheral) 64 | .collect(); 65 | 66 | let address_spaces = device 67 | .get_child("address-spaces") 68 | .unwrap() 69 | .children 70 | .iter() 71 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 72 | .map(self::read_address_space) 73 | .collect(); 74 | 75 | let interrupts = device 76 | .get_child("interrupts") 77 | .unwrap() 78 | .children 79 | .iter() 80 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 81 | .map(self::read_interrupt) 82 | .collect(); 83 | 84 | Device { name: device_name, address_spaces: address_spaces, peripherals, interrupts } 85 | } 86 | 87 | fn read_interrupt(interrupt: &Element) -> Interrupt { 88 | let index: u32 = read_int(interrupt.attributes.get("index")).clone(); 89 | Interrupt { 90 | name: interrupt.attributes.get("name").unwrap_or(&format!("INT{}", index)).clone(), 91 | caption: interrupt.attributes.get("caption").unwrap_or(&format!("INT{}", index)).clone(), 92 | index, 93 | } 94 | } 95 | 96 | fn read_peripheral(module: &Element) -> Peripheral { 97 | let name = module.attributes.get("name").unwrap().clone(); 98 | let mut instances = Vec::new(); 99 | 100 | for child in module.children.iter().filter_map(|node| { 101 | if let XMLNode::Element(el) = node { 102 | Some(el) 103 | } else { 104 | None 105 | } 106 | }) { 107 | match &child.name[..] { 108 | "instance" => instances.push(read_instance(child)), 109 | // Unimplemented tags. 110 | _ => (), 111 | } 112 | } 113 | 114 | Peripheral { name, instances } 115 | } 116 | 117 | fn read_module(module: &Element) -> Module { 118 | let module_name = module.attributes.get("name").unwrap().clone(); 119 | let mut register_groups = Vec::new(); 120 | let mut value_groups = Vec::new(); 121 | 122 | for child in module.children.iter().filter_map(|node| { 123 | if let XMLNode::Element(el) = node { 124 | Some(el) 125 | } else { 126 | None 127 | } 128 | }) { 129 | match &child.name[..] { 130 | "register-group" => register_groups.push(read_register_group(child)), 131 | "value-group" => value_groups.push(read_value_group(child)), 132 | // Unimplemented tags. 133 | _ => (), 134 | } 135 | } 136 | 137 | Module { name: module_name, register_groups: register_groups, value_groups } 138 | } 139 | 140 | fn read_variant(variant: &Element) -> Variant { 141 | Variant { 142 | name: variant.attributes.get("ordercode").unwrap().clone(), 143 | temperature_min: variant.attributes.get("tempmin").unwrap().parse().unwrap(), 144 | temperature_max: variant.attributes.get("tempmax").unwrap().parse().unwrap(), 145 | voltage_min: variant.attributes.get("vccmin").unwrap().parse().unwrap(), 146 | voltage_max: variant.attributes.get("vccmax").unwrap().parse().unwrap(), 147 | package: variant.attributes.get("package").unwrap().clone(), 148 | pinout: variant.attributes.get("pinout").map(|p| p.clone()), 149 | speed_max_hz: variant.attributes.get("speedmax").unwrap().parse().unwrap(), 150 | } 151 | } 152 | 153 | fn read_instance(instance: &Element) -> Instance { 154 | let instance_name = instance.attributes.get("name").unwrap().clone(); 155 | 156 | let signals = match instance.get_child("signals") { 157 | Some(signals) => signals 158 | .children 159 | .iter() 160 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 161 | .map(read_signal) 162 | .collect(), 163 | None => Vec::new(), 164 | }; 165 | 166 | Instance { name: instance_name, signals: signals } 167 | } 168 | 169 | fn read_signal(signal: &Element) -> Signal { 170 | Signal { 171 | pad: signal.attributes.get("pad").unwrap().clone(), 172 | group: signal.attributes.get("group").map(|p| p.clone()), 173 | index: signal.attributes.get("index").map(|i| i.parse().unwrap()), 174 | } 175 | } 176 | 177 | /// Reads a register group. 178 | /// 179 | /// This looks like so 180 | /// 181 | /// ```xml 182 | /// 183 | /// 184 | /// 185 | /// 186 | fn read_register_group(register_group: &Element) -> RegisterGroup { 187 | let (name, caption) = ( 188 | register_group.attributes.get("name").unwrap(), 189 | register_group.attributes.get("caption").unwrap(), 190 | ); 191 | let registers = register_group 192 | .children 193 | .iter() 194 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 195 | .filter_map(|child| match &child.name[..] { 196 | "register" => Some(self::read_register(child)), 197 | // FIXME: leave this out for now, ATtiny816 has nested register-group 198 | // _ => panic!("unknown register-group child: '{}'", child.name), 199 | _ => None, 200 | }) 201 | .collect(); 202 | 203 | RegisterGroup { name: name.clone(), caption: caption.clone(), registers: registers } 204 | } 205 | 206 | /// Reads a value group. 207 | /// 208 | /// This looks like so 209 | /// 210 | /// ```xml 211 | /// 212 | /// 213 | /// 214 | /// 215 | /// ``` 216 | fn read_value_group(value_group: &Element) -> ValueGroup { 217 | let (name, caption) = ( 218 | value_group.attributes.get("name").unwrap(), 219 | value_group.attributes.get("caption").unwrap(), 220 | ); 221 | let values = value_group 222 | .children 223 | .iter() 224 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 225 | .filter_map(|child| match &child.name[..] { 226 | "value" => Some(self::read_value(child)), 227 | _ => panic!("unknown value-group child: '{}'", child.name), 228 | }) 229 | .collect(); 230 | 231 | ValueGroup { name: name.clone(), caption: caption.clone(), values } 232 | } 233 | 234 | /// Reads a value. 235 | /// 236 | /// This looks like 237 | /// 238 | /// ```xml 239 | /// 240 | /// ``` 241 | fn read_value(value: &Element) -> Value { 242 | Value { 243 | name: value.attributes.get("name").unwrap().clone(), 244 | caption: value.attributes.get("caption").unwrap().clone(), 245 | value: read_int(value.attributes.get("value")).clone(), 246 | } 247 | } 248 | 249 | /// Reads a register. 250 | /// 251 | /// This looks like 252 | /// 253 | /// ```xml 254 | /// 255 | /// ``` 256 | fn read_register(register: &Element) -> Register { 257 | let byte_count = register.attributes.get("size").unwrap().parse().unwrap(); 258 | let rw = match register.attributes.get("ocd-rw").map(String::as_ref) { 259 | Some("R") => ReadWrite::ReadOnly, 260 | Some("W") => ReadWrite::WriteOnly, 261 | _ => ReadWrite::ReadAndWrite, 262 | }; 263 | 264 | let bitfields = register 265 | .children 266 | .iter() 267 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 268 | .filter_map(|child| match &child.name[..] { 269 | "bitfield" => Some(self::read_bitfield(child, byte_count)), 270 | _ => None, 271 | }) 272 | .collect(); 273 | 274 | Register { 275 | name: register.attributes.get("name").unwrap().clone(), 276 | caption: register.attributes.get("caption").unwrap().clone(), 277 | offset: read_int(register.attributes.get("offset")).clone(), 278 | mask: read_opt_int(register.attributes.get("mask")).clone(), 279 | size: byte_count, 280 | bitfields, 281 | rw, 282 | } 283 | } 284 | 285 | /// Reads a bitfield. 286 | /// 287 | /// This looks like 288 | /// 289 | /// ```xml 290 | /// 291 | /// 292 | /// ``` 293 | fn read_bitfield(bitfield: &Element, byte_count: u32) -> Bitfield { 294 | Bitfield { 295 | name: bitfield.attributes.get("name").expect("bitfield name").clone(), 296 | caption: bitfield.attributes.get("caption").unwrap_or(&"".to_owned()).clone(), 297 | mask: read_int(bitfield.attributes.get("mask")).clone(), 298 | values: bitfield.attributes.get("values").map(String::clone), 299 | size: byte_count, 300 | } 301 | } 302 | 303 | /// Reads an eddress space. 304 | /// 305 | /// This looks like 306 | /// 307 | /// ```xml 308 | /// 309 | /// 310 | /// 311 | /// ``` 312 | fn read_address_space(address_space: &Element) -> AddressSpace { 313 | let id = address_space.attributes.get("id").unwrap().clone(); 314 | let start_address = read_int(address_space.attributes.get("start")); 315 | let size = read_int(address_space.attributes.get("size")); 316 | let segments = address_space 317 | .children 318 | .iter() 319 | .filter_map(|node| if let XMLNode::Element(el) = node { Some(el) } else { None }) 320 | .map(read_memory_segment) 321 | .collect(); 322 | 323 | AddressSpace { 324 | id: id, 325 | name: address_space.attributes.get("name").unwrap().clone(), 326 | start_address: start_address, 327 | size: size, 328 | segments: segments, 329 | } 330 | } 331 | 332 | /// Reads a memory segment. 333 | /// 334 | /// ```xml 335 | /// 336 | /// ``` 337 | fn read_memory_segment(memory_segment: &Element) -> MemorySegment { 338 | let default_perms = "".to_owned(); 339 | 340 | let start_address = read_int(memory_segment.attributes.get("start")); 341 | let size = read_int(memory_segment.attributes.get("size")); 342 | let ty = memory_segment.attributes.get("type").unwrap().clone(); 343 | let rw = memory_segment.attributes.get("rw").unwrap_or(&default_perms); 344 | let exec = memory_segment.attributes.get("exec").unwrap_or(&default_perms); 345 | let name = memory_segment.attributes.get("name").unwrap().clone(); 346 | let page_size = memory_segment.attributes.get("pagesize").map(|p| read_int(Some(p))); 347 | 348 | let readable = rw.contains("r") || rw.contains("R"); 349 | let writable = rw.contains("w") || rw.contains("W"); 350 | let executable = exec == "1"; 351 | 352 | MemorySegment { start_address, size, ty, name, readable, writable, executable, page_size } 353 | } 354 | 355 | fn read_int(value: Option<&String>) -> u32 { 356 | let value = value.unwrap(); 357 | 358 | match value.starts_with("0x") { 359 | true => read_hex(Some(value)), 360 | false => value.parse().unwrap(), 361 | } 362 | } 363 | 364 | fn read_opt_int(value: Option<&String>) -> Option { 365 | value.map(|v| if v.starts_with("0x") { read_hex(Some(v)) } else { v.parse().unwrap() }) 366 | } 367 | 368 | fn read_hex(value: Option<&String>) -> u32 { 369 | let value = value.unwrap().replacen("0x", "", 1); 370 | u32::from_str_radix(&value, 16).unwrap() 371 | } 372 | --------------------------------------------------------------------------------