ncp5623c.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /****************************************************************************
  2. * include/nuttx/leds/ncp5623c.h
  3. * based on include/nuttx/leds/pca9635pw.c
  4. *
  5. * Author: Konstantin Berzenko <kpberezenko@gmail.com>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __INCLUDE_NUTTX_LEDS_NCP5623C_H
  36. #define __INCLUDE_NUTTX_LEDS_NCP5623C_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <nuttx/fs/ioctl.h>
  42. /* Configuration
  43. * CONFIG_I2C - Enables support for I2C drivers
  44. * CONFIG_NCP5623C - Enables support for the NCP5623C driver
  45. */
  46. #if defined(CONFIG_I2C) && defined(CONFIG_NCP5623C)
  47. /****************************************************************************
  48. * Pre-processor Definitions
  49. ****************************************************************************/
  50. /* I2C definitions */
  51. #define I2C_BUS_FREQ_HZ (400000)
  52. /* NCP5623C register addresses */
  53. #define NCP5623C_SHUTDOWN (0x00) /* System Shut Down */
  54. #define NCP5623C_ILED (0x1) /* ILED current */
  55. #define NCP5623C_PWM1 (0x2) /* LED 1 brightness control */
  56. #define NCP5623C_PWM2 (0x3) /* LED 2 brightness control */
  57. #define NCP5623C_PWM3 (0x4) /* LED 3 brightness control */
  58. #define NCP5623C_UPWARD (0x5) /* Set Up the IEND Upward */
  59. #define NCP5623C_DWNWRD (0x6) /* Set Up the IEND Downward */
  60. #define NCP5623C_GRAD (0x7) /* Set Up the Gradual Dimming */
  61. #define NCP5623C_MAX_REG (0x7) /* Highest register */
  62. #define NCP5623C_ADDRESS_MASK (0xe0) /* Address part of reg */
  63. #define NCP5623C_VALUE_MASK (0x1f) /* Value part of reg */
  64. #define NCP5623C_SHIFT_ADDRESS (5)
  65. #define NCP5623C_MAX_VALUE (0x1f) /* Max value of all registers */
  66. #define NCP5623C_SET_REG(addr, val) \
  67. (((addr << NCP5623C_SHIFT_ADDRESS) & NCP5623C_ADDRESS_MASK) | \
  68. (val & NCP5623C_VALUE_MASK)) /* combine addr and val */
  69. /* IOCTL commands */
  70. #define LEDIOC_SET_REG _ULEDIOC(1) /* Arg: ncp5623c_set_reg_s * pointer */
  71. /****************************************************************************
  72. * Public Types
  73. ****************************************************************************/
  74. enum led_select_e
  75. {
  76. LED_1 = NCP5623C_PWM1,
  77. LED_2 = NCP5623C_PWM2,
  78. LED_3 = NCP5623C_PWM3
  79. };
  80. /* This structure is used in an IOCTL command for setting the PWM of an individual
  81. * LED. The desired LED is selected by setting the 'led' parameter accordingly
  82. * whereas the 'led_pwm' field governs the brightness of the selected LED. A value
  83. * of 0 (0x00) leads to a duty cycle of 0 % = LED off while a value of 255 (0xFF)
  84. * leads to a duty cycle of 99.6 % = Maximum brightness.
  85. */
  86. struct ncp5623c_set_reg_s
  87. {
  88. uint8_t reg;
  89. uint8_t val;
  90. };
  91. /****************************************************************************
  92. * Forward declarations
  93. ****************************************************************************/
  94. struct i2c_master_s;
  95. /****************************************************************************
  96. * Public Types
  97. ****************************************************************************/
  98. #ifdef __cplusplus
  99. #define EXTERN extern "C"
  100. extern "C"
  101. {
  102. #else
  103. #define EXTERN extern
  104. #endif
  105. /****************************************************************************
  106. * Name: ncp5623c_register
  107. *
  108. * Description:
  109. * Register the NCP5623C device as 'devpath'
  110. *
  111. * Input Parameters:
  112. * devpath - The full path to the driver to register. E.g., "/dev/leddrv0".
  113. * i2c - An instance of the I2C interface to use to communicate
  114. * with the LM92.
  115. * ncp5623c_i2c_addr
  116. * - The I2C address of the NCP5623C.
  117. *
  118. * Returned Value:
  119. * Zero (OK) on success; a negated errno value on failure.
  120. *
  121. ****************************************************************************/
  122. int ncp5623c_register(FAR const char *devpath, FAR struct i2c_master_s *i2c,
  123. uint8_t const ncp5623c_i2c_addr);
  124. #undef EXTERN
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif /* CONFIG_I2C && CONFIG_I2C_NCP5623C */
  129. #endif /* __INCLUDE_NUTTX_LEDS_NCP5623C_H */