Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
Tento repozitář je archivovaný. Můžete prohlížet soubory, klonovat, ale nemůžete nahrávat a vytvářet nové úkoly a požadavky na natažení.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  2. This software may be distributed and modified under the terms of the GNU
  3. General Public License version 2 (GPL2) as published by the Free Software
  4. Foundation and appearing in the file GPL2.TXT included in the packaging of
  5. this file. Please note that GPL2 Section 2[b] requires that all works based
  6. on this software must also be made publicly available under the terms of
  7. the GPL2 ("Copyleft").
  8. Contact information
  9. -------------------
  10. Circuits At Home, LTD
  11. Web : http://www.circuitsathome.com
  12. e-mail : [email protected]
  13. */
  14. /* derived from Konstantin Chizhov's AVR port templates */
  15. #if !defined(_usb_h_) || defined(_avrpins_h_)
  16. #error "Never include avrpins.h directly; include Usb.h instead"
  17. #else
  18. #define _avrpins_h_
  19. #if defined(__AVR__)
  20. // pointers are 16 bits on AVR
  21. #define pgm_read_pointer(p) pgm_read_word(p)
  22. // Support for these boards needs to be manually activated in settings.h or in a makefile
  23. #if !defined(BOARD_MEGA_ADK) && defined(__AVR_ATmega2560__) && (USE_UHS_MEGA_ADK || defined(ARDUINO_AVR_ADK))
  24. #define BOARD_MEGA_ADK
  25. #elif !defined(BOARD_BLACK_WIDDOW) && USE_UHS_BLACK_WIDDOW
  26. #define BOARD_BLACK_WIDDOW
  27. #endif
  28. #ifdef PORTA
  29. #define USE_PORTA
  30. #endif
  31. #ifdef PORTB
  32. #define USE_PORTB
  33. #endif
  34. #ifdef PORTC
  35. #define USE_PORTC
  36. #endif
  37. #ifdef PORTD
  38. #define USE_PORTD
  39. #endif
  40. #ifdef PORTE
  41. #define USE_PORTE
  42. #endif
  43. #ifdef PORTF
  44. #define USE_PORTF
  45. #endif
  46. #ifdef PORTG
  47. #define USE_PORTG
  48. #endif
  49. #ifdef PORTH
  50. #define USE_PORTH
  51. #endif
  52. #ifdef PORTJ
  53. #define USE_PORTJ
  54. #endif
  55. #ifdef PORTK
  56. #define USE_PORTK
  57. #endif
  58. #ifdef PORTL
  59. #define USE_PORTL
  60. #endif
  61. #ifdef PORTQ
  62. #define USE_PORTQ
  63. #endif
  64. #ifdef PORTR
  65. #define USE_PORTR
  66. #endif
  67. #ifdef TCCR0A
  68. #define USE_TCCR0A
  69. #endif
  70. #ifdef TCCR1A
  71. #define USE_TCCR1A
  72. #endif
  73. #ifdef TCCR2A
  74. #define USE_TCCR2A
  75. #endif
  76. //Port definitions for AtTiny, AtMega families.
  77. #define MAKE_PORT(portName, ddrName, pinName, className, ID) \
  78. class className{\
  79. public:\
  80. typedef uint8_t DataT;\
  81. public:\
  82. static void Write(DataT value){portName = value;}\
  83. static void ClearAndSet(DataT clearMask, DataT value){portName = (portName & ~clearMask) | value;}\
  84. static DataT Read(){return portName;}\
  85. static void DirWrite(DataT value){ddrName = value;}\
  86. static DataT DirRead(){return ddrName;}\
  87. static void Set(DataT value){portName |= value;}\
  88. static void Clear(DataT value){portName &= ~value;}\
  89. static void Toggle(DataT value){portName ^= value;}\
  90. static void DirSet(DataT value){ddrName |= value;}\
  91. static void DirClear(DataT value){ddrName &= ~value;}\
  92. static void DirToggle(DataT value){ddrName ^= value;}\
  93. static DataT PinRead(){return pinName;}\
  94. enum{Id = ID};\
  95. enum{Width=sizeof(DataT)*8};\
  96. };
  97. // TCCR registers to set/clear Arduino PWM
  98. #define MAKE_TCCR(TccrName, className) \
  99. class className{\
  100. public:\
  101. typedef uint8_t DataT;\
  102. public:\
  103. static void Write(DataT value){TccrName = value;}\
  104. static void ClearAndSet(DataT clearMask, DataT value){TccrName = (TccrName & ~clearMask) | value;}\
  105. static DataT Read(){return TccrName;}\
  106. static void Set(DataT value){TccrName |= value;}\
  107. static void Clear(DataT value){TccrName &= ~value;}\
  108. static void Toggle(DataT value){TccrName ^= value;}\
  109. enum{Width=sizeof(DataT)*8};\
  110. };
  111. #ifdef USE_PORTA
  112. MAKE_PORT(PORTA, DDRA, PINA, Porta, 'A')
  113. #endif
  114. #ifdef USE_PORTB
  115. MAKE_PORT(PORTB, DDRB, PINB, Portb, 'B')
  116. #endif
  117. #ifdef USE_PORTC
  118. MAKE_PORT(PORTC, DDRC, PINC, Portc, 'C')
  119. #endif
  120. #ifdef USE_PORTD
  121. MAKE_PORT(PORTD, DDRD, PIND, Portd, 'D')
  122. #endif
  123. #ifdef USE_PORTE
  124. MAKE_PORT(PORTE, DDRE, PINE, Porte, 'E')
  125. #endif
  126. #ifdef USE_PORTF
  127. MAKE_PORT(PORTF, DDRF, PINF, Portf, 'F')
  128. #endif
  129. #ifdef USE_PORTG
  130. MAKE_PORT(PORTG, DDRG, PING, Portg, 'G')
  131. #endif
  132. #ifdef USE_PORTH
  133. MAKE_PORT(PORTH, DDRH, PINH, Porth, 'H')
  134. #endif
  135. #ifdef USE_PORTJ
  136. MAKE_PORT(PORTJ, DDRJ, PINJ, Portj, 'J')
  137. #endif
  138. #ifdef USE_PORTK
  139. MAKE_PORT(PORTK, DDRK, PINK, Portk, 'K')
  140. #endif
  141. #ifdef USE_PORTL
  142. MAKE_PORT(PORTL, DDRL, PINL, Portl, 'L')
  143. #endif
  144. #ifdef USE_PORTQ
  145. MAKE_PORT(PORTQ, DDRQ, PINQ, Portq, 'Q')
  146. #endif
  147. #ifdef USE_PORTR
  148. MAKE_PORT(PORTR, DDRR, PINR, Portr, 'R')
  149. #endif
  150. #ifdef USE_TCCR0A
  151. MAKE_TCCR(TCCR0A, Tccr0a)
  152. #endif
  153. #ifdef USE_TCCR1A
  154. MAKE_TCCR(TCCR1A, Tccr1a)
  155. #endif
  156. #ifdef USE_TCCR2A
  157. MAKE_TCCR(TCCR2A, Tccr2a)
  158. #endif
  159. // this class represents one pin in a IO port.
  160. // It is fully static.
  161. template<typename PORT, uint8_t PIN>
  162. class TPin {
  163. // BOOST_STATIC_ASSERT(PIN < PORT::Width);
  164. public:
  165. typedef PORT Port;
  166. enum {
  167. Number = PIN
  168. };
  169. static void Set() {
  170. PORT::Set(1 << PIN);
  171. }
  172. static void Set(uint8_t val) {
  173. if(val)
  174. Set();
  175. else Clear();
  176. }
  177. static void SetDir(uint8_t val) {
  178. if(val)
  179. SetDirWrite();
  180. else SetDirRead();
  181. }
  182. static void Clear() {
  183. PORT::Clear(1 << PIN);
  184. }
  185. static void Toggle() {
  186. PORT::Toggle(1 << PIN);
  187. }
  188. static void SetDirRead() {
  189. PORT::DirClear(1 << PIN);
  190. }
  191. static void SetDirWrite() {
  192. PORT::DirSet(1 << PIN);
  193. }
  194. static uint8_t IsSet() {
  195. return PORT::PinRead() & (uint8_t)(1 << PIN);
  196. }
  197. static void WaiteForSet() {
  198. while(IsSet() == 0) {
  199. }
  200. }
  201. static void WaiteForClear() {
  202. while(IsSet()) {
  203. }
  204. }
  205. }; //class TPin...
  206. // this class represents one bit in TCCR port.
  207. // used to set/clear TCCRx bits
  208. // It is fully static.
  209. template<typename TCCR, uint8_t COM>
  210. class TCom {
  211. // BOOST_STATIC_ASSERT(PIN < PORT::Width);
  212. public:
  213. typedef TCCR Tccr;
  214. enum {
  215. Com = COM
  216. };
  217. static void Set() {
  218. TCCR::Set(1 << COM);
  219. }
  220. static void Clear() {
  221. TCCR::Clear(1 << COM);
  222. }
  223. static void Toggle() {
  224. TCCR::Toggle(1 << COM);
  225. }
  226. }; //class TCom...
  227. //Short pin definitions
  228. #ifdef USE_PORTA
  229. typedef TPin<Porta, 0 > Pa0;
  230. typedef TPin<Porta, 1 > Pa1;
  231. typedef TPin<Porta, 2 > Pa2;
  232. typedef TPin<Porta, 3 > Pa3;
  233. typedef TPin<Porta, 4 > Pa4;
  234. typedef TPin<Porta, 5 > Pa5;
  235. typedef TPin<Porta, 6 > Pa6;
  236. typedef TPin<Porta, 7 > Pa7;
  237. #endif
  238. #ifdef USE_PORTB
  239. typedef TPin<Portb, 0 > Pb0;
  240. typedef TPin<Portb, 1 > Pb1;
  241. typedef TPin<Portb, 2 > Pb2;
  242. typedef TPin<Portb, 3 > Pb3;
  243. typedef TPin<Portb, 4 > Pb4;
  244. typedef TPin<Portb, 5 > Pb5;
  245. typedef TPin<Portb, 6 > Pb6;
  246. typedef TPin<Portb, 7 > Pb7;
  247. #endif
  248. #ifdef USE_PORTC
  249. typedef TPin<Portc, 0 > Pc0;
  250. typedef TPin<Portc, 1 > Pc1;
  251. typedef TPin<Portc, 2 > Pc2;
  252. typedef TPin<Portc, 3 > Pc3;
  253. typedef TPin<Portc, 4 > Pc4;
  254. typedef TPin<Portc, 5 > Pc5;
  255. typedef TPin<Portc, 6 > Pc6;
  256. typedef TPin<Portc, 7 > Pc7;
  257. #endif
  258. #ifdef USE_PORTD
  259. typedef TPin<Portd, 0 > Pd0;
  260. typedef TPin<Portd, 1 > Pd1;
  261. typedef TPin<Portd, 2 > Pd2;
  262. typedef TPin<Portd, 3 > Pd3;
  263. typedef TPin<Portd, 4 > Pd4;
  264. typedef TPin<Portd, 5 > Pd5;
  265. typedef TPin<Portd, 6 > Pd6;
  266. typedef TPin<Portd, 7 > Pd7;
  267. #endif
  268. #ifdef USE_PORTE
  269. typedef TPin<Porte, 0 > Pe0;
  270. typedef TPin<Porte, 1 > Pe1;
  271. typedef TPin<Porte, 2 > Pe2;
  272. typedef TPin<Porte, 3 > Pe3;
  273. typedef TPin<Porte, 4 > Pe4;
  274. typedef TPin<Porte, 5 > Pe5;
  275. typedef TPin<Porte, 6 > Pe6;
  276. typedef TPin<Porte, 7 > Pe7;
  277. #endif
  278. #ifdef USE_PORTF
  279. typedef TPin<Portf, 0 > Pf0;
  280. typedef TPin<Portf, 1 > Pf1;
  281. typedef TPin<Portf, 2 > Pf2;
  282. typedef TPin<Portf, 3 > Pf3;
  283. typedef TPin<Portf, 4 > Pf4;
  284. typedef TPin<Portf, 5 > Pf5;
  285. typedef TPin<Portf, 6 > Pf6;
  286. typedef TPin<Portf, 7 > Pf7;
  287. #endif
  288. #ifdef USE_PORTG
  289. typedef TPin<Portg, 0 > Pg0;
  290. typedef TPin<Portg, 1 > Pg1;
  291. typedef TPin<Portg, 2 > Pg2;
  292. typedef TPin<Portg, 3 > Pg3;
  293. typedef TPin<Portg, 4 > Pg4;
  294. typedef TPin<Portg, 5 > Pg5;
  295. typedef TPin<Portg, 6 > Pg6;
  296. typedef TPin<Portg, 7 > Pg7;
  297. #endif
  298. #ifdef USE_PORTH
  299. typedef TPin<Porth, 0 > Ph0;
  300. typedef TPin<Porth, 1 > Ph1;
  301. typedef TPin<Porth, 2 > Ph2;
  302. typedef TPin<Porth, 3 > Ph3;
  303. typedef TPin<Porth, 4 > Ph4;
  304. typedef TPin<Porth, 5 > Ph5;
  305. typedef TPin<Porth, 6 > Ph6;
  306. typedef TPin<Porth, 7 > Ph7;
  307. #endif
  308. #ifdef USE_PORTJ
  309. typedef TPin<Portj, 0 > Pj0;
  310. typedef TPin<Portj, 1 > Pj1;
  311. typedef TPin<Portj, 2 > Pj2;
  312. typedef TPin<Portj, 3 > Pj3;
  313. typedef TPin<Portj, 4 > Pj4;
  314. typedef TPin<Portj, 5 > Pj5;
  315. typedef TPin<Portj, 6 > Pj6;
  316. typedef TPin<Portj, 7 > Pj7;
  317. #endif
  318. #ifdef USE_PORTK
  319. typedef TPin<Portk, 0 > Pk0;
  320. typedef TPin<Portk, 1 > Pk1;
  321. typedef TPin<Portk, 2 > Pk2;
  322. typedef TPin<Portk, 3 > Pk3;
  323. typedef TPin<Portk, 4 > Pk4;
  324. typedef TPin<Portk, 5 > Pk5;
  325. typedef TPin<Portk, 6 > Pk6;
  326. typedef TPin<Portk, 7 > Pk7;
  327. #endif
  328. #ifdef USE_PORTL
  329. typedef TPin<Portl, 0 > Pl0;
  330. typedef TPin<Portl, 1 > Pl1;
  331. typedef TPin<Portl, 2 > Pl2;
  332. typedef TPin<Portl, 3 > Pl3;
  333. typedef TPin<Portl, 4 > Pl4;
  334. typedef TPin<Portl, 5 > Pl5;
  335. typedef TPin<Portl, 6 > Pl6;
  336. typedef TPin<Portl, 7 > Pl7;
  337. #endif
  338. #ifdef USE_PORTQ
  339. typedef TPin<Portq, 0 > Pq0;
  340. typedef TPin<Portq, 1 > Pq1;
  341. typedef TPin<Portq, 2 > Pq2;
  342. typedef TPin<Portq, 3 > Pq3;
  343. typedef TPin<Portq, 4 > Pq4;
  344. typedef TPin<Portq, 5 > Pq5;
  345. typedef TPin<Portq, 6 > Pq6;
  346. typedef TPin<Portq, 7 > Pq7;
  347. #endif
  348. #ifdef USE_PORTR
  349. typedef TPin<Portr, 0 > Pr0;
  350. typedef TPin<Portr, 1 > Pr1;
  351. typedef TPin<Portr, 2 > Pr2;
  352. typedef TPin<Portr, 3 > Pr3;
  353. typedef TPin<Portr, 4 > Pr4;
  354. typedef TPin<Portr, 5 > Pr5;
  355. typedef TPin<Portr, 6 > Pr6;
  356. typedef TPin<Portr, 7 > Pr7;
  357. #endif
  358. #ifdef USE_TCCR0A
  359. typedef TCom<Tccr0a, COM0A1> Tc0a; //P6
  360. typedef TCom<Tccr0a, COM0B1> Tc0b; //P5
  361. #endif
  362. #ifdef USE_TCCR1A
  363. typedef TCom<Tccr1a, COM1A1> Tc1a; //P9
  364. typedef TCom<Tccr1a, COM1B1> Tc1b; //P10
  365. #endif
  366. #ifdef USE_TCCR2A
  367. typedef TCom<Tccr2a, COM2A1> Tc2a; //P11
  368. typedef TCom<Tccr2a, COM2B1> Tc2b; //P3
  369. #endif
  370. template<typename Tp_pin, typename Tc_bit>
  371. class Tp_Tc {
  372. public:
  373. static void SetDir(uint8_t val) {
  374. if(val)
  375. SetDirWrite();
  376. else SetDirRead();
  377. }
  378. static void SetDirRead() {
  379. Tp_pin::SetDirRead(); //set pin direction
  380. Tc_bit::Clear(); //disconnect pin from PWM
  381. }
  382. static void SetDirWrite() {
  383. Tp_pin::SetDirWrite();
  384. Tc_bit::Clear();
  385. }
  386. };
  387. /* pin definitions for cases where it's necessary to clear compare output mode bits */
  388. //typedef Tp_Tc<Pd3, Tc2b> P3; //Arduino pin 3
  389. //typedef Tp_Tc<Pd5, Tc0b> P5; //Arduino pin 5
  390. //typedef Tp_Tc<Pd6, Tc0a> P6; //Arduino pin 6
  391. //typedef Tp_Tc<Pb1, Tc1a> P9; //Arduino pin 9
  392. //typedef Tp_Tc<Pb2, Tc1b> P10; //Arduino pin 10
  393. //typedef Tp_Tc<Pb3, Tc2a> P11; //Arduino pin 11
  394. /* Arduino pin definitions */
  395. #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  396. // "Mega" Arduino pin numbers
  397. #define P0 Pe0
  398. #define P1 Pe1
  399. #define P2 Pe4
  400. #define P3 Pe5
  401. #define P4 Pg5
  402. #define P5 Pe3
  403. #define P6 Ph3
  404. #define P7 Ph4
  405. #define P8 Ph5
  406. #define P9 Ph6
  407. #define P10 Pb4
  408. #define P11 Pb5
  409. #define P12 Pb6
  410. #define P13 Pb7
  411. #define P14 Pj1
  412. #define P15 Pj0
  413. #define P16 Ph1
  414. #define P17 Ph0
  415. #define P18 Pd3
  416. #define P19 Pd2
  417. #define P20 Pd1
  418. #define P21 Pd0
  419. #define P22 Pa0
  420. #define P23 Pa1
  421. #define P24 Pa2
  422. #define P25 Pa3
  423. #define P26 Pa4
  424. #define P27 Pa5
  425. #define P28 Pa6
  426. #define P29 Pa7
  427. #define P30 Pc7
  428. #define P31 Pc6
  429. #define P32 Pc5
  430. #define P33 Pc4
  431. #define P34 Pc3
  432. #define P35 Pc2
  433. #define P36 Pc1
  434. #define P37 Pc0
  435. #define P38 Pd7
  436. #define P39 Pg2
  437. #define P40 Pg1
  438. #define P41 Pg0
  439. #define P42 Pl7
  440. #define P43 Pl6
  441. #define P44 Pl5
  442. #define P45 Pl4
  443. #define P46 Pl3
  444. #define P47 Pl2
  445. #define P48 Pl1
  446. #define P49 Pl0
  447. #define P50 Pb3
  448. #define P51 Pb2
  449. #define P52 Pb1
  450. #define P53 Pb0
  451. #ifdef BOARD_MEGA_ADK // These pins are not broken out on the Arduino ADK
  452. #define P54 Pe6 // INT on Arduino ADK
  453. #define P55 Pj2 // MAX_RESET on Arduino ADK
  454. #endif
  455. // "Mega" pin numbers
  456. #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
  457. // "Classic" Arduino pin numbers
  458. #define P0 Pd0
  459. #define P1 Pd1
  460. #define P2 Pd2
  461. #define P3 Pd3
  462. #define P4 Pd4
  463. #define P5 Pd5
  464. #define P6 Pd6
  465. #define P7 Pd7
  466. #define P8 Pb0
  467. #define P9 Pb1
  468. #define P10 Pb2
  469. #define P11 Pb3
  470. #define P12 Pb4
  471. #define P13 Pb5
  472. #define P14 Pc0
  473. #define P15 Pc1
  474. #define P16 Pc2
  475. #define P17 Pc3
  476. #define P18 Pc4
  477. #define P19 Pc5
  478. // "Classic" Arduino pin numbers
  479. #elif defined(CORE_TEENSY) && defined(__AVR_ATmega32U4__)
  480. // Teensy 2.0 pin numbers
  481. // http://www.pjrc.com/teensy/pinout.html
  482. #define P0 Pb0
  483. #define P1 Pb1
  484. #define P2 Pb2
  485. #define P3 Pb3
  486. #define P4 Pb7
  487. #define P5 Pd0
  488. #define P6 Pd1
  489. #define P7 Pd2
  490. #define P8 Pd3
  491. #define P9 Pc6
  492. #define P10 Pc7
  493. #define P11 Pd6
  494. #define P12 Pd7
  495. #define P13 Pb4
  496. #define P14 Pb5
  497. #define P15 Pb6
  498. #define P16 Pf7
  499. #define P17 Pf6
  500. #define P18 Pf5
  501. #define P19 Pf4
  502. #define P20 Pf1
  503. #define P21 Pf0
  504. #define P22 Pd4
  505. #define P23 Pd5
  506. #define P24 Pe6
  507. // Teensy 2.0
  508. #elif defined(__AVR_ATmega32U4__)
  509. // Arduino Leonardo pin numbers
  510. #define P0 Pd2 // D0 - PD2
  511. #define P1 Pd3 // D1 - PD3
  512. #define P2 Pd1 // D2 - PD1
  513. #define P3 Pd0 // D3 - PD0
  514. #define P4 Pd4 // D4 - PD4
  515. #define P5 Pc6 // D5 - PC6
  516. #define P6 Pd7 // D6 - PD7
  517. #define P7 Pe6 // D7 - PE6
  518. #define P8 Pb4 // D8 - PB4
  519. #define P9 Pb5 // D9 - PB5
  520. #define P10 Pb6 // D10 - PB6
  521. #define P11 Pb7 // D11 - PB7
  522. #define P12 Pd6 // D12 - PD6
  523. #define P13 Pc7 // D13 - PC7
  524. #define P14 Pb3 // D14 - MISO - PB3
  525. #define P15 Pb1 // D15 - SCK - PB1
  526. #define P16 Pb2 // D16 - MOSI - PB2
  527. #define P17 Pb0 // D17 - SS - PB0
  528. #define P18 Pf7 // D18 - A0 - PF7
  529. #define P19 Pf6 // D19 - A1 - PF6
  530. #define P20 Pf5 // D20 - A2 - PF5
  531. #define P21 Pf4 // D21 - A3 - PF4
  532. #define P22 Pf1 // D22 - A4 - PF1
  533. #define P23 Pf0 // D23 - A5 - PF0
  534. #define P24 Pd4 // D24 / D4 - A6 - PD4
  535. #define P25 Pd7 // D25 / D6 - A7 - PD7
  536. #define P26 Pb4 // D26 / D8 - A8 - PB4
  537. #define P27 Pb5 // D27 / D9 - A9 - PB5
  538. #define P28 Pb6 // D28 / D10 - A10 - PB6
  539. #define P29 Pd6 // D29 / D12 - A11 - PD6
  540. // Arduino Leonardo pin numbers
  541. #elif defined(CORE_TEENSY) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__))
  542. // Teensy++ 1.0 and 2.0 pin numbers
  543. // http://www.pjrc.com/teensy/pinout.html
  544. #define P0 Pd0
  545. #define P1 Pd1
  546. #define P2 Pd2
  547. #define P3 Pd3
  548. #define P4 Pd4
  549. #define P5 Pd5
  550. #define P6 Pd6
  551. #define P7 Pd7
  552. #define P8 Pe0
  553. #define P9 Pe1
  554. #define P10 Pc0
  555. #define P11 Pc1
  556. #define P12 Pc2
  557. #define P13 Pc3
  558. #define P14 Pc4
  559. #define P15 Pc5
  560. #define P16 Pc6
  561. #define P17 Pc7
  562. #define P18 Pe6
  563. #define P19 Pe7
  564. #define P20 Pb0
  565. #define P21 Pb1
  566. #define P22 Pb2
  567. #define P23 Pb3
  568. #define P24 Pb4
  569. #define P25 Pb5
  570. #define P26 Pb6
  571. #define P27 Pb7
  572. #define P28 Pa0
  573. #define P29 Pa1
  574. #define P30 Pa2
  575. #define P31 Pa3
  576. #define P32 Pa4
  577. #define P33 Pa5
  578. #define P34 Pa6
  579. #define P35 Pa7
  580. #define P36 Pe4
  581. #define P37 Pe5
  582. #define P38 Pf0
  583. #define P39 Pf1
  584. #define P40 Pf2
  585. #define P41 Pf3
  586. #define P42 Pf4
  587. #define P43 Pf5
  588. #define P44 Pf6
  589. #define P45 Pf7
  590. // Teensy++ 1.0 and 2.0
  591. #elif defined(ARDUINO_AVR_BALANDUINO) && (defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__))
  592. // Balanduino pin numbers
  593. // http://balanduino.net/
  594. #define P0 Pd0 /* 0 - PD0 */
  595. #define P1 Pd1 /* 1 - PD1 */
  596. #if BALANDUINO_REVISION < 13
  597. #define P2 Pb2 /* 2 - PB2 */
  598. #define P3 Pd6 /* 3 - PD6 */
  599. #define P4 Pd7 /* 4 - PD7 */
  600. #define P5 Pb3 /* 5 - PB3 */
  601. #else
  602. #define P2 Pd2 /* 2 - PD2 */
  603. #define P3 Pd3 /* 3 - PD3 */
  604. #define P4 Pd6 /* 4 - PD6 */
  605. #define P5 Pd7 /* 5 - PD7 */
  606. #endif
  607. #define P6 Pb4 /* 6 - PB4 */
  608. #define P7 Pa0 /* 7 - PA0 */
  609. #define P8 Pa1 /* 8 - PA1 */
  610. #define P9 Pa2 /* 9 - PA2 */
  611. #define P10 Pa3 /* 10 - PA3 */
  612. #define P11 Pa4 /* 11 - PA4 */
  613. #define P12 Pa5 /* 12 - PA5 */
  614. #define P13 Pc1 /* 13 - PC1 */
  615. #define P14 Pc0 /* 14 - PC0 */
  616. #if BALANDUINO_REVISION < 13
  617. #define P15 Pd2 /* 15 - PD2 */
  618. #define P16 Pd3 /* 16 - PD3 */
  619. #else
  620. #define P15 Pb2 /* 15 - PB2 */
  621. #define P16 Pb3 /* 16 - PB2 */
  622. #endif
  623. #define P17 Pd4 /* 17 - PD4 */
  624. #define P18 Pd5 /* 18 - PD5 */
  625. #define P19 Pc2 /* 19 - PC2 */
  626. #define P20 Pc3 /* 20 - PC3 */
  627. #define P21 Pc4 /* 21 - PC4 */
  628. #define P22 Pc5 /* 22 - PC5 */
  629. #define P23 Pc6 /* 23 - PC6 */
  630. #define P24 Pc7 /* 24 - PC7 */
  631. #define P25 Pb0 /* 25 - PB0 */
  632. #define P26 Pb1 /* 26 - PB1 */
  633. #define P27 Pb5 /* 27 - PB5 */
  634. #define P28 Pb6 /* 28 - PB6 */
  635. #define P29 Pb7 /* 29 - PB7 */
  636. #define P30 Pa6 /* 30 - PA6 */
  637. #define P31 Pa7 /* 31 - PA7 */
  638. // Balanduino
  639. #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
  640. // Sanguino pin numbers
  641. // Homepage: http://sanguino.cc/hardware
  642. // Hardware add-on: https://github.com/Lauszus/Sanguino
  643. #define P0 Pb0
  644. #define P1 Pb1
  645. #define P2 Pb2
  646. #define P3 Pb3
  647. #define P4 Pb4
  648. #define P5 Pb5
  649. #define P6 Pb6
  650. #define P7 Pb7
  651. #define P8 Pd0
  652. #define P9 Pd1
  653. #define P10 Pd2
  654. #define P11 Pd3
  655. #define P12 Pd4
  656. #define P13 Pd5
  657. #define P14 Pd6
  658. #define P15 Pd7
  659. #define P16 Pc0
  660. #define P17 Pc1
  661. #define P18 Pc2
  662. #define P19 Pc3
  663. #define P20 Pc4
  664. #define P21 Pc5
  665. #define P22 Pc6
  666. #define P23 Pc7
  667. #define P24 Pa0
  668. #define P25 Pa1
  669. #define P26 Pa2
  670. #define P27 Pa3
  671. #define P28 Pa4
  672. #define P29 Pa5
  673. #define P30 Pa6
  674. #define P31 Pa7
  675. // Sanguino
  676. #else
  677. #error "Please define board in avrpins.h"
  678. #endif // Arduino pin definitions
  679. #elif defined(__arm__)
  680. // pointers are 32 bits on ARM
  681. #define pgm_read_pointer(p) pgm_read_dword(p)
  682. #if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__))
  683. #include "core_pins.h"
  684. #include "avr_emulation.h"
  685. #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
  686. #define GPIO_BITBAND_PTR(reg, bit) ((uint8_t *)GPIO_BITBAND_ADDR((reg), (bit)))
  687. #define MAKE_PIN(className, baseReg, pinNum, configReg) \
  688. class className { \
  689. public: \
  690. static void Set() { \
  691. *GPIO_BITBAND_PTR(baseReg, pinNum) = 1; \
  692. } \
  693. static void Clear() { \
  694. *GPIO_BITBAND_PTR(baseReg, pinNum) = 0; \
  695. } \
  696. static void SetDirRead() { \
  697. configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
  698. *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 0; \
  699. } \
  700. static void SetDirWrite() { \
  701. configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \
  702. *(GPIO_BITBAND_PTR(baseReg, pinNum) + 640) = 1; \
  703. } \
  704. static uint8_t IsSet() { \
  705. return *(GPIO_BITBAND_PTR(baseReg, pinNum) + 512); \
  706. } \
  707. };
  708. MAKE_PIN(P0, CORE_PIN0_PORTREG, CORE_PIN0_BIT, CORE_PIN0_CONFIG);
  709. MAKE_PIN(P1, CORE_PIN1_PORTREG, CORE_PIN1_BIT, CORE_PIN1_CONFIG);
  710. MAKE_PIN(P2, CORE_PIN2_PORTREG, CORE_PIN2_BIT, CORE_PIN2_CONFIG);
  711. MAKE_PIN(P3, CORE_PIN3_PORTREG, CORE_PIN3_BIT, CORE_PIN3_CONFIG);
  712. MAKE_PIN(P4, CORE_PIN4_PORTREG, CORE_PIN4_BIT, CORE_PIN4_CONFIG);
  713. MAKE_PIN(P5, CORE_PIN5_PORTREG, CORE_PIN5_BIT, CORE_PIN5_CONFIG);
  714. MAKE_PIN(P6, CORE_PIN6_PORTREG, CORE_PIN6_BIT, CORE_PIN6_CONFIG);
  715. MAKE_PIN(P7, CORE_PIN7_PORTREG, CORE_PIN7_BIT, CORE_PIN7_CONFIG);
  716. MAKE_PIN(P8, CORE_PIN8_PORTREG, CORE_PIN8_BIT, CORE_PIN8_CONFIG);
  717. MAKE_PIN(P9, CORE_PIN9_PORTREG, CORE_PIN9_BIT, CORE_PIN9_CONFIG);
  718. MAKE_PIN(P10, CORE_PIN10_PORTREG, CORE_PIN10_BIT, CORE_PIN10_CONFIG);
  719. MAKE_PIN(P11, CORE_PIN11_PORTREG, CORE_PIN11_BIT, CORE_PIN11_CONFIG);
  720. MAKE_PIN(P12, CORE_PIN12_PORTREG, CORE_PIN12_BIT, CORE_PIN12_CONFIG);
  721. MAKE_PIN(P13, CORE_PIN13_PORTREG, CORE_PIN13_BIT, CORE_PIN13_CONFIG);
  722. MAKE_PIN(P14, CORE_PIN14_PORTREG, CORE_PIN14_BIT, CORE_PIN14_CONFIG);
  723. MAKE_PIN(P15, CORE_PIN15_PORTREG, CORE_PIN15_BIT, CORE_PIN15_CONFIG);
  724. MAKE_PIN(P16, CORE_PIN16_PORTREG, CORE_PIN16_BIT, CORE_PIN16_CONFIG);
  725. MAKE_PIN(P17, CORE_PIN17_PORTREG, CORE_PIN17_BIT, CORE_PIN17_CONFIG);
  726. MAKE_PIN(P18, CORE_PIN18_PORTREG, CORE_PIN18_BIT, CORE_PIN18_CONFIG);
  727. MAKE_PIN(P19, CORE_PIN19_PORTREG, CORE_PIN19_BIT, CORE_PIN19_CONFIG);
  728. MAKE_PIN(P20, CORE_PIN20_PORTREG, CORE_PIN20_BIT, CORE_PIN20_CONFIG);
  729. MAKE_PIN(P21, CORE_PIN21_PORTREG, CORE_PIN21_BIT, CORE_PIN21_CONFIG);
  730. MAKE_PIN(P22, CORE_PIN22_PORTREG, CORE_PIN22_BIT, CORE_PIN22_CONFIG);
  731. MAKE_PIN(P23, CORE_PIN23_PORTREG, CORE_PIN23_BIT, CORE_PIN23_CONFIG);
  732. MAKE_PIN(P24, CORE_PIN24_PORTREG, CORE_PIN24_BIT, CORE_PIN24_CONFIG);
  733. MAKE_PIN(P25, CORE_PIN25_PORTREG, CORE_PIN25_BIT, CORE_PIN25_CONFIG);
  734. MAKE_PIN(P26, CORE_PIN26_PORTREG, CORE_PIN26_BIT, CORE_PIN26_CONFIG);
  735. MAKE_PIN(P27, CORE_PIN27_PORTREG, CORE_PIN27_BIT, CORE_PIN27_CONFIG);
  736. MAKE_PIN(P28, CORE_PIN28_PORTREG, CORE_PIN28_BIT, CORE_PIN28_CONFIG);
  737. MAKE_PIN(P29, CORE_PIN29_PORTREG, CORE_PIN29_BIT, CORE_PIN29_CONFIG);
  738. MAKE_PIN(P30, CORE_PIN30_PORTREG, CORE_PIN30_BIT, CORE_PIN30_CONFIG);
  739. MAKE_PIN(P31, CORE_PIN31_PORTREG, CORE_PIN31_BIT, CORE_PIN31_CONFIG);
  740. MAKE_PIN(P32, CORE_PIN32_PORTREG, CORE_PIN32_BIT, CORE_PIN32_CONFIG);
  741. MAKE_PIN(P33, CORE_PIN33_PORTREG, CORE_PIN33_BIT, CORE_PIN33_CONFIG);
  742. #undef MAKE_PIN
  743. #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
  744. // SetDirRead:
  745. // Disable interrupts
  746. // Disable the pull up resistor
  747. // Set to INPUT
  748. // Enable PIO
  749. // SetDirWrite:
  750. // Disable interrupts
  751. // Disable the pull up resistor
  752. // Set to OUTPUT
  753. // Enable PIO
  754. #define MAKE_PIN(className, pio, pinMask) \
  755. class className { \
  756. public: \
  757. static void Set() { \
  758. pio->PIO_SODR = pinMask; \
  759. } \
  760. static void Clear() { \
  761. pio->PIO_CODR = pinMask; \
  762. } \
  763. static void SetDirRead() { \
  764. pio->PIO_IDR = pinMask ; \
  765. pio->PIO_PUDR = pinMask; \
  766. pio->PIO_ODR = pinMask; \
  767. pio->PIO_PER = pinMask; \
  768. } \
  769. static void SetDirWrite() { \
  770. pio->PIO_IDR = pinMask ; \
  771. pio->PIO_PUDR = pinMask; \
  772. pio->PIO_OER = pinMask; \
  773. pio->PIO_PER = pinMask; \
  774. } \
  775. static uint8_t IsSet() { \
  776. return pio->PIO_PDSR & pinMask; \
  777. } \
  778. };
  779. // See: http://arduino.cc/en/Hacking/PinMappingSAM3X and variant.cpp
  780. MAKE_PIN(P0, PIOA, PIO_PA8);
  781. MAKE_PIN(P1, PIOA, PIO_PA9);
  782. MAKE_PIN(P2, PIOB, PIO_PB25);
  783. MAKE_PIN(P3, PIOC, PIO_PC28);
  784. MAKE_PIN(P4, PIOC, PIO_PC26);
  785. MAKE_PIN(P5, PIOC, PIO_PC25);
  786. MAKE_PIN(P6, PIOC, PIO_PC24);
  787. MAKE_PIN(P7, PIOC, PIO_PC23);
  788. MAKE_PIN(P8, PIOC, PIO_PC22);
  789. MAKE_PIN(P9, PIOC, PIO_PC21);
  790. MAKE_PIN(P10, PIOC, PIO_PC29);
  791. MAKE_PIN(P11, PIOD, PIO_PD7);
  792. MAKE_PIN(P12, PIOD, PIO_PD8);
  793. MAKE_PIN(P13, PIOB, PIO_PB27);
  794. MAKE_PIN(P14, PIOD, PIO_PD4);
  795. MAKE_PIN(P15, PIOD, PIO_PD5);
  796. MAKE_PIN(P16, PIOA, PIO_PA13);
  797. MAKE_PIN(P17, PIOA, PIO_PA12);
  798. MAKE_PIN(P18, PIOA, PIO_PA11);
  799. MAKE_PIN(P19, PIOA, PIO_PA10);
  800. MAKE_PIN(P20, PIOB, PIO_PB12);
  801. MAKE_PIN(P21, PIOB, PIO_PB13);
  802. MAKE_PIN(P22, PIOB, PIO_PB26);
  803. MAKE_PIN(P23, PIOA, PIO_PA14);
  804. MAKE_PIN(P24, PIOA, PIO_PA15);
  805. MAKE_PIN(P25, PIOD, PIO_PD0);
  806. MAKE_PIN(P26, PIOD, PIO_PD1);
  807. MAKE_PIN(P27, PIOD, PIO_PD2);
  808. MAKE_PIN(P28, PIOD, PIO_PD3);
  809. MAKE_PIN(P29, PIOD, PIO_PD6);
  810. MAKE_PIN(P30, PIOD, PIO_PD9);
  811. MAKE_PIN(P31, PIOA, PIO_PA7);
  812. MAKE_PIN(P32, PIOD, PIO_PD10);
  813. MAKE_PIN(P33, PIOC, PIO_PC1);
  814. MAKE_PIN(P34, PIOC, PIO_PC2);
  815. MAKE_PIN(P35, PIOC, PIO_PC3);
  816. MAKE_PIN(P36, PIOC, PIO_PC4);
  817. MAKE_PIN(P37, PIOC, PIO_PC5);
  818. MAKE_PIN(P38, PIOC, PIO_PC6);
  819. MAKE_PIN(P39, PIOC, PIO_PC7);
  820. MAKE_PIN(P40, PIOC, PIO_PC8);
  821. MAKE_PIN(P41, PIOC, PIO_PC9);
  822. MAKE_PIN(P42, PIOA, PIO_PA19);
  823. MAKE_PIN(P43, PIOA, PIO_PA20);
  824. MAKE_PIN(P44, PIOC, PIO_PC19);
  825. MAKE_PIN(P45, PIOC, PIO_PC18);
  826. MAKE_PIN(P46, PIOC, PIO_PC17);
  827. MAKE_PIN(P47, PIOC, PIO_PC16);
  828. MAKE_PIN(P48, PIOC, PIO_PC15);
  829. MAKE_PIN(P49, PIOC, PIO_PC14);
  830. MAKE_PIN(P50, PIOC, PIO_PC13);
  831. MAKE_PIN(P51, PIOC, PIO_PC12);
  832. MAKE_PIN(P52, PIOB, PIO_PB21);
  833. MAKE_PIN(P53, PIOB, PIO_PB14);
  834. MAKE_PIN(P54, PIOA, PIO_PA16);
  835. MAKE_PIN(P55, PIOA, PIO_PA24);
  836. MAKE_PIN(P56, PIOA, PIO_PA23);
  837. MAKE_PIN(P57, PIOA, PIO_PA22);
  838. MAKE_PIN(P58, PIOA, PIO_PA6);
  839. MAKE_PIN(P59, PIOA, PIO_PA4);
  840. MAKE_PIN(P60, PIOA, PIO_PA3);
  841. MAKE_PIN(P61, PIOA, PIO_PA2);
  842. MAKE_PIN(P62, PIOB, PIO_PB17);
  843. MAKE_PIN(P63, PIOB, PIO_PB18);
  844. MAKE_PIN(P64, PIOB, PIO_PB19);
  845. MAKE_PIN(P65, PIOB, PIO_PB20);
  846. MAKE_PIN(P66, PIOB, PIO_PB15);
  847. MAKE_PIN(P67, PIOB, PIO_PB16);
  848. MAKE_PIN(P68, PIOA, PIO_PA1);
  849. MAKE_PIN(P69, PIOA, PIO_PA0);
  850. MAKE_PIN(P70, PIOA, PIO_PA17);
  851. MAKE_PIN(P71, PIOA, PIO_PA18);
  852. MAKE_PIN(P72, PIOC, PIO_PC30);
  853. MAKE_PIN(P73, PIOA, PIO_PA21);
  854. MAKE_PIN(P74, PIOA, PIO_PA25); // MISO
  855. MAKE_PIN(P75, PIOA, PIO_PA26); // MOSI
  856. MAKE_PIN(P76, PIOA, PIO_PA27); // CLK
  857. MAKE_PIN(P77, PIOA, PIO_PA28);
  858. MAKE_PIN(P78, PIOB, PIO_PB23); // Unconnected
  859. #undef MAKE_PIN
  860. #elif defined(RBL_NRF51822)
  861. #define MAKE_PIN(className, pin) \
  862. class className { \
  863. public: \
  864. static void Set() { \
  865. nrf_gpio_pin_set(pin); \
  866. } \
  867. static void Clear() { \
  868. nrf_gpio_pin_clear(pin); \
  869. } \
  870. static void SetDirRead() { \
  871. nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \
  872. } \
  873. static void SetDirWrite() { \
  874. nrf_gpio_cfg_output(pin); \
  875. } \
  876. static uint8_t IsSet() { \
  877. return (uint8_t)nrf_gpio_pin_read(pin); \
  878. } \
  879. };
  880. // See: pin_transform.c in RBL nRF51822 SDK
  881. MAKE_PIN(P0, Pin_nRF51822_to_Arduino(D0));
  882. MAKE_PIN(P1, Pin_nRF51822_to_Arduino(D1));
  883. MAKE_PIN(P2, Pin_nRF51822_to_Arduino(D2));
  884. MAKE_PIN(P3, Pin_nRF51822_to_Arduino(D3));
  885. MAKE_PIN(P4, Pin_nRF51822_to_Arduino(D4));
  886. MAKE_PIN(P5, Pin_nRF51822_to_Arduino(D5));
  887. MAKE_PIN(P6, Pin_nRF51822_to_Arduino(D6));
  888. MAKE_PIN(P7, Pin_nRF51822_to_Arduino(D7));
  889. MAKE_PIN(P8, Pin_nRF51822_to_Arduino(D8));
  890. MAKE_PIN(P9, Pin_nRF51822_to_Arduino(D9)); // INT
  891. MAKE_PIN(P10, Pin_nRF51822_to_Arduino(D10)); // SS
  892. MAKE_PIN(P11, Pin_nRF51822_to_Arduino(D11));
  893. MAKE_PIN(P12, Pin_nRF51822_to_Arduino(D12));
  894. MAKE_PIN(P13, Pin_nRF51822_to_Arduino(D13));
  895. MAKE_PIN(P14, Pin_nRF51822_to_Arduino(D14));
  896. MAKE_PIN(P15, Pin_nRF51822_to_Arduino(D15));
  897. MAKE_PIN(P17, Pin_nRF51822_to_Arduino(D17)); // MISO
  898. MAKE_PIN(P18, Pin_nRF51822_to_Arduino(D18)); // MOSI
  899. MAKE_PIN(P16, Pin_nRF51822_to_Arduino(D16)); // CLK
  900. MAKE_PIN(P19, Pin_nRF51822_to_Arduino(D19));
  901. MAKE_PIN(P20, Pin_nRF51822_to_Arduino(D20));
  902. MAKE_PIN(P21, Pin_nRF51822_to_Arduino(D21));
  903. MAKE_PIN(P22, Pin_nRF51822_to_Arduino(D22));
  904. MAKE_PIN(P23, Pin_nRF51822_to_Arduino(D23));
  905. MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24));
  906. #undef MAKE_PIN
  907. #else
  908. #error "Please define board in avrpins.h"
  909. #endif
  910. #elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison
  911. #include <avr/pgmspace.h>
  912. // Pointers are 32 bits on x86
  913. #define pgm_read_pointer(p) pgm_read_dword(p)
  914. #if PLATFORM_ID == 0xE1 // Edison platform id
  915. #define pinToFastPin(pin) 1 // As far as I can tell all pins can be used as fast pins
  916. #endif
  917. // Pin 2 and 3 on the Intel Galileo supports a higher rate,
  918. // so it is recommended to use one of these as the SS pin.
  919. #define MAKE_PIN(className, pin) \
  920. class className { \
  921. public: \
  922. static void Set() { \
  923. fastDigitalWrite(pin, HIGH); \
  924. } \
  925. static void Clear() { \
  926. fastDigitalWrite(pin, LOW); \
  927. } \
  928. static void SetDirRead() { \
  929. if (pinToFastPin(pin)) \
  930. pinMode(pin, INPUT_FAST); \
  931. else \
  932. pinMode(pin, INPUT); \
  933. } \
  934. static void SetDirWrite() { \
  935. if (pinToFastPin(pin)) \
  936. pinMode(pin, OUTPUT_FAST); \
  937. else \
  938. pinMode(pin, OUTPUT); \
  939. } \
  940. static uint8_t IsSet() { \
  941. return fastDigitalRead(pin); \
  942. } \
  943. };
  944. MAKE_PIN(P0, 0);
  945. MAKE_PIN(P1, 1);
  946. MAKE_PIN(P2, 2);
  947. MAKE_PIN(P3, 3);
  948. MAKE_PIN(P4, 4);
  949. MAKE_PIN(P5, 5);
  950. MAKE_PIN(P6, 6);
  951. MAKE_PIN(P7, 7);
  952. MAKE_PIN(P8, 8);
  953. MAKE_PIN(P9, 9);
  954. MAKE_PIN(P10, 10);
  955. MAKE_PIN(P11, 11);
  956. MAKE_PIN(P12, 12);
  957. MAKE_PIN(P13, 13);
  958. MAKE_PIN(P14, 14); // A0
  959. MAKE_PIN(P15, 15); // A1
  960. MAKE_PIN(P16, 16); // A2
  961. MAKE_PIN(P17, 17); // A3
  962. MAKE_PIN(P18, 18); // A4
  963. MAKE_PIN(P19, 19); // A5
  964. #undef MAKE_PIN
  965. #elif defined(__MIPSEL__)
  966. // MIPSEL (MIPS architecture using a little endian byte order)
  967. // MIPS size_t = 4
  968. #define pgm_read_pointer(p) pgm_read_dword(p)
  969. #define MAKE_PIN(className, pin) \
  970. class className { \
  971. public: \
  972. static void Set() { \
  973. digitalWrite(pin, HIGH);\
  974. } \
  975. static void Clear() { \
  976. digitalWrite(pin, LOW); \
  977. } \
  978. static void SetDirRead() { \
  979. pinMode(pin, INPUT); \
  980. } \
  981. static void SetDirWrite() { \
  982. pinMode(pin, OUTPUT); \
  983. } \
  984. static uint8_t IsSet() { \
  985. return digitalRead(pin); \
  986. } \
  987. };
  988. // 0 .. 13 - Digital pins
  989. MAKE_PIN(P0, 0); // RX
  990. MAKE_PIN(P1, 1); // TX
  991. MAKE_PIN(P2, 2); //
  992. MAKE_PIN(P3, 3); //
  993. MAKE_PIN(P4, 4); //
  994. MAKE_PIN(P5, 5); //
  995. MAKE_PIN(P6, 6); //
  996. MAKE_PIN(P7, 7); //
  997. MAKE_PIN(P8, 8); //
  998. MAKE_PIN(P9, 9); //
  999. MAKE_PIN(P10, 10); //
  1000. MAKE_PIN(P11, 11); //
  1001. MAKE_PIN(P12, 12); //
  1002. MAKE_PIN(P13, 13); //
  1003. #undef MAKE_PIN
  1004. #else
  1005. #error "Please define board in avrpins.h"
  1006. #endif
  1007. #endif //_avrpins_h_