Library for MAX7300 GPIO Expander
Diff: max7300.h
- Revision:
- 0:350a850a7191
- Child:
- 1:e1ee2549a047
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max7300.h Wed Jul 15 15:10:04 2015 +0000 @@ -0,0 +1,350 @@ +/******************************************************************//** +* @file max7300.h +* +* @author Justin Jordan +* +* @version 0.0 +* +* Started: 14JUL15 +* +* Updated: +* +* @brief Header file for Max7300 class +* +*********************************************************************** +* Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +**********************************************************************/ + + +#ifndef MAX7300_H +#define MAX7300_H + +#include "mbed.h" + + +class Max7300 +{ + public: + + typedef enum + { + MAX7300_I2C_ADRS0 = 0x40, + MAX7300_I2C_ADRS1, + MAX7300_I2C_ADRS2, + MAX7300_I2C_ADRS3, + MAX7300_I2C_ADRS4, + MAX7300_I2C_ADRS5, + MAX7300_I2C_ADRS6, + MAX7300_I2C_ADRS7, + MAX7300_I2C_ADRS8, + MAX7300_I2C_ADRS9, + MAX7300_I2C_ADRS10, + MAX7300_I2C_ADRS11, + MAX7300_I2C_ADRS12, + MAX7300_I2C_ADRS13, + MAX7300_I2C_ADRS14, + MAX7300_I2C_ADRS15 + }max7300_i2c_adrs_t; + + + typedef enum + { + MAX7300_PORT_OUTPUT = 1, + MAX7300_PORT_INPUT, + MAX7300_PORT_INPUT_PULLUP + }max7300_port_type_t; + + + typedef enum + { + MAX7300_PORT_04 = 4, + MAX7300_PORT_05, + MAX7300_PORT_06, + MAX7300_PORT_07, + MAX7300_PORT_08, + MAX7300_PORT_09, + MAX7300_PORT_10, + MAX7300_PORT_11, + MAX7300_PORT_12, + MAX7300_PORT_13, + MAX7300_PORT_14, + MAX7300_PORT_15, + MAX7300_PORT_16, + MAX7300_PORT_17, + MAX7300_PORT_18, + MAX7300_PORT_19, + MAX7300_PORT_20, + MAX7300_PORT_21, + MAX7300_PORT_22, + MAX7300_PORT_23, + MAX7300_PORT_24, + MAX7300_PORT_25, + MAX7300_PORT_26, + MAX7300_PORT_27, + MAX7300_PORT_28, + MAX7300_PORT_29, + MAX7300_PORT_30, + MAX7300_PORT_31 + }max7300_port_number_t; + + + typedef enum + { + MAX7300_NO_OP = 0, + MAX7300_CONFIGURATION = 4, + MAX7300_MASK = 6, + MAX7300_PORT_CONFIG_P07_P04 = 9, + MAX7300_PORT_CONFIG_P11_P8, + MAX7300_PORT_CONFIG_P15_P12, + MAX7300_PORT_CONFIG_P19_P16, + MAX7300_PORT_CONFIG_P23_P20, + MAX7300_PORT_CONFIG_P27_P24, + MAX7300_PORT_CONFIG_P31_P28, + MAX7300_PORT_04_DATA = 0x24, + MAX7300_PORT_05_DATA, + MAX7300_PORT_06_DATA, + MAX7300_PORT_07_DATA, + MAX7300_PORT_08_DATA, + MAX7300_PORT_09_DATA, + MAX7300_PORT_10_DATA, + MAX7300_PORT_11_DATA, + MAX7300_PORT_12_DATA, + MAX7300_PORT_13_DATA, + MAX7300_PORT_14_DATA, + MAX7300_PORT_15_DATA, + MAX7300_PORT_16_DATA, + MAX7300_PORT_17_DATA, + MAX7300_PORT_18_DATA, + MAX7300_PORT_19_DATA, + MAX7300_PORT_20_DATA, + MAX7300_PORT_21_DATA, + MAX7300_PORT_22_DATA, + MAX7300_PORT_23_DATA, + MAX7300_PORT_24_DATA, + MAX7300_PORT_25_DATA, + MAX7300_PORT_26_DATA, + MAX7300_PORT_27_DATA, + MAX7300_PORT_28_DATA, + MAX7300_PORT_29_DATA, + MAX7300_PORT_30_DATA, + MAX7300_PORT_31_DATA, + MAX7300_8_PORTS_P04_P11_DATA = 0x44, + MAX7300_8_PORTS_P12_P19_DATA = 0x4C, + MAX7300_8_PORTS_P20_P27_DATA = 0x54, + MAX7300_8_PORTS_P24_P31_DATA = 0x58 + }max7300_registers_t; + + + /**********************************************************//** + * @brief Constructor for Max7300 Class. + * + * @details Allows user to use existing I2C object + * + * On Entry: + * @param[in] i2c_bus - pointer to existing I2C object + * @param[in] i2c_adrs - 7-bit slave address of MAX7300 + * + * On Exit: + * @return none + **************************************************************/ + Max7300(I2C *i2c_bus, max7300_i2c_adrs_t i2c_adrs); + + + /**********************************************************//** + * @brief Constructor for Max7300 Class. + * + * @details Allows user to create a new I2C object if not + * already using one + * + * On Entry: + * @param[in] sda - sda pin of I2C bus + * @param[in] scl - scl pin of I2C bus + * @param[in] i2c_adrs - 7-bit slave address of MAX7300 + * + * On Exit: + * @return none + **************************************************************/ + Max7300(PinName sda, PinName scl, max7300_i2c_adrs_t i2c_adrs); + + + /**********************************************************//** + * @brief Default destructor for Max7300 Class. + * + * @details Destroys I2C object if owner + * + * On Entry: + * + * On Exit: + * @return none + **************************************************************/ + ~Max7300(); + + + /**********************************************************//** + * @brief Enables MAX7300 GPIO Ports + * + * @details Sets 'S' bit of configuration register + * + * On Entry: + * + * On Exit: + * @return 0 on success, non-0 on failure + **************************************************************/ + int16_t enable_ports(void); + + + /**********************************************************//** + * @brief Disables MAX7300 GPIO Ports + * + * @details Clears 'S' bit of configuration register + * + * On Entry: + * + * On Exit: + * @return 0 on success, non-0 on failure + **************************************************************/ + int16_t disable_ports(void); + + + /**********************************************************//** + * @brief Configures a single MAX7300 GPIO port + * + * @details Configures MAX7300 GPIO port as either an output, + * input, or input with pullup. + * + * On Entry: + * @param[in] port_num - GPIO port to configure + * @param[in] port_type - One of the following port types + * MAX7300_PORT_OUTPUT + * MAX7300_PORT_INPUT + * MAX7300_PORT_INPUT_PULLUP + * + * On Exit: + * @return 0 on success, non-0 on failure + **************************************************************/ + int16_t config_port(max7300_port_number_t port_num, max7300_port_type_t port_type); + + + /**********************************************************//** + * @brief Configure 4 MAX7300 GPIO ports + * + * @details Allows user to configure 4 ports at a time + * + * On Entry: + * @param[in] reg - One of the following 7 registers + * MAX7300_PORT_CONFIG_P7_P4, + * MAX7300_PORT_CONFIG_P11_P8, + * MAX7300_PORT_CONFIG_P15_P12, + * MAX7300_PORT_CONFIG_P19_P16, + * MAX7300_PORT_CONFIG_P23_P20, + * MAX7300_PORT_CONFIG_P27_P24, + * MAX7300_PORT_CONFIG_P31_P28 + * + * @param[in] data - Byte with each ports desired type with + * the following format - xx|xx|xx|xx + * + * On Exit: + * @return 0 on success, non-0 on failure + **************************************************************/ + int16_t config_ports(max7300_registers_t reg, uint8_t data); + + + /**********************************************************//** + * @brief Read a single MAX7300 GPIO port + * + * @details + * + * On Entry: + * + * On Exit: + * @return state of port, or + **************************************************************/ + int16_t read_port(max7300_port_number_t port_num); + + + /**********************************************************//** + * @brief Write a single MAX7300 GPIO port + * + * @details + * + * On Entry: + * + * On Exit: + * @return none + **************************************************************/ + int16_t write_port(max7300_port_number_t port_num, uint8_t data); + + + /**********************************************************//** + * @brief Read 8 MAX7300 GPIO ports + * + * @details + * + * On Entry: + * + * On Exit: + * @return none + **************************************************************/ + int16_t read_eight_ports(max7300_registers_t reg); + + + /**********************************************************//** + * @brief Write 8 MAX7300 GPIO ports + * + * @details + * + * On Entry: + * + * On Exit: + * @return none + **************************************************************/ + int16_t write_eight_ports(max7300_registers_t reg, uint8_t data); + + + /**********************************************************//** + * @brief + * + * @details + * + * On Entry: + * + * On Exit: + * @return none + **************************************************************/ + + private: + + I2C *_p_i2c; + bool _i2c_owner; + uint8_t _w_adrs; + uint8_t _r_adrs; +}; +#endif /* MAX7300_H*/ \ No newline at end of file