opamp.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /**
  2. * \file
  3. *
  4. * \brief SAM Operational Amplifier Controller (OPAMP) Driver
  5. *
  6. * Copyright (C) 2014-2015 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. /*
  44. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  45. */
  46. #ifndef OPAMP_H_INCLUDED
  47. #define OPAMP_H_INCLUDED
  48. /**
  49. * \defgroup asfdoc_sam0_opamp_group SAM Operational Amplifier Controller (OPAMP) Driver
  50. *
  51. * This driver for Atmel&reg; | SMART ARM&reg;-based microcontrollers provides an interface for the configuration
  52. * and management of the device's Operational Amplifier Controller functionality.
  53. *
  54. * The following peripheral is used by this module:
  55. * - OPAMP (Operational Amplifier Controller)
  56. *
  57. * The following devices can use this module:
  58. * - Atmel | SMART SAM L21
  59. *
  60. * The outline of this documentation is as follows:
  61. * - \ref asfdoc_sam0_opamp_prerequisites
  62. * - \ref asfdoc_sam0_opamp_module_overview
  63. * - \ref asfdoc_sam0_opamp_special_considerations
  64. * - \ref asfdoc_sam0_opamp_extra_info
  65. * - \ref asfdoc_sam0_opamp_examples
  66. * - \ref asfdoc_sam0_opamp_api_overview
  67. *
  68. *
  69. * \section asfdoc_sam0_opamp_prerequisites Prerequisites
  70. *
  71. * There are no prerequisites for this module.
  72. *
  73. *
  74. * \section asfdoc_sam0_opamp_module_overview Module Overview
  75. *
  76. * The OPAMP is an individually configurable low power, general purpose operational
  77. * amplifier offering a high degree of flexibility and rail-to-rail inputs.
  78. *
  79. * Each operational amplifier can be configured in standalone operational amplifier
  80. * and operational amplifier with built-in feedback. All OPAMPs can be cascaded
  81. * to support circuits such as differential amplifiers.
  82. * \note For more detail configuration reference, refer to the "Built-in Modes"
  83. * section in the device datasheet.
  84. *
  85. * Each OPAMP has one positive and one negative input which can be flexible chosen
  86. * from analog input pins including the output of another OPAMP, internal inputs
  87. * such as the DAC or the resistor ladder, and the ground.
  88. *
  89. * Each OPAMP output can be selected as input for AC or ADC, also available
  90. * on I/O pins.
  91. *
  92. * Four modes are available to select the trade-off between speed and power
  93. * consumption to best fit the application requirements and optimize the power
  94. * consumption.
  95. *
  96. * \section asfdoc_sam0_opamp_special_considerations Special Considerations
  97. *
  98. * There are no special considerations for this module.
  99. *
  100. *
  101. * \section asfdoc_sam0_opamp_extra_info Extra Information
  102. *
  103. * For extra information, see \ref asfdoc_sam0_opamp_extra. This includes:
  104. * - \ref asfdoc_sam0_opamp_extra_acronyms
  105. * - \ref asfdoc_sam0_opamp_extra_dependencies
  106. * - \ref asfdoc_sam0_opamp_extra_errata
  107. * - \ref asfdoc_sam0_opamp_extra_history
  108. *
  109. *
  110. * \section asfdoc_sam0_opamp_examples Examples
  111. *
  112. * For a list of examples related to this driver, see
  113. * \ref asfdoc_sam0_opamp_exqsg.
  114. *
  115. *
  116. * \section asfdoc_sam0_opamp_api_overview API Overview
  117. * @{
  118. */
  119. #include <compiler.h>
  120. #include <system.h>
  121. #ifdef __cplusplus
  122. extern "C" {
  123. #endif
  124. /**
  125. * \brief OPAMP ID number enum.
  126. */
  127. enum opamp_id {
  128. /** OPAMP 0 */
  129. OPAMP_0 = 0,
  130. /** OPAMP 1 */
  131. OPAMP_1 = 1,
  132. /** OPAMP 2 */
  133. OPAMP_2 = 2,
  134. /** OPAMP number */
  135. OPAMP_NUM,
  136. };
  137. /**
  138. * \brief Negative input MUX selection configuration enum.
  139. *
  140. * Enum for the negative input of OPAMP0.
  141. */
  142. enum opamp0_neg_mux {
  143. /** Negative I/O pin 0 */
  144. OPAMP0_NEG_MUX_PIN0 = OPAMP_OPAMPCTRL_MUXNEG(0),
  145. /** Resistor ladder 0 taps */
  146. OPAMP0_NEG_MUX_TAP0 = OPAMP_OPAMPCTRL_MUXNEG(1),
  147. /** OPAMP output */
  148. OPAMP0_NEG_MUX_OUT0 = OPAMP_OPAMPCTRL_MUXNEG(2),
  149. /** DAC output */
  150. OPAMP0_NEG_MUX_DAC = OPAMP_OPAMPCTRL_MUXNEG(3),
  151. };
  152. /**
  153. * \brief Negative input MUX selection configuration enum.
  154. *
  155. * Enum for the negative input of OPAMP1.
  156. */
  157. enum opamp1_neg_mux {
  158. /** Negative I/O pin 1 */
  159. OPAMP1_NEG_MUX_PIN1 = OPAMP_OPAMPCTRL_MUXNEG(0),
  160. /** Resistor ladder 1 taps */
  161. OPAMP1_NEG_MUX_TAP1 = OPAMP_OPAMPCTRL_MUXNEG(1),
  162. /** OPAMP output */
  163. OPAMP1_NEG_MUX_OUT1 = OPAMP_OPAMPCTRL_MUXNEG(2),
  164. /** DAC output */
  165. OPAMP1_NEG_MUX_DAC = OPAMP_OPAMPCTRL_MUXNEG(3),
  166. };
  167. /**
  168. * \brief Negative input MUX selection configuration enum.
  169. *
  170. * Enum for the negative input of OPAMP2.
  171. */
  172. enum opamp2_neg_mux {
  173. /** Negative I/O pin 2 */
  174. OPAMP2_NEG_MUX_PIN2 = OPAMP_OPAMPCTRL_MUXNEG(0),
  175. /** Resistor ladder 2 taps */
  176. OPAMP2_NEG_MUX_TAP2 = OPAMP_OPAMPCTRL_MUXNEG(1),
  177. /** OPAMP output */
  178. OPAMP2_NEG_MUX_OUT2 = OPAMP_OPAMPCTRL_MUXNEG(2),
  179. /** Negative I/O pin 0 */
  180. OPAMP2_NEG_MUX_PIN0 = OPAMP_OPAMPCTRL_MUXNEG(3),
  181. /** Negative I/O pin 1 */
  182. OPAMP2_NEG_MUX_PIN1 = OPAMP_OPAMPCTRL_MUXNEG(4),
  183. /** DAC output */
  184. OPAMP2_NEG_MUX_DAC = OPAMP_OPAMPCTRL_MUXNEG(5),
  185. };
  186. /**
  187. * \brief Positive input MUX selection configuration enum.
  188. *
  189. * Enum for the positive input of OPAMP0.
  190. */
  191. enum opamp0_pos_mux {
  192. /** Positive I/O pin 0 */
  193. OPAMP0_POS_MUX_PIN0 = OPAMP_OPAMPCTRL_MUXPOS(0),
  194. /** Resistor ladder 0 taps */
  195. OPAMP0_POS_MUX_TAP0 = OPAMP_OPAMPCTRL_MUXPOS(1),
  196. /** DAC output */
  197. OPAMP0_POS_MUX_DAC = OPAMP_OPAMPCTRL_MUXPOS(2),
  198. /** Ground */
  199. OPAMP0_POS_MUX_GND = OPAMP_OPAMPCTRL_MUXPOS(3),
  200. };
  201. /**
  202. * \brief Positive input MUX selection configuration enum.
  203. *
  204. * Enum for the positive input of OPAMP1.
  205. */
  206. enum opamp1_pos_mux {
  207. /** Positive I/O pin 1 */
  208. OPAMP1_POS_MUX_PIN1 = OPAMP_OPAMPCTRL_MUXPOS(0),
  209. /** Resistor ladder 1 taps */
  210. OPAMP1_POS_MUX_TAP1 = OPAMP_OPAMPCTRL_MUXPOS(1),
  211. /** OPAMP0 output */
  212. OPAMP1_POS_MUX_OUT0 = OPAMP_OPAMPCTRL_MUXPOS(2),
  213. /** Ground */
  214. OPAMP1_POS_MUX_GND = OPAMP_OPAMPCTRL_MUXPOS(3),
  215. };
  216. /**
  217. * \brief Positive input MUX selection configuration enum.
  218. *
  219. * Enum for the positive input of OPAMP2.
  220. */
  221. enum opamp2_pos_mux {
  222. /** Positive I/O pin 2 */
  223. OPAMP2_POS_MUX_PIN2 = OPAMP_OPAMPCTRL_MUXPOS(0),
  224. /** Resistor ladder 2 taps */
  225. OPAMP2_POS_MUX_TAP2 = OPAMP_OPAMPCTRL_MUXPOS(1),
  226. /** OPAMP1 output */
  227. OPAMP2_POS_MUX_OUT1 = OPAMP_OPAMPCTRL_MUXPOS(2),
  228. /** Ground */
  229. OPAMP2_POS_MUX_GND = OPAMP_OPAMPCTRL_MUXPOS(3),
  230. /** Positive I/O pin 0 */
  231. OPAMP2_POS_MUX_PIN0 = OPAMP_OPAMPCTRL_MUXPOS(4),
  232. /** Positive I/O pin 1 */
  233. OPAMP2_POS_MUX_PIN1 = OPAMP_OPAMPCTRL_MUXPOS(5),
  234. /** Resistor ladder 0 taps */
  235. OPAMP2_POS_MUX_TAP0 = OPAMP_OPAMPCTRL_MUXPOS(6),
  236. };
  237. /**
  238. * \brief Potentiometer selection MUX configuration enum.
  239. *
  240. * Enum for the potentiometer selection of OPAMP 0 to 2.
  241. */
  242. enum opamp_pot_mux {
  243. /** Gain = R2/R1 = 1/7 */
  244. OPAMP_POT_MUX_14R_2R = OPAMP_OPAMPCTRL_POTMUX(0),
  245. /** Gain = R2/R1 = 1/3 */
  246. OPAMP_POT_MUX_12R_4R = OPAMP_OPAMPCTRL_POTMUX(1),
  247. /** Gain = R2/R1 = 1 */
  248. OPAMP_POT_MUX_8R_8R = OPAMP_OPAMPCTRL_POTMUX(2),
  249. /** Gain = R2/R1 = 1 + 2/3 */
  250. OPAMP_POT_MUX_6R_10R = OPAMP_OPAMPCTRL_POTMUX(3),
  251. /** Gain = R2/R1 = 3 */
  252. OPAMP_POT_MUX_4R_12R = OPAMP_OPAMPCTRL_POTMUX(4),
  253. /** Gain = R2/R1 = 4 + 1/3 */
  254. OPAMP_POT_MUX_3R_13R = OPAMP_OPAMPCTRL_POTMUX(5),
  255. /** Gain = R2/R1 = 7 */
  256. OPAMP_POT_MUX_2R_14R = OPAMP_OPAMPCTRL_POTMUX(6),
  257. /** Gain = R2/R1 = 15 */
  258. OPAMP_POT_MUX_R_15R = OPAMP_OPAMPCTRL_POTMUX(7),
  259. };
  260. /**
  261. * \brief Resistor 1 MUX selection configuration enum.
  262. *
  263. * Enum for the Resistor 1 of OPAMP0.
  264. */
  265. enum opamp0_res1_mux {
  266. /** Positive input of OPAMP0 */
  267. OPAMP0_RES1_MUX_POS_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(0),
  268. /** Negative input of OPAMP0 */
  269. OPAMP0_RES1_MUX_NEG_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(1),
  270. /** DAC output */
  271. OPAMP0_RES1_MUX_DAC = OPAMP_OPAMPCTRL_RES1MUX(2),
  272. /** Ground */
  273. OPAMP0_RES1_MUX_GND = OPAMP_OPAMPCTRL_RES1MUX(3),
  274. };
  275. /**
  276. * \brief Resistor 1 MUX selection configuration enum.
  277. *
  278. * Enum for the Resistor 1 of OPAMP1.
  279. */
  280. enum opamp1_res1_mux {
  281. /** Positive input of OPAMP1 */
  282. OPAMP1_RES1_MUX_POS_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(0),
  283. /** Negative input of OPAMP1 */
  284. OPAMP1_RES1_MUX_NEG_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(1),
  285. /** OPAMP0 output */
  286. OPAMP1_RES1_MUX_OUT0 = OPAMP_OPAMPCTRL_RES1MUX(2),
  287. /** Ground */
  288. OPAMP1_RES1_MUX_GND = OPAMP_OPAMPCTRL_RES1MUX(3),
  289. };
  290. /**
  291. * \brief Resistor 1 MUX selection configuration enum.
  292. *
  293. * Enum for the Resistor 1 of OPAMP2.
  294. */
  295. enum opamp2_res1_mux {
  296. /** Positive input of OPAMP2 */
  297. OPAMP2_RES1_MUX_POS_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(0),
  298. /** Negative input of OPAMP2 */
  299. OPAMP2_RES1_MUX_NEG_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(1),
  300. /** OPAMP1 output */
  301. OPAMP2_RES1_MUX_OUT1 = OPAMP_OPAMPCTRL_RES1MUX(2),
  302. /** Ground */
  303. OPAMP2_RES1_MUX_GND = OPAMP_OPAMPCTRL_RES1MUX(3),
  304. };
  305. /**
  306. * \brief Bias mode selection MUX configuration enum.
  307. *
  308. * Enum for the Bias mode selection of OPAMP 0 to 2.
  309. */
  310. enum opamp_bias_selection {
  311. /** Minimum current consumption but the slowest mode */
  312. OPAMP_BIAS_MODE_0 = OPAMP_OPAMPCTRL_BIAS(0),
  313. /** Low current consumption, slow speed */
  314. OPAMP_BIAS_MODE_1 = OPAMP_OPAMPCTRL_BIAS(1),
  315. /** High current consumption, fast speed */
  316. OPAMP_BIAS_MODE_2 = OPAMP_OPAMPCTRL_BIAS(2),
  317. /** Maximum current consumption but the fastest mode */
  318. OPAMP_BIAS_MODE_3 = OPAMP_OPAMPCTRL_BIAS(3),
  319. };
  320. /**
  321. * \brief OPAMP 0 to 2 common configuration structure.
  322. *
  323. * Common configuration structure for OPAMP 0 to 2.
  324. */
  325. struct opamp_config_common {
  326. /** Potentiometer selection */
  327. enum opamp_pot_mux potentiometer_selection;
  328. /** If \c true, R1 connected to RES1MUX */
  329. bool r1_enable;
  330. /** If \c true, resistor ladder to V<SUB>CC</SUB> */
  331. bool r2_vcc;
  332. /** If \c true, resistor ladder to output */
  333. bool r2_out;
  334. /** If \c true, the OPAMPx is enabled when a peripheral is requesting
  335. * the OPAMPx to be used as an input. The OPAMPx is
  336. * disabled if no peripheral is requesting it as an input. */
  337. bool on_demand;
  338. /** If \c true, the OPAMPx is not stopped during sleep
  339. * mode when triggered */
  340. bool run_in_standby;
  341. /** Bias mode selection */
  342. enum opamp_bias_selection bias_value;
  343. /** If \c true, OPAMP output is connected to the ADC or AC input */
  344. bool analog_out;
  345. };
  346. /**
  347. * \brief OPAMP 0 configuration structure.
  348. *
  349. * Configuration structure for OPAMP 0.
  350. */
  351. struct opamp0_config {
  352. /** Negative input MUX selection */
  353. enum opamp0_neg_mux negative_input;
  354. /** Positive input MUX selection */
  355. enum opamp0_pos_mux positive_input;
  356. /** Resistor 1 MUX selection */
  357. enum opamp0_res1_mux r1_connection;
  358. /** If \c true, the comparator will continue to sample during sleep
  359. * mode when triggered */
  360. struct opamp_config_common config_common;
  361. };
  362. /**
  363. * \brief OPAMP 1 configuration structure.
  364. *
  365. * Configuration structure for OPAMP 1.
  366. */
  367. struct opamp1_config {
  368. /** Negative input MUX selection */
  369. enum opamp1_neg_mux negative_input;
  370. /** Positive input MUX selection */
  371. enum opamp1_pos_mux positive_input;
  372. /** Resistor 1 MUX selection */
  373. enum opamp1_res1_mux r1_connection;
  374. /** If \c true, the comparator will continue to sample during sleep
  375. * mode when triggered */
  376. struct opamp_config_common config_common;
  377. };
  378. /**
  379. * \brief OPAMP 2 configuration structure.
  380. *
  381. * Configuration structure for OPAMP 2.
  382. */
  383. struct opamp2_config {
  384. /** Negative input MUX selection */
  385. enum opamp2_neg_mux negative_input;
  386. /** Positive input MUX selection */
  387. enum opamp2_pos_mux positive_input;
  388. /** Resistor 1 MUX selection */
  389. enum opamp2_res1_mux r1_connection;
  390. /** If \c true, the comparator will continue to sample during sleep
  391. * mode when triggered */
  392. struct opamp_config_common config_common;
  393. };
  394. /**
  395. * \brief Initializes OPAMP module.
  396. *
  397. * Resets all registers in the MODULE to their initial state,
  398. * and then enable the module.
  399. */
  400. void opamp_module_init(void);
  401. /**
  402. * \brief Resets OPAMP module.
  403. *
  404. * Resets all registers in the MODULE to their initial state,
  405. * and the OPAMP will be disabled.
  406. */
  407. static inline void opamp_module_reset(void)
  408. {
  409. /* Reset OPAMP. */
  410. OPAMP->CTRLA.reg |= OPAMP_CTRLA_SWRST;
  411. }
  412. /**
  413. * \brief Enables OPAMP module.
  414. *
  415. * Enable the peripheral. Each OPAMP must also be enabled individually
  416. * by the Enable bit in the corresponding OPAMP Control register.
  417. *
  418. */
  419. static inline void opamp_module_enable(void)
  420. {
  421. /* Enable OPAMP. */
  422. OPAMP->CTRLA.reg |= OPAMP_CTRLA_ENABLE;
  423. }
  424. /**
  425. * \brief Disables OPAMP module.
  426. *
  427. * Disables the peripheral.
  428. */
  429. static inline void opamp_module_disable(void)
  430. {
  431. /* Disable OPAMP. */
  432. OPAMP->CTRLA.reg &= ~OPAMP_CTRLA_ENABLE;
  433. }
  434. /**
  435. * \brief Enables OPAMP voltage doubler.
  436. *
  437. * The analog input MUXes have low resistance, but consume more
  438. * power at lower voltages (e.g., driven by the voltage doubler).
  439. *
  440. */
  441. static inline void opamp_voltage_doubler_enable(void)
  442. {
  443. struct system_clock_source_osculp32k_config config;
  444. /* Enable the OSCULP32K clock. */
  445. system_clock_source_osculp32k_get_config_defaults(&config);
  446. system_clock_source_osculp32k_set_config(&config);
  447. /* Enable Voltage Doubler. */
  448. OPAMP->CTRLA.reg &= ~ OPAMP_CTRLA_LPMUX;
  449. }
  450. /**
  451. * \brief Disables OPAMP voltage doubler.
  452. *
  453. * The analog input MUXes have high resistance, but consume less power
  454. * at lower voltages (e.g., the voltage doubler is disabled).
  455. */
  456. static inline void opamp_voltage_doubler_disable(void)
  457. {
  458. /* Disable Voltage Doubler. */
  459. OPAMP->CTRLA.reg |= OPAMP_CTRLA_LPMUX;
  460. }
  461. /**
  462. * \brief Initializes all members of OPAMP0 configuration
  463. * structure to safe defaults.
  464. *
  465. * Initializes all members of OPAMP0 configuration
  466. * structure to safe defaults. This function should be called on all new
  467. * instances of these configuration structures before being modified by the
  468. * user application.
  469. *
  470. * The default configuration is setting OPAMP0 as "Voltage Follower", refer to
  471. * the first mode of "Built-in Modes" in the device datasheet.
  472. *
  473. * \param[out] config OPAMP0 configuration structure to initialize to
  474. * default values
  475. */
  476. void opamp0_get_config_defaults(struct opamp0_config *const config);
  477. /**
  478. * \brief Initializes all members of OPAMP1 configuration
  479. * structure to safe defaults.
  480. *
  481. * Initializes all members of OPAMP1 configuration
  482. * structure to safe defaults. This function should be called on all new
  483. * instances of these configuration structures before being modified by the
  484. * user application.
  485. *
  486. * The default configuration is setting OPAMP1 as "Voltage Follower", refer to
  487. * the first mode of "Built-in Modes" in the device datasheet.
  488. *
  489. * \param[out] config OPAMP1 configuration structure to initialize to
  490. * default values
  491. */
  492. void opamp1_get_config_defaults(struct opamp1_config *const config);
  493. /**
  494. * \brief Initializes all members of OPAMP2 configuration
  495. * structure to safe defaults.
  496. *
  497. * Initializes all members of OPAMP2 configuration
  498. * structure to safe defaults. This function should be called on all new
  499. * instances of these configuration structures before being modified by the
  500. * user application.
  501. *
  502. * The default configuration is setting OPAMP2 as "Voltage Follower", refer to
  503. * the first mode of "Built-in Modes" in the device datasheet.
  504. *
  505. * \param[out] config OPAMP2 configuration structure to initialize to
  506. * default values
  507. */
  508. void opamp2_get_config_defaults(struct opamp2_config *const config);
  509. /** \brief Writes OPAMP0 configuration to the hardware module.
  510. *
  511. * Writes a given OPAMP0 configuration to the hardware module.
  512. *
  513. * \param[in] config Pointer to the OPAMP0 configuration struct
  514. */
  515. void opamp0_set_config(struct opamp0_config *const config);
  516. /** \brief Writes OPAMP1 configuration to the hardware module.
  517. *
  518. * Writes a given OPAMP1 configuration to the hardware module.
  519. *
  520. * \param[in] config Pointer to the OPAMP1 configuration struct
  521. */
  522. void opamp1_set_config(struct opamp1_config *const config);
  523. /** \brief Writes OPAMP2 configuration to the hardware module.
  524. *
  525. * Writes a given OPAMP2 configuration to the hardware module.
  526. *
  527. * \param[in] config Pointer to the OPAMP2 configuration struct
  528. */
  529. void opamp2_set_config(struct opamp2_config *const config);
  530. /**
  531. * \brief Enables an OPAMP that was previously configured.
  532. *
  533. * Enables an OPAMP that was previously configured via a call to
  534. * the set configuration function.
  535. *
  536. * \param[in] number OPAMP number to enable
  537. */
  538. void opamp_enable(const enum opamp_id number);
  539. /**
  540. * \brief Disables an OPAMP that was previously enabled.
  541. *
  542. * Disables an OPAMP that was previously enabled via a call to
  543. * \ref opamp_enable().
  544. *
  545. * \param[in] number OPAMP number to disable
  546. */
  547. void opamp_disable(const enum opamp_id number);
  548. /**
  549. * \brief Checks an OPAMP output ready status.
  550. *
  551. * Checks if an OPAMP output is ready.
  552. *
  553. * \param[in] number OPAMP number to check
  554. *
  555. * \return Ready status of the select OPAMP.
  556. *
  557. * \retval false If the select OPAMP output is not ready
  558. * \retval ture If the select OPAMP output is ready
  559. */
  560. bool opamp_is_ready(const enum opamp_id number);
  561. #ifdef __cplusplus
  562. }
  563. #endif
  564. /** @} */
  565. /**
  566. * \page asfdoc_sam0_opamp_extra Extra Information for OPAMP Driver
  567. *
  568. * \section asfdoc_sam0_opamp_extra_acronyms Acronyms
  569. * Below is a table listing the acronyms used in this module, along with their
  570. * intended meanings.
  571. *
  572. * <table>
  573. * <tr>
  574. * <th>Acronym</th>
  575. * <th>Description</th>
  576. * </tr>
  577. * <tr>
  578. * <td>OPAMP</td>
  579. * <td>Operational Amplifier Controller</td>
  580. * </tr>
  581. * </table>
  582. *
  583. *
  584. * \section asfdoc_sam0_opamp_extra_dependencies Dependencies
  585. * This driver has no dependencies.
  586. *
  587. *
  588. * \section asfdoc_sam0_opamp_extra_errata Errata
  589. * There are no errata related to this driver.
  590. *
  591. *
  592. * \section asfdoc_sam0_opamp_extra_history Module History
  593. * An overview of the module history is presented in the table below, with
  594. * details on the enhancements and fixes made to the module since its first
  595. * release. The current version of this corresponds to the newest version in
  596. * the table.
  597. *
  598. * <table>
  599. * <tr>
  600. * <th>Changelog</th>
  601. * </tr>
  602. * <tr>
  603. * <td>Initial Release</td>
  604. * </tr>
  605. * </table>
  606. */
  607. /**
  608. * \page asfdoc_sam0_opamp_exqsg Examples for OPAMP Driver
  609. *
  610. * This is a list of the available Quick Start guides (QSGs) and example
  611. * applications for \ref asfdoc_sam0_opamp_group. QSGs are simple examples with
  612. * step-by-step instructions to configure and use this driver in a selection of
  613. * use cases. Note that a QSG can be compiled as a standalone application or be
  614. * added to the user application.
  615. *
  616. * - \subpage asfdoc_sam0_opamp_basic_use_case
  617. *
  618. * \page asfdoc_sam0_opamp_document_revision_history Document Revision History
  619. *
  620. * <table>
  621. * <tr>
  622. * <th>Doc. Rev.</td>
  623. * <th>Date</td>
  624. * <th>Comments</td>
  625. * </tr>
  626. * <tr>
  627. * <td>42446A</td>
  628. * <td>07/2015</td>
  629. * <td>Initial document release</td>
  630. * </tr>
  631. * </table>
  632. */
  633. #endif /* OPAMP_H_INCLUDED */