logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

mcp23018.h (1355B)


  1. // Copyright 2022 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. * Port ID
  8. */
  9. typedef enum {
  10. mcp23018_PORTA,
  11. mcp23018_PORTB,
  12. } mcp23018_port_t;
  13. /**
  14. * Helpers for set_config
  15. */
  16. enum {
  17. ALL_OUTPUT = 0,
  18. ALL_INPUT = 0xFF,
  19. };
  20. /**
  21. * Helpers for set_output
  22. */
  23. enum {
  24. ALL_LOW = 0,
  25. ALL_HIGH = 0xFF,
  26. };
  27. /**
  28. * Init expander and any other dependent drivers
  29. */
  30. void mcp23018_init(uint8_t slave_addr);
  31. /**
  32. * Configure input/output to a given port
  33. */
  34. bool mcp23018_set_config(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf);
  35. /**
  36. * Write high/low to a given port
  37. */
  38. bool mcp23018_set_output(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf);
  39. /**
  40. * Write high/low to both ports sequentially
  41. *
  42. * - slightly faster than multiple set_output
  43. */
  44. bool mcp23018_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB);
  45. /**
  46. * Read state of a given port
  47. */
  48. bool mcp23018_read_pins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* ret);
  49. /**
  50. * Read state of both ports sequentially
  51. *
  52. * - slightly faster than multiple readPins
  53. */
  54. bool mcp23018_read_pins_all(uint8_t slave_addr, uint16_t* ret);
  55. // DEPRECATED - DO NOT USE
  56. #define mcp23018_readPins mcp23018_read_pins
  57. #define mcp23018_readPins_all mcp23018_read_pins_all