/* esp8266_peri.h - Peripheral registers exposed in more AVR style for esp8266 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 ESP8266_PERI_H_INCLUDED #define ESP8266_PERI_H_INCLUDED // we expect mocking framework to provide these #ifndef CORE_MOCK #include "c_types.h" #include "esp8266_undocumented.h" #define ESP8266_REG(addr) *((volatile uint32_t *)(0x60000000+(addr))) #define ESP8266_DREG(addr) *((volatile uint32_t *)(0x3FF00000+(addr))) #define ESP8266_CLOCK 80000000UL #define i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) rom_i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) #define i2c_readReg_Mask_def(block, reg_add) i2c_readReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb) #define i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) rom_i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) #define i2c_writeReg_Mask_def(block, reg_add, indata) i2c_writeReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb, indata) //CPU Register #define CPU2X ESP8266_DREG(0x14) //when bit 0 is set, F_CPU = 160MHz //OTP Registers #define MAC0 ESP8266_DREG(0x50) #define MAC1 ESP8266_DREG(0x54) #define CHIPID ESP8266_DREG(0x58) //GPIO (0-15) Control Registers #define GPO ESP8266_REG(0x300) //GPIO_OUT R/W (Output Level) #define GPOS ESP8266_REG(0x304) //GPIO_OUT_SET WO #define GPOC ESP8266_REG(0x308) //GPIO_OUT_CLR WO #define GPE ESP8266_REG(0x30C) //GPIO_ENABLE R/W (Enable) #define GPES ESP8266_REG(0x310) //GPIO_ENABLE_SET WO #define GPEC ESP8266_REG(0x314) //GPIO_ENABLE_CLR WO #define GPI ESP8266_REG(0x318) //GPIO_IN RO (Read Input Level) #define GPIE ESP8266_REG(0x31C) //GPIO_STATUS R/W (Interrupt Enable) #define GPIES ESP8266_REG(0x320) //GPIO_STATUS_SET WO #define GPIEC ESP8266_REG(0x324) //GPIO_STATUS_CLR WO #define GPOP(p) ((GPO & (1 << ((p) & 0xF))) != 0) #define GPEP(p) ((GPE & (1 << ((p) & 0xF))) != 0) #define GPIP(p) ((GPI & (1 << ((p) & 0xF))) != 0) #define GPIEP(p) ((GPIE & (1 << ((p) & 0xF))) != 0) //GPIO (0-15) PIN Control Registers #define GPC(p) ESP8266_REG(0x328 + ((p & 0xF) * 4)) #define GPC0 ESP8266_REG(0x328) //GPIO_PIN0 #define GPC1 ESP8266_REG(0x32C) //GPIO_PIN1 #define GPC2 ESP8266_REG(0x330) //GPIO_PIN2 #define GPC3 ESP8266_REG(0x334) //GPIO_PIN3 #define GPC4 ESP8266_REG(0x338) //GPIO_PIN4 #define GPC5 ESP8266_REG(0x33C) //GPIO_PIN5 #define GPC6 ESP8266_REG(0x340) //GPIO_PIN6 #define GPC7 ESP8266_REG(0x344) //GPIO_PIN7 #define GPC8 ESP8266_REG(0x348) //GPIO_PIN8 #define GPC9 ESP8266_REG(0x34C) //GPIO_PIN9 #define GPC10 ESP8266_REG(0x350) //GPIO_PIN10 #define GPC11 ESP8266_REG(0x354) //GPIO_PIN11 #define GPC12 ESP8266_REG(0x358) //GPIO_PIN12 #define GPC13 ESP8266_REG(0x35C) //GPIO_PIN13 #define GPC14 ESP8266_REG(0x360) //GPIO_PIN14 #define GPC15 ESP8266_REG(0x364) //GPIO_PIN15 //GPIO (0-15) PIN Control Bits #define GPCWE 10 //WAKEUP_ENABLE (can be 1 only when INT_TYPE is high or low) #define GPCI 7 //INT_TYPE (3bits) 0:disable,1:rising,2:falling,3:change,4:low,5:high #define GPCD 2 //DRIVER 0:normal,1:open drain #define GPCS 0 //SOURCE 0:GPIO_DATA,1:SigmaDelta #define GPMUX ESP8266_REG(0x800) //GPIO (0-15) PIN Function Registers #define GPF0 ESP8266_REG(0x834) #define GPF1 ESP8266_REG(0x818) #define GPF2 ESP8266_REG(0x838) #define GPF3 ESP8266_REG(0x814) #define GPF4 ESP8266_REG(0x83C) #define GPF5 ESP8266_REG(0x840) #define GPF6 ESP8266_REG(0x81C) #define GPF7 ESP8266_REG(0x820) #define GPF8 ESP8266_REG(0x824) #define GPF9 ESP8266_REG(0x828) #define GPF10 ESP8266_REG(0x82C) #define GPF11 ESP8266_REG(0x830) #define GPF12 ESP8266_REG(0x804) #define GPF13 ESP8266_REG(0x808) #define GPF14 ESP8266_REG(0x80C) #define GPF15 ESP8266_REG(0x810) extern volatile uint32_t* const esp8266_gpioToFn[16]; #define GPF(p) (*esp8266_gpioToFn[(p & 0xF)]) //GPIO (0-15) PIN Function Bits #define GPFSOE 0 //Sleep OE #define GPFSS 1 //Sleep Sel #define GPFSPD 2 //Sleep Pulldown #define GPFSPU 3 //Sleep Pullup #define GPFFS0 4 //Function Select bit 0 #define GPFFS1 5 //Function Select bit 1 #define GPFPD 6 //Pulldown #define GPFPU 7 //Pullup #define GPFFS2 8 //Function Select bit 2 #define GPFFS(f) (((((f) & 4) != 0) << GPFFS2) | ((((f) & 2) != 0) << GPFFS1) | ((((f) & 1) != 0) << GPFFS0)) #define GPFFS_GPIO(p) (((p)==0||(p)==2||(p)==4||(p)==5)?0:((p)==16)?1:3) #define GPFFS_BUS(p) (((p)==1||(p)==3)?0:((p)==2||(p)==12||(p)==13||(p)==14||(p)==15)?2:((p)==0)?4:1) //GPIO 16 Control Registers #define GP16O ESP8266_REG(0x768) #define GP16E ESP8266_REG(0x774) #define GP16I ESP8266_REG(0x78C) //GPIO 16 PIN Control Register #define GP16C ESP8266_REG(0x790) #define GPC16 GP16C //GPIO 16 PIN Function Register #define GP16F ESP8266_REG(0x7A0) #define GPF16 GP16F //GPIO 16 PIN Function Bits #define GP16FFS0 0 //Function Select bit 0 #define GP16FFS1 1 //Function Select bit 1 #define GP16FPD 3 //Pulldown #define GP16FSPD 5 //Sleep Pulldown #define GP16FFS2 6 //Function Select bit 2 #define GP16FFS(f) (((f) & 0x03) | (((f) & 0x04) << 4)) //Timer 1 Registers (23bit CountDown Timer) #define T1L ESP8266_REG(0x600) //Load Value (Starting Value of Counter) 23bit (0-8388607) #define T1V ESP8266_REG(0x604) //(RO) Current Value #define T1C ESP8266_REG(0x608) //Control Register #define T1I ESP8266_REG(0x60C) //Interrupt Status Register (1bit) write to clear //edge interrupt enable register #define TEIE ESP8266_DREG(0x04) #define TEIE1 0x02 //bit for timer 1 //Timer 2 Registers (32bit CountUp Timer) #define T2L ESP8266_REG(0x620) //Load Value (Starting Value of Counter) #define T2V ESP8266_REG(0x624) //(RO) Current Value #define T2C ESP8266_REG(0x628) //Control Register #define T2I ESP8266_REG(0x62C) //Interrupt Status Register (1bit) write to clear #define T2A ESP8266_REG(0x630) //Alarm Value //Timer Control Bits #define TCIS 8 //Interrupt Status #define TCTE 7 //Timer Enable #define TCAR 6 //AutoReload (restart timer when condition is reached) #define TCPD 2 //Prescale Devider (2bit) 0:1(12.5ns/tick), 1:16(0.2us/tick), 2/3:256(3.2us/tick) #define TCIT 0 //Interrupt Type 0:edge, 1:level //RTC Registers #define RTCSV ESP8266_REG(0x704) //RTC SLEEP COUNTER Target Value #define RTCCV ESP8266_REG(0x71C) //RTC SLEEP COUNTER Value #define RTCIS ESP8266_REG(0x720) //RTC INT Status #define RTCIC ESP8266_REG(0x724) //RTC INT Clear #define RTCIE ESP8266_REG(0x728) //RTC INT Enable #define RTC_USER_MEM ((volatile uint32_t*)0x60001200) //IO SWAP Register #define IOSWAP ESP8266_DREG(0x28) #define IOSWAPU 0 //Swaps UART #define IOSWAPS 1 //Swaps SPI #define IOSWAPU0 2 //Swaps UART 0 pins (u0rxd <-> u0cts), (u0txd <-> u0rts) #define IOSWAPU1 3 //Swaps UART 1 pins (u1rxd <-> u1cts), (u1txd <-> u1rts) #define IOSWAPHS 5 //Sets HSPI with higher prio #define IOSWAP2HS 6 //Sets Two SPI Masters on HSPI #define IOSWAP2CS 7 //Sets Two SPI Masters on CSPI //UART INT Status #define UIS ESP8266_DREG(0x20020) #define UIS0 0 #define UIS1 2 //UART 0 Registers #define U0F ESP8266_REG(0x000) //UART FIFO #define U0IR ESP8266_REG(0x004) //INT_RAW #define U0IS ESP8266_REG(0x008) //INT_STATUS #define U0IE ESP8266_REG(0x00c) //INT_ENABLE #define U0IC ESP8266_REG(0x010) //INT_CLEAR #define U0D ESP8266_REG(0x014) //CLKDIV #define U0A ESP8266_REG(0x018) //AUTOBAUD #define U0S ESP8266_REG(0x01C) //STATUS #define U0C0 ESP8266_REG(0x020) //CONF0 #define U0C1 ESP8266_REG(0x024) //CONF1 #define U0LP ESP8266_REG(0x028) //LOW_PULSE #define U0HP ESP8266_REG(0x02C) //HIGH_PULSE #define U0PN ESP8266_REG(0x030) //PULSE_NUM #define U0DT ESP8266_REG(0x078) //DATE #define U0ID ESP8266_REG(0x07C) //ID //UART 1 Registers #define U1F ESP8266_REG(0xF00) //UART FIFO #define U1IR ESP8266_REG(0xF04) //INT_RAW #define U1IS ESP8266_REG(0xF08) //INT_STATUS #define U1IE ESP8266_REG(0xF0c) //INT_ENABLE #define U1IC ESP8266_REG(0xF10) //INT_CLEAR #define U1D ESP8266_REG(0xF14) //CLKDIV #define U1A ESP8266_REG(0xF18) //AUTOBAUD #define U1S ESP8266_REG(0xF1C) //STATUS #define U1C0 ESP8266_REG(0xF20) //CONF0 #define U1C1 ESP8266_REG(0xF24) //CONF1 #define U1LP ESP8266_REG(0xF28) //LOW_PULSE #define U1HP ESP8266_REG(0xF2C) //HIGH_PULSE #define U1PN ESP8266_REG(0xF30) //PULSE_NUM #define U1DT ESP8266_REG(0xF78) //DATE #define U1ID ESP8266_REG(0xF7C) //ID //UART(uart) Registers #define USF(u) ESP8266_REG(0x000+(0xF00*(u&1))) //UART FIFO #define USIR(u) ESP8266_REG(0x004+(0xF00*(u&1))) //INT_RAW #define USIS(u) ESP8266_REG(0x008+(0xF00*(u&1))) //INT_STATUS #define USIE(u) ESP8266_REG(0x00c+(0xF00*(u&1))) //INT_ENABLE #define USIC(u) ESP8266_REG(0x010+(0xF00*(u&1))) //INT_CLEAR #define USD(u) ESP8266_REG(0x014+(0xF00*(u&1))) //CLKDIV #define USA(u) ESP8266_REG(0x018+(0xF00*(u&1))) //AUTOBAUD #define USS(u) ESP8266_REG(0x01C+(0xF00*(u&1))) //STATUS #define USC0(u) ESP8266_REG(0x020+(0xF00*(u&1))) //CONF0 #define USC1(u) ESP8266_REG(0x024+(0xF00*(u&1))) //CONF1 #define USLP(u) ESP8266_REG(0x028+(0xF00*(u&1))) //LOW_PULSE #define USHP(u) ESP8266_REG(0x02C+(0xF00*(u&1))) //HIGH_PULSE #define USPN(u) ESP8266_REG(0x030+(0xF00*(u&1))) //PULSE_NUM #define USDT(u) ESP8266_REG(0x078+(0xF00*(u&1))) //DATE #define USID(u) ESP8266_REG(0x07C+(0xF00*(u&1))) //ID //UART INT Registers Bits #define UITO 8 //RX FIFO TimeOut #define UIBD 7 //Break Detected #define UICTS 6 //CTS Changed #define UIDSR 5 //DSR Change #define UIOF 4 //RX FIFO OverFlow #define UIFR 3 //Frame Error #define UIPE 2 //Parity Error #define UIFE 1 //TX FIFO Empty #define UIFF 0 //RX FIFO Full //UART STATUS Registers Bits #define USTX 31 //TX PIN Level (Doesn't seem to work, always reads as 0 for both uarts. HW bug? Possible workaround: Enable loopback UxC0 |= 1<