Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MAXREFDES130_131_Demo MAXREFDES130_Demo
MAX4822.h
00001 /********************************************************************** 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 **********************************************************************/ 00032 00033 #ifndef MAX4822_H 00034 #define MAX4822_H 00035 00036 #include "mbed.h" 00037 00038 /** 00039 * @brief MAX4822 - +3.3V/+5V, 8-Channel, Relay Drivers with Fast Recovery 00040 * Time and Power-Save Mode 00041 * 00042 * @details The MAX4822–MAX4825 8-channel relay drivers offer built-in 00043 * kickback protection and drive +3V/+5V nonlatching or dual-coil-latching 00044 * relays. Each independent open-drain output features a 2.7Ω (typ) 00045 * on-resistance and is guaranteed to sink 70mA (min) of load current. 00046 * These devices consume less than 300µA (max) quiescent current and have 00047 * 1µA output off-leakage current. A Zener-kickback-protection circuit 00048 * significantly reduces recovery time in applications where switching 00049 * speed is critical. 00050 */ 00051 00052 class MAX4822 00053 { 00054 public: 00055 00056 static const uint8_t OUTPUT_CNTL_REG = 0; 00057 00058 static const uint8_t POWER_SAVE_REG = 1; 00059 00060 enum RelayChannel 00061 { 00062 NONE, 00063 RLY_1, 00064 RLY_2, 00065 RLY_3, 00066 RLY_4, 00067 RLY_5, 00068 RLY_6, 00069 RLY_7, 00070 RLY_8 00071 }; 00072 00073 enum PowerSave 00074 { 00075 DISABLED, 00076 SEVENTY_PERCENT_VCC, 00077 SIXTY_PERCENT_VCC, 00078 FIFTY_PERCENT_VCC, 00079 FORTY_PERCENT_VCC, 00080 THIRTY_PERCENT_VCC, 00081 TWENTY_PERCENT_VCC, 00082 TEN_PERCENT_VCC 00083 }; 00084 00085 enum CmdResult 00086 { 00087 OpFailure, 00088 Success 00089 }; 00090 00091 00092 ///@brief MAX4822 Constructor 00093 ///@param[in] spi_bus - reference to SPI bus for this device 00094 ///@param[in] cs - Pin connected to chip select of this device 00095 ///@param[in] num_devices - Number of daisychained devices; defaults to 0. 00096 MAX4822(SPI & spi_bus, PinName cs = D10, uint8_t num_devices = 0); 00097 00098 ///@brief MAX4822 Destructor 00099 ~MAX4822(); 00100 00101 ///@brief Sets all relays of device connected to set 00102 ///@param[in] set - Pin connected to SET pin of device 00103 ///@param[in] device - Device number in daisychain mode, defaults to 0 00104 ///@return Result of operation. 00105 CmdResult set_all_relays(DigitalOut & set, uint8_t device = 0); 00106 00107 ///@brief Resets all relays of device connected to reset 00108 ///@param[in] reset - Pin connected to RESET pin of device 00109 ///@param[in] device - Device number in daisychain mode, defaults to 0 00110 ///@return Result of operation. 00111 CmdResult reset_all_relays(DigitalOut & reset, uint8_t device = 0); 00112 00113 ///@brief Sets private relay state and sends it if 'send_data' is true 00114 ///@param[in] r - Relay to set 00115 ///@param[in] send_data - Default value is true. 00116 ///If false, private array is updated appropriately. This allows the user to 00117 ///update the data array and then send all data on last update. 00118 ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. 00119 ///@return Result of operation. 00120 CmdResult set_relay(RelayChannel r, bool send_data = true, uint8_t n = 0); 00121 00122 ///@brief Clears private relay state and sends it if 'send_data' is true 00123 ///@param[in] r - Relay to reset 00124 ///@param[in] send_data - Default value is true. 00125 ///If false, private array is updated appropriately. This allows the user to 00126 ///update the data array and then send all data on last update. 00127 ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. 00128 ///@return Result of operation. 00129 CmdResult reset_relay(RelayChannel r, bool send_data = true, uint8_t n = 0); 00130 00131 ///@brief Sets private power save value nd sends it if 'send_data' is true 00132 ///@param[in] pwr_save - Power save value 00133 ///@param[in] send_data - Default value is true. 00134 ///If false, private array is updated appropriately. This allows the user to 00135 ///update the data array and then send all data on last update. 00136 ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. 00137 ///@return Result of operation. 00138 CmdResult set_pwr_save(PowerSave pwr_save, bool send_data = true, uint8_t n = 0); 00139 00140 private: 00141 00142 SPI & m_spi; 00143 DigitalOut m_cs; 00144 uint8_t m_num_devices; 00145 PowerSave pwr_save; 00146 00147 uint8_t m_relay_data[256]; 00148 uint8_t m_pwr_save_data[256]; 00149 }; 00150 00151 #endif /* MAX4822_H */
Generated on Thu Jul 14 2022 02:24:35 by
1.7.2