/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */

/*
 * ----------------------------------------------------------------------------------
 * The code in this file is copied (with a slight modifications) from:
 *     avr/include/util/twi.h
 * ----------------------------------------------------------------------------------
 * Copyright (c) 2002      Marek Michalkiewicz
 * Copyright (c) 2005-2007 Joerg Wunsch
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *     # Redistributions of source code must retain the above copyright notice, this
 *       list of conditions and the following disclaimer.
 *     # Redistributions in binary form must reproduce the above copyright notice,
 *       this list of conditions and the following disclaimer in the documentation
 *       and/or other materials provided with the distribution.
 *     # Neither the name of the copyright holders nor the names of contributors may
 *       be used to endorse or promote products derived from this software without
 *       specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Modified January 2017 by Bjorn Hammarberg (bjoham@esp8266.com) - i2c slave support
 * ----------------------------------------------------------------------------------
 */


#ifndef ECXX_PLATFORM_NODEMCU_TWI_DEFS_H
#define ECXX_PLATFORM_NODEMCU_TWI_DEFS_H


//
// TWI state machine constants
//

// Master and slave
#define TW_NO_INFO               0xF8
#define TW_BUS_ERROR             0x00

// Master transmitter and receiver
#define TW_START                 0x08
#define TW_REP_START             0x10

// Master transmitter
#define TW_MT_SLA_ACK            0x18
#define TW_MT_SLA_NACK           0x20
#define TW_MT_DATA_ACK           0x28
#define TW_MT_DATA_NACK          0x30
#define TW_MT_ARB_LOST           0x38

// Master receiver
#define TW_MR_ARB_LOST           0x38
#define TW_MR_SLA_ACK            0x40
#define TW_MR_SLA_NACK           0x48
#define TW_MR_DATA_ACK           0x50
#define TW_MR_DATA_NACK          0x58

// Slave transmitter
#define TW_ST_SLA_ACK            0xA8
#define TW_ST_ARB_LOST_SLA_ACK   0xB0
#define TW_ST_DATA_ACK           0xB8
#define TW_ST_DATA_NACK          0xC0
#define TW_ST_LAST_DATA          0xC8

// Slave receiver
#define TW_SR_SLA_ACK            0x60
#define TW_SR_ARB_LOST_SLA_ACK   0x68
#define TW_SR_GCALL_ACK          0x70
#define TW_SR_ARB_LOST_GCALL_ACK 0x78
#define TW_SR_DATA_ACK           0x80
#define TW_SR_DATA_NACK          0x88
#define TW_SR_GCALL_DATA_ACK     0x90
#define TW_SR_GCALL_DATA_NACK    0x98
#define TW_SR_STOP               0xA0


#endif
