You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9 KiB

  1. /* Copyright 2018 Mike Roberts
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef MAP23017_H
  17. #define MAP23017_H
  18. #define EXPANDER_ADDR 0x27
  19. #define I2C_TIMEOUT 200 // milliseconds
  20. #define EXPANDER_PAUSE 0 // microseconds
  21. enum EXPANDER_REGISTERS {
  22. EXPANDER_REG_IODIRA = 0x00,
  23. EXPANDER_REG_IODIRB = 0x01,
  24. EXPANDER_REG_IPOLA = 0x02,
  25. EXPANDER_REG_IPOLB = 0x03,
  26. EXPANDER_REG_GPINTENA = 0x04,
  27. EXPANDER_REG_GPINTENB = 0x05,
  28. EXPANDER_REG_DEFVALA = 0x06,
  29. EXPANDER_REG_DEFVALB = 0x07,
  30. EXPANDER_REG_INTCONA = 0x08,
  31. EXPANDER_REG_INTCONB = 0x09,
  32. EXPANDER_REG_IOCONA = 0x0A,
  33. EXPANDER_REG_IOCONB = 0x0B,
  34. EXPANDER_REG_GPPUA = 0x0C,
  35. EXPANDER_REG_GPPUB = 0x0D,
  36. EXPANDER_REG_INTFA = 0x0E,
  37. EXPANDER_REG_INTFB = 0x0F,
  38. EXPANDER_REG_INTCAPA = 0x10,
  39. EXPANDER_REG_INTCAPB = 0x11,
  40. EXPANDER_REG_GPIOA = 0x12,
  41. EXPANDER_REG_GPIOB = 0x13,
  42. EXPANDER_REG_OLATA = 0x14,
  43. EXPANDER_REG_OLATB = 0x15
  44. };
  45. #define GPA0 0x0
  46. #define GPA1 0x1
  47. #define GPA2 0x2
  48. #define GPA3 0x3
  49. #define GPA4 0x4
  50. #define GPA5 0x5
  51. #define GPA6 0x6
  52. #define GPA7 0x7
  53. #define GPB0 0x8
  54. #define GPB1 0x9
  55. #define GPB2 0xA
  56. #define GPB3 0xB
  57. #define GPB4 0xC
  58. #define GPB5 0xD
  59. #define GPB6 0xE
  60. #define GPB7 0xF
  61. void expander_init(void);
  62. void expander_select(uint8_t pin);
  63. void expander_unselect(uint8_t pin);
  64. void expander_unselect_all(void);
  65. #endif