gpio_avr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. /*!
  2. * Copyright (C) 2007 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. */
  32. /*!
  33. * $Id: gpio_avr.c 5194 2013-06-11 12:33:49Z u_bonnes $
  34. */
  35. #include <arch/avr.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <dev/gpio.h>
  39. int GpioPinGet(int bank, int bit)
  40. {
  41. switch(bank) {
  42. #ifdef PINA
  43. case AVRPORTA:
  44. return bit_is_set(PINA, bit) != 0;
  45. #endif
  46. #ifdef PINB
  47. case AVRPORTB:
  48. return bit_is_set(PINB, bit) != 0;
  49. #endif
  50. #ifdef PINC
  51. case AVRPORTC:
  52. return bit_is_set(PINC, bit) != 0;
  53. #endif
  54. #ifdef PIND
  55. case AVRPORTD:
  56. return bit_is_set(PIND, bit) != 0;
  57. #endif
  58. #ifdef PINE
  59. case AVRPORTE:
  60. return bit_is_set(PINE, bit) != 0;
  61. #endif
  62. #ifdef PINF
  63. case AVRPORTF:
  64. return bit_is_set(PINF, bit) != 0;
  65. #endif
  66. #ifdef PING
  67. case AVRPORTG:
  68. return bit_is_set(PING, bit) != 0;
  69. #endif
  70. #ifdef PINH
  71. case AVRPORTH:
  72. return bit_is_set(PINH, bit) != 0;
  73. #endif
  74. #ifdef PINI
  75. case AVRPORTI:
  76. return bit_is_set(PINI, bit) != 0;
  77. #endif
  78. #ifdef PINJ
  79. case AVRPORTJ:
  80. return bit_is_set(PINJ, bit) != 0;
  81. #endif
  82. #ifdef PINK
  83. case AVRPORTK:
  84. return bit_is_set(PINK, bit) != 0;
  85. #endif
  86. #ifdef PINL
  87. case AVRPORTL:
  88. return bit_is_set(PINL, bit) != 0;
  89. #endif
  90. }
  91. return 0;
  92. }
  93. void GpioPinSetLow(int bank, int bit)
  94. {
  95. switch(bank) {
  96. #ifdef PORTA
  97. case AVRPORTA:
  98. cbi(PORTA, bit);
  99. break;
  100. #endif
  101. #ifdef PORTB
  102. case AVRPORTB:
  103. cbi(PORTB, bit);
  104. break;
  105. #endif
  106. #ifdef PORTC
  107. case AVRPORTC:
  108. cbi(PORTC, bit);
  109. break;
  110. #endif
  111. #ifdef PORTD
  112. case AVRPORTD:
  113. cbi(PORTD, bit);
  114. break;
  115. #endif
  116. #ifdef PORTE
  117. case AVRPORTE:
  118. cbi(PORTE, bit);
  119. break;
  120. #endif
  121. #ifdef PORTF
  122. case AVRPORTF:
  123. cbi(PORTF, bit);
  124. break;
  125. #endif
  126. #ifdef PORTG
  127. case AVRPORTG:
  128. cbi(PORTG, bit);
  129. break;
  130. #endif
  131. #ifdef PORTH
  132. case AVRPORTH:
  133. cbi(PORTH, bit);
  134. break;
  135. #endif
  136. #ifdef PORTI
  137. case AVRPORTI:
  138. cbi(PORTI, bit);
  139. break;
  140. #endif
  141. #ifdef PORTJ
  142. case AVRPORTJ:
  143. cbi(PORTJ, bit);
  144. break;
  145. #endif
  146. #ifdef PORTK
  147. case AVRPORTK:
  148. cbi(PORTK, bit);
  149. break;
  150. #endif
  151. #ifdef PORTL
  152. case AVRPORTL:
  153. cbi(PORTL, bit);
  154. break;
  155. #endif
  156. }
  157. }
  158. void GpioPinSetHigh(int bank, int bit)
  159. {
  160. switch(bank) {
  161. #ifdef PORTA
  162. case AVRPORTA:
  163. sbi(PORTA, bit);
  164. break;
  165. #endif
  166. #ifdef PORTB
  167. case AVRPORTB:
  168. sbi(PORTB, bit);
  169. break;
  170. #endif
  171. #ifdef PORTC
  172. case AVRPORTC:
  173. sbi(PORTC, bit);
  174. break;
  175. #endif
  176. #ifdef PORTD
  177. case AVRPORTD:
  178. sbi(PORTD, bit);
  179. break;
  180. #endif
  181. #ifdef PORTE
  182. case AVRPORTE:
  183. sbi(PORTE, bit);
  184. break;
  185. #endif
  186. #ifdef PORTF
  187. case AVRPORTF:
  188. sbi(PORTF, bit);
  189. break;
  190. #endif
  191. #ifdef PORTG
  192. case AVRPORTG:
  193. sbi(PORTG, bit);
  194. break;
  195. #endif
  196. #ifdef PORTH
  197. case AVRPORTH:
  198. sbi(PORTH, bit);
  199. break;
  200. #endif
  201. #ifdef PORTI
  202. case AVRPORTI:
  203. sbi(PORTI, bit);
  204. break;
  205. #endif
  206. #ifdef PORTJ
  207. case AVRPORTJ:
  208. sbi(PORTJ, bit);
  209. break;
  210. #endif
  211. #ifdef PORTK
  212. case AVRPORTK:
  213. sbi(PORTK, bit);
  214. break;
  215. #endif
  216. #ifdef PORTL
  217. case AVRPORTL:
  218. sbi(PORTL, bit);
  219. break;
  220. #endif
  221. }
  222. }
  223. void GpioPinSet(int bank, int bit, int value)
  224. {
  225. if (value) {
  226. GpioPinSetHigh(bank, bit);
  227. }
  228. else {
  229. GpioPinSetLow(bank, bit);
  230. }
  231. }
  232. unsigned int GpioPortGet(int bank)
  233. {
  234. switch(bank) {
  235. #ifdef PINA
  236. case AVRPORTA:
  237. return inb(PINA);
  238. #endif
  239. #ifdef PINB
  240. case AVRPORTB:
  241. return inb(PINB);
  242. #endif
  243. #ifdef PINC
  244. case AVRPORTC:
  245. return inb(PINC);
  246. #endif
  247. #ifdef PIND
  248. case AVRPORTD:
  249. return inb(PIND);
  250. #endif
  251. #ifdef PINE
  252. case AVRPORTE:
  253. return inb(PINE);
  254. #endif
  255. #ifdef PINF
  256. case AVRPORTF:
  257. return inb(PINF);
  258. #endif
  259. #ifdef PING
  260. case AVRPORTG:
  261. return inb(PING);
  262. #endif
  263. #ifdef PINH
  264. case AVRPORTH:
  265. return inb(PINH);
  266. #endif
  267. #ifdef PINI
  268. case AVRPORTI:
  269. return inb(PINI);
  270. #endif
  271. #ifdef PINJ
  272. case AVRPORTJ:
  273. return inb(PINJ);
  274. #endif
  275. #ifdef PINK
  276. case AVRPORTK:
  277. return inb(PINK);
  278. #endif
  279. #ifdef PINL
  280. case AVRPORTL:
  281. return inb(PINL);
  282. #endif
  283. }
  284. return 0;
  285. }
  286. void GpioPortSet(int bank, unsigned int value)
  287. {
  288. switch(bank) {
  289. #ifdef PORTA
  290. case AVRPORTA:
  291. outb(PORTA, (uint8_t)value);
  292. break;
  293. #endif
  294. #ifdef PORTB
  295. case AVRPORTB:
  296. outb(PORTB, (uint8_t)value);
  297. break;
  298. #endif
  299. #ifdef PORTC
  300. case AVRPORTC:
  301. outb(PORTC, (uint8_t)value);
  302. break;
  303. #endif
  304. #ifdef PORTD
  305. case AVRPORTD:
  306. outb(PORTD, (uint8_t)value);
  307. break;
  308. #endif
  309. #ifdef PORTE
  310. case AVRPORTE:
  311. outb(PORTE, (uint8_t)value);
  312. break;
  313. #endif
  314. #ifdef PORTF
  315. case AVRPORTF:
  316. outb(PORTF, (uint8_t)value);
  317. break;
  318. #endif
  319. #ifdef PORTG
  320. case AVRPORTG:
  321. outb(PORTG, (uint8_t)value);
  322. break;
  323. #endif
  324. #ifdef PORTH
  325. case AVRPORTH:
  326. outb(PORTH, (uint8_t)value);
  327. break;
  328. #endif
  329. #ifdef PORTI
  330. case AVRPORTI:
  331. outb(PORTI, (uint8_t)value);
  332. break;
  333. #endif
  334. #ifdef PORTJ
  335. case AVRPORTJ:
  336. outb(PORTJ, (uint8_t)value);
  337. break;
  338. #endif
  339. #ifdef PORTK
  340. case AVRPORTK:
  341. outb(PORTK, (uint8_t)value);
  342. break;
  343. #endif
  344. #ifdef PORTL
  345. case AVRPORTL:
  346. outb(PORTL, (uint8_t)value);
  347. break;
  348. #endif
  349. }
  350. }
  351. void GpioPortSetLow(int bank, unsigned int mask)
  352. {
  353. GpioPortSet(bank, GpioPortGet(bank) & ~mask);
  354. }
  355. void GpioPortSetHigh(int bank, unsigned int mask)
  356. {
  357. GpioPortSet(bank, GpioPortGet(bank) | mask);
  358. }
  359. uint32_t GpioPinConfigGet(int bank, int bit)
  360. {
  361. uint32_t rc = 0;
  362. switch(bank) {
  363. #ifdef DDRA
  364. case AVRPORTA:
  365. if (inb(DDRA) & _BV(bit)) {
  366. rc |= GPIO_CFG_OUTPUT;
  367. }
  368. else if (inb(PORTA) & _BV(bit)) {
  369. rc |= GPIO_CFG_PULLUP;
  370. }
  371. break;
  372. #endif
  373. #ifdef DDRB
  374. case AVRPORTB:
  375. if (inb(DDRB) & _BV(bit)) {
  376. rc |= GPIO_CFG_OUTPUT;
  377. }
  378. else if (inb(PORTB) & _BV(bit)) {
  379. rc |= GPIO_CFG_PULLUP;
  380. }
  381. break;
  382. #endif
  383. #ifdef DDRC
  384. case AVRPORTC:
  385. if (inb(DDRC) & _BV(bit)) {
  386. rc |= GPIO_CFG_OUTPUT;
  387. }
  388. else if (inb(PORTC) & _BV(bit)) {
  389. rc |= GPIO_CFG_PULLUP;
  390. }
  391. break;
  392. #endif
  393. #ifdef DDRD
  394. case AVRPORTD:
  395. if (inb(DDRD) & _BV(bit)) {
  396. rc |= GPIO_CFG_OUTPUT;
  397. }
  398. else if (inb(PORTD) & _BV(bit)) {
  399. rc |= GPIO_CFG_PULLUP;
  400. }
  401. break;
  402. #endif
  403. #ifdef DDRE
  404. case AVRPORTE:
  405. if (inb(DDRE) & _BV(bit)) {
  406. rc |= GPIO_CFG_OUTPUT;
  407. }
  408. else if (inb(PORTE) & _BV(bit)) {
  409. rc |= GPIO_CFG_PULLUP;
  410. }
  411. break;
  412. #endif
  413. #ifdef DDRF
  414. case AVRPORTF:
  415. if (inb(DDRF) & _BV(bit)) {
  416. rc |= GPIO_CFG_OUTPUT;
  417. }
  418. else if (inb(PORTF) & _BV(bit)) {
  419. rc |= GPIO_CFG_PULLUP;
  420. }
  421. break;
  422. #endif
  423. #ifdef DDRG
  424. case AVRPORTG:
  425. if (inb(DDRG) & _BV(bit)) {
  426. rc |= GPIO_CFG_OUTPUT;
  427. }
  428. else if (inb(PORTG) & _BV(bit)) {
  429. rc |= GPIO_CFG_PULLUP;
  430. }
  431. break;
  432. #endif
  433. #ifdef DDRH
  434. case AVRPORTH:
  435. if (inb(DDRH) & _BV(bit)) {
  436. rc |= GPIO_CFG_OUTPUT;
  437. }
  438. else if (inb(PORTH) & _BV(bit)) {
  439. rc |= GPIO_CFG_PULLUP;
  440. }
  441. break;
  442. #endif
  443. #ifdef DDRI
  444. case AVRPORTI:
  445. if (inb(DDRI) & _BV(bit)) {
  446. rc |= GPIO_CFG_OUTPUT;
  447. }
  448. else if (inb(PORTI) & _BV(bit)) {
  449. rc |= GPIO_CFG_PULLUP;
  450. }
  451. break;
  452. #endif
  453. #ifdef DDRJ
  454. case AVRPORTJ:
  455. if (inb(DDRJ) & _BV(bit)) {
  456. rc |= GPIO_CFG_OUTPUT;
  457. }
  458. else if (inb(PORTJ) & _BV(bit)) {
  459. rc |= GPIO_CFG_PULLUP;
  460. }
  461. break;
  462. #endif
  463. #ifdef DDRK
  464. case AVRPORTK:
  465. if (inb(DDRK) & _BV(bit)) {
  466. rc |= GPIO_CFG_OUTPUT;
  467. }
  468. else if (inb(PORTK) & _BV(bit)) {
  469. rc |= GPIO_CFG_PULLUP;
  470. }
  471. break;
  472. #endif
  473. #ifdef DDRL
  474. case AVRPORTL:
  475. if (inb(DDRL) & _BV(bit)) {
  476. rc |= GPIO_CFG_OUTPUT;
  477. }
  478. else if (inb(PORTL) & _BV(bit)) {
  479. rc |= GPIO_CFG_PULLUP;
  480. }
  481. break;
  482. #endif
  483. }
  484. return rc;
  485. }
  486. int GpioPortConfigSet(int bank, unsigned int mask, uint32_t flags)
  487. {
  488. switch(bank) {
  489. #ifdef DDRA
  490. case AVRPORTA:
  491. if (flags & GPIO_CFG_PULLUP) {
  492. outb(PORTA, inb(PORTA) | mask);
  493. }
  494. else {
  495. outb(PORTA, inb(PORTA) & ~mask);
  496. }
  497. if (flags & GPIO_CFG_OUTPUT) {
  498. outb(DDRA, inb(DDRA) | mask);
  499. }
  500. else {
  501. outb(DDRA, inb(DDRA) & ~mask);
  502. }
  503. break;
  504. #endif
  505. #ifdef DDRB
  506. case AVRPORTB:
  507. if (flags & GPIO_CFG_PULLUP) {
  508. outb(PORTB, inb(PORTB) | mask);
  509. }
  510. else {
  511. outb(PORTB, inb(PORTB) & ~mask);
  512. }
  513. if (flags & GPIO_CFG_OUTPUT) {
  514. outb(DDRB, inb(DDRB) | mask);
  515. }
  516. else {
  517. outb(DDRB, inb(DDRB) & ~mask);
  518. }
  519. break;
  520. #endif
  521. #ifdef DDRC
  522. case AVRPORTC:
  523. if (flags & GPIO_CFG_PULLUP) {
  524. outb(PORTC, inb(PORTC) | mask);
  525. }
  526. else {
  527. outb(PORTC, inb(PORTC) & ~mask);
  528. }
  529. if (flags & GPIO_CFG_OUTPUT) {
  530. outb(DDRC, inb(DDRC) | mask);
  531. }
  532. else {
  533. outb(DDRC, inb(DDRC) & ~mask);
  534. }
  535. break;
  536. #endif
  537. #ifdef DDRD
  538. case AVRPORTD:
  539. if (flags & GPIO_CFG_PULLUP) {
  540. outb(PORTD, inb(PORTD) | mask);
  541. }
  542. else {
  543. outb(PORTD, inb(PORTD) & ~mask);
  544. }
  545. if (flags & GPIO_CFG_OUTPUT) {
  546. outb(DDRD, inb(DDRD) | mask);
  547. }
  548. else {
  549. outb(DDRD, inb(DDRD) & ~mask);
  550. }
  551. break;
  552. #endif
  553. #ifdef DDRE
  554. case AVRPORTE:
  555. if (flags & GPIO_CFG_PULLUP) {
  556. outb(PORTE, inb(PORTE) | mask);
  557. }
  558. else {
  559. outb(PORTE, inb(PORTE) & ~mask);
  560. }
  561. if (flags & GPIO_CFG_OUTPUT) {
  562. outb(DDRE, inb(DDRE) | mask);
  563. }
  564. else {
  565. outb(DDRE, inb(DDRE) & ~mask);
  566. }
  567. break;
  568. #endif
  569. #ifdef DDRF
  570. case AVRPORTF:
  571. if (flags & GPIO_CFG_PULLUP) {
  572. outb(PORTF, inb(PORTF) | mask);
  573. }
  574. else {
  575. outb(PORTF, inb(PORTF) & ~mask);
  576. }
  577. if (flags & GPIO_CFG_OUTPUT) {
  578. outb(DDRF, inb(DDRF) | mask);
  579. }
  580. else {
  581. outb(DDRF, inb(DDRF) & ~mask);
  582. }
  583. break;
  584. #endif
  585. #ifdef DDRG
  586. case AVRPORTG:
  587. if (flags & GPIO_CFG_PULLUP) {
  588. outb(PORTG, inb(PORTG) | mask);
  589. }
  590. else {
  591. outb(PORTG, inb(PORTG) & ~mask);
  592. }
  593. if (flags & GPIO_CFG_OUTPUT) {
  594. outb(DDRG, inb(DDRG) | mask);
  595. }
  596. else {
  597. outb(DDRG, inb(DDRG) & ~mask);
  598. }
  599. break;
  600. #endif
  601. #ifdef DDRH
  602. case AVRPORTH:
  603. if (flags & GPIO_CFG_PULLUP) {
  604. outb(PORTH, inb(PORTH) | mask);
  605. }
  606. else {
  607. outb(PORTH, inb(PORTH) & ~mask);
  608. }
  609. if (flags & GPIO_CFG_OUTPUT) {
  610. outb(DDRH, inb(DDRH) | mask);
  611. }
  612. else {
  613. outb(DDRH, inb(DDRH) & ~mask);
  614. }
  615. break;
  616. #endif
  617. #ifdef DDRI
  618. case AVRPORTI:
  619. if (flags & GPIO_CFG_PULLUP) {
  620. outb(PORTI, inb(PORTI) | mask);
  621. }
  622. else {
  623. outb(PORTI, inb(PORTI) & ~mask);
  624. }
  625. if (flags & GPIO_CFG_OUTPUT) {
  626. outb(DDRI, inb(DDRI) | mask);
  627. }
  628. else {
  629. outb(DDRI, inb(DDRI) & ~mask);
  630. }
  631. break;
  632. #endif
  633. #ifdef DDRJ
  634. case AVRPORTJ:
  635. if (flags & GPIO_CFG_PULLUP) {
  636. outb(PORTJ, inb(PORTJ) | mask);
  637. }
  638. else {
  639. outb(PORTJ, inb(PORTJ) & ~mask);
  640. }
  641. if (flags & GPIO_CFG_OUTPUT) {
  642. outb(DDRJ, inb(DDRJ) | mask);
  643. }
  644. else {
  645. outb(DDRJ, inb(DDRJ) & ~mask);
  646. }
  647. break;
  648. #endif
  649. #ifdef DDRK
  650. case AVRPORTK:
  651. if (flags & GPIO_CFG_PULLUP) {
  652. outb(PORTK, inb(PORTK) | mask);
  653. }
  654. else {
  655. outb(PORTK, inb(PORTK) & ~mask);
  656. }
  657. if (flags & GPIO_CFG_OUTPUT) {
  658. outb(DDRK, inb(DDRK) | mask);
  659. }
  660. else {
  661. outb(DDRK, inb(DDRK) & ~mask);
  662. }
  663. break;
  664. #endif
  665. #ifdef DDRL
  666. case AVRPORTL:
  667. if (flags & GPIO_CFG_PULLUP) {
  668. outb(PORTL, inb(PORTL) | mask);
  669. }
  670. else {
  671. outb(PORTL, inb(PORTL) & ~mask);
  672. }
  673. if (flags & GPIO_CFG_OUTPUT) {
  674. outb(DDRL, inb(DDRL) | mask);
  675. }
  676. else {
  677. outb(DDRL, inb(DDRL) & ~mask);
  678. }
  679. break;
  680. #endif
  681. }
  682. return 0;
  683. }
  684. int GpioPinConfigSet(int bank, int bit, uint32_t flags)
  685. {
  686. switch(bank) {
  687. #ifdef DDRA
  688. case AVRPORTA:
  689. if (flags & GPIO_CFG_OUTPUT) {
  690. sbi(DDRA, bit);
  691. }
  692. else {
  693. if (flags & GPIO_CFG_PULLUP) {
  694. sbi(PORTA, bit);
  695. }
  696. else {
  697. cbi(PORTA, bit);
  698. }
  699. cbi(DDRA, bit);
  700. }
  701. break;
  702. #endif
  703. #ifdef DDRB
  704. case AVRPORTB:
  705. if (flags & GPIO_CFG_OUTPUT) {
  706. sbi(DDRB, bit);
  707. }
  708. else {
  709. if (flags & GPIO_CFG_PULLUP) {
  710. sbi(PORTB, bit);
  711. }
  712. else {
  713. cbi(PORTB, bit);
  714. }
  715. cbi(DDRB, bit);
  716. }
  717. break;
  718. #endif
  719. #ifdef DDRC
  720. case AVRPORTC:
  721. if (flags & GPIO_CFG_OUTPUT) {
  722. sbi(DDRC, bit);
  723. }
  724. else {
  725. if (flags & GPIO_CFG_PULLUP) {
  726. sbi(PORTC, bit);
  727. }
  728. else {
  729. cbi(PORTC, bit);
  730. }
  731. cbi(DDRC, bit);
  732. }
  733. break;
  734. #endif
  735. #ifdef DDRD
  736. case AVRPORTD:
  737. if (flags & GPIO_CFG_OUTPUT) {
  738. sbi(DDRD, bit);
  739. }
  740. else {
  741. if (flags & GPIO_CFG_PULLUP) {
  742. sbi(PORTD, bit);
  743. }
  744. else {
  745. cbi(PORTD, bit);
  746. }
  747. cbi(DDRD, bit);
  748. }
  749. break;
  750. #endif
  751. #ifdef DDRE
  752. case AVRPORTE:
  753. if (flags & GPIO_CFG_OUTPUT) {
  754. sbi(DDRE, bit);
  755. }
  756. else {
  757. if (flags & GPIO_CFG_PULLUP) {
  758. sbi(PORTE, bit);
  759. }
  760. else {
  761. cbi(PORTE, bit);
  762. }
  763. cbi(DDRE, bit);
  764. }
  765. break;
  766. #endif
  767. #ifdef DDRF
  768. case AVRPORTF:
  769. if (flags & GPIO_CFG_OUTPUT) {
  770. sbi(DDRF, bit);
  771. }
  772. else {
  773. if (flags & GPIO_CFG_PULLUP) {
  774. sbi(PORTF, bit);
  775. }
  776. else {
  777. cbi(PORTF, bit);
  778. }
  779. cbi(DDRF, bit);
  780. }
  781. break;
  782. #endif
  783. default:
  784. /* Use port wide function for registers above I/O space. */
  785. GpioPortConfigSet(bank, _BV(bit), flags);
  786. break;
  787. }
  788. /* Check the result. */
  789. if (GpioPinConfigGet(bank, bit) != flags) {
  790. return -1;
  791. }
  792. return 0;
  793. }
  794. int GpioRegisterIrqHandler(GPIO_SIGNAL * sig, int bit, void (*handler) (void *), void *arg)
  795. {
  796. return -1;
  797. }
  798. int GpioIrqEnable(GPIO_SIGNAL * sig, int bit)
  799. {
  800. return -1;
  801. }
  802. int GpioIrqDisable(GPIO_SIGNAL * sig, int bit)
  803. {
  804. return -1;
  805. }