expander.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. extern unsigned char exp_output[EXPANDER_COUNT*2];
  39. void expander_init(unsigned char addr, unsigned char p1in, unsigned char p2in);
  40. void expander_set_dir(unsigned char addr, unsigned char p1in, unsigned char p2in);
  41. unsigned int expander_read(unsigned char addr);
  42. unsigned int expander_read_byte(unsigned char addr, unsigned char reg);
  43. void expander_write(unsigned char addr);
  44. void expander_write_all(void);
  45. void expander_set_bit(unsigned char port, unsigned char val, unsigned char on);
  46. void expander_set_bit_no_send(unsigned char port, unsigned char val, unsigned char on);
  47. #endif /* EXPANDER_H_ */