Library for interfacing with the MAX4822 relay driver.
Dependents: MAXREFDES130_131_Demo MAXREFDES130_Demo
Diff: MAX4822.h
- Revision:
- 1:0263f798de82
- Parent:
- 0:074983020f27
- Child:
- 3:90f7cd976f18
--- a/MAX4822.h Thu Jul 28 18:42:58 2016 +0000 +++ b/MAX4822.h Thu Jul 28 21:41:40 2016 +0000 @@ -53,8 +53,13 @@ { public: + static const uint8_t OUTPUT_CNTL_REG = 0; + + static const uint8_t POWER_SAVE_REG = 1; + enum RelayChannel { + NONE, RLY_1, RLY_2, RLY_3, @@ -87,57 +92,56 @@ ///@brief MAX4822 Constructor ///@param[in] spi_bus - reference to SPI bus for this device ///@param[in] cs - Pin connected to chip select of this device - ///@param[in] set - Pin connected to active low SET pin of device; - /// default = NC - ///@param[in] reset - Pin connected to active low RESET pin of device; - /// default = NC - MAX4822(SPI & spi_bus, PinName cs = D10, PinName set = NC, PinName reset = NC); + ///@param[in] num_devices - Number of daisychained devices; defaults to 0. + MAX4822(SPI & spi_bus, PinName cs = D10, uint8_t num_devices = 0); ///@brief MAX4822 Destructor ~MAX4822(); - ///@brief Used to set the number of devices in daisy chained configuration - ///@param[in] n - number of daisy chained MAX4822, default is 1. - ///@return Result of operation, only fails if n = 0. - CmdResult set_num_devices(uint8_t n); + ///@brief Sets all relays of device connected to set + ///@param[in] set - Pin connected to SET pin of device + void set_all_relays(DigitalOut & set); - ///@brief Sets all relays for given device - ///@param[in] n - MAX4822 device in daisychained mode; defaults to 1. - /// When more than one device, i.e. daisychained, the first device on the - /// bus is 1, then 2, and so on. Not 0. - ///@return Result of operation. - CmdResult set_all_relays(uint8_t n = 1); + ///@brief Resets all relays of device connected to reset + ///@param[in] reset - Pin connected to RESET pin of device + void reset_all_relays(DigitalOut & reset); - ///@brief - ///@param[in] n - MAX4822 device in daisychained mode; defaults to 1. - /// When more than one device, i.e. daisychained, the first device on the - /// bus is 1, then 2, and so on. Not 0. + ///@brief Sets private relay state and sends it if 'send_data' is true + ///@param[in] r - Relay to set + ///@param[in] send_data - Default value is true. + ///If false, private array is updated appropriately. This allows the user to + ///update the data array and then send all data on last update. + ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. ///@return Result of operation. - CmdResult reset_all_relays(uint8_t n = 1); + CmdResult set_relay(RelayChannel r, bool send_data = true, uint8_t n = 0); - ///@brief - ///@param[in] r - Relay to set - ///@param[in] n - MAX4822 device in daisychained mode; defaults to 1. - /// When more than one device, i.e. daisychained, the first device on the - /// bus is 1, then 2, and so on. Not 0. + ///@brief Clears private relay state and sends it if 'send_data' is true + ///@param[in] r - Relay to reset + ///@param[in] send_data - Default value is true. + ///If false, private array is updated appropriately. This allows the user to + ///update the data array and then send all data on last update. + ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. ///@return Result of operation. - CmdResult set_relay(RelayChannel r, uint8_t n = 1); + CmdResult reset_relay(RelayChannel r, bool send_data = true, uint8_t n = 0); - ///@brief - ///@param[in] r - Relay to reset - ///@param[in] n - MAX4822 device in daisychained mode; defaults to 1. - /// When more than one device, i.e. daisychained, the first device on the - /// bus is 1, then 2, and so on. Not 0. + ///@brief Sets private power save value nd sends it if 'send_data' is true + ///@param[in] pwr_save - Power save value + ///@param[in] send_data - Default value is true. + ///If false, private array is updated appropriately. This allows the user to + ///update the data array and then send all data on last update. + ///@param[in] n - MAX4822 device in daisychained mode; defaults to 0. ///@return Result of operation. - CmdResult reset_relay(RelayChannel r, uint8_t n = 1); + CmdResult set_pwr_save(PowerSave pwr_save, bool send_data = true, uint8_t n = 0); private: SPI & m_spi; DigitalOut m_cs; - DigitalOut m_set; - DigitalOut m_reset; uint8_t m_num_devices; + PowerSave pwr_save; + + uint8_t m_relay_data[256]; + uint8_t m_pwr_save_data[256]; }; #endif /* MAX4822_H */ \ No newline at end of file