Library for interfacing with the MAX4822 relay driver.

Dependents:   MAXREFDES130_131_Demo MAXREFDES130_Demo

Committer:
j3
Date:
Tue Aug 02 23:17:48 2016 +0000
Revision:
3:90f7cd976f18
Parent:
1:0263f798de82
Updated set_all/reset_all fxs to update private data array

Who changed what in which revision?

UserRevisionLine numberNew 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 3:90f7cd976f18 103 ///@param[in] device - Device number in daisychain mode, defaults to 0
j3 3:90f7cd976f18 104 ///@return Result of operation.
j3 3:90f7cd976f18 105 CmdResult set_all_relays(DigitalOut & set, uint8_t device = 0);
j3 0:074983020f27 106
j3 1:0263f798de82 107 ///@brief Resets all relays of device connected to reset
j3 1:0263f798de82 108 ///@param[in] reset - Pin connected to RESET pin of device
j3 3:90f7cd976f18 109 ///@param[in] device - Device number in daisychain mode, defaults to 0
j3 3:90f7cd976f18 110 ///@return Result of operation.
j3 3:90f7cd976f18 111 CmdResult reset_all_relays(DigitalOut & reset, uint8_t device = 0);
j3 0:074983020f27 112
j3 1:0263f798de82 113 ///@brief Sets private relay state and sends it if 'send_data' is true
j3 1:0263f798de82 114 ///@param[in] r - Relay to set
j3 1:0263f798de82 115 ///@param[in] send_data - Default value is true.
j3 1:0263f798de82 116 ///If false, private array is updated appropriately. This allows the user to
j3 1:0263f798de82 117 ///update the data array and then send all data on last update.
j3 1:0263f798de82 118 ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0.
j3 0:074983020f27 119 ///@return Result of operation.
j3 1:0263f798de82 120 CmdResult set_relay(RelayChannel r, bool send_data = true, uint8_t n = 0);
j3 0:074983020f27 121
j3 1:0263f798de82 122 ///@brief Clears private relay state and sends it if 'send_data' is true
j3 1:0263f798de82 123 ///@param[in] r - Relay to reset
j3 1:0263f798de82 124 ///@param[in] send_data - Default value is true.
j3 1:0263f798de82 125 ///If false, private array is updated appropriately. This allows the user to
j3 1:0263f798de82 126 ///update the data array and then send all data on last update.
j3 1:0263f798de82 127 ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0.
j3 0:074983020f27 128 ///@return Result of operation.
j3 1:0263f798de82 129 CmdResult reset_relay(RelayChannel r, bool send_data = true, uint8_t n = 0);
j3 0:074983020f27 130
j3 1:0263f798de82 131 ///@brief Sets private power save value nd sends it if 'send_data' is true
j3 1:0263f798de82 132 ///@param[in] pwr_save - Power save value
j3 1:0263f798de82 133 ///@param[in] send_data - Default value is true.
j3 1:0263f798de82 134 ///If false, private array is updated appropriately. This allows the user to
j3 1:0263f798de82 135 ///update the data array and then send all data on last update.
j3 1:0263f798de82 136 ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0.
j3 0:074983020f27 137 ///@return Result of operation.
j3 1:0263f798de82 138 CmdResult set_pwr_save(PowerSave pwr_save, bool send_data = true, uint8_t n = 0);
j3 0:074983020f27 139
j3 0:074983020f27 140 private:
j3 0:074983020f27 141
j3 0:074983020f27 142 SPI & m_spi;
j3 0:074983020f27 143 DigitalOut m_cs;
j3 0:074983020f27 144 uint8_t m_num_devices;
j3 1:0263f798de82 145 PowerSave pwr_save;
j3 1:0263f798de82 146
j3 1:0263f798de82 147 uint8_t m_relay_data[256];
j3 1:0263f798de82 148 uint8_t m_pwr_save_data[256];
j3 0:074983020f27 149 };
j3 0:074983020f27 150
j3 0:074983020f27 151 #endif /* MAX4822_H */