Library for interfacing with the MAX4822 relay driver.
Dependents: MAXREFDES130_131_Demo MAXREFDES130_Demo
MAX4822.h@1:0263f798de82, 2016-07-28 (annotated)
- Committer:
- j3
- Date:
- Thu Jul 28 21:41:40 2016 +0000
- Revision:
- 1:0263f798de82
- Parent:
- 0:074983020f27
- Child:
- 3:90f7cd976f18
Added implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:074983020f27 | 1 | /********************************************************************** |
j3 | 0:074983020f27 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:074983020f27 | 3 | * |
j3 | 0:074983020f27 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:074983020f27 | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:074983020f27 | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 0:074983020f27 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:074983020f27 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:074983020f27 | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:074983020f27 | 10 | * |
j3 | 0:074983020f27 | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 0:074983020f27 | 12 | * in all copies or substantial portions of the Software. |
j3 | 0:074983020f27 | 13 | * |
j3 | 0:074983020f27 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:074983020f27 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:074983020f27 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:074983020f27 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:074983020f27 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:074983020f27 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:074983020f27 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:074983020f27 | 21 | * |
j3 | 0:074983020f27 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:074983020f27 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:074983020f27 | 24 | * Products, Inc. Branding Policy. |
j3 | 0:074983020f27 | 25 | * |
j3 | 0:074983020f27 | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 0:074983020f27 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:074983020f27 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:074983020f27 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:074983020f27 | 30 | * ownership rights. |
j3 | 0:074983020f27 | 31 | **********************************************************************/ |
j3 | 0:074983020f27 | 32 | |
j3 | 0:074983020f27 | 33 | #ifndef MAX4822_H |
j3 | 0:074983020f27 | 34 | #define MAX4822_H |
j3 | 0:074983020f27 | 35 | |
j3 | 0:074983020f27 | 36 | #include "mbed.h" |
j3 | 0:074983020f27 | 37 | |
j3 | 0:074983020f27 | 38 | /** |
j3 | 0:074983020f27 | 39 | * @brief MAX4822 - +3.3V/+5V, 8-Channel, Relay Drivers with Fast Recovery |
j3 | 0:074983020f27 | 40 | * Time and Power-Save Mode |
j3 | 0:074983020f27 | 41 | * |
j3 | 0:074983020f27 | 42 | * @details The MAX4822–MAX4825 8-channel relay drivers offer built-in |
j3 | 0:074983020f27 | 43 | * kickback protection and drive +3V/+5V nonlatching or dual-coil-latching |
j3 | 0:074983020f27 | 44 | * relays. Each independent open-drain output features a 2.7Ω (typ) |
j3 | 0:074983020f27 | 45 | * on-resistance and is guaranteed to sink 70mA (min) of load current. |
j3 | 0:074983020f27 | 46 | * These devices consume less than 300µA (max) quiescent current and have |
j3 | 0:074983020f27 | 47 | * 1µA output off-leakage current. A Zener-kickback-protection circuit |
j3 | 0:074983020f27 | 48 | * significantly reduces recovery time in applications where switching |
j3 | 0:074983020f27 | 49 | * speed is critical. |
j3 | 0:074983020f27 | 50 | */ |
j3 | 0:074983020f27 | 51 | |
j3 | 0:074983020f27 | 52 | class MAX4822 |
j3 | 0:074983020f27 | 53 | { |
j3 | 0:074983020f27 | 54 | public: |
j3 | 0:074983020f27 | 55 | |
j3 | 1:0263f798de82 | 56 | static const uint8_t OUTPUT_CNTL_REG = 0; |
j3 | 1:0263f798de82 | 57 | |
j3 | 1:0263f798de82 | 58 | static const uint8_t POWER_SAVE_REG = 1; |
j3 | 1:0263f798de82 | 59 | |
j3 | 0:074983020f27 | 60 | enum RelayChannel |
j3 | 0:074983020f27 | 61 | { |
j3 | 1:0263f798de82 | 62 | NONE, |
j3 | 0:074983020f27 | 63 | RLY_1, |
j3 | 0:074983020f27 | 64 | RLY_2, |
j3 | 0:074983020f27 | 65 | RLY_3, |
j3 | 0:074983020f27 | 66 | RLY_4, |
j3 | 0:074983020f27 | 67 | RLY_5, |
j3 | 0:074983020f27 | 68 | RLY_6, |
j3 | 0:074983020f27 | 69 | RLY_7, |
j3 | 0:074983020f27 | 70 | RLY_8 |
j3 | 0:074983020f27 | 71 | }; |
j3 | 0:074983020f27 | 72 | |
j3 | 0:074983020f27 | 73 | enum PowerSave |
j3 | 0:074983020f27 | 74 | { |
j3 | 0:074983020f27 | 75 | DISABLED, |
j3 | 0:074983020f27 | 76 | SEVENTY_PERCENT_VCC, |
j3 | 0:074983020f27 | 77 | SIXTY_PERCENT_VCC, |
j3 | 0:074983020f27 | 78 | FIFTY_PERCENT_VCC, |
j3 | 0:074983020f27 | 79 | FORTY_PERCENT_VCC, |
j3 | 0:074983020f27 | 80 | THIRTY_PERCENT_VCC, |
j3 | 0:074983020f27 | 81 | TWENTY_PERCENT_VCC, |
j3 | 0:074983020f27 | 82 | TEN_PERCENT_VCC |
j3 | 0:074983020f27 | 83 | }; |
j3 | 0:074983020f27 | 84 | |
j3 | 0:074983020f27 | 85 | enum CmdResult |
j3 | 0:074983020f27 | 86 | { |
j3 | 0:074983020f27 | 87 | OpFailure, |
j3 | 0:074983020f27 | 88 | Success |
j3 | 0:074983020f27 | 89 | }; |
j3 | 0:074983020f27 | 90 | |
j3 | 0:074983020f27 | 91 | |
j3 | 0:074983020f27 | 92 | ///@brief MAX4822 Constructor |
j3 | 0:074983020f27 | 93 | ///@param[in] spi_bus - reference to SPI bus for this device |
j3 | 0:074983020f27 | 94 | ///@param[in] cs - Pin connected to chip select of this device |
j3 | 1:0263f798de82 | 95 | ///@param[in] num_devices - Number of daisychained devices; defaults to 0. |
j3 | 1:0263f798de82 | 96 | MAX4822(SPI & spi_bus, PinName cs = D10, uint8_t num_devices = 0); |
j3 | 0:074983020f27 | 97 | |
j3 | 0:074983020f27 | 98 | ///@brief MAX4822 Destructor |
j3 | 0:074983020f27 | 99 | ~MAX4822(); |
j3 | 0:074983020f27 | 100 | |
j3 | 1:0263f798de82 | 101 | ///@brief Sets all relays of device connected to set |
j3 | 1:0263f798de82 | 102 | ///@param[in] set - Pin connected to SET pin of device |
j3 | 1:0263f798de82 | 103 | void set_all_relays(DigitalOut & set); |
j3 | 0:074983020f27 | 104 | |
j3 | 1:0263f798de82 | 105 | ///@brief Resets all relays of device connected to reset |
j3 | 1:0263f798de82 | 106 | ///@param[in] reset - Pin connected to RESET pin of device |
j3 | 1:0263f798de82 | 107 | void reset_all_relays(DigitalOut & reset); |
j3 | 0:074983020f27 | 108 | |
j3 | 1:0263f798de82 | 109 | ///@brief Sets private relay state and sends it if 'send_data' is true |
j3 | 1:0263f798de82 | 110 | ///@param[in] r - Relay to set |
j3 | 1:0263f798de82 | 111 | ///@param[in] send_data - Default value is true. |
j3 | 1:0263f798de82 | 112 | ///If false, private array is updated appropriately. This allows the user to |
j3 | 1:0263f798de82 | 113 | ///update the data array and then send all data on last update. |
j3 | 1:0263f798de82 | 114 | ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. |
j3 | 0:074983020f27 | 115 | ///@return Result of operation. |
j3 | 1:0263f798de82 | 116 | CmdResult set_relay(RelayChannel r, bool send_data = true, uint8_t n = 0); |
j3 | 0:074983020f27 | 117 | |
j3 | 1:0263f798de82 | 118 | ///@brief Clears private relay state and sends it if 'send_data' is true |
j3 | 1:0263f798de82 | 119 | ///@param[in] r - Relay to reset |
j3 | 1:0263f798de82 | 120 | ///@param[in] send_data - Default value is true. |
j3 | 1:0263f798de82 | 121 | ///If false, private array is updated appropriately. This allows the user to |
j3 | 1:0263f798de82 | 122 | ///update the data array and then send all data on last update. |
j3 | 1:0263f798de82 | 123 | ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. |
j3 | 0:074983020f27 | 124 | ///@return Result of operation. |
j3 | 1:0263f798de82 | 125 | CmdResult reset_relay(RelayChannel r, bool send_data = true, uint8_t n = 0); |
j3 | 0:074983020f27 | 126 | |
j3 | 1:0263f798de82 | 127 | ///@brief Sets private power save value nd sends it if 'send_data' is true |
j3 | 1:0263f798de82 | 128 | ///@param[in] pwr_save - Power save value |
j3 | 1:0263f798de82 | 129 | ///@param[in] send_data - Default value is true. |
j3 | 1:0263f798de82 | 130 | ///If false, private array is updated appropriately. This allows the user to |
j3 | 1:0263f798de82 | 131 | ///update the data array and then send all data on last update. |
j3 | 1:0263f798de82 | 132 | ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. |
j3 | 0:074983020f27 | 133 | ///@return Result of operation. |
j3 | 1:0263f798de82 | 134 | CmdResult set_pwr_save(PowerSave pwr_save, bool send_data = true, uint8_t n = 0); |
j3 | 0:074983020f27 | 135 | |
j3 | 0:074983020f27 | 136 | private: |
j3 | 0:074983020f27 | 137 | |
j3 | 0:074983020f27 | 138 | SPI & m_spi; |
j3 | 0:074983020f27 | 139 | DigitalOut m_cs; |
j3 | 0:074983020f27 | 140 | uint8_t m_num_devices; |
j3 | 1:0263f798de82 | 141 | PowerSave pwr_save; |
j3 | 1:0263f798de82 | 142 | |
j3 | 1:0263f798de82 | 143 | uint8_t m_relay_data[256]; |
j3 | 1:0263f798de82 | 144 | uint8_t m_pwr_save_data[256]; |
j3 | 0:074983020f27 | 145 | }; |
j3 | 0:074983020f27 | 146 | |
j3 | 0:074983020f27 | 147 | #endif /* MAX4822_H */ |