pca9505.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2022 nirim000
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. /**
  7. * Port ID
  8. */
  9. typedef enum {
  10. PCA9505_PORT0,
  11. PCA9505_PORT1,
  12. PCA9505_PORT2,
  13. PCA9505_PORT3,
  14. PCA9505_PORT4,
  15. } pca9505_port_t;
  16. /**
  17. * Helpers for set_config
  18. */
  19. enum {
  20. ALL_NORMAL = 0,
  21. ALL_INVERTED = 0xFF,
  22. };
  23. /**
  24. * Helpers for set_config
  25. */
  26. enum {
  27. ALL_OUTPUT = 0,
  28. ALL_INPUT = 0xFF,
  29. };
  30. /**
  31. * Helpers for set_output
  32. */
  33. enum {
  34. ALL_LOW = 0,
  35. ALL_HIGH = 0xFF,
  36. };
  37. /**
  38. * Init expander and any other dependent drivers
  39. */
  40. void pca9505_init(uint8_t slave_addr);
  41. /**
  42. * Configure input/output to a given port
  43. */
  44. bool pca9505_set_config(uint8_t slave_addr, pca9505_port_t port, uint8_t conf);
  45. /**
  46. * Configure polarity to a given port
  47. */
  48. bool pca9505_set_polarity(uint8_t slave_addr, pca9505_port_t port, uint8_t conf);
  49. /**
  50. * Write high/low to a given port
  51. */
  52. bool pca9505_set_output(uint8_t slave_addr, pca9505_port_t port, uint8_t conf);
  53. /**
  54. * Read state of a given port
  55. */
  56. bool pca9505_readPins(uint8_t slave_addr, pca9505_port_t port, uint8_t* ret);