nrf_csense_macros.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /**
  2. * Copyright (c) 2016 - 2019, 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 NRF_CSENSE_MACROS_H__
  41. #define NRF_CSENSE_MACROS_H__
  42. /** @file
  43. *
  44. * @defgroup nrf_csense_macros Capacitive sensor macros
  45. * @{
  46. * @ingroup nrf_csense
  47. *
  48. * @brief A set of macros to facilitate creation of a new capacitive sensor instance.
  49. */
  50. #define NRF_CSENSE_INTERNAL_BUTTON_DEF(name, p1) \
  51. static nrf_csense_pad_t CONCAT_2(name, _pad) = \
  52. { \
  53. .p_next_pad = NULL, \
  54. .threshold = GET_ARG_2 p1, \
  55. .pad_index = 0, \
  56. .analog_input_number = GET_ARG_1 p1 \
  57. }; \
  58. static nrf_csense_min_max_t CONCAT_2(name, _minmax); \
  59. static nrf_csense_instance_t name = \
  60. { \
  61. .p_nrf_csense_pad = &CONCAT_2(name, _pad), \
  62. .min_max = &CONCAT_2(name, _minmax), \
  63. .steps = 1, \
  64. .number_of_pads = 1, \
  65. .is_active = false, \
  66. .is_touched = false \
  67. };
  68. #define NRF_CSENSE_INTERNAL_SLIDER_2_DEF(name, steps_no, p1, p2) \
  69. static nrf_csense_pad_t CONCAT_2(name, _pad)[2] = \
  70. { \
  71. { \
  72. .p_next_pad = &CONCAT_2(name, _pad)[1], \
  73. .threshold = GET_ARG_2 p1, \
  74. .pad_index = 0, \
  75. .analog_input_number = GET_ARG_1 p1 \
  76. }, \
  77. { \
  78. .p_next_pad = NULL, \
  79. .threshold = GET_ARG_2 p2, \
  80. .pad_index = 1, \
  81. .analog_input_number = GET_ARG_1 p2 \
  82. } \
  83. }; \
  84. \
  85. static nrf_csense_min_max_t CONCAT_2(name, _minmax)[2]; \
  86. static nrf_csense_instance_t name = \
  87. { \
  88. .p_nrf_csense_pad = CONCAT_2(name, _pad), \
  89. .min_max = CONCAT_2(name, _minmax), \
  90. .steps = steps_no, \
  91. .number_of_pads = 2, \
  92. .is_active = false, \
  93. .is_touched = false \
  94. };
  95. #define NRF_CSENSE_INTERNAL_SLIDER_3_DEF(name, steps_no, p1, p2, p3) \
  96. static nrf_csense_pad_t CONCAT_2(name, _pad)[3] = \
  97. { \
  98. { \
  99. .p_next_pad = &CONCAT_2(name, _pad)[1], \
  100. .threshold = GET_ARG_2 p1, \
  101. .pad_index = 0, \
  102. .analog_input_number = GET_ARG_1 p1 \
  103. }, \
  104. { \
  105. .p_next_pad = &CONCAT_2(name, _pad)[2], \
  106. .threshold = GET_ARG_2 p2, \
  107. .pad_index = 1, \
  108. .analog_input_number = GET_ARG_1 p2 \
  109. }, \
  110. { \
  111. .p_next_pad = NULL, \
  112. .threshold = GET_ARG_2 p3, \
  113. .pad_index = 2, \
  114. .analog_input_number = GET_ARG_1 p3 \
  115. } \
  116. }; \
  117. \
  118. static nrf_csense_min_max_t CONCAT_2(name, _minmax)[3]; \
  119. static nrf_csense_instance_t name = \
  120. { \
  121. .p_nrf_csense_pad = CONCAT_2(name, _pad), \
  122. .min_max = CONCAT_2(name, _minmax), \
  123. .steps = steps_no, \
  124. .number_of_pads = 3, \
  125. .is_active = false, \
  126. .is_touched = false \
  127. };
  128. #define NRF_CSENSE_INTERNAL_SLIDER_4_DEF(name, steps_no, p1, p2, p3, p4) \
  129. static nrf_csense_pad_t CONCAT_2(name, _pad)[4] = \
  130. { \
  131. { \
  132. .p_next_pad = &CONCAT_2(name, _pad)[1], \
  133. .threshold = GET_ARG_2 p1, \
  134. .pad_index = 0, \
  135. .analog_input_number = GET_ARG_1 p1 \
  136. }, \
  137. { \
  138. .p_next_pad = &CONCAT_2(name, _pad)[2], \
  139. .threshold = GET_ARG_2 p2, \
  140. .pad_index = 1, \
  141. .analog_input_number = GET_ARG_1 p2 \
  142. }, \
  143. { \
  144. .p_next_pad = &CONCAT_2(name, _pad)[3], \
  145. .threshold = GET_ARG_2 p3, \
  146. .pad_index = 2, \
  147. .analog_input_number = GET_ARG_1 p3 \
  148. }, \
  149. { \
  150. .p_next_pad = NULL, \
  151. .threshold = GET_ARG_2 p4, \
  152. .pad_index = 3, \
  153. .analog_input_number = GET_ARG_1 p4 \
  154. } \
  155. }; \
  156. static nrf_csense_min_max_t CONCAT_2(name, _minmax)[4]; \
  157. static nrf_csense_instance_t name = \
  158. { \
  159. .p_nrf_csense_pad = CONCAT_2(name, _pad), \
  160. .min_max = CONCAT_2(name, _minmax), \
  161. .steps = steps_no, \
  162. .number_of_pads = 4, \
  163. .is_active = false, \
  164. .is_touched = false \
  165. };
  166. #define NRF_CSENSE_INTERNAL_SLIDER_5_DEF(name, steps_no, p1, p2, p3, p4, p5) \
  167. static nrf_csense_pad_t CONCAT_2(name, _pad)[5] = \
  168. { \
  169. { \
  170. .p_next_pad = &CONCAT_2(name, _pad)[1], \
  171. .threshold = GET_ARG_2 p1, \
  172. .pad_index = 0, \
  173. .analog_input_number = GET_ARG_1 p1 \
  174. }, \
  175. { \
  176. .p_next_pad = &CONCAT_2(name, _pad)[2], \
  177. .threshold = GET_ARG_2 p2, \
  178. .pad_index = 1, \
  179. .analog_input_number = GET_ARG_1 p2 \
  180. }, \
  181. { \
  182. .p_next_pad = &CONCAT_2(name, _pad)[3], \
  183. .threshold = GET_ARG_2 p3, \
  184. .pad_index = 2, \
  185. .analog_input_number = GET_ARG_1 p3 \
  186. }, \
  187. { \
  188. .p_next_pad = &CONCAT_2(name, _pad)[4], \
  189. .threshold = GET_ARG_2 p4, \
  190. .pad_index = 3, \
  191. .analog_input_number = GET_ARG_1 p4 \
  192. }, \
  193. { \
  194. .p_next_pad = NULL, \
  195. .threshold = GET_ARG_2 p5, \
  196. .pad_index = 4, \
  197. .analog_input_number = GET_ARG_1 p5 \
  198. } \
  199. }; \
  200. \
  201. static nrf_csense_min_max_t CONCAT_2(name, _minmax)[5]; \
  202. static nrf_csense_instance_t name = \
  203. { \
  204. .p_nrf_csense_pad = CONCAT_2(name, _pad), \
  205. .min_max = CONCAT_2(name, _minmax), \
  206. .steps = steps_no, \
  207. .number_of_pads = 5, \
  208. .is_active = false, \
  209. .is_touched = false \
  210. };
  211. #define NRF_CSENSE_INTERNAL_WHEEL_3_DEF(name, steps_no, p1, p2, p3) \
  212. static nrf_csense_pad_t CONCAT_2(name, _pad)[4] = \
  213. { \
  214. { \
  215. .p_next_pad = &CONCAT_2(name, _pad)[1], \
  216. .threshold = GET_ARG_2 p1, \
  217. .pad_index = 0, \
  218. .analog_input_number = GET_ARG_1 p1 \
  219. }, \
  220. { \
  221. .p_next_pad = &CONCAT_2(name, _pad)[2], \
  222. .threshold = GET_ARG_2 p2, \
  223. .pad_index = 1, \
  224. .analog_input_number = GET_ARG_1 p2 \
  225. }, \
  226. { \
  227. .p_next_pad = &CONCAT_2(name, _pad)[3], \
  228. .threshold = GET_ARG_2 p3, \
  229. .pad_index = 2, \
  230. .analog_input_number = GET_ARG_1 p3 \
  231. }, \
  232. { \
  233. .p_next_pad = NULL, \
  234. .threshold = GET_ARG_2 p1, \
  235. .pad_index = 3, \
  236. .analog_input_number = GET_ARG_1 p1 \
  237. } \
  238. }; \
  239. \
  240. static nrf_csense_min_max_t CONCAT_2(name, _minmax)[4]; \
  241. static nrf_csense_instance_t name = \
  242. { \
  243. .p_nrf_csense_pad = CONCAT_2(name, _pad), \
  244. .min_max = CONCAT_2(name, _minmax), \
  245. .steps = steps_no, \
  246. .number_of_pads = 4, \
  247. .is_active = false, \
  248. .is_touched = false \
  249. };
  250. #define NRF_CSENSE_INTERNAL_WHEEL_4_DEF(name, steps_no, p1, p2, p3, p4) \
  251. static nrf_csense_pad_t CONCAT_2(name, _pad)[5] = \
  252. { \
  253. { \
  254. .p_next_pad = &CONCAT_2(name, _pad)[1], \
  255. .threshold = GET_ARG_2 p1, \
  256. .pad_index = 0, \
  257. .analog_input_number = GET_ARG_1 p1 \
  258. }, \
  259. { \
  260. .p_next_pad = &CONCAT_2(name, _pad)[2], \
  261. .threshold = GET_ARG_2 p2, \
  262. .pad_index = 1, \
  263. .analog_input_number = GET_ARG_1 p2 \
  264. }, \
  265. { \
  266. .p_next_pad = &CONCAT_2(name, _pad)[3], \
  267. .threshold = GET_ARG_2 p3, \
  268. .pad_index = 2, \
  269. .analog_input_number = GET_ARG_1 p3 \
  270. }, \
  271. { \
  272. .p_next_pad = &CONCAT_2(name, _pad)[4], \
  273. .threshold = GET_ARG_2 p4, \
  274. .pad_index = 3, \
  275. .analog_input_number = GET_ARG_1 p4 \
  276. }, \
  277. { \
  278. .p_next_pad = NULL, \
  279. .threshold = GET_ARG_2 p1, \
  280. .pad_index = 4, \
  281. .analog_input_number = GET_ARG_1 p1 \
  282. } \
  283. }; \
  284. \
  285. static nrf_csense_min_max_t CONCAT_2(name, _minmax)[5]; \
  286. static nrf_csense_instance_t name = \
  287. { \
  288. .p_nrf_csense_pad = CONCAT_2(name, _pad), \
  289. .min_max = CONCAT_2(name, _minmax), \
  290. .steps = steps_no, \
  291. .number_of_pads = 5, \
  292. .is_active = false, \
  293. .is_touched = false \
  294. };
  295. #define NRF_CSENSE_INTERNAL_WHEEL_5_DEF(name, steps_no, p1, p2, p3, p4, p5)\
  296. static nrf_csense_pad_t CONCAT_2(name, _pad)[6] = \
  297. { \
  298. { \
  299. .p_next_pad = &CONCAT_2(name, _pad)[1], \
  300. .threshold = GET_ARG_2 p1, \
  301. .pad_index = 0, \
  302. .analog_input_number = GET_ARG_1 p1 \
  303. }, \
  304. { \
  305. .p_next_pad = &CONCAT_2(name, _pad)[2], \
  306. .threshold = GET_ARG_2 p2, \
  307. .pad_index = 1, \
  308. .analog_input_number = GET_ARG_1 p2 \
  309. }, \
  310. { \
  311. .p_next_pad = &CONCAT_2(name, _pad)[3], \
  312. .threshold = GET_ARG_2 p3, \
  313. .pad_index = 2, \
  314. .analog_input_number = GET_ARG_1 p3 \
  315. }, \
  316. { \
  317. .p_next_pad = &CONCAT_2(name, _pad)[4], \
  318. .threshold = GET_ARG_2 p4, \
  319. .pad_index = 3, \
  320. .analog_input_number = GET_ARG_1 p4 \
  321. }, \
  322. { \
  323. .p_next_pad = &CONCAT_2(name, _pad)[5], \
  324. .threshold = GET_ARG_2 p5, \
  325. .pad_index = 4, \
  326. .analog_input_number = GET_ARG_1 p5 \
  327. }, \
  328. { \
  329. .p_next_pad = NULL, \
  330. .threshold = GET_ARG_2 p1, \
  331. .pad_index = 5, \
  332. .analog_input_number = GET_ARG_1 p1 \
  333. } \
  334. }; \
  335. \
  336. static nrf_csense_min_max_t CONCAT_2(name, _minmax)[6]; \
  337. static nrf_csense_instance_t name = \
  338. { \
  339. .p_nrf_csense_pad = CONCAT_2(name, _pad), \
  340. .min_max = CONCAT_2(name, _minmax), \
  341. .steps = steps_no, \
  342. .number_of_pads = 6, \
  343. .is_active = false, \
  344. .is_touched = false \
  345. };
  346. /** @} */
  347. #endif // NRF_CSENSE_MACROS_H__