sx1509b_internal.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef SX1509B_INTERNAL_H
  41. #define SX1509B_INTERNAL_H
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /**
  46. * @brief Device and IO banks registers.
  47. */
  48. typedef enum
  49. {
  50. SX1509B_REG_INPUT_DISABLE_B,
  51. SX1509B_REG_INPUT_DISABLE_A,
  52. SX1509B_REG_LONG_SLEW_B,
  53. SX1509B_REG_LONG_SLEW_A,
  54. SX1509B_REG_LOW_DRIVE_B,
  55. SX1509B_REG_LOW_DRIVE_A,
  56. SX1509B_REG_PULL_UP_B,
  57. SX1509B_REG_PULL_UP_A,
  58. SX1509B_REG_PULL_DOWN_B,
  59. SX1509B_REG_PULL_DOWN_A,
  60. SX1509B_REG_OPEN_DRAIN_B,
  61. SX1509B_REG_OPEN_DRAIN_A,
  62. SX1509B_REG_POLARITY_B,
  63. SX1509B_REG_POLARITY_A,
  64. SX1509B_REG_DIR_B,
  65. SX1509B_REG_DIR_A,
  66. SX1509B_REG_DATA_B,
  67. SX1509B_REG_DATA_A,
  68. SX1509B_REG_INT_MASK_B,
  69. SX1509B_REG_INT_MASK_A,
  70. SX1509B_REG_SENSE_H_B,
  71. SX1509B_REG_SENSE_L_B,
  72. SX1509B_REG_SENSE_H_A,
  73. SX1509B_REG_SENSE_L_A,
  74. SX1509B_REG_INT_SRC_B,
  75. SX1509B_REG_INT_SRC_A,
  76. SX1509B_REG_EVENT_STATUS_B,
  77. SX1509B_REG_EVENT_STATUS_A,
  78. SX1509B_REG_LEVEL_SHIFTER_1,
  79. SX1509B_REG_LEVEL_SHIFTER_2,
  80. SX1509B_REG_CLOCK,
  81. SX1509B_REG_MISC,
  82. SX1509B_REG_LED_DRV_ENABLE_B,
  83. SX1509B_REG_LED_DRV_ENABLE_A,
  84. SX1509B_REG_DEBOUNCE_CONFIG,
  85. SX1509B_REG_DEBOUNCE_EN_B,
  86. SX1509B_REG_DEBOUNCE_EN_A,
  87. SX1509B_REG_KEY_CONFIG_1,
  88. SX1509B_REG_KEY_CONFIG_2,
  89. SX1509B_REG_KEY_DATA_1,
  90. SX1509B_REG_KEY_DATA_2,
  91. SX1509B_REG_COUNT
  92. } sx1509b_registers_t;
  93. #define SX1509B_INNER_PIN_COUNT 16
  94. #define SX1509B_INNER_NEXT_BANK 8
  95. #define SX1509B_INNER_PORT_COUNT 2
  96. #define SX1509B_INNER_SENSE_REG_NUM 4
  97. #define SX1509B_INNER_RESET_BYTE1 0x12
  98. #define SX1509B_INNER_RESET_BYTE2 0x34
  99. /**
  100. * @brief LED Driver registers.
  101. */
  102. #define SX1509B_REG_LED_BANK_A_START 0x29
  103. #define SX1509B_REG_LED_FADE_A_START 0x35
  104. #define SX1509B_REG_LED_BANK_B_START 0x49
  105. #define SX1509B_REG_LED_FADE_B_START 0x55
  106. #define SX1509B_LED_DRIVER_TIME_REG_LEN 3
  107. #define SX1509B_LED_DRIVER_FADE_REG_LEN 5
  108. #define SX1509B_LED_DRIVER_TIME_REG_NUM ((SX1509B_REG_LED_FADE_A_START \
  109. - SX1509B_REG_LED_BANK_A_START) \
  110. / SX1509B_LED_DRIVER_TIME_REG_LEN)
  111. #define SX1509B_LED_DRIVER_FADE_REG_NUM ((SX1509B_REG_LED_BANK_B_START \
  112. - SX1509B_REG_LED_FADE_A_START) \
  113. / SX1509B_LED_DRIVER_FADE_REG_LEN)
  114. /**
  115. * @brief Clock register bitmasks.
  116. */
  117. // Bitmasks for osc src.
  118. #define SX1509B_OSC_SRC_POS 5
  119. #define SX1509B_OSC_SRC_MASK (3 << SX1509B_OSC_SRC_POS)
  120. // Bitmasks for oscio pin.
  121. #define SX1509B_OSCIO_PIN_POS 4
  122. #define SX1509B_OSCIO_PIN_MASK (1 << SX1509B_OSCIO_PIN_POS)
  123. // Bitmasks for oscout freq.
  124. #define SX1509B_OSCOUT_FREQ_POS 0
  125. #define SX1509B_OSCOUT_FREQ_MASK (0x0F << SX1509B_OSCOUT_FREQ_POS)
  126. /**
  127. * @brief Miscellaneous register bitmasks.
  128. */
  129. // Bitmasks for led mode b.
  130. #define SX1509B_LED_MODE_B_POS 7
  131. #define SX1509B_LED_MODE_B_MASK (1 << SX1509B_LED_MODE_B_POS)
  132. // Bitmasks for led freq.
  133. #define SX1509B_LED_FREQ_POS 4
  134. #define SX1509B_LED_FREQ_MASK (7 << SX1509B_LED_FREQ_POS)
  135. // Bitmasks for led mode a.
  136. #define SX1509B_LED_MODE_A_POS 3
  137. #define SX1509B_LED_MODE_A_MASK (1 << SX1509B_LED_MODE_A_POS)
  138. // Bitmasks for nreset pin.
  139. #define SX1509B_NRESET_PIN_POS 2
  140. #define SX1509B_NRESET_PIN_MASK (1 << SX1509B_NRESET_PIN_POS)
  141. // Bitmasks for auto incr.
  142. #define SX1509B_AUTO_INCR_POS 1
  143. #define SX1509B_AUTO_INCR_MASK (1 << SX1509B_AUTO_INCR_POS)
  144. // Bitmasks for auto clear nint.
  145. #define SX1509B_AUTO_CLEAR_NINT_POS 0
  146. #define SX1509B_AUTO_CLEAR_NINT_MASK (1 << SX1509B_AUTO_CLEAR_NINT_POS)
  147. /**
  148. * @brief Key config 1 register bitmasks.
  149. */
  150. // Bitmasks for sleep time.
  151. #define SX1509B_SLEEP_TIME_POS 4
  152. #define SX1509B_SLEEP_TIME_MASK (7 << SX1509B_SLEEP_TIME_POS)
  153. // Bitmasks for scan time.
  154. #define SX1509B_SCAN_TIME_POS 0
  155. #define SX1509B_SCAN_TIME_MASK (7 << SX1509B_SCAN_TIME_POS)
  156. /**
  157. * @brief Key config 2 register bitmasks.
  158. */
  159. // Bitmasks for row num.
  160. #define SX1509B_ROW_NUM_POS 3
  161. #define SX1509B_ROW_NUM_MASK (7 << SX1509B_ROW_NUM_POS)
  162. // Bitmasks for col num.
  163. #define SX1509B_COL_NUM_POS 0
  164. #define SX1509B_COL_NUM_MASK (7 << SX1509B_COL_NUM_POS)
  165. /**
  166. * @brief Led driver off register bitmasks.
  167. */
  168. // Bitmasks for OFF_TIME.
  169. #define SX1509B_OFF_TIME_POS 3
  170. #define SX1509B_OFF_TIME_MASK (0x1F << SX1509B_OFF_TIME_POS)
  171. // Bitmasks for off intensity.
  172. #define SX1509B_OFF_INTENSITY_POS 0
  173. #define SX1509B_OFF_INTENSITY_MASK (7 << SX1509B_OFF_INTENSITY_POS)
  174. /**
  175. * @brief Miscellaneous registers.
  176. */
  177. #define SX1509B_REG_HIGH_INPUT_B 0x69
  178. #define SX1509B_REG_HIGH_INPUT_A 0x6A
  179. #define SX1509B_REG_SW_RESET 0x7D
  180. #define SX1509B_REG_TEST_1 0x7E
  181. #define SX1509B_REG_TEST_2 0x7F
  182. /**
  183. * @brief Structure containing expander instance.
  184. */
  185. typedef struct
  186. {
  187. nrf_twi_sensor_t * p_sensor_data;
  188. uint8_t sensor_addr;
  189. uint8_t start_addr;
  190. uint8_t registers[SX1509B_REG_COUNT];
  191. uint8_t high_input[2];
  192. } sx1509b_instance_t;
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #endif // SX1509B_INTERNAL_H