1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.

Dependents:   MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more

Superseded by MaximInterface.

OneWire_Masters/DS248x/ds248x.h

Committer:
j3
Date:
2016-01-31
Revision:
3:644fc630f958
Parent:
2:02d228c25fd4
Child:
5:ce108eeb878d

File content as of revision 3:644fc630f958:

/******************************************************************//**
* @file ds248x.h
*
* @author Justin Jordan
*
* @version 0.0.0
*
* Started: 30JAN16
*
* Updated: 
*
* @brief Header file for Ds248x I2C to 1-wire master 
***********************************************************************
* Copyright (C) 2016 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 DS248X_H
#define DS248X_H


#include "mbed.h"
#include "OneWireInterface.h"


class Ds248x: public OneWireInterface
{
    public:
    
    typedef enum
    {
        DS248X_I2C_ADRS0 = 0x18,
        DS248X_I2C_ADRS1,
        DS248X_I2C_ADRS2,
        DS248X_I2C_ADRS3,
        DS248X_I2C_ADRS4,
        DS248X_I2C_ADRS5,
        DS248X_I2C_ADRS6,
        DS248X_I2C_ADRS7,
    }ds248x_i2c_adrs_t;
    
    /**
    * Member functions that directly support DS248x I2C to 1-wire
    * masters are documented in this file.  Virtual function 
    * inerited from the interface class 'OneWireInterface'
    * are documented in 'OneWireInterface.h', trying to follow
    * a 'DRY' methodology, Don't Repeat Yourself.
    */ 
    
    /**********************************************************//**
    * @brief Ds248x constructor
    * 
    * @details allows user to use existing I2C object
    *
    * On Entry:
    *     @param[in] p_i2c_bus - pointer to existing I2C object
    *
    * On Exit:
    *    @return 
    **************************************************************/
    Ds248x(I2C *p_i2c_bus, ds248x_i2c_adrs_t adrs);
    
    
    /**********************************************************//**
    * @brief Ds248x constructor
    * 
    * @details Object instantiates a new I2C object with no 
    *          public access
    *
    * On Entry:
    *     @param[in] sda - sda pin of I2C bus
    *     @param[in] scl - scl pin of I2C bus
    *
    * On Exit:
    *    @return 
    **************************************************************/
    Ds248x(PinName sda, PinName scl, ds248x_i2c_adrs_t adrs);
    
    
    /**********************************************************//**
    * @brief Ds248x destructor 
    * 
    * @details deletes I2C object if owner 
    *
    * On Entry:
    *
    * On Exit:
    *    @return 
    **************************************************************/
    ~Ds248x();
    
    
    /**********************************************************//**
    * @brief detect() 
    * 
    * @details Detect routine that performs a device reset 
    *          followed by writing the configuration byte to default 
    *          values:
    *          1-Wire speed (c1WS) = standard (0)
    *          Strong pull-up (cSPU) = off (0)
    *          Presence pulse masking (cPPM) = off (0)
    *          Active pull-up (cAPU) = on (CONFIG_APU = 0x01)
    *
    * On Entry:
    *
    * On Exit:
    *    @return TRUE if device was detected and written
    *            FALSE device not detected or failure to write 
    *            configuration byte
    **************************************************************/
    bool detect(void);
    
    
    /**********************************************************//**
    * @brief reset()
    * 
    * @details Perform a device reset on the Ds248x
    *
    * On Entry:
    *
    * On Exit:
    *    @return TRUE if device was reset
    *            FALSE device not detected or failure to perform reset
    **************************************************************/
    bool reset(void);
    
    
    /**********************************************************//**
    * @brief write_config()
    * 
    * @details Write the configuration register in the Ds248x. The 
    *          configuration options are provided in the lower nibble 
    *          of the provided config byte. The uppper nibble is 
    *          bitwise inverted when written to the Ds248x.
    *
    * On Entry:
    *     @param[in] config - lower nib of configuration register
    *
    * On Exit:
    *    @return TRUE: config written and response correct
    *            FALSE: response incorrect
    **************************************************************/
    bool write_config(uint8_t config);
    
    
    /**********************************************************//**
    * @brief channel_select()
    * 
    * @details Select the 1-Wire channel on a DS2482-800. 
    *          Min channel = 1
    *
    * On Entry:
    *     @param[in] channel - desired channel of the DS2482
    *
    * On Exit:
    *    @return TRUE if channel selected
    *            FALSE device not detected or failure to perform select
    **************************************************************/
    bool channel_select(uint8_t channel);
    
    
    /**********************************************************//**
    * @brief adjust_timing()
    * 
    * @details adjustable timming available in DS2484 only
    *
    * On Entry:
    *     @param[in] param - 1 of 8 adjustable parameters
    *     @param[in] val - new value for parameter, see datasheet 
    *                      for codes
    *
    * On Exit:
    *    @return TRUE: parameter successfully adjusted
    *            FALSE: failed to adjust parameter
    **************************************************************/
    bool adjust_timing(uint8_t param, uint8_t val);
    
    
    /**********************************************************//**
    * @brief search_triplet()
    * 
    * @details Use the Ds248x help command '1-Wire triplet' to perform 
    *          one bit of a 1-Wire search. This command does two read 
    *          bits and one write bit. The write bit is either the 
    *          default direction (all device have same bit) or in case 
    *          of a discrepancy, the 'search_direction' parameter is 
    *          used. 
    *
    * On Entry:
    *     @param[in] search_direction
    *
    * On Exit:
    *    @return The Ds248x status byte result from the triplet command
    **************************************************************/
    uint8_t search_triplet(uint8_t search_direction);
    
    /***** OW API ****************************************************/
    virtual bool OWReset();
    
    virtual void OWWriteBit(uint8_t sendbit);
    
    virtual uint8_t OWReadBit();
    
    virtual uint8_t OWTouchBit(uint8_t sendbit);

    virtual bool OWWriteByte(uint8_t sendbyte);

    virtual uint8_t OWReadByte(void);

    virtual uint8_t OWTouchByte(uint8_t sendbyte);

    virtual void OWBlock(uint8_t *tran_buf, uint8_t tran_len);

    virtual bool OWFirst(void);

    virtual bool OWNext(void);

    virtual bool OWVerify(void);

    virtual void OWTargetSetup(uint8_t family_code);

    virtual void OWFamilySkipSetup(void);
    
    virtual bool OWSearch(void);

    virtual uint8_t OWSpeed(uint8_t new_speed);

    virtual uint8_t OWLevel(uint8_t new_level);

    virtual bool OWWriteBytePower(uint8_t sendbyte);

    virtual bool OWReadBitPower(uint8_t applyPowerResponse);

    virtual uint8_t OWCalc_crc8(uint8_t data);

    virtual void OWgetROMnumber(uint8_t *p_rom_buff);
    
    private:
    
    I2C *_p_i2c_bus;
    bool i2c_owner;
    uint8_t _w_adrs, _r_adrs;
    
    // ds248x state
    uint8_t _short_detected;
    uint8_t _c1WS, _cSPU, _cPDN, _cAPU;

    // Search state
    uint8_t _rom_number[8];
    uint8_t _last_discrepancy;
    uint8_t _last_family_discrepancy;
    uint8_t _last_device_flag;
    uint8_t _crc8; 
};

#endif /*DS248X_H*/