pin_defs_x.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. /*
  2. * pin_defs_x.h
  3. * optiboot helper defining the default pin assignments (LED, SOFT_UART)
  4. * for the various chips that are supported. This also has some ugly macros
  5. * for selecting among various UARTs and LED possibilities using command-line
  6. * defines like "UART=2 LED=B5"
  7. *
  8. * Copyright 2013-2020 by Bill Westfield.
  9. * Copyright 2010 by Peter Knight.
  10. * This software is licensed under version 2 of the Gnu Public Licence.
  11. * See optiboot.c for details.
  12. */
  13. /*
  14. * A bunch of macros to enable the LED to be specified as "B5" for bit 5
  15. * of port B, and similar.
  16. * We define symbols for all the legal combination of port/bit on a chip,
  17. * and do pre-processor tests to see if there's a match. This ends up
  18. * being very verbose, but it is pretty easy to generate semi-automatically.
  19. * (We wouldn't need this if the preprocessor could do string compares.)
  20. */
  21. // Symbols for each PortA bit.
  22. #define A0 0x100
  23. #define A1 0x101
  24. #define A2 0x102
  25. #define A3 0x103
  26. #define A4 0x104
  27. #define A5 0x105
  28. #define A6 0x106
  29. #define A7 0x107
  30. // If there is no PORTA on this chip, don't allow these to be used
  31. // (and indicate the error by redefining LED)
  32. #if !defined(PORTA)
  33. #if LED >= A0 && LED <= A7
  34. #undef LED
  35. #define LED -1
  36. #endif
  37. #endif
  38. #define B0 0x200
  39. #define B1 0x201
  40. #define B2 0x202
  41. #define B3 0x203
  42. #define B4 0x204
  43. #define B5 0x205
  44. #define B6 0x206
  45. #define B7 0x207
  46. #if !defined(PORTB)
  47. #if LED >= B0 && LED <= B7
  48. #undef LED
  49. #define LED -1
  50. #endif
  51. #endif
  52. #define C0 0x300
  53. #define C1 0x301
  54. #define C2 0x302
  55. #define C3 0x303
  56. #define C4 0x304
  57. #define C5 0x305
  58. #define C6 0x306
  59. #define C7 0x307
  60. #if !(defined(PORTC))
  61. #if LED >= C0 && LED <= C7
  62. #undef LED
  63. #define LED -1
  64. #endif
  65. #endif
  66. #define D0 0x400
  67. #define D1 0x401
  68. #define D2 0x402
  69. #define D3 0x403
  70. #define D4 0x404
  71. #define D5 0x405
  72. #define D6 0x406
  73. #define D7 0x407
  74. #if !(defined(PORTD))
  75. #if LED >= D0 && LED <= D7
  76. #undef LED
  77. #define LED -1
  78. #endif
  79. #endif
  80. #define E0 0x500
  81. #define E1 0x501
  82. #define E2 0x502
  83. #define E3 0x503
  84. #define E4 0x504
  85. #define E5 0x505
  86. #define E6 0x506
  87. #define E7 0x507
  88. #if !(defined(PORTE))
  89. #if LED >= E0 && LED <= E7
  90. #undef LED
  91. #define LED -1
  92. #endif
  93. #endif
  94. #define F0 0x600
  95. #define F1 0x601
  96. #define F2 0x602
  97. #define F3 0x603
  98. #define F4 0x604
  99. #define F5 0x605
  100. #define F6 0x606
  101. #define F7 0x607
  102. #if !(defined(PORTF))
  103. #if LED >= F0 && LED <= F7
  104. #undef LED
  105. #define LED -1
  106. #endif
  107. #endif
  108. #define G0 0x700
  109. #define G1 0x701
  110. #define G2 0x702
  111. #define G3 0x703
  112. #define G4 0x704
  113. #define G5 0x705
  114. #define G6 0x706
  115. #define G7 0x707
  116. #if !defined(PORTG)
  117. #if LED >= G0 && LED <= G7
  118. #undef LED
  119. #define LED -1
  120. #endif
  121. #endif
  122. #define H0 0x800
  123. #define H1 0x801
  124. #define H2 0x802
  125. #define H3 0x803
  126. #define H4 0x804
  127. #define H5 0x805
  128. #define H6 0x806
  129. #define H7 0x807
  130. #if !(defined(PORTH))
  131. #if LED >= H0 && LED <= H7
  132. #undef LED
  133. #define LED -1
  134. #endif
  135. #endif
  136. #define J0 0xA00
  137. #define J1 0xA01
  138. #define J2 0xA02
  139. #define J3 0xA03
  140. #define J4 0xA04
  141. #define J5 0xA05
  142. #define J6 0xA06
  143. #define J7 0xA07
  144. #if !(defined(PORTJ))
  145. #if LED >= J0 && LED <= J7
  146. #undef LED
  147. #define LED -1
  148. #endif
  149. #endif
  150. #define K0 0xB00
  151. #define K1 0xB01
  152. #define K2 0xB02
  153. #define K3 0xB03
  154. #define K4 0xB04
  155. #define K5 0xB05
  156. #define K6 0xB06
  157. #define K7 0xB07
  158. #if !(defined(PORTK))
  159. #if LED >= K0 && LED <= K7
  160. #undef LED
  161. #define LED -1
  162. #endif
  163. #endif
  164. #define L0 0xC00
  165. #define L1 0xC01
  166. #define L2 0xC02
  167. #define L3 0xC03
  168. #define L4 0xC04
  169. #define L5 0xC05
  170. #define L6 0xC06
  171. #define L7 0xC07
  172. #if !(defined(PORTL))
  173. #if LED >= L0 && LED <= L7
  174. #undef LED
  175. #define LED -1
  176. #endif
  177. #endif
  178. /*
  179. * A statement like "#if LED == B0" will evaluation (in the preprocessor)
  180. * to #if C0 == B0, and then to #if 0x301 == 0x201
  181. */
  182. #if LED == B0
  183. #define LED_NAME "B0"
  184. #undef LED
  185. #define LED_PORT VPORTB
  186. #define LED (1<<PORT0)
  187. #elif LED == B1
  188. #define LED_NAME "B1"
  189. #undef LED
  190. #define LED_PORT VPORTB
  191. #define LED (1<<PORT1)
  192. #elif LED == B2
  193. #define LED_NAME "B2"
  194. #undef LED
  195. #define LED_PORT VPORTB
  196. #define LED (1<<PORT2)
  197. #elif LED == B3
  198. #define LED_NAME "B3"
  199. #undef LED
  200. #define LED_PORT VPORTB
  201. #define LED (1<<PORT3)
  202. #elif LED == B4
  203. #define LED_NAME "B4"
  204. #undef LED
  205. #define LED_PORT VPORTB
  206. #define LED (1<<PORT4)
  207. #elif LED == B5
  208. #define LED_NAME "B5"
  209. #undef LED
  210. #define LED_PORT VPORTB
  211. #define LED (1<<PORT5)
  212. #elif LED == B6
  213. #define LED_NAME "B6"
  214. #undef LED
  215. #define LED_PORT VPORTB
  216. #define LED (1<<PORT6)
  217. #elif LED == B7
  218. #define LED_NAME "B7"
  219. #undef LED
  220. #define LED_PORT VPORTB
  221. #define LED (1<<PORT7)
  222. #elif LED == C0
  223. #define LED_NAME "C0"
  224. #undef LED
  225. #define LED_PORT VPORTC
  226. #define LED (1<<PORT0)
  227. #elif LED == C1
  228. #define LED_NAME "C1"
  229. #undef LED
  230. #define LED_PORT VPORTC
  231. #define LED (1<<PORT1)
  232. #elif LED == C2
  233. #define LED_NAME "C2"
  234. #undef LED
  235. #define LED_PORT VPORTC
  236. #define LED (1<<PORT2)
  237. #elif LED == C3
  238. #define LED_NAME "C3"
  239. #undef LED
  240. #define LED_PORT VPORTC
  241. #define LED (1<<PORT3)
  242. #elif LED == C4
  243. #define LED_NAME "C4"
  244. #undef LED
  245. #define LED_PORT VPORTC
  246. #define LED (1<<PORT4)
  247. #elif LED == C5
  248. #define LED_NAME "C5"
  249. #undef LED
  250. #define LED_PORT VPORTC
  251. #define LED (1<<PORT5)
  252. #elif LED == C6
  253. #define LED_NAME "C6"
  254. #undef LED
  255. #define LED_PORT VPORTC
  256. #define LED (1<<PORT6)
  257. #elif LED == C7
  258. #define LED_NAME "C7"
  259. #undef LED
  260. #define LED_PORT VPORTC
  261. #define LED (1<<PORT7)
  262. #elif LED == D0
  263. #define LED_NAME "D0"
  264. #undef LED
  265. #define LED_PORT VPORTD
  266. #define LED (1<<PORT0)
  267. #elif LED == D1
  268. #define LED_NAME "D1"
  269. #undef LED
  270. #define LED_PORT VPORTD
  271. #define LED (1<<PORT1)
  272. #elif LED == D2
  273. #define LED_NAME "D2"
  274. #undef LED
  275. #define LED_PORT VPORTD
  276. #define LED (1<<PORT2)
  277. #elif LED == D3
  278. #define LED_NAME "D3"
  279. #undef LED
  280. #define LED_PORT VPORTD
  281. #define LED (1<<PORT3)
  282. #elif LED == D4
  283. #define LED_NAME "D4"
  284. #undef LED
  285. #define LED_PORT VPORTD
  286. #define LED (1<<PORT4)
  287. #elif LED == D5
  288. #define LED_NAME "D5"
  289. #undef LED
  290. #define LED_PORT VPORTD
  291. #define LED (1<<PORT5)
  292. #elif LED == D6
  293. #define LED_NAME "D6"
  294. #undef LED
  295. #define LED_PORT VPORTD
  296. #define LED (1<<PORT6)
  297. #elif LED == D7
  298. #define LED_NAME "D7"
  299. #undef LED
  300. #define LED_PORT VPORTD
  301. #define LED (1<<PORT7)
  302. #elif LED == E0
  303. #define LED_NAME "E0"
  304. #undef LED
  305. #define LED_PORT VPORTE
  306. #define LED (1<<PORT0)
  307. #elif LED == E1
  308. #define LED_NAME "E1"
  309. #undef LED
  310. #define LED_PORT VPORTE
  311. #define LED (1<<PORT1)
  312. #elif LED == E2
  313. #define LED_NAME "E2"
  314. #undef LED
  315. #define LED_PORT VPORTE
  316. #define LED (1<<PORT2)
  317. #elif LED == E3
  318. #define LED_NAME "E3"
  319. #undef LED
  320. #define LED_PORT VPORTE
  321. #define LED (1<<PORT3)
  322. #elif LED == E4
  323. #define LED_NAME "E4"
  324. #undef LED
  325. #define LED_PORT VPORTE
  326. #define LED (1<<PORT4)
  327. #elif LED == E5
  328. #define LED_NAME "E5"
  329. #undef LED
  330. #define LED_PORT VPORTE
  331. #define LED (1<<PORT5)
  332. #elif LED == E6
  333. #define LED_NAME "E6"
  334. #undef LED
  335. #define LED_PORT VPORTE
  336. #define LED (1<<PORT6)
  337. #elif LED == E7
  338. #define LED_NAME "E7"
  339. #undef LED
  340. #define LED_PORT VPORTE
  341. #define LED (1<<PORT7)
  342. #elif LED == F0
  343. #define LED_NAME "F0"
  344. #undef LED
  345. #define LED_PORT VPORTF
  346. #define LED (1<<PORT0)
  347. #elif LED == F1
  348. #define LED_NAME "F1"
  349. #undef LED
  350. #define LED_PORT VPORTF
  351. #define LED (1<<PORT1)
  352. #elif LED == F2
  353. #define LED_NAME "F2"
  354. #undef LED
  355. #define LED_PORT VPORTF
  356. #define LED (1<<PORT2)
  357. #elif LED == F3
  358. #define LED_NAME "F3"
  359. #undef LED
  360. #define LED_PORT VPORTF
  361. #define LED (1<<PORT3)
  362. #elif LED == F4
  363. #define LED_NAME "F4"
  364. #undef LED
  365. #define LED_PORT VPORTF
  366. #define LED (1<<PORT4)
  367. #elif LED == F5
  368. #define LED_NAME "F5"
  369. #undef LED
  370. #define LED_PORT VPORTF
  371. #define LED (1<<PORT5)
  372. #elif LED == F6
  373. #define LED_NAME "F6"
  374. #undef LED
  375. #define LED_PORT VPORTF
  376. #define LED (1<<PORT6)
  377. #elif LED == F7
  378. #define LED_NAME "F7"
  379. #undef LED
  380. #define LED_PORT VPORTF
  381. #define LED (1<<PORT7)
  382. #elif LED == G0
  383. #define LED_NAME "G0"
  384. #undef LED
  385. #define LED_PORT VPORTG
  386. #define LED (1<<PORT0)
  387. #elif LED == G1
  388. #define LED_NAME "G1"
  389. #undef LED
  390. #define LED_PORT VPORTG
  391. #define LED (1<<PORT1)
  392. #elif LED == G2
  393. #define LED_NAME "G2"
  394. #undef LED
  395. #define LED_PORT VPORTG
  396. #define LED (1<<PORT2)
  397. #elif LED == G3
  398. #define LED_NAME "G3"
  399. #undef LED
  400. #define LED_PORT VPORTG
  401. #define LED (1<<PORT3)
  402. #elif LED == G4
  403. #define LED_NAME "G4"
  404. #undef LED
  405. #define LED_PORT VPORTG
  406. #define LED (1<<PORT4)
  407. #elif LED == G5
  408. #define LED_NAME "G5"
  409. #undef LED
  410. #define LED_PORT VPORTG
  411. #define LED (1<<PORT5)
  412. #elif LED == G6
  413. #define LED_NAME "G6"
  414. #undef LED
  415. #define LED_PORT VPORTG
  416. #define LED (1<<PORT6)
  417. #elif LED == G7
  418. #define LED_NAME "G7"
  419. #undef LED
  420. #define LED_PORT VPORTG
  421. #define LED (1<<PORT7)
  422. #elif LED == H0
  423. #define LED_NAME "H0"
  424. #undef LED
  425. #define LED_PORT VPORTH
  426. #define LED (1<<PORT0)
  427. #elif LED == H1
  428. #define LED_NAME "H1"
  429. #undef LED
  430. #define LED_PORT VPORTH
  431. #define LED (1<<PORT1)
  432. #elif LED == H2
  433. #define LED_NAME "H2"
  434. #undef LED
  435. #define LED_PORT VPORTH
  436. #define LED (1<<PORT2)
  437. #elif LED == H3
  438. #define LED_NAME "H3"
  439. #undef LED
  440. #define LED_PORT VPORTH
  441. #define LED (1<<PORT3)
  442. #elif LED == H4
  443. #define LED_NAME "H4"
  444. #undef LED
  445. #define LED_PORT VPORTH
  446. #define LED (1<<PORT4)
  447. #elif LED == H5
  448. #define LED_NAME "H5"
  449. #undef LED
  450. #define LED_PORT VPORTH
  451. #define LED (1<<PORT5)
  452. #elif LED == H6
  453. #define LED_NAME "H6"
  454. #undef LED
  455. #define LED_PORT VPORTH
  456. #define LED (1<<PORT6)
  457. #elif LED == H7
  458. #define LED_NAME "H7"
  459. #undef LED
  460. #define LED_PORT VPORTH
  461. #define LED (1<<PORT7)
  462. #elif LED == J0
  463. #define LED_NAME "J0"
  464. #undef LED
  465. #define LED_PORT VPORTJ
  466. #define LED (1<<PORT0)
  467. #elif LED == J1
  468. #define LED_NAME "J1"
  469. #undef LED
  470. #define LED_PORT VPORTJ
  471. #define LED (1<<PORT1)
  472. #elif LED == J2
  473. #define LED_NAME "J2"
  474. #undef LED
  475. #define LED_PORT VPORTJ
  476. #define LED (1<<PORT2)
  477. #elif LED == J3
  478. #define LED_NAME "J3"
  479. #undef LED
  480. #define LED_PORT VPORTJ
  481. #define LED (1<<PORT3)
  482. #elif LED == J4
  483. #define LED_NAME "J4"
  484. #undef LED
  485. #define LED_PORT VPORTJ
  486. #define LED (1<<PORT4)
  487. #elif LED == J5
  488. #define LED_NAME "J5"
  489. #undef LED
  490. #define LED_PORT VPORTJ
  491. #define LED (1<<PORT5)
  492. #elif LED == J6
  493. #define LED_NAME "J6"
  494. #undef LED
  495. #define LED_PORT VPORTJ
  496. #define LED (1<<PORT6)
  497. #elif LED == J7
  498. #define LED_NAME "J7"
  499. #undef LED
  500. #define LED_PORT VPORTJ
  501. #define LED (1<<PORT7)
  502. #elif LED == K0
  503. #define LED_NAME "K0"
  504. #undef LED
  505. #define LED_PORT VPORTK
  506. #define LED (1<<PORT0)
  507. #elif LED == K1
  508. #define LED_NAME "K1"
  509. #undef LED
  510. #define LED_PORT VPORTK
  511. #define LED (1<<PORT1)
  512. #elif LED == K2
  513. #define LED_NAME "K2"
  514. #undef LED
  515. #define LED_PORT VPORTK
  516. #define LED (1<<PORT2)
  517. #elif LED == K3
  518. #define LED_NAME "K3"
  519. #undef LED
  520. #define LED_PORT VPORTK
  521. #define LED (1<<PORT3)
  522. #elif LED == K4
  523. #define LED_NAME "K4"
  524. #undef LED
  525. #define LED_PORT VPORTK
  526. #define LED (1<<PORT4)
  527. #elif LED == K5
  528. #define LED_NAME "K5"
  529. #undef LED
  530. #define LED_PORT VPORTK
  531. #define LED (1<<PORT5)
  532. #elif LED == K6
  533. #define LED_NAME "K6"
  534. #undef LED
  535. #define LED_PORT VPORTK
  536. #define LED (1<<PORT6)
  537. #elif LED == K7
  538. #define LED_NAME "K7"
  539. #undef LED
  540. #define LED_PORT VPORTK
  541. #define LED (1<<PORT7)
  542. #elif LED == L0
  543. #define LED_NAME "L0"
  544. #undef LED
  545. #define LED_PORT VPORTL
  546. #define LED (1<<PORT0)
  547. #elif LED == L1
  548. #define LED_NAME "L1"
  549. #undef LED
  550. #define LED_PORT VPORTL
  551. #define LED (1<<PORT1)
  552. #elif LED == L2
  553. #define LED_NAME "L2"
  554. #undef LED
  555. #define LED_PORT VPORTL
  556. #define LED (1<<PORT2)
  557. #elif LED == L3
  558. #define LED_NAME "L3"
  559. #undef LED
  560. #define LED_PORT VPORTL
  561. #define LED (1<<PORT3)
  562. #elif LED == L4
  563. #define LED_NAME "L4"
  564. #undef LED
  565. #define LED_PORT VPORTL
  566. #define LED (1<<PORT4)
  567. #elif LED == L5
  568. #define LED_NAME "L5"
  569. #undef LED
  570. #define LED_PORT VPORTL
  571. #define LED (1<<PORT5)
  572. #elif LED == L6
  573. #define LED_NAME "L6"
  574. #undef LED
  575. #define LED_PORT VPORTL
  576. #define LED (1<<PORT6)
  577. #elif LED == L7
  578. #define LED_NAME "L7"
  579. #undef LED
  580. #define LED_PORT VPORTL
  581. #define LED (1<<PORT7)
  582. #elif LED == A0
  583. #define LED_NAME "A0"
  584. #undef LED
  585. #ifdef VPORTA
  586. #define LED_PORT VPORTA.OUT
  587. #define LED_PORT VPORTA.IN
  588. #else
  589. #define LED_PORT VPORTA
  590. #endif
  591. #define LED (1<<PORT0)
  592. #elif LED == A1
  593. #define LED_NAME "A1"
  594. #undef LED
  595. #define LED_PORT VPORTA
  596. #define LED (1<<PORT1)
  597. #elif LED == A2
  598. #define LED_NAME "A2"
  599. #undef LED
  600. #define LED_PORT VPORTA
  601. #define LED (1<<PORT2)
  602. #elif LED == A3
  603. #define LED_NAME "A3"
  604. #undef LED
  605. #define LED_PORT VPORTA
  606. #define LED (1<<PORT3)
  607. #elif LED == A4
  608. #define LED_NAME "A4"
  609. #undef LED
  610. #define LED_PORT VPORTA
  611. #define LED (1<<PORT4)
  612. #elif LED == A5
  613. #define LED_NAME "A5"
  614. #undef LED
  615. #define LED_PORT VPORTA
  616. #define LED (1<<PORT5)
  617. #elif LED == A6
  618. #define LED_NAME "A6"
  619. #undef LED
  620. #define LED_PORT VPORTA
  621. #define LED (1<<PORT6)
  622. #elif LED == A7
  623. #define LED_NAME "A7"
  624. #undef LED
  625. #define LED_PORT VPORTA
  626. #define LED (1<<PORT7)
  627. #else
  628. // Stop compilation right away, so we don't get more errors.
  629. #if LED == -1
  630. #error Unrecognized LED name. Should be like "B5"
  631. // Stop compilation right away, so we don't get more errors.
  632. #pragma GCC diagnostic warning "-Wfatal-errors"
  633. #error Nonexistent LED PORT. Check datasheet.
  634. #endif
  635. #pragma GCC diagnostic warning "-Wfatal-errors"
  636. #error Unrecognized LED name. Should be like "B5"
  637. #endif
  638. /*
  639. * Handle devices with up to 4 uarts. Rather inelegantly.
  640. */
  641. #define USART_ALTPMUX 1
  642. #if defined(__AVR_ATmega4809__) || defined(__AVR_ATmega4808__) || \
  643. defined(__AVR_ATmega3209__) || defined(__AVR_ATmega3208__) || \
  644. defined(__AVR_ATmega1609__) || defined(__AVR_ATmega1608__) || \
  645. defined(__AVR_ATmega809__) || defined(__AVR_ATmega808__)
  646. #define MYPMUX_REG PORTMUX.USARTROUTEA
  647. # if (UARTTX == A0)
  648. # define UART_NAME "A0"
  649. # ifndef USART0
  650. # error Pin on USART0, but no USART0 exists
  651. # endif
  652. # define MYUART USART0
  653. # define MYUART_TXPORT VPORTA
  654. # define MYUART_TXPIN (1<<PORT0)
  655. # define MYUART_PMUX_VAL (PORTMUX_USART0_DEFAULT_gc)
  656. # elif (UARTTX == A4)
  657. # define UART_NAME "A4"
  658. # ifndef USART0
  659. # error Pin on USART0, but no USART0 exists
  660. # endif
  661. # define MYUART USART0
  662. # define MYUART_TXPORT VPORTA
  663. # define MYUART_TXPIN (1<<PORT4)
  664. # define MYUART_PMUX_VAL (PORTMUX_USART0_ALT1_gc)
  665. # elif (UARTTX == B0)
  666. # define UART_NAME "B0"
  667. # ifndef USART3
  668. # error Pin on USART3, but no USART3 exists
  669. # endif
  670. # define MYUART USART3
  671. # define MYUART_TXPORT VPORTB
  672. # define MYUART_TXPIN (1<<PORT0)
  673. # define MYUART_PMUX_VAL (PORTMUX_USART3_DEFAULT_gc)
  674. # elif (UARTTX == B4)
  675. # define UART_NAME "B4"
  676. # ifndef USART3
  677. # error Pin on USART3, but no USART3 exists
  678. # endif
  679. # define MYUART USART3
  680. # define MYUART_TXPORT VPORTB
  681. # define MYUART_TXPIN (1<<PORT4)
  682. # define MYUART_PMUX_VAL (PORTMUX_USART3_ALT1_gc)
  683. # elif (UARTTX == C0)
  684. # define UART_NAME "C0"
  685. # ifndef USART1
  686. # error Pin on USART1, but no USART1 exists
  687. # endif
  688. # define MYUART USART1
  689. # define MYUART_TXPORT VPORTC
  690. # define MYUART_TXPIN (1<<PORT0)
  691. # define MYUART_PMUX_VAL (PORTMUX_USART1_DEFAULT_gc)
  692. # elif (UARTTX == C4)
  693. # define UART_NAME "C4"
  694. # ifndef USART1
  695. # error Pin on USART1, but no USART1 exists
  696. # endif
  697. # define MYUART USART1
  698. # define MYUART_TXPORT VPORTC
  699. # define MYUART_TXPIN (1<<PORT4)
  700. # define MYUART_PMUX_VAL (PORTMUX_USART1_ALT1_gc)
  701. # elif (UARTTX == F0)
  702. # define UART_NAME "F0"
  703. # ifndef USART2
  704. # error Pin on USART2, but no USART2 exists
  705. # endif
  706. # define MYUART USART2
  707. # define MYUART_TXPORT VPORTF
  708. # define MYUART_TXPIN (1<<PORT0)
  709. # define MYUART_PMUX_VAL (PORTMUX_USART2_DEFAULT_gc)
  710. # elif (UARTTX == F4)
  711. # define UART_NAME "F4"
  712. # ifndef USART2
  713. # error Pin on USART2, but no USART2 exists
  714. # endif
  715. # define MYUART USART2
  716. # define MYUART_TXPORT VPORTF
  717. # define MYUART_TXPIN (1<<PORT4)
  718. # define MYUART_PMUX_VAL (PORTMUX_USART2_ALT1_gc)
  719. # else
  720. # pragma GCC diagnostic warning "-Wfatal-errors"
  721. # pragma GCC error "Invalid UARTTX pin for chip"
  722. # endif
  723. #endif // ATmega4809
  724. /*
  725. * 8pin Tiny0 and Tiny1
  726. */
  727. #if defined(__AVR_ATtiny402__) || defined(__AVR_ATtiny202__) || \
  728. defined(__AVR_ATtiny412__) || defined(__AVR_ATtiny212__)
  729. #define MYPMUX_REG PORTMUX.CTRLB
  730. # if (UARTTX == A6)
  731. # define UART_NAME "A6"
  732. # ifndef USART0
  733. # error Pin on USART0, but no USART0 exists
  734. # endif
  735. # define MYUART USART0
  736. # define MYUART_TXPORT VPORTA
  737. # define MYUART_TXPIN (1<<PORT6)
  738. # define MYUART_PMUX_VAL 0
  739. # elif (UARTTX == A1)
  740. # define UART_NAME "A1"
  741. # ifndef USART0
  742. # error Pin on USART0, but no USART0 exists
  743. # endif
  744. # define MYUART USART0
  745. # define MYUART_TXPORT VPORTA
  746. # define MYUART_TXPIN (1<<PORT1)
  747. # define MYUART_PMUX_VAL (USART_ALTPMUX)
  748. # else
  749. # pragma GCC diagnostic warning "-Wfatal-errors"
  750. # pragma GCC error "Invalid UARTTX pin for chip"
  751. # endif
  752. #endif // Tiny402/etc
  753. /*
  754. * 14, 20, and 24 pin Tiny0, Tiny1
  755. * The 14, 20, and 24pin packages all conveniently have the UART on the
  756. * same port pins, and the same pinmux structure!
  757. */
  758. #if defined(__AVR_ATtiny1614__) || defined(__AVR_ATtiny1604__) || \
  759. defined(__AVR_ATtiny814__) || defined(__AVR_ATtiny804__) || \
  760. defined(__AVR_ATtiny1606__) || defined(__AVR_ATtiny806__) || \
  761. defined(__AVR_ATtiny406__) || defined(__AVR_ATtiny3216__) || \
  762. defined(__AVR_ATtiny816__) || defined(__AVR_ATtiny416__) || \
  763. defined(__AVR_ATtiny1617__) || defined(__AVR_ATtiny3217__) || \
  764. defined(__AVR_ATtiny1607__) || defined(__AVR_ATtiny817__)
  765. #define MYPMUX_REG PORTMUX.CTRLB
  766. # if (UARTTX == B2)
  767. # define UART_NAME "B2"
  768. # ifndef USART0
  769. # error Pin on USART0, but no USART0 exists
  770. # endif
  771. # define MYUART USART0
  772. # define MYUART_TXPORT VPORTB
  773. # define MYUART_TXPIN (1<<PORT2)
  774. # define MYUART_PMUX_VAL 0
  775. # elif (UARTTX == A1)
  776. # define UART_NAME "A1"
  777. # ifndef USART0
  778. # error Pin on USART0, but no USART0 exists
  779. # endif
  780. # define MYUART USART0
  781. # define MYUART_TXPORT VPORTA
  782. # define MYUART_TXPIN (1<<PORT1)
  783. # define MYUART_PMUX_VAL (USART_ALTPMUX)
  784. # else
  785. # pragma GCC diagnostic warning "-Wfatal-errors"
  786. # pragma GCC error "Invalid UARTTX pin for chip"
  787. # endif
  788. #endif
  789. #ifndef MYUART
  790. # warning No UARTTX pin specified.
  791. #endif
  792. #ifdef RS485
  793. #include "pins_rs485.h"
  794. #endif