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.

88 lines
1.7 KiB

  1. // Copyright 2020 zvecr<git@zvecr.com>
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. /*
  7. PCA9555
  8. ,----------.
  9. SDA --| SDA P00 |-- P00
  10. SCL --| SCL P01 |-- P01
  11. INT --| INT P02 |-- P02
  12. | P03 |-- P03
  13. A0 --| A0 P04 |-- P04
  14. A1 --| A1 P05 |-- P05
  15. A2 --| A2 P06 |-- P06
  16. | P07 |-- P07
  17. | |
  18. | P10 |-- P10
  19. | P11 |-- P11
  20. | P12 |-- P12
  21. | P13 |-- P13
  22. | P14 |-- P14
  23. | P15 |-- P15
  24. | P16 |-- P16
  25. | P17 |-- P17
  26. `----------'
  27. */
  28. /**
  29. * Port ID
  30. */
  31. typedef enum {
  32. PCA9555_PORT0,
  33. PCA9555_PORT1,
  34. } pca9555_port_t;
  35. /**
  36. * Helpers for set_config
  37. */
  38. enum {
  39. ALL_OUTPUT = 0,
  40. ALL_INPUT = 0xFF,
  41. };
  42. /**
  43. * Helpers for set_output
  44. */
  45. enum {
  46. ALL_LOW = 0,
  47. ALL_HIGH = 0xFF,
  48. };
  49. /**
  50. * Init expander and any other dependent drivers
  51. */
  52. void pca9555_init(uint8_t slave_addr);
  53. /**
  54. * Configure input/output to a given port
  55. */
  56. bool pca9555_set_config(uint8_t slave_addr, pca9555_port_t port, uint8_t conf);
  57. /**
  58. * Write high/low to a given port
  59. */
  60. bool pca9555_set_output(uint8_t slave_addr, pca9555_port_t port, uint8_t conf);
  61. /**
  62. * Write high/low to both ports sequentially
  63. *
  64. * - slightly faster than multiple set_output
  65. */
  66. bool pca9555_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB);
  67. /**
  68. * Read state of a given port
  69. */
  70. bool pca9555_readPins(uint8_t slave_addr, pca9555_port_t port, uint8_t* ret);
  71. /**
  72. * Read state of both ports sequentially
  73. *
  74. * - slightly faster than multiple readPins
  75. */
  76. bool pca9555_readPins_all(uint8_t slave_addr, uint16_t* ret);