/*
 * 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:
 *     esp8266_undocumented.h - ROM and blob calls without official headers available
 * ----------------------------------------------------------------------------------
 * Copyright (C) 2015 Hristo Gochkov. All rights reserved.
 *
 * This file is part of the esp8266 core for Arduino environment.
 *
 * This library is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any later
 * version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 * ----------------------------------------------------------------------------------
 */


#ifndef ECXX_PLATFORM_NODEMCU_ESP8266_UNDOCUMENTED_H
#define ECXX_PLATFORM_NODEMCU_ESP8266_UNDOCUMENTED_H


#ifndef XCHAL_EXCCAUSE_NUM
    #define XCHAL_EXCCAUSE_NUM 64
#endif


//
// ROM and blob calls without official headers available
//
extern "C" {

    extern void rom_i2c_writeReg_Mask(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t);
    extern int32_t rom_i2c_readReg_Mask(int32_t, int32_t, int32_t, int32_t, int32_t);

    extern void ets_delay_us(uint32_t us);

    extern int32_t uart_baudrate_detect(int32_t, int32_t);

    /*
     * # Switch printing between UART0 and UART1.
     * # It updates a structure that only controls a select group of print functions.
     *
     * # ets_putc() and ets_uart_printf() are examples and are not affected by calls to ets_install_putc1().
     *
     * # Use : 0 for UART0 (also clears Rx FIFO);
     *         1 for UART1
     */
    extern void uart_buff_switch(uint8_t);

    /*
     * # Prints on the UART selected by uart_buff_switch().
     * # Supported format options are the same as vprintf().
     * # Has cooked newline behavior.
     * # Has no flash format/string support.
     * # ISR safe.
     */
    extern int32_t ets_uart_printf(const char *format, ...) __EXCC_ATTR_PRINTF(1, 2);

} // extern "C"


#endif
