Library for MAX7300 GPIO Expander

Dependents:   MAX14871_Shield

Committer:
j3
Date:
Thu Jul 16 21:27:05 2015 +0000
Revision:
1:e1ee2549a047
Parent:
0:350a850a7191
Child:
2:fd2de5d21702
Finished library, ready for review.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:350a850a7191 1 /******************************************************************//**
j3 0:350a850a7191 2 * @file max7300.h
j3 0:350a850a7191 3 *
j3 0:350a850a7191 4 * @author Justin Jordan
j3 0:350a850a7191 5 *
j3 0:350a850a7191 6 * @version 0.0
j3 0:350a850a7191 7 *
j3 0:350a850a7191 8 * Started: 14JUL15
j3 0:350a850a7191 9 *
j3 0:350a850a7191 10 * Updated:
j3 0:350a850a7191 11 *
j3 0:350a850a7191 12 * @brief Header file for Max7300 class
j3 0:350a850a7191 13 ***********************************************************************
j3 0:350a850a7191 14 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:350a850a7191 15 *
j3 0:350a850a7191 16 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:350a850a7191 17 * copy of this software and associated documentation files (the "Software"),
j3 0:350a850a7191 18 * to deal in the Software without restriction, including without limitation
j3 0:350a850a7191 19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:350a850a7191 20 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:350a850a7191 21 * Software is furnished to do so, subject to the following conditions:
j3 0:350a850a7191 22 *
j3 0:350a850a7191 23 * The above copyright notice and this permission notice shall be included
j3 0:350a850a7191 24 * in all copies or substantial portions of the Software.
j3 0:350a850a7191 25 *
j3 0:350a850a7191 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:350a850a7191 27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:350a850a7191 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:350a850a7191 29 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:350a850a7191 30 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:350a850a7191 31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:350a850a7191 32 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:350a850a7191 33 *
j3 0:350a850a7191 34 * Except as contained in this notice, the name of Maxim Integrated
j3 0:350a850a7191 35 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:350a850a7191 36 * Products, Inc. Branding Policy.
j3 0:350a850a7191 37 *
j3 0:350a850a7191 38 * The mere transfer of this software does not imply any licenses
j3 0:350a850a7191 39 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:350a850a7191 40 * trademarks, maskwork rights, or any other form of intellectual
j3 0:350a850a7191 41 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:350a850a7191 42 * ownership rights.
j3 0:350a850a7191 43 **********************************************************************/
j3 0:350a850a7191 44
j3 0:350a850a7191 45
j3 0:350a850a7191 46 #ifndef MAX7300_H
j3 0:350a850a7191 47 #define MAX7300_H
j3 0:350a850a7191 48
j3 0:350a850a7191 49 #include "mbed.h"
j3 0:350a850a7191 50
j3 0:350a850a7191 51
j3 0:350a850a7191 52 class Max7300
j3 0:350a850a7191 53 {
j3 0:350a850a7191 54 public:
j3 0:350a850a7191 55
j3 0:350a850a7191 56 typedef enum
j3 0:350a850a7191 57 {
j3 0:350a850a7191 58 MAX7300_I2C_ADRS0 = 0x40,
j3 0:350a850a7191 59 MAX7300_I2C_ADRS1,
j3 0:350a850a7191 60 MAX7300_I2C_ADRS2,
j3 0:350a850a7191 61 MAX7300_I2C_ADRS3,
j3 0:350a850a7191 62 MAX7300_I2C_ADRS4,
j3 0:350a850a7191 63 MAX7300_I2C_ADRS5,
j3 0:350a850a7191 64 MAX7300_I2C_ADRS6,
j3 0:350a850a7191 65 MAX7300_I2C_ADRS7,
j3 0:350a850a7191 66 MAX7300_I2C_ADRS8,
j3 0:350a850a7191 67 MAX7300_I2C_ADRS9,
j3 0:350a850a7191 68 MAX7300_I2C_ADRS10,
j3 0:350a850a7191 69 MAX7300_I2C_ADRS11,
j3 0:350a850a7191 70 MAX7300_I2C_ADRS12,
j3 0:350a850a7191 71 MAX7300_I2C_ADRS13,
j3 0:350a850a7191 72 MAX7300_I2C_ADRS14,
j3 0:350a850a7191 73 MAX7300_I2C_ADRS15
j3 0:350a850a7191 74 }max7300_i2c_adrs_t;
j3 0:350a850a7191 75
j3 0:350a850a7191 76
j3 0:350a850a7191 77 typedef enum
j3 0:350a850a7191 78 {
j3 0:350a850a7191 79 MAX7300_PORT_OUTPUT = 1,
j3 0:350a850a7191 80 MAX7300_PORT_INPUT,
j3 0:350a850a7191 81 MAX7300_PORT_INPUT_PULLUP
j3 0:350a850a7191 82 }max7300_port_type_t;
j3 0:350a850a7191 83
j3 0:350a850a7191 84
j3 0:350a850a7191 85 typedef enum
j3 0:350a850a7191 86 {
j3 0:350a850a7191 87 MAX7300_PORT_04 = 4,
j3 0:350a850a7191 88 MAX7300_PORT_05,
j3 0:350a850a7191 89 MAX7300_PORT_06,
j3 0:350a850a7191 90 MAX7300_PORT_07,
j3 0:350a850a7191 91 MAX7300_PORT_08,
j3 0:350a850a7191 92 MAX7300_PORT_09,
j3 0:350a850a7191 93 MAX7300_PORT_10,
j3 0:350a850a7191 94 MAX7300_PORT_11,
j3 0:350a850a7191 95 MAX7300_PORT_12,
j3 0:350a850a7191 96 MAX7300_PORT_13,
j3 0:350a850a7191 97 MAX7300_PORT_14,
j3 0:350a850a7191 98 MAX7300_PORT_15,
j3 0:350a850a7191 99 MAX7300_PORT_16,
j3 0:350a850a7191 100 MAX7300_PORT_17,
j3 0:350a850a7191 101 MAX7300_PORT_18,
j3 0:350a850a7191 102 MAX7300_PORT_19,
j3 0:350a850a7191 103 MAX7300_PORT_20,
j3 0:350a850a7191 104 MAX7300_PORT_21,
j3 0:350a850a7191 105 MAX7300_PORT_22,
j3 0:350a850a7191 106 MAX7300_PORT_23,
j3 0:350a850a7191 107 MAX7300_PORT_24,
j3 0:350a850a7191 108 MAX7300_PORT_25,
j3 0:350a850a7191 109 MAX7300_PORT_26,
j3 0:350a850a7191 110 MAX7300_PORT_27,
j3 0:350a850a7191 111 MAX7300_PORT_28,
j3 0:350a850a7191 112 MAX7300_PORT_29,
j3 0:350a850a7191 113 MAX7300_PORT_30,
j3 0:350a850a7191 114 MAX7300_PORT_31
j3 0:350a850a7191 115 }max7300_port_number_t;
j3 0:350a850a7191 116
j3 0:350a850a7191 117
j3 0:350a850a7191 118 /**********************************************************//**
j3 0:350a850a7191 119 * @brief Constructor for Max7300 Class.
j3 0:350a850a7191 120 *
j3 0:350a850a7191 121 * @details Allows user to use existing I2C object
j3 0:350a850a7191 122 *
j3 0:350a850a7191 123 * On Entry:
j3 0:350a850a7191 124 * @param[in] i2c_bus - pointer to existing I2C object
j3 0:350a850a7191 125 * @param[in] i2c_adrs - 7-bit slave address of MAX7300
j3 0:350a850a7191 126 *
j3 0:350a850a7191 127 * On Exit:
j3 0:350a850a7191 128 * @return none
j3 0:350a850a7191 129 **************************************************************/
j3 0:350a850a7191 130 Max7300(I2C *i2c_bus, max7300_i2c_adrs_t i2c_adrs);
j3 0:350a850a7191 131
j3 0:350a850a7191 132
j3 0:350a850a7191 133 /**********************************************************//**
j3 0:350a850a7191 134 * @brief Constructor for Max7300 Class.
j3 0:350a850a7191 135 *
j3 0:350a850a7191 136 * @details Allows user to create a new I2C object if not
j3 0:350a850a7191 137 * already using one
j3 0:350a850a7191 138 *
j3 0:350a850a7191 139 * On Entry:
j3 0:350a850a7191 140 * @param[in] sda - sda pin of I2C bus
j3 0:350a850a7191 141 * @param[in] scl - scl pin of I2C bus
j3 0:350a850a7191 142 * @param[in] i2c_adrs - 7-bit slave address of MAX7300
j3 0:350a850a7191 143 *
j3 0:350a850a7191 144 * On Exit:
j3 0:350a850a7191 145 * @return none
j3 0:350a850a7191 146 **************************************************************/
j3 0:350a850a7191 147 Max7300(PinName sda, PinName scl, max7300_i2c_adrs_t i2c_adrs);
j3 0:350a850a7191 148
j3 0:350a850a7191 149
j3 0:350a850a7191 150 /**********************************************************//**
j3 0:350a850a7191 151 * @brief Default destructor for Max7300 Class.
j3 0:350a850a7191 152 *
j3 0:350a850a7191 153 * @details Destroys I2C object if owner
j3 0:350a850a7191 154 *
j3 0:350a850a7191 155 * On Entry:
j3 0:350a850a7191 156 *
j3 0:350a850a7191 157 * On Exit:
j3 0:350a850a7191 158 * @return none
j3 0:350a850a7191 159 **************************************************************/
j3 0:350a850a7191 160 ~Max7300();
j3 0:350a850a7191 161
j3 0:350a850a7191 162
j3 0:350a850a7191 163 /**********************************************************//**
j3 0:350a850a7191 164 * @brief Enables MAX7300 GPIO Ports
j3 0:350a850a7191 165 *
j3 0:350a850a7191 166 * @details Sets 'S' bit of configuration register
j3 0:350a850a7191 167 *
j3 0:350a850a7191 168 * On Entry:
j3 0:350a850a7191 169 *
j3 0:350a850a7191 170 * On Exit:
j3 0:350a850a7191 171 * @return 0 on success, non-0 on failure
j3 0:350a850a7191 172 **************************************************************/
j3 0:350a850a7191 173 int16_t enable_ports(void);
j3 0:350a850a7191 174
j3 0:350a850a7191 175
j3 0:350a850a7191 176 /**********************************************************//**
j3 0:350a850a7191 177 * @brief Disables MAX7300 GPIO Ports
j3 0:350a850a7191 178 *
j3 0:350a850a7191 179 * @details Clears 'S' bit of configuration register
j3 0:350a850a7191 180 *
j3 0:350a850a7191 181 * On Entry:
j3 0:350a850a7191 182 *
j3 0:350a850a7191 183 * On Exit:
j3 0:350a850a7191 184 * @return 0 on success, non-0 on failure
j3 0:350a850a7191 185 **************************************************************/
j3 0:350a850a7191 186 int16_t disable_ports(void);
j3 0:350a850a7191 187
j3 0:350a850a7191 188
j3 0:350a850a7191 189 /**********************************************************//**
j3 1:e1ee2549a047 190 * @brief Enables Transition Detection
j3 1:e1ee2549a047 191 *
j3 1:e1ee2549a047 192 * @details Sets 'M' bit of configuration register
j3 1:e1ee2549a047 193 *
j3 1:e1ee2549a047 194 * On Entry:
j3 1:e1ee2549a047 195 *
j3 1:e1ee2549a047 196 * On Exit:
j3 1:e1ee2549a047 197 * @return 0 on success, non-0 on failure
j3 1:e1ee2549a047 198 **************************************************************/
j3 1:e1ee2549a047 199 int16_t enable_transition_detection(void);
j3 1:e1ee2549a047 200
j3 1:e1ee2549a047 201
j3 1:e1ee2549a047 202 /**********************************************************//**
j3 1:e1ee2549a047 203 * @brief Disables Transition Detection
j3 1:e1ee2549a047 204 *
j3 1:e1ee2549a047 205 * @details Clears 'M' bit of configuration register
j3 1:e1ee2549a047 206 *
j3 1:e1ee2549a047 207 * On Entry:
j3 1:e1ee2549a047 208 *
j3 1:e1ee2549a047 209 * On Exit:
j3 1:e1ee2549a047 210 * @return 0 on success, non-0 on failure
j3 1:e1ee2549a047 211 **************************************************************/
j3 1:e1ee2549a047 212 int16_t disable_transition_detection(void);
j3 1:e1ee2549a047 213
j3 1:e1ee2549a047 214
j3 1:e1ee2549a047 215 /**********************************************************//**
j3 0:350a850a7191 216 * @brief Configures a single MAX7300 GPIO port
j3 0:350a850a7191 217 *
j3 0:350a850a7191 218 * @details Configures MAX7300 GPIO port as either an output,
j3 0:350a850a7191 219 * input, or input with pullup.
j3 0:350a850a7191 220 *
j3 0:350a850a7191 221 * On Entry:
j3 0:350a850a7191 222 * @param[in] port_num - GPIO port to configure
j3 0:350a850a7191 223 * @param[in] port_type - One of the following port types
j3 0:350a850a7191 224 * MAX7300_PORT_OUTPUT
j3 0:350a850a7191 225 * MAX7300_PORT_INPUT
j3 0:350a850a7191 226 * MAX7300_PORT_INPUT_PULLUP
j3 0:350a850a7191 227 *
j3 0:350a850a7191 228 * On Exit:
j3 0:350a850a7191 229 * @return 0 on success, non-0 on failure
j3 0:350a850a7191 230 **************************************************************/
j3 0:350a850a7191 231 int16_t config_port(max7300_port_number_t port_num, max7300_port_type_t port_type);
j3 0:350a850a7191 232
j3 0:350a850a7191 233
j3 0:350a850a7191 234 /**********************************************************//**
j3 0:350a850a7191 235 * @brief Configure 4 MAX7300 GPIO ports
j3 0:350a850a7191 236 *
j3 0:350a850a7191 237 * @details Allows user to configure 4 ports at a time
j3 0:350a850a7191 238 *
j3 0:350a850a7191 239 * On Entry:
j3 1:e1ee2549a047 240 * @param[in] low_port - lowest of 4 ports to configure,
j3 1:e1ee2549a047 241 * on 4 port boundaries as in datasheet
j3 0:350a850a7191 242 *
j3 0:350a850a7191 243 * @param[in] data - Byte with each ports desired type with
j3 0:350a850a7191 244 * the following format - xx|xx|xx|xx
j3 0:350a850a7191 245 *
j3 0:350a850a7191 246 * On Exit:
j3 0:350a850a7191 247 * @return 0 on success, non-0 on failure
j3 0:350a850a7191 248 **************************************************************/
j3 1:e1ee2549a047 249 int16_t config_4_ports(max7300_port_number_t low_port, uint8_t data);
j3 1:e1ee2549a047 250
j3 1:e1ee2549a047 251
j3 1:e1ee2549a047 252 /**********************************************************//**
j3 1:e1ee2549a047 253 * @brief Configures all MAX7300 GPIO ports
j3 1:e1ee2549a047 254 *
j3 1:e1ee2549a047 255 * @details Allows user to configure all ports to a single type
j3 1:e1ee2549a047 256 *
j3 1:e1ee2549a047 257 * On Entry:
j3 1:e1ee2549a047 258 * @param[in] port_type - One of the following port types
j3 1:e1ee2549a047 259 * MAX7300_PORT_OUTPUT
j3 1:e1ee2549a047 260 * MAX7300_PORT_INPUT
j3 1:e1ee2549a047 261 * MAX7300_PORT_INPUT_PULLUP
j3 1:e1ee2549a047 262 *
j3 1:e1ee2549a047 263 * On Exit:
j3 1:e1ee2549a047 264 * @return 0 on success, non-0 on failure
j3 1:e1ee2549a047 265 **************************************************************/
j3 1:e1ee2549a047 266 int16_t config_all_ports(max7300_port_type_t port_type);
j3 0:350a850a7191 267
j3 0:350a850a7191 268
j3 0:350a850a7191 269 /**********************************************************//**
j3 0:350a850a7191 270 * @brief Read a single MAX7300 GPIO port
j3 0:350a850a7191 271 *
j3 0:350a850a7191 272 * @details
j3 0:350a850a7191 273 *
j3 0:350a850a7191 274 * On Entry:
j3 1:e1ee2549a047 275 * @param[in] port_num - MAX7300 port number to read
j3 0:350a850a7191 276 *
j3 0:350a850a7191 277 * On Exit:
j3 1:e1ee2549a047 278 * @return state of port, or -1 on failure
j3 0:350a850a7191 279 **************************************************************/
j3 0:350a850a7191 280 int16_t read_port(max7300_port_number_t port_num);
j3 0:350a850a7191 281
j3 0:350a850a7191 282
j3 0:350a850a7191 283 /**********************************************************//**
j3 0:350a850a7191 284 * @brief Write a single MAX7300 GPIO port
j3 0:350a850a7191 285 *
j3 0:350a850a7191 286 * @details
j3 0:350a850a7191 287 *
j3 0:350a850a7191 288 * On Entry:
j3 1:e1ee2549a047 289 * @param[in] port_num - MAX7300 port to write
j3 1:e1ee2549a047 290 * @param[in] data - lsb of byte is written to port
j3 0:350a850a7191 291 *
j3 0:350a850a7191 292 * On Exit:
j3 1:e1ee2549a047 293 * @return 0 on success, non-0 on failure
j3 0:350a850a7191 294 **************************************************************/
j3 0:350a850a7191 295 int16_t write_port(max7300_port_number_t port_num, uint8_t data);
j3 0:350a850a7191 296
j3 0:350a850a7191 297
j3 0:350a850a7191 298 /**********************************************************//**
j3 0:350a850a7191 299 * @brief Read 8 MAX7300 GPIO ports
j3 0:350a850a7191 300 *
j3 0:350a850a7191 301 * @details
j3 0:350a850a7191 302 *
j3 0:350a850a7191 303 * On Entry:
j3 1:e1ee2549a047 304 * @param[in] low_port - lowest port of 8 ports to read,
j3 1:e1ee2549a047 305 * on 8 port boundaries as in datasheet.
j3 1:e1ee2549a047 306 * Max is port 24
j3 0:350a850a7191 307 *
j3 0:350a850a7191 308 * On Exit:
j3 1:e1ee2549a047 309 * @return state of ports, or -1 on failure
j3 0:350a850a7191 310 **************************************************************/
j3 1:e1ee2549a047 311 int16_t read_8_ports(max7300_port_number_t low_port);
j3 0:350a850a7191 312
j3 0:350a850a7191 313
j3 0:350a850a7191 314 /**********************************************************//**
j3 0:350a850a7191 315 * @brief Write 8 MAX7300 GPIO ports
j3 0:350a850a7191 316 *
j3 0:350a850a7191 317 * @details
j3 0:350a850a7191 318 *
j3 0:350a850a7191 319 * On Entry:
j3 1:e1ee2549a047 320 * @param[in] low_port - lowest port of 8 ports to write,
j3 1:e1ee2549a047 321 * on 8 port boundaries as in datasheet.
j3 1:e1ee2549a047 322 * Max is port 24
j3 1:e1ee2549a047 323 *
j3 1:e1ee2549a047 324 * @param[in] data - Data is written to ports
j3 0:350a850a7191 325 *
j3 0:350a850a7191 326 * On Exit:
j3 1:e1ee2549a047 327 * @return 0 on success, non-0 on failure
j3 0:350a850a7191 328 **************************************************************/
j3 1:e1ee2549a047 329 int16_t write_8_ports(max7300_port_number_t low_port, uint8_t data);
j3 1:e1ee2549a047 330
j3 1:e1ee2549a047 331
j3 1:e1ee2549a047 332 /**********************************************************//**
j3 1:e1ee2549a047 333 * @brief Read transition detection mask register
j3 1:e1ee2549a047 334 *
j3 1:e1ee2549a047 335 * @details See page 11 of DS, right hand side column, paragraph 2
j3 1:e1ee2549a047 336 * for details on one-shot event.
j3 1:e1ee2549a047 337 *
j3 1:e1ee2549a047 338 * On Entry:
j3 1:e1ee2549a047 339 * @param[in] enable_snapshot - true to re-enable transition
j3 1:e1ee2549a047 340 * detection
j3 1:e1ee2549a047 341 *
j3 1:e1ee2549a047 342 * On Exit:
j3 1:e1ee2549a047 343 * @return contents of mask register, or -1 on failure
j3 1:e1ee2549a047 344 **************************************************************/
j3 1:e1ee2549a047 345 int16_t read_mask_register(bool enable_snapshot);
j3 0:350a850a7191 346
j3 0:350a850a7191 347
j3 0:350a850a7191 348 /**********************************************************//**
j3 1:e1ee2549a047 349 * @brief Write transition detection mask register
j3 0:350a850a7191 350 *
j3 1:e1ee2549a047 351 * @details Enables transition detection on Ports 30-24
j3 1:e1ee2549a047 352 *
j3 0:350a850a7191 353 *
j3 0:350a850a7191 354 * On Entry:
j3 1:e1ee2549a047 355 * @param[in] data - Bits to set
j3 0:350a850a7191 356 *
j3 0:350a850a7191 357 * On Exit:
j3 1:e1ee2549a047 358 * @return 0 on success, non-0 on failure
j3 0:350a850a7191 359 **************************************************************/
j3 1:e1ee2549a047 360 int16_t write_mask_register(uint8_t data);
j3 1:e1ee2549a047 361
j3 0:350a850a7191 362
j3 0:350a850a7191 363 private:
j3 0:350a850a7191 364
j3 0:350a850a7191 365 I2C *_p_i2c;
j3 0:350a850a7191 366 bool _i2c_owner;
j3 0:350a850a7191 367 uint8_t _w_adrs;
j3 0:350a850a7191 368 uint8_t _r_adrs;
j3 1:e1ee2549a047 369
j3 1:e1ee2549a047 370
j3 1:e1ee2549a047 371 /**********************************************************//**
j3 1:e1ee2549a047 372 * @brief Write MAX7300 configuration register
j3 1:e1ee2549a047 373 *
j3 1:e1ee2549a047 374 * @details
j3 1:e1ee2549a047 375 *
j3 1:e1ee2549a047 376 * On Entry:
j3 1:e1ee2549a047 377 * @param[in] set_clear - If true set bit defined by data
j3 1:e1ee2549a047 378 *
j3 1:e1ee2549a047 379 * @param[in] data - 'S' or 'M' bit of configuration register
j3 1:e1ee2549a047 380 *
j3 1:e1ee2549a047 381 * On Exit:
j3 1:e1ee2549a047 382 * @return 0 on success, non-0 on failure
j3 1:e1ee2549a047 383 **************************************************************/
j3 1:e1ee2549a047 384 int16_t write_config_register(bool set_clear, uint8_t data);
j3 0:350a850a7191 385 };
j3 0:350a850a7191 386 #endif /* MAX7300_H*/