expander.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * expander.h
  3. * k4be 2022
  4. * License: BSD
  5. *
  6. * PCA9539/TCA9539 GPIO expander driver
  7. */
  8. #ifndef EXPANDER_H_
  9. #define EXPANDER_H_
  10. #define P00 0
  11. #define P01 1
  12. #define P02 2
  13. #define P03 3
  14. #define P04 4
  15. #define P05 5
  16. #define P06 6
  17. #define P07 7
  18. #define P10 0
  19. #define P11 1
  20. #define P12 2
  21. #define P13 3
  22. #define P14 4
  23. #define P15 5
  24. #define P16 6
  25. #define P17 7
  26. #define EXP_PORT0 (128|0)
  27. #define EXP_PORT1 (128|1)
  28. #define CMD_PORT0_INPUT 0
  29. #define CMD_PORT1_INPUT 1
  30. #define CMD_PORT0_OUTPUT 2
  31. #define CMD_PORT1_OUTPUT 3
  32. #define CMD_PORT0_INV 4
  33. #define CMD_PORT1_INV 5
  34. #define CMD_PORT0_CONFIG 6
  35. #define CMD_PORT1_CONFIG 7
  36. #define EXPANDER_ADDR 0b1110100 // first address
  37. #define EXPANDER_COUNT 1 // number of expanders (contiguous addresses)
  38. void expander_init(unsigned char addr, unsigned char p1in, unsigned char p2in);
  39. unsigned int expander_read(unsigned char addr);
  40. void expander_write(unsigned char addr);
  41. void expander_write_all(void);
  42. void expander_set_bit(unsigned char port, unsigned char val, unsigned char on);
  43. #endif /* EXPANDER_H_ */