sx1509b.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. /**
  2. * Copyright (c) 2017 - 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 SX1509B_H
  41. #define SX1509B_H
  42. #include "nrf_twi_sensor.h"
  43. #include "sx1509b_internal.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /**
  48. * @brief Possible sensor addresses.
  49. */
  50. #define SX1509B_BASE_ADDRESS_FIRST 0x3Eu
  51. #define SX1509B_BASE_ADDRESS_SECOND 0x3Fu
  52. #define SX1509B_BASE_ADDRESS_THIRD 0x70u
  53. #define SX1509B_BASE_ADDRESS_FOURTH 0x71u
  54. /**
  55. * @brief Led driver registers.
  56. */
  57. typedef enum
  58. {
  59. SX1509B_LED_DRIVER_T_ON,
  60. SX1509B_LED_DRIVER_I_ON,
  61. SX1509B_LED_DRIVER_OFF,
  62. SX1509B_LED_DRIVER_T_RISE,
  63. SX1509B_LED_DRIVER_T_FALL
  64. } sx1509b_led_driver_set_t;
  65. /**
  66. * @brief Pin direction setting.
  67. */
  68. typedef enum
  69. {
  70. SX1509B_PIN_DIR_OUTPUT,
  71. SX1509B_PIN_DIR_INPUT
  72. } sx1509b_pin_dir_t;
  73. /**
  74. * @brief Pin output setting.
  75. */
  76. typedef enum
  77. {
  78. SX1509B_PIN_CLR,
  79. SX1509B_PIN_SET
  80. } sx1509b_pin_set_t;
  81. /**
  82. * @brief Pin pull setting.
  83. */
  84. typedef enum
  85. {
  86. SX1509B_PIN_NOPULL,
  87. SX1509B_PIN_PULLDOWN,
  88. SX1509B_PIN_PULLUP
  89. } sx1509b_pin_pull_t;
  90. /**
  91. * @brief Pin sense setting.
  92. */
  93. typedef enum
  94. {
  95. SX1509B_PIN_NOSENSE,
  96. SX1509B_PIN_SENSE_RISING,
  97. SX1509B_PIN_SENSE_FALLING,
  98. SX1509B_PIN_SENSE_BOTH
  99. } sx1509b_pin_sense_t;
  100. /**
  101. * @brief Port operation setting.
  102. *
  103. * SX1509B_PORT_WRITE - mask is written to the port.
  104. * SX1509B_PORT_CLEAR - positive bits in mask are cleared in port.
  105. * SX1509B_PORT_SET - positive bits in mask are set in port.
  106. */
  107. typedef enum
  108. {
  109. SX1509B_PORT_WRITE,
  110. SX1509B_PORT_CLEAR,
  111. SX1509B_PORT_SET
  112. } sx1509b_port_op_t;
  113. /**
  114. * @brief Level shifter setting.
  115. */
  116. typedef enum
  117. {
  118. SX1509B_LEVEL_OFF,
  119. SX1509B_LEVEL_A_TO_B,
  120. SX1509B_LEVEL_B_TO_A
  121. } sx1509b_level_shift_t;
  122. /**
  123. * @brief Debounce settings.
  124. */
  125. typedef enum
  126. {
  127. SX1509B_DEBOUNCE_0_5MS,
  128. SX1509B_DEBOUNCE_1MS,
  129. SX1509B_DEBOUNCE_2MS,
  130. SX1509B_DEBOUNCE_4MS,
  131. SX1509B_DEBOUNCE_8MS,
  132. SX1509B_DEBOUNCE_16MS,
  133. SX1509B_DEBOUNCE_32MS,
  134. SX1509B_DEBOUNCE_64MS
  135. } sx1509b_debounce_t;
  136. /**
  137. * @brief Clock setting.
  138. */
  139. typedef enum
  140. {
  141. SX1509B_CLOCK_DISABLED,
  142. SX1509B_CLOCK_EXTERNAL,
  143. SX1509B_CLOCK_INTERNAL
  144. } sx1509b_clock_t;
  145. /**
  146. * @brief Key engine sleep time setting.
  147. */
  148. typedef enum
  149. {
  150. SX1509B_KEY_TIME_SLEEP_OFF,
  151. SX1509B_KEY_TIME_SLEEP_128MS,
  152. SX1509B_KEY_TIME_SLEEP_256MS,
  153. SX1509B_KEY_TIME_SLEEP_512MS,
  154. SX1509B_KEY_TIME_SLEEP_1S,
  155. SX1509B_KEY_TIME_SLEEP_2S,
  156. SX1509B_KEY_TIME_SLEEP_4S,
  157. SX1509B_KEY_TIME_SLEEP_8S
  158. } sx1509b_key_sleep_t;
  159. /**
  160. * @brief Key engine scan time setting.
  161. */
  162. typedef enum
  163. {
  164. SX1509B_KEY_TIME_SCAN_1MS,
  165. SX1509B_KEY_TIME_SCAN_2MS,
  166. SX1509B_KEY_TIME_SCAN_4MS,
  167. SX1509B_KEY_TIME_SCAN_8MS,
  168. SX1509B_KEY_TIME_SCAN_16MS,
  169. SX1509B_KEY_TIME_SCAN_32MS,
  170. SX1509B_KEY_TIME_SCAN_64MS,
  171. SX1509B_KEY_TIME_SCAN_128MS
  172. } sx1509b_key_scan_t;
  173. /**
  174. * @brief Macro that defines expander module.
  175. *
  176. * @param[in] sx1509b_inst_name Name of the instance to be created.
  177. * @param[in] instance_count Number of connected expanders.
  178. */
  179. #define SX1509B_INSTANCES_DEF_START(sx1509b_inst_name, instance_count)\
  180. static sx1509b_instance_t sx1509b_inst_name[instance_count]
  181. /**
  182. * ===============================================================================================
  183. * @brief General expander utility functions.
  184. */
  185. /**
  186. * @brief Function initialising expander module.
  187. *
  188. * @param[in] p_instances Pointer to expander module.
  189. * @param[in] Number of connected expanders.
  190. */
  191. void sx1509b_init(sx1509b_instance_t * p_instances, uint8_t count);
  192. /**
  193. * @brief Function adding expander instance.
  194. *
  195. * @note Should be called for every connected expander.
  196. * Order of calls define order of pins and ports.
  197. *
  198. * @param[in] p_twi_sensor Pointer to common sensor instance. @ref NRF_TWI_SENSOR_DEF
  199. * @param[in] sensor_address Address of expander on I2C bus.
  200. *
  201. * @retval NRF_ERROR_MODULE_NOT_INITIALIZED Returned if expander module wasn't initialised
  202. * @retval NRF_ERROR_STORAGE_FULL Returned if trying to add more instances than defined.
  203. * @retval other Return error code from nrf_twi_sensor
  204. * @ref nrf_twi_sensor_write
  205. */
  206. ret_code_t sx1509b_add_instance(nrf_twi_sensor_t * p_twi_sensor, uint8_t sensor_address);
  207. /**
  208. * @brief Function for writing current configuration to expander.
  209. *
  210. * @param[in] instance_num Number of expander, order is the same as sx1509b_add_instance calls.
  211. *
  212. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with given number.
  213. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  214. */
  215. ret_code_t sx1509b_cfg_write(uint8_t instance_num);
  216. /**
  217. * @brief Function for reading current configuration of expander.
  218. *
  219. * @param[in] instance_num Number of expander, order is the same as sx1509b_add_instance calls.
  220. *
  221. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with given number.
  222. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  223. */
  224. ret_code_t sx1509b_cfg_read(uint8_t instance_num);
  225. /**
  226. * @brief Function for setting clock configuration.
  227. *
  228. * @param instance_num Number of expander.
  229. * @param source Clock source.
  230. * @param oscio_set Oscio pin setting. True if pin is enabled.
  231. * @param oscio_freq Oscio frequency divider. Refer to expander documentation.
  232. *
  233. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with given number.
  234. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  235. */
  236. ret_code_t sx1509b_clock_set(uint8_t instance_num,
  237. sx1509b_clock_t source,
  238. bool oscio_set,
  239. uint8_t oscio_freq);
  240. /*
  241. * @brief Function for setting nreset and debounce time.
  242. *
  243. * @param instance_num Number of expander.
  244. * @param nreset_func Purpose of nreset pin.
  245. * @arg true Pin resets PWM/Blink/Fade counters.
  246. * @arg false Pin is equivalent to POR.
  247. * @param debounce_time Debounce time setting.
  248. * @param autoclear_nint Autoclear nint and interrupt source registers when pin data is read.
  249. * True if disabled.
  250. *
  251. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with such number.
  252. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  253. */
  254. ret_code_t sx1509b_misc_set(uint8_t instance_num,
  255. bool nreset_func,
  256. sx1509b_debounce_t debounce_time,
  257. bool autoclear_nint);
  258. /**
  259. * @brief Function sending software reset command to expander.
  260. *
  261. * @param instance_num Number of expander.
  262. *
  263. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with such number.
  264. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  265. */
  266. ret_code_t sx1509b_sw_reset(uint8_t instance_num);
  267. /**
  268. * @brief Function for setting register configuration of a single pin.
  269. *
  270. * @param[in] reg Register address, if register has two banks, address of bank B has to be used.
  271. * @param[in] pin Pin number.
  272. * @param[in] set Value to set.
  273. *
  274. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no pin with such number.
  275. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  276. */
  277. ret_code_t sx1509b_pin_cfg_reg_set(sx1509b_registers_t reg, uint32_t pin, uint8_t set);
  278. /**
  279. * @brief Function for getting register configuration of a single pin.
  280. *
  281. * @param[in] reg Register address, if register has two banks, address of bank B has to be used.
  282. * @param[in] pin Pin number.
  283. *
  284. * @retval 0xFF Returned if there is no pin with given number.
  285. * @return other Pin setting value at given register.
  286. */
  287. uint8_t sx1509b_pin_cfg_reg_get(sx1509b_registers_t reg, uint32_t pin);
  288. /**
  289. * @brief Function for setting register configuration of a port.
  290. *
  291. * @param reg Register address, if register has two banks, address of bank B has to be used.
  292. * @param port Port number.
  293. * @param mask Mask for the operating.
  294. * @param flag Operation, should the mask be written into register, clear values or set them.
  295. *
  296. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no port with such number.
  297. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  298. */
  299. ret_code_t sx1509b_port_cfg_reg_set(sx1509b_registers_t reg,
  300. uint32_t port,
  301. uint8_t mask,
  302. sx1509b_port_op_t flag);
  303. /**
  304. * @brief Function for getting register configuration of a port.
  305. *
  306. * @param reg Register address, if register has two banks, address of bank B has to be used.
  307. * @param port Port number.
  308. *
  309. * @retval Register value.
  310. */
  311. uint8_t sx1509b_port_cfg_reg_get(sx1509b_registers_t reg, uint32_t port);
  312. /**
  313. * @brief Function for updating pin data.
  314. *
  315. * @param user_cb Function to be called after pin data update is done.
  316. *
  317. * @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_reg_read
  318. */
  319. ret_code_t sx1509b_pin_data_update(nrf_twi_sensor_reg_cb_t user_cb);
  320. /**
  321. * @brief Function for updating latch data.
  322. *
  323. * @param user_cb Function to be called after latch update is done.
  324. *
  325. * @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_reg_read
  326. */
  327. ret_code_t sx1509b_pin_latch_update(nrf_twi_sensor_reg_cb_t user_cb);
  328. /**
  329. * @brief Function for setting long slew for given pin.
  330. *
  331. * @param pin_number Pin number.
  332. * @param set Long slew setting.
  333. * @arg true Long slew is enabled.
  334. * @arg false Long slew is disabled.
  335. *
  336. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  337. */
  338. __STATIC_INLINE ret_code_t sx1509b_pin_long_slew(uint32_t pin_number, bool set);
  339. /**
  340. * @brief Function for setting low drive for given pin.
  341. *
  342. * @param pin_number Pin number.
  343. * @param set Low drive setting.
  344. * @arg true Low drive is enabled.
  345. * @arg false Low drive is disabled.
  346. *
  347. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  348. */
  349. __STATIC_INLINE ret_code_t sx1509b_pin_low_drive(uint32_t pin_number, bool set);
  350. /**
  351. * @brief Function for setting open drain for given pin.
  352. *
  353. * @param pin_number Pin number.
  354. * @param set Open drain setting.
  355. * @arg true Open drain is enabled.
  356. * @arg false Open drain is disabled.
  357. *
  358. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  359. */
  360. __STATIC_INLINE ret_code_t sx1509b_pin_open_drain(uint32_t pin_number, bool set);
  361. /**
  362. * @brief Function for setting polarity for given pin.
  363. *
  364. * @param pin_number Pin number.
  365. * @param set Polarity setting.
  366. * @arg true Inverted polarity.
  367. * @arg false Normal polarity.
  368. *
  369. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  370. */
  371. __STATIC_INLINE ret_code_t sx1509b_pin_polarity(uint32_t pin_number, bool set);
  372. /**
  373. * @brief Function for setting debounce for given pin.
  374. *
  375. * @param pin_number Pin number.
  376. * @param set Debounce setting.
  377. * @arg true Debouncing is enabled.
  378. * @arg false Debouncing is disabled.
  379. *
  380. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  381. */
  382. __STATIC_INLINE ret_code_t sx1509b_pin_debounce(uint32_t pin_number, bool set);
  383. /**
  384. * @brief Function for setting high input for given pin.
  385. *
  386. * @param pin_number Pin number.
  387. * @param set High input setting.
  388. * @arg true High input is enabled.
  389. * @arg false High input is disabled.
  390. *
  391. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no pin with such number.
  392. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  393. */
  394. ret_code_t sx1509b_pin_high_input(uint32_t pin_number, bool set);
  395. /**
  396. * @brief Function for setting level shift for given pin.
  397. *
  398. * @param pin_number Pin number.
  399. * @param set Level shift setting.
  400. *
  401. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  402. */
  403. __STATIC_INLINE ret_code_t sx1509b_pin_level_shifter(uint32_t pin_number,
  404. sx1509b_level_shift_t set);
  405. /**
  406. * @brief Function for setting longslew for given port.
  407. *
  408. * @param port_num Port number.
  409. * @param out_mask Long slew mask.
  410. * @param flag Port operation flag. @ref sx1509b_port_op_t
  411. *
  412. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  413. */
  414. __STATIC_INLINE ret_code_t sx1509b_port_long_slew(uint8_t port_num,
  415. uint8_t out_mask,
  416. sx1509b_port_op_t flag);
  417. /**
  418. * @brief Function for setting low drive for given port.
  419. *
  420. * @param port_num Port number.
  421. * @param out_mask Low drive mask.
  422. * @param flag Port operation flag. @ref sx1509b_port_op_t
  423. *
  424. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  425. */
  426. __STATIC_INLINE ret_code_t sx1509b_port_low_drive(uint8_t port_num,
  427. uint8_t out_mask,
  428. sx1509b_port_op_t flag);
  429. /**
  430. * @brief Function for setting open drain for given port.
  431. *
  432. * @param port_num Port number.
  433. * @param out_mask Open drain mask.
  434. * @param flag Port operation flag. @ref sx1509b_port_op_t
  435. *
  436. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  437. */
  438. __STATIC_INLINE ret_code_t sx1509b_port_open_drain(uint8_t port_num,
  439. uint8_t out_mask,
  440. sx1509b_port_op_t flag);
  441. /**
  442. * @brief Function for setting polarity for given port.
  443. *
  444. * @param port_num Port number.
  445. * @param out_mask Polarity mask.
  446. * @param flag Port operation flag. @ref sx1509b_port_op_t
  447. *
  448. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  449. */
  450. __STATIC_INLINE ret_code_t sx1509b_port_polarity(uint8_t port_num,
  451. uint8_t out_mask,
  452. sx1509b_port_op_t flag);
  453. /**
  454. * @brief Function for setting debounce for given port.
  455. *
  456. * @param port_num Port number.
  457. * @param out_mask Debounce mask.
  458. * @param flag Port operation flag. @ref sx1509b_port_op_t
  459. *
  460. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  461. */
  462. __STATIC_INLINE ret_code_t sx1509b_port_debounce(uint8_t port_num,
  463. uint8_t out_mask,
  464. sx1509b_port_op_t flag);
  465. /**
  466. * @brief Function for setting high input for given port.
  467. *
  468. * @param port_num Port number.
  469. * @param out_mask High input mask.
  470. * @param flag Port operation flag. @ref sx1509b_port_op_t
  471. *
  472. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no pin with such number.
  473. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  474. */
  475. ret_code_t sx1509b_port_high_input(uint8_t port_num, uint8_t out_mask, sx1509b_port_op_t flag);
  476. /**
  477. * @brief Function for setting pull up for given port.
  478. *
  479. * @param port_num Port number.
  480. * @param out_mask Pull up mask.
  481. * @param flag Port operation flag. @ref sx1509b_port_op_t
  482. *
  483. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  484. */
  485. __STATIC_INLINE ret_code_t sx1509b_port_pull_up(uint8_t port_num,
  486. uint8_t out_mask,
  487. sx1509b_port_op_t flag);
  488. /**
  489. * @brief Function for setting pull down for given port.
  490. *
  491. * @param port_num Port number.
  492. * @param out_mask Pull down mask.
  493. * @param flag Port operation flag. @ref sx1509b_port_op_t
  494. *
  495. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  496. */
  497. __STATIC_INLINE ret_code_t sx1509b_port_pull_down(uint8_t port_num,
  498. uint8_t out_mask,
  499. sx1509b_port_op_t flag);
  500. /**
  501. * ===============================================================================================
  502. * @brief Functions compatible with nrf_gpio
  503. */
  504. /**
  505. * @brief Function for configuring the given GPIO pin number as output, hiding inner details.
  506. * This function can be used to configure a pin as simple output with gate driving.
  507. *
  508. * @param pin_number Specifies the pin number.
  509. *
  510. * @note Sense capability on the pin is disabled as the pins are configured as output.
  511. *
  512. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  513. */
  514. __STATIC_INLINE ret_code_t sx1509b_pin_cfg_output(uint32_t pin_number);
  515. /**
  516. * @brief Function for configuring the given GPIO pin number as input, hiding inner details.
  517. * This function can be used to configure a pin as simple input.
  518. *
  519. * @param pin_number Specifies the pin number.
  520. * @param pull_config State of the pin range pull resistor (no pull, pulled down, or pulled high).
  521. *
  522. * @note Sense capability on the pin is disabled and input is connected to buffer.
  523. *
  524. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  525. */
  526. ret_code_t sx1509b_pin_cfg_input(uint32_t pin_number, sx1509b_pin_pull_t pull_config);
  527. /**
  528. * @brief Function for resetting pin configuration to its default state.
  529. *
  530. * @param pin_number Specifies the pin number.
  531. *
  532. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  533. */
  534. ret_code_t sx1509b_pin_cfg_default(uint32_t pin_number);
  535. /**
  536. * @brief Function for configuring the given GPIO pin number as a watcher. Only input is connected.
  537. *
  538. * @param pin_number Specifies the pin number.
  539. *
  540. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  541. */
  542. __STATIC_INLINE ret_code_t sx1509b_pin_cfg_watcher(uint32_t pin_number); // non
  543. /**
  544. * @brief Function for disconnecting input for the given GPIO.
  545. *
  546. * @param pin_number Specifies the pin number.
  547. *
  548. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  549. */
  550. __STATIC_INLINE ret_code_t sx1509b_pin_cfg_input_disconnect(uint32_t pin_number);
  551. /**
  552. * @brief Function for configuring the given GPIO pin number as input, hiding inner details.
  553. * Sense capability on the pin is configurable and input is connected to buffer.
  554. *
  555. * @param pin_number Specifies the pin number.
  556. * @param pull_config State of the pin pull resistor (no pull, pulled down, or pulled high).
  557. * @param sense_config Sense level of the pin (no sense, sense low, sense high or sense both).
  558. *
  559. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  560. */
  561. ret_code_t sx1509b_pin_cfg_sense_input(uint32_t pin_number,
  562. sx1509b_pin_pull_t pull_config,
  563. sx1509b_pin_sense_t sense_config);
  564. /**
  565. * @brief Function for configuring sense level for the given GPIO.
  566. *
  567. * @param pin_number Specifies the pin number.
  568. * @param sense_config Sense configuration.
  569. *
  570. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  571. */
  572. ret_code_t sx1509b_pin_cfg_sense_set(uint32_t pin_number, sx1509b_pin_sense_t sense_config);
  573. /**
  574. * @brief Function for setting the direction for a GPIO pin.
  575. *
  576. * @param pin_number Specifies the pin number for which to set the direction.
  577. * @param direction Specifies the direction.
  578. *
  579. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  580. */
  581. ret_code_t sx1509b_pin_dir_set(uint32_t pin_number, sx1509b_pin_dir_t direction);
  582. /**
  583. * @brief Function for setting a GPIO pin.
  584. *
  585. * Note that the pin must be configured as an output for this function to have any effect.
  586. *
  587. * @param pin_number Specifies the pin number to set.
  588. *
  589. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  590. */
  591. __STATIC_INLINE ret_code_t sx1509b_pin_set(uint32_t pin_number);
  592. /**
  593. * @brief Function for clearing a GPIO pin.
  594. *
  595. * Note that the pin must be configured as an output for this
  596. * function to have any effect.
  597. *
  598. * @param pin_number Specifies the pin number to clear.
  599. *
  600. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  601. */
  602. __STATIC_INLINE ret_code_t sx1509b_pin_clear(uint32_t pin_number);
  603. /**
  604. * @brief Function for toggling a GPIO pin.
  605. *
  606. * Note that the pin must be configured as an output for this
  607. * function to have any effect.
  608. *
  609. * @param pin_number Specifies the pin number to toggle.
  610. *
  611. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  612. */
  613. __STATIC_INLINE ret_code_t sx1509b_pin_toggle(uint32_t pin_number);
  614. /**
  615. * @brief Function for writing a value to a GPIO pin.
  616. *
  617. * Note that the pin must be configured as an output for this
  618. * function to have any effect.
  619. *
  620. * @param pin_number Specifies the pin number to write.
  621. *
  622. * @param value Specifies the value to be written to the pin.
  623. * @arg 0 Clears the pin.
  624. * @arg >=1 Sets the pin.
  625. *
  626. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  627. */
  628. __STATIC_INLINE ret_code_t sx1509b_pin_write(uint32_t pin_number, sx1509b_pin_set_t value);
  629. /**
  630. * @brief Function for reading the input level of a GPIO pin.
  631. *
  632. * @note The pin must have input connected for the value
  633. * returned from this function to be valid.
  634. * Due to specifics of TWI expander, pin data must be updated first
  635. * to get current value @ref sx1509b_pin_data_update
  636. *
  637. * @param pin_number Specifies the pin number to read.
  638. *
  639. * @return 0 if the pin input level is low. Positive value if the pin is high.
  640. */
  641. __STATIC_INLINE uint32_t sx1509b_pin_read(uint32_t pin_number);
  642. /**
  643. * @brief Function for reading the output level of a GPIO pin.
  644. *
  645. * @param pin_number Specifies the pin number to read.
  646. *
  647. * @return 0 if the pin output level is low. Positive value if pin output is high.
  648. */
  649. __STATIC_INLINE uint32_t sx1509b_pin_out_read(uint32_t pin_number);
  650. /**
  651. * @brief Function for reading the sense configuration of a GPIO pin.
  652. *
  653. * @param pin_number Specifies the pin number to read.
  654. *
  655. * @retval Sense configuration.
  656. */
  657. __STATIC_INLINE sx1509b_pin_sense_t sx1509b_pin_sense_get(uint32_t pin_number);
  658. /**
  659. * @brief Function for getting expander port number based on pin number.
  660. *
  661. * @retval Port number.
  662. */
  663. __STATIC_INLINE uint8_t sx1509b_pin_port_decode(uint32_t pin_number);
  664. /**
  665. * @brief Function for setting output direction on selected pins on a given port.
  666. *
  667. * @param port_num Port number.
  668. * @param out_mask Mask specifying the pins to set as output.
  669. *
  670. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  671. */
  672. __STATIC_INLINE ret_code_t sx1509b_port_dir_output_set(uint8_t port_num, uint8_t out_mask);
  673. /**
  674. * @brief Function for setting input direction on selected pins on a given port.
  675. *
  676. * @param port_num Port number.
  677. * @param in_mask Mask specifying the pins to set as input.
  678. *
  679. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  680. */
  681. __STATIC_INLINE ret_code_t sx1509b_port_dir_input_set(uint8_t port_num, uint8_t in_mask);
  682. /**
  683. * @brief Function for writing the direction configuration of GPIO pins in a given port.
  684. *
  685. * @param port_num Port number.
  686. * @param dir_mask Mask specifying the direction of pins.
  687. * Bit set means that the given pin is configured as output.
  688. *
  689. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  690. */
  691. __STATIC_INLINE ret_code_t sx1509b_port_dir_write(uint8_t port_num, uint8_t dir_mask);
  692. /**
  693. * @brief Function for reading the direction configuration of a GPIO port.
  694. *
  695. * @param port_num Port number.
  696. *
  697. * @note Returns 0 if port doesn't exist.
  698. *
  699. * @retval Pin configuration of the current direction settings.
  700. * Bit set means that the given pin is configured as output.
  701. */
  702. __STATIC_INLINE uint8_t sx1509b_port_dir_read(uint8_t port_num);
  703. /**
  704. * @brief Function for reading the input signals of GPIO pins on a given port.
  705. *
  706. * @param port_num Port number.
  707. *
  708. * @note Returns 0 if port doesn't exist.
  709. *
  710. * @retval Port input values.
  711. */
  712. __STATIC_INLINE uint8_t sx1509b_port_in_read(uint8_t port_num);
  713. /**
  714. * @brief Function for reading the output signals of GPIO pins of a given port.
  715. *
  716. * @param port_num Port number.
  717. *
  718. * @note Returns 0 if port doesn't exist.
  719. *
  720. * @retval Port output values.
  721. */
  722. __STATIC_INLINE uint8_t sx1509b_port_out_read(uint8_t port_num);
  723. /**
  724. * @brief Function for writing the GPIO pins output on a given port.
  725. *
  726. * @param port_num Port number.
  727. * @param value Output port mask.
  728. *
  729. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  730. */
  731. __STATIC_INLINE ret_code_t sx1509b_port_out_write(uint8_t port_num, uint8_t value);
  732. /**
  733. * @brief Function for setting high level on selected GPIO pins of a given port.
  734. *
  735. * @param port_num Port number.
  736. * @param set_mask Mask with pins to set as logical high level.
  737. *
  738. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  739. */
  740. __STATIC_INLINE ret_code_t sx1509b_port_out_set(uint8_t port_num, uint8_t set_mask);
  741. /**
  742. * @brief Function for setting low level on selected GPIO pins of a given port.
  743. *
  744. * @param port_num Port number.
  745. * @param clr_mask Mask with pins to set as logical low level.
  746. *
  747. * @return Return error code from port config set @ref sx1509b_port_cfg_reg_set
  748. */
  749. __STATIC_INLINE ret_code_t sx1509b_port_out_clear(uint8_t port_num, uint8_t clr_mask);
  750. /**
  751. * @brief Function for reading pins state of multiple consecutive ports.
  752. *
  753. * @note Due to specifics of TWI expander, pin data must be updated first
  754. * to get current value @ref sx1509b_pin_data_update
  755. *
  756. * @param start_port Index of the first port to read.
  757. * @param length Number of ports to read.
  758. * @param p_masks Pointer to output array where port states will be stored.
  759. *
  760. * @retval NRF_ERROR_INVALID_LENGTH If trying to read more ports than available.
  761. * @retval NRF_SUCCESS If operation was successful.
  762. */
  763. ret_code_t sx1509b_ports_read(uint8_t start_port, uint32_t length, uint8_t * p_masks);
  764. /**
  765. * @brief Function for reading latch state of multiple consecutive ports.
  766. *
  767. * @note Due to specifics of TWI expander, latch data must be updated first
  768. * to get current value @ref sx1509b_pin_latch_update
  769. *
  770. * @param start_port Index of the first port to read.
  771. * @param length Number of ports to read.
  772. * @param p_masks Pointer to output array where latch states will be stored.
  773. *
  774. * @retval NRF_ERROR_INVALID_LENGTH If trying to read more ports than available.
  775. * @retval NRF_SUCCESS If operation was successful.
  776. */
  777. ret_code_t sx1509b_latches_read(uint8_t start_port, uint32_t length, uint8_t * p_masks);
  778. /**
  779. * @brief Function for reading latch state of single pin.
  780. *
  781. * @note Due to specifics of TWI expander, latch data must be updated first
  782. * to get current value @ref sx1509b_pin_latch_update
  783. *
  784. * @param pin_number Pin number.
  785. *
  786. * @retval 0 Returned if latch is not set
  787. * @retval 1 Returned if latch is set.
  788. * @retval other Return from @ref sx1509b_pin_cfg_reg_get
  789. */
  790. __STATIC_INLINE uint32_t sx1509b_pin_latch_get(uint32_t pin_number);
  791. /**
  792. * @brief Function for clearing latch state of a single pin.
  793. *
  794. * @param pin_number Pin number.
  795. *
  796. * @return Return error code from pin config set @ref sx1509b_pin_cfg_reg_set
  797. */
  798. ret_code_t sx1509b_pin_latch_clear(uint32_t pin_number);
  799. /**
  800. * ===============================================================================================
  801. * @brief Led driver functions.
  802. */
  803. /**
  804. * @brief Function enabling led driver.
  805. *
  806. * @param instance_num Number of expander instance.
  807. * @param clock_internal Sets clock source.
  808. * @arg true External clock source
  809. * @arg false Internal 2Mhz clock
  810. * @param frequency Frequency divider.
  811. * @arg 0 Led driver functionality is disabled for all IOs.
  812. * @arg Else Divider value, refer to expander documentation.
  813. *
  814. * @retval NRF_ERROR_INVALID_PARAM Returned if given instance isn't present.
  815. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  816. */
  817. ret_code_t sx1509b_led_driver_enable(uint8_t instance_num, bool clock_internal, uint8_t frequency);
  818. /**
  819. * @brief Function for setting led driver mode.
  820. *
  821. * @param port_num Port for which mode will be set.
  822. * @param mode Led driver mode.
  823. * @arg true Logarithmic mode
  824. * @arg false Linear mode
  825. *
  826. * @retval NRF_ERROR_INVALID_PARAM Returned if given port isn't present.
  827. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  828. */
  829. ret_code_t sx1509b_led_mode(uint8_t port_num, bool mode);
  830. /**
  831. * @brief Function for setting led driver pin times.
  832. *
  833. * @param pin_number Pin which settings will be changed.
  834. * @param on_time On time of pin. Refer to expander documentation.
  835. * @param on_intensity Intensity during on time. Between 0 and 255.
  836. * @param off_time Off time of pin. Refer to expander documentation.
  837. * @param off_intensity Intensity during off time. Between 0 and 7.
  838. *
  839. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no pin with given number.
  840. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  841. */
  842. ret_code_t sx1509b_led_pin_time(uint32_t pin_number,
  843. uint8_t on_time,
  844. uint8_t on_intensity,
  845. uint8_t off_time,
  846. uint8_t off_intensity);
  847. /**
  848. * @brief Function for setting led driver pin fade characteristics.
  849. *
  850. * @param pin_number Pin which settings will be changed.
  851. * @param fade_in Fade in time of pin. Refer to expander documentation.
  852. * @param fade_out Fade out time of pin. Refer to expander documentation.
  853. *
  854. * @retval NRF_ERROR_INVALID_PARAM Returned if given pin has no fade capability,
  855. * or there is no pin with given number.
  856. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  857. */
  858. ret_code_t sx1509b_led_pin_fade(uint32_t pin_number, uint8_t fade_in, uint8_t fade_out);
  859. /**
  860. * @brief Function for enabling led driver on selected pin.
  861. *
  862. * @param pin_number Pin number.
  863. *
  864. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no pin with given number.
  865. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  866. */
  867. ret_code_t sx1509b_led_pin_enable(uint32_t pin_number);
  868. /**
  869. * @brief Function for disabling led driver on selected pin.
  870. *
  871. * @param pin_number Pin number.
  872. *
  873. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no pin with given number.
  874. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  875. */
  876. ret_code_t sx1509b_led_pin_disable(uint32_t pin_number);
  877. /**
  878. * @brief Function for getting led driver time on register of selected pin.
  879. *
  880. * @param pin_number Pin number.
  881. *
  882. * @retval Time on led driver register of selected pin
  883. */
  884. uint8_t sx1509b_led_driver_get_reg(uint32_t pin_number);
  885. /**
  886. * ===============================================================================================
  887. * @brief Key Engine functions.
  888. */
  889. /**
  890. * @brief Function enabling key engine.
  891. *
  892. * @param instance_num Number of expander.
  893. * @param rows Number of keyboard rows.
  894. * @arg < 2 Disable key engine.
  895. * @arg >= 2 Number of rows (max 8).
  896. * @param columns Number of columns (max 8).
  897. * @param sleep_time Time of inactivity before key engine enters sleep mode.
  898. * @param scan_time Scan time per column. Must be bigger than debounce time.
  899. * @param debounce_time Input debounce time.
  900. *
  901. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with given number.
  902. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  903. */
  904. ret_code_t sx1509b_key_engine_enable(uint8_t instance_num,
  905. uint8_t rows,
  906. uint8_t columns,
  907. sx1509b_key_sleep_t sleep_time,
  908. sx1509b_key_scan_t scan_time,
  909. sx1509b_debounce_t debounce_time);
  910. /**
  911. * @brief Function scheduling key data update.
  912. *
  913. * @param instance_num Number of expander to update.
  914. * @param user_cb Function called after key data update.
  915. *
  916. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with given number.
  917. * @retval other Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
  918. */
  919. ret_code_t sx1509b_key_data_update(uint8_t instance_num, nrf_twi_sensor_reg_cb_t user_cb);
  920. /**
  921. * @brief Function returning pressed key column.
  922. *
  923. * @param instance_num Number of expander.
  924. *
  925. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with given number.
  926. * @retval 0xFF If no key was pressed.
  927. * @retval 0 - 7 Column number.
  928. */
  929. uint8_t sx1509b_key_column_get(uint8_t instance_num);
  930. /**
  931. * @brief Function returning pressed key row.
  932. *
  933. * @param instance_num Number of expander.
  934. *
  935. * @retval NRF_ERROR_INVALID_PARAM Returned if there is no expander with given number.
  936. * @retval 0xFF If no key was pressed.
  937. * @retval 0 - 7 Row number.
  938. */
  939. uint8_t sx1509b_key_row_get(uint8_t instance_num);
  940. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  941. /**
  942. * ===============================================================================================
  943. * @brief General expander inline utility functions.
  944. */
  945. __STATIC_INLINE ret_code_t sx1509b_pin_long_slew(uint32_t pin_number, bool set)
  946. {
  947. return sx1509b_pin_cfg_reg_set(SX1509B_REG_LONG_SLEW_B, pin_number, set);
  948. }
  949. __STATIC_INLINE ret_code_t sx1509b_pin_low_drive(uint32_t pin_number, bool set)
  950. {
  951. return sx1509b_pin_cfg_reg_set(SX1509B_REG_LOW_DRIVE_B, pin_number, set);
  952. }
  953. __STATIC_INLINE ret_code_t sx1509b_pin_open_drain(uint32_t pin_number, bool set)
  954. {
  955. return sx1509b_pin_cfg_reg_set(SX1509B_REG_OPEN_DRAIN_B, pin_number, set);
  956. }
  957. __STATIC_INLINE ret_code_t sx1509b_pin_polarity(uint32_t pin_number, bool set)
  958. {
  959. return sx1509b_pin_cfg_reg_set(SX1509B_REG_POLARITY_B, pin_number, set);
  960. }
  961. __STATIC_INLINE ret_code_t sx1509b_pin_debounce(uint32_t pin_number, bool set)
  962. {
  963. return sx1509b_pin_cfg_reg_set(SX1509B_REG_DEBOUNCE_EN_B, pin_number, set);
  964. }
  965. __STATIC_INLINE ret_code_t sx1509b_pin_level_shifter(uint32_t pin_number, sx1509b_level_shift_t set)
  966. {
  967. return sx1509b_pin_cfg_reg_set(SX1509B_REG_LEVEL_SHIFTER_1, pin_number, set);
  968. }
  969. __STATIC_INLINE ret_code_t sx1509b_port_long_slew(uint8_t port_num,
  970. uint8_t out_mask,
  971. sx1509b_port_op_t flag)
  972. {
  973. return sx1509b_port_cfg_reg_set(SX1509B_REG_LONG_SLEW_B, port_num, out_mask, flag);
  974. }
  975. __STATIC_INLINE ret_code_t sx1509b_port_low_drive(uint8_t port_num,
  976. uint8_t out_mask,
  977. sx1509b_port_op_t flag)
  978. {
  979. return sx1509b_port_cfg_reg_set(SX1509B_REG_LOW_DRIVE_B, port_num, out_mask, flag);
  980. }
  981. __STATIC_INLINE ret_code_t sx1509b_port_open_drain(uint8_t port_num,
  982. uint8_t out_mask,
  983. sx1509b_port_op_t flag)
  984. {
  985. return sx1509b_port_cfg_reg_set(SX1509B_REG_OPEN_DRAIN_B, port_num, out_mask, flag);
  986. }
  987. __STATIC_INLINE ret_code_t sx1509b_port_polarity(uint8_t port_num,
  988. uint8_t out_mask,
  989. sx1509b_port_op_t flag)
  990. {
  991. return sx1509b_port_cfg_reg_set(SX1509B_REG_POLARITY_B, port_num, out_mask, flag);
  992. }
  993. __STATIC_INLINE ret_code_t sx1509b_port_debounce(uint8_t port_num,
  994. uint8_t out_mask,
  995. sx1509b_port_op_t flag)
  996. {
  997. return sx1509b_port_cfg_reg_set(SX1509B_REG_DEBOUNCE_EN_B, port_num, out_mask, flag);
  998. }
  999. __STATIC_INLINE ret_code_t sx1509b_port_pull_up(uint8_t port_num,
  1000. uint8_t out_mask,
  1001. sx1509b_port_op_t flag)
  1002. {
  1003. return sx1509b_port_cfg_reg_set(SX1509B_REG_PULL_UP_B, port_num, out_mask, flag);
  1004. }
  1005. __STATIC_INLINE ret_code_t sx1509b_port_pull_down(uint8_t port_num,
  1006. uint8_t out_mask,
  1007. sx1509b_port_op_t flag)
  1008. {
  1009. return sx1509b_port_cfg_reg_set(SX1509B_REG_PULL_DOWN_B, port_num, out_mask, flag);
  1010. }
  1011. /**
  1012. * ===============================================================================================
  1013. * @brief Inline functions compatible with nrf_gpio
  1014. */
  1015. __STATIC_INLINE ret_code_t sx1509b_pin_cfg_output(uint32_t pin_number)
  1016. {
  1017. return sx1509b_pin_cfg_reg_set(SX1509B_REG_DIR_B, pin_number, SX1509B_PIN_DIR_OUTPUT);
  1018. }
  1019. __STATIC_INLINE ret_code_t sx1509b_pin_cfg_watcher(uint32_t pin_number)
  1020. {
  1021. return sx1509b_pin_cfg_input(pin_number, SX1509B_PIN_NOPULL);
  1022. }
  1023. __STATIC_INLINE ret_code_t sx1509b_pin_cfg_input_disconnect(uint32_t pin_number)
  1024. {
  1025. return sx1509b_pin_cfg_reg_set(SX1509B_REG_INPUT_DISABLE_B, pin_number, 1);
  1026. }
  1027. __STATIC_INLINE ret_code_t sx1509b_pin_set(uint32_t pin_number)
  1028. {
  1029. return sx1509b_pin_cfg_reg_set(SX1509B_REG_DATA_B, pin_number, SX1509B_PIN_SET);
  1030. }
  1031. __STATIC_INLINE ret_code_t sx1509b_pin_clear(uint32_t pin_number)
  1032. {
  1033. return sx1509b_pin_cfg_reg_set(SX1509B_REG_DATA_B, pin_number, SX1509B_PIN_CLR);
  1034. }
  1035. __STATIC_INLINE ret_code_t sx1509b_pin_toggle(uint32_t pin_number)
  1036. {
  1037. uint8_t val = sx1509b_pin_cfg_reg_get(SX1509B_REG_DATA_B, pin_number);
  1038. val = !val;
  1039. return sx1509b_pin_cfg_reg_set(SX1509B_REG_DATA_B, pin_number, val);
  1040. }
  1041. __STATIC_INLINE ret_code_t sx1509b_pin_write(uint32_t pin_number, sx1509b_pin_set_t value)
  1042. {
  1043. value = (value >= 1) ? 1 : 0;
  1044. return sx1509b_pin_cfg_reg_set(SX1509B_REG_DATA_B, pin_number, value);
  1045. }
  1046. __STATIC_INLINE uint32_t sx1509b_pin_read(uint32_t pin_number)
  1047. {
  1048. return sx1509b_pin_cfg_reg_get(SX1509B_REG_DATA_B, pin_number);
  1049. }
  1050. __STATIC_INLINE uint32_t sx1509b_pin_out_read(uint32_t pin_number)
  1051. {
  1052. return sx1509b_pin_cfg_reg_get(SX1509B_REG_DATA_B, pin_number);
  1053. }
  1054. __STATIC_INLINE sx1509b_pin_sense_t sx1509b_pin_sense_get(uint32_t pin_number)
  1055. {
  1056. return sx1509b_pin_cfg_reg_get(SX1509B_REG_SENSE_H_B, pin_number);
  1057. }
  1058. __STATIC_INLINE uint8_t sx1509b_pin_port_decode(uint32_t pin_number)
  1059. {
  1060. return pin_number / SX1509B_INNER_NEXT_BANK;
  1061. }
  1062. __STATIC_INLINE ret_code_t sx1509b_port_dir_output_set(uint8_t port_num, uint8_t out_mask)
  1063. {
  1064. return sx1509b_port_cfg_reg_set(SX1509B_REG_DIR_B, port_num, out_mask, SX1509B_PORT_CLEAR);
  1065. }
  1066. __STATIC_INLINE ret_code_t sx1509b_port_dir_input_set(uint8_t port_num, uint8_t in_mask)
  1067. {
  1068. return sx1509b_port_cfg_reg_set(SX1509B_REG_DIR_B, port_num, in_mask, SX1509B_PORT_SET);
  1069. }
  1070. __STATIC_INLINE ret_code_t sx1509b_port_dir_write(uint8_t port_num, uint8_t dir_mask)
  1071. {
  1072. return sx1509b_port_cfg_reg_set(SX1509B_REG_DIR_B, port_num, ~dir_mask, SX1509B_PORT_WRITE);
  1073. }
  1074. __STATIC_INLINE uint8_t sx1509b_port_dir_read(uint8_t port_num)
  1075. {
  1076. return ~sx1509b_port_cfg_reg_get(SX1509B_REG_DIR_B, port_num);
  1077. }
  1078. __STATIC_INLINE uint8_t sx1509b_port_in_read(uint8_t port_num)
  1079. {
  1080. return sx1509b_port_cfg_reg_get(SX1509B_REG_DATA_B, port_num);
  1081. }
  1082. __STATIC_INLINE uint8_t sx1509b_port_out_read(uint8_t port_num)
  1083. {
  1084. return sx1509b_port_cfg_reg_get(SX1509B_REG_DATA_B, port_num);
  1085. }
  1086. __STATIC_INLINE ret_code_t sx1509b_port_out_write(uint8_t port_num, uint8_t value)
  1087. {
  1088. return sx1509b_port_cfg_reg_set(SX1509B_REG_DATA_B, port_num, value, SX1509B_PORT_WRITE);
  1089. }
  1090. __STATIC_INLINE ret_code_t sx1509b_port_out_set(uint8_t port_num, uint8_t set_mask)
  1091. {
  1092. return sx1509b_port_cfg_reg_set(SX1509B_REG_DATA_B, port_num, set_mask, SX1509B_PORT_SET);
  1093. }
  1094. __STATIC_INLINE ret_code_t sx1509b_port_out_clear(uint8_t port_num, uint8_t clr_mask)
  1095. {
  1096. return sx1509b_port_cfg_reg_set(SX1509B_REG_DATA_B, port_num, clr_mask, SX1509B_PORT_CLEAR);
  1097. }
  1098. __STATIC_INLINE uint32_t sx1509b_pin_latch_get(uint32_t pin_number)
  1099. {
  1100. return sx1509b_pin_cfg_reg_get(SX1509B_REG_INT_SRC_B, pin_number);
  1101. }
  1102. #endif //SUPPRESS_INLINE_IMPLEMENTATION
  1103. #ifdef __cplusplus
  1104. }
  1105. #endif
  1106. #endif // SX1509B_H