pca9538.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /****************************************************************************
  2. * include/nuttx/ioexpander/pca9538.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_NUTTX_IOEXPANDER_PCA9538_H
  21. #define __INCLUDE_NUTTX_IOEXPANDER_PCA9538_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <nuttx/i2c/i2c_master.h>
  27. #include <stdbool.h>
  28. /****************************************************************************
  29. * Public Types
  30. ****************************************************************************/
  31. /* A reference to a structure of this type must be passed to the pca9538
  32. * driver when the driver is instantiated. This structure provides
  33. * information about the configuration of the pca9538 and provides some
  34. * board-specific hooks.
  35. *
  36. * Memory for this structure is provided by the caller. It is not copied by
  37. * the driver and is presumed to persist while the driver is active. The
  38. * memory must be writeable because, under certain circumstances, the driver
  39. * may modify the frequency.
  40. */
  41. struct pca9538_config_s
  42. {
  43. /* Device characterization */
  44. uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
  45. uint32_t frequency; /* I2C or SPI frequency */
  46. /* Sets the state of the PCA9538's nReset pin */
  47. CODE void (*set_nreset_pin)(bool state);
  48. #ifdef CONFIG_IOEXPANDER_INT_ENABLE
  49. /* If multiple pca9538 devices are supported, then an IRQ number must
  50. * be provided for each so that their interrupts can be distinguished.
  51. */
  52. /* IRQ/GPIO access callbacks. These operations all hidden behind
  53. * callbacks to isolate the pca9538 driver from differences in GPIO
  54. * interrupt handling by varying boards and MCUs.
  55. *
  56. * attach - Attach the pca9538 interrupt handler to the GPIO interrupt
  57. * enable - Enable or disable the GPIO interrupt
  58. */
  59. CODE int (*attach)(FAR struct pca9538_config_s *state, xcpt_t isr,
  60. FAR void *arg);
  61. CODE void (*enable)(FAR struct pca9538_config_s *state, bool enable);
  62. #endif
  63. };
  64. /****************************************************************************
  65. * Public Function Prototypes
  66. ****************************************************************************/
  67. #ifdef __cplusplus
  68. #define EXTERN extern "C"
  69. extern "C"
  70. {
  71. #else
  72. #define EXTERN extern
  73. #endif
  74. /****************************************************************************
  75. * Name: pca9538_initialize
  76. *
  77. * Description:
  78. * Instantiate and configure the pca9538 device driver to use the provided
  79. * I2C device
  80. * instance.
  81. *
  82. * Input Parameters:
  83. * dev - An I2C driver instance
  84. * minor - The device i2c address
  85. * config - Persistent board configuration data
  86. *
  87. * Returned Value:
  88. * an ioexpander_dev_s instance on success, NULL on failure.
  89. *
  90. ****************************************************************************/
  91. FAR struct ioexpander_dev_s *pca9538_initialize(FAR struct i2c_master_s *dev,
  92. FAR struct pca9538_config_s *config);
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* __INCLUDE_NUTTX_IOEXPANDER_PCA9538_H */