Added files
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Some random cgi routines. Used in the LED example and the page that returns the entire
|
||||
flash as a binary. Also handles the hit counter on the main page.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
|
||||
* this notice you can do whatever you want with this stuff. If we meet some day,
|
||||
* and you think this stuff is worth it, you can buy me a beer in return.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include <esp8266.h>
|
||||
#include "cgi.h"
|
||||
|
||||
static long hitCounter=0;
|
||||
|
||||
//Template code for the counter on the index page.
|
||||
int ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg) {
|
||||
char buff[128];
|
||||
if (token==NULL) return HTTPD_CGI_DONE;
|
||||
|
||||
if (os_strcmp(token, "counter")==0) {
|
||||
hitCounter++;
|
||||
os_sprintf(buff, "%ld", hitCounter);
|
||||
}
|
||||
httpdSend(connData, buff, -1);
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef CGI_H
|
||||
#define CGI_H
|
||||
|
||||
#include <esp8266.h>
|
||||
#include "httpd.h"
|
||||
|
||||
int tplCounter(HttpdConnData *connData, char *token, void **arg);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
|
||||
* this notice you can do whatever you want with this stuff. If we meet some day,
|
||||
* and you think this stuff is worth it, you can buy me a beer in return.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
// Edited: do not fuck with GPIO2, it's used for debug usart output
|
||||
|
||||
// GPIO0 remains used as reset btn.
|
||||
|
||||
|
||||
|
||||
#include <esp8266.h>
|
||||
|
||||
//#define LEDGPIO 2
|
||||
#define BTNGPIO 0
|
||||
|
||||
static ETSTimer resetBtntimer;
|
||||
|
||||
//void ICACHE_FLASH_ATTR ioLed(int ena) {
|
||||
// //gpio_output_set is overkill. ToDo: use better mactos
|
||||
// if (ena) {
|
||||
// gpio_output_set((1<<LEDGPIO), 0, (1<<LEDGPIO), 0);
|
||||
// } else {
|
||||
// gpio_output_set(0, (1<<LEDGPIO), (1<<LEDGPIO), 0);
|
||||
// }
|
||||
//}
|
||||
|
||||
static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) {
|
||||
static int resetCnt=0;
|
||||
if (!GPIO_INPUT_GET(BTNGPIO)) {
|
||||
resetCnt++;
|
||||
} else {
|
||||
if (resetCnt>=6) { //3 sec pressed
|
||||
wifi_station_disconnect();
|
||||
wifi_set_opmode(0x3); //reset to AP+STA mode
|
||||
os_printf("Reset to AP mode. Restarting system...\n");
|
||||
system_restart();
|
||||
}
|
||||
resetCnt=0;
|
||||
}
|
||||
}
|
||||
|
||||
void ioInit() {
|
||||
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
|
||||
gpio_output_set(0, 0, 0/*(1<<LEDGPIO)*/, (1<<BTNGPIO));
|
||||
os_timer_disarm(&resetBtntimer);
|
||||
os_timer_setfn(&resetBtntimer, resetBtnTimerCb, NULL);
|
||||
os_timer_arm(&resetBtntimer, 500, 1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef IO_H
|
||||
#define IO_H
|
||||
|
||||
#include <esp8266.h>
|
||||
|
||||
//void ICACHE_FLASH_ATTR ioLed(int ena);
|
||||
void ioInit(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
//Stupid bit of code that does the bare minimum to make os_printf work.
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
|
||||
* this notice you can do whatever you want with this stuff. If we meet some day,
|
||||
* and you think this stuff is worth it, you can buy me a beer in return.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <esp8266.h>
|
||||
#include "uart.h"
|
||||
|
||||
|
||||
///** USART1 write routine */
|
||||
//static void ICACHE_FLASH_ATTR stdoutUart1Txd(char c)
|
||||
//{
|
||||
// //Wait until there is room in the FIFO
|
||||
// while (((READ_PERI_REG(UART_STATUS(0)) >> UART_TXFIFO_CNT_S) & UART_TXFIFO_CNT) >= 126) ;
|
||||
// //Send the character
|
||||
// WRITE_PERI_REG(UART_FIFO(0), c);
|
||||
//}
|
||||
|
||||
|
||||
///** Putchar to USART1 */
|
||||
//static void ICACHE_FLASH_ATTR stdoutPutcharUSART1(char c)
|
||||
//{
|
||||
// //convert \n -> \r\n
|
||||
// if (c == '\n') stdoutUart1Txd('\r');
|
||||
// stdoutUart1Txd(c);
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configure UART 115200-8-N-1
|
||||
* @param uart_no
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR
|
||||
my_uart_init(UARTn uart_no)
|
||||
{
|
||||
UART_SetParity(uart_no, PARITY_NONE);
|
||||
UART_SetStopBits(uart_no, ONE_STOP_BIT);
|
||||
UART_SetWordLength(uart_no, EIGHT_BITS);
|
||||
UART_SetBaudrate(uart_no, BIT_RATE_115200);
|
||||
UART_ResetFifo(uart_no);
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
stdoutInit()
|
||||
{
|
||||
// U0TXD
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
|
||||
PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
|
||||
|
||||
// U0RXD
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD);
|
||||
|
||||
// U1TXD (GPIO2)
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
|
||||
|
||||
// Configure the UART peripherals
|
||||
my_uart_init(UART0); // main
|
||||
my_uart_init(UART1); // debug (output only)
|
||||
|
||||
// Select debug port
|
||||
UART_SetPrintPort(UART1);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef STDOUT_H
|
||||
#define STDOUT_H
|
||||
|
||||
#include <esp8266.h>
|
||||
|
||||
void stdoutInit();
|
||||
|
||||
#endif
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Driver file for ESP8266 UART, works with the SDK.
|
||||
*/
|
||||
|
||||
#include "uart.h"
|
||||
|
||||
#include <esp8266.h>
|
||||
|
||||
#include "ets_sys.h"
|
||||
#include "osapi.h"
|
||||
#include "mem.h"
|
||||
#include "os_type.h"
|
||||
|
||||
#include "ets_sys_extra.h"
|
||||
#include "uart_register.h"
|
||||
|
||||
//========================================================
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetWordLength(UARTn uart_no, UartBitsNum4Char len)
|
||||
{
|
||||
SET_PERI_REG_BITS(UART_CONF0(uart_no), UART_BIT_NUM, len, UART_BIT_NUM_S);
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetStopBits(UARTn uart_no, UartStopBitsNum bit_num)
|
||||
{
|
||||
SET_PERI_REG_BITS(UART_CONF0(uart_no), UART_STOP_BIT_NUM, bit_num, UART_STOP_BIT_NUM_S);
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetLineInverse(UARTn uart_no, UART_LineLevelInverse inverse_mask)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_LINE_INV_MASK);
|
||||
SET_PERI_REG_MASK(UART_CONF0(uart_no), inverse_mask);
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetParity(UARTn uart_no, UartParityMode Parity_mode)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_PARITY | UART_PARITY_EN);
|
||||
if (Parity_mode == PARITY_NONE) {
|
||||
} else {
|
||||
SET_PERI_REG_MASK(UART_CONF0(uart_no), Parity_mode | UART_PARITY_EN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetBaudrate(UARTn uart_no, uint32 baud_rate)
|
||||
{
|
||||
uart_div_modify(uart_no, UART_CLK_FREQ / baud_rate);
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetFlowCtrl(UARTn uart_no, UART_HwFlowCtrl flow_ctrl, uint8 rx_thresh)
|
||||
{
|
||||
if (flow_ctrl & USART_HWFlow_RTS) {
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS);
|
||||
SET_PERI_REG_BITS(UART_CONF1(uart_no), UART_RX_FLOW_THRHD, rx_thresh, UART_RX_FLOW_THRHD_S);
|
||||
SET_PERI_REG_MASK(UART_CONF1(uart_no), UART_RX_FLOW_EN);
|
||||
} else {
|
||||
CLEAR_PERI_REG_MASK(UART_CONF1(uart_no), UART_RX_FLOW_EN);
|
||||
}
|
||||
|
||||
if (flow_ctrl & USART_HWFlow_CTS) {
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_UART0_CTS);
|
||||
SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_TX_FLOW_EN);
|
||||
} else {
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_TX_FLOW_EN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_WaitTxFifoEmpty(UARTn uart_no , uint32 time_out_us) //do not use if tx flow control enabled
|
||||
{
|
||||
uint32 t_s = system_get_time();
|
||||
while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S)) {
|
||||
|
||||
if ((system_get_time() - t_s) > time_out_us) {
|
||||
break;
|
||||
}
|
||||
|
||||
system_soft_wdt_feed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ICACHE_FLASH_ATTR
|
||||
UART_CheckOutputFinished(UARTn uart_no, uint32 time_out_us)
|
||||
{
|
||||
uint32 t_start = system_get_time();
|
||||
uint8 tx_fifo_len;
|
||||
|
||||
while (1) {
|
||||
tx_fifo_len = UART_TxQueLen(uart_no);
|
||||
|
||||
// TODO If using output circbuf, check if empty
|
||||
|
||||
if (tx_fifo_len == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (system_get_time() - t_start > time_out_us) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
system_soft_wdt_feed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_ResetFifo(UARTn uart_no)
|
||||
{
|
||||
SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_ClearIntrStatus(UARTn uart_no, uint32 clr_mask)
|
||||
{
|
||||
WRITE_PERI_REG(UART_INT_CLR(uart_no), clr_mask);
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetIntrEna(UARTn uart_no, uint32 ena_mask)
|
||||
{
|
||||
SET_PERI_REG_MASK(UART_INT_ENA(uart_no), ena_mask);
|
||||
}
|
||||
|
||||
|
||||
LOCAL void u0_putc_crlf(char c)
|
||||
{
|
||||
UART_WriteCharCRLF(UART0, (u8)c, UART_TIMEOUT_US);
|
||||
}
|
||||
|
||||
|
||||
LOCAL void u1_putc_crlf(char c)
|
||||
{
|
||||
UART_WriteCharCRLF(UART1, (u8)c, UART_TIMEOUT_US);
|
||||
}
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetPrintPort(UARTn uart_no)
|
||||
{
|
||||
if (uart_no == UART0) {
|
||||
os_install_putc1(u0_putc_crlf);
|
||||
} else {
|
||||
os_install_putc1(u1_putc_crlf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -------------- Custom UART functions -------------------------
|
||||
|
||||
// !!! write handlers are not ICACHE_FLASH_ATTR -> can be used in IRQ !!!
|
||||
|
||||
/**
|
||||
* @brief Write a char to UART.
|
||||
* @param uart_no
|
||||
* @param c
|
||||
* @param timeout_us - how long to max wait for space in FIFO.
|
||||
* @return write success
|
||||
*/
|
||||
STATUS UART_WriteChar(UARTn uart_no, uint8 c, uint32 timeout_us)
|
||||
{
|
||||
if (timeout_us == 0) {
|
||||
timeout_us = UART_TIMEOUT_US;
|
||||
}
|
||||
|
||||
|
||||
uint32 t_s = system_get_time();
|
||||
|
||||
while ((system_get_time() - t_s) < timeout_us) {
|
||||
uint8 fifo_cnt = UART_TxQueLen(uart_no);
|
||||
|
||||
if (fifo_cnt < UART_TX_FULL_THRESH_VAL) {
|
||||
WRITE_PERI_REG(UART_FIFO(uart_no), c);
|
||||
return OK;
|
||||
}
|
||||
|
||||
system_soft_wdt_feed();
|
||||
}
|
||||
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write a char to UART, translating LF to CRLF and discarding CR.
|
||||
* @param uart_no
|
||||
* @param c
|
||||
* @param timeout_us - how long to max wait for space in FIFO.
|
||||
* @return write success
|
||||
*/
|
||||
STATUS UART_WriteCharCRLF(UARTn uart_no, uint8 c, uint32 timeout_us)
|
||||
{
|
||||
STATUS st;
|
||||
|
||||
if (c == '\r') {
|
||||
return OK;
|
||||
} else if (c == '\n') {
|
||||
|
||||
st = UART_WriteChar(uart_no, '\r', timeout_us);
|
||||
if (st != OK) return st;
|
||||
|
||||
st = UART_WriteChar(uart_no, '\n', timeout_us);
|
||||
return st;
|
||||
|
||||
} else {
|
||||
return UART_WriteChar(uart_no, c, timeout_us);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send a string to UART.
|
||||
* @param uart_no
|
||||
* @param str
|
||||
* @param timeout_us - how long to max wait for space in FIFO.
|
||||
* @return write success
|
||||
*/
|
||||
STATUS UART_WriteString(UARTn uart_no, const char *str, uint32 timeout_us)
|
||||
{
|
||||
while (*str) {
|
||||
STATUS suc = UART_WriteChar(uart_no, (u8) * str++, timeout_us);
|
||||
if (suc != OK) return suc;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send a buffer
|
||||
* @param uart_no
|
||||
* @param buffer - buffer to send
|
||||
* @param len - buffer size
|
||||
* @param timeout_us - how long to max wait for space in FIFO.
|
||||
* @return write success
|
||||
*/
|
||||
STATUS UART_WriteBuffer(UARTn uart_no, const uint8 *buffer, size_t len, uint32 timeout_us)
|
||||
{
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
STATUS suc = UART_WriteChar(uart_no, (u8) * buffer++, timeout_us);
|
||||
if (suc != OK) return suc;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* File : uart.h
|
||||
* Copyright (C) 2013 - 2016, Espressif Systems
|
||||
* Copyright (C) 2016, Ondřej Hruška (cleaning, modif.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of version 3 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef UART_APP_H
|
||||
#define UART_APP_H
|
||||
|
||||
#include "uart_register.h"
|
||||
|
||||
#include "eagle_soc.h"
|
||||
#include "c_types.h"
|
||||
|
||||
|
||||
// ===========
|
||||
|
||||
// timeout for sending / receiving a char (default)
|
||||
#define UART_TIMEOUT_US 5000
|
||||
|
||||
#define UART_TX_FULL_THRESH_VAL (UART_FIFO_LEN - 2) // if more than this many bytes in queue, don't write more
|
||||
#define UART_TX_EMPTY_THRESH_VAL 16
|
||||
|
||||
// ===========
|
||||
|
||||
|
||||
typedef enum {
|
||||
UART0 = 0,
|
||||
UART1 = 1
|
||||
} UARTn;
|
||||
|
||||
|
||||
typedef enum {
|
||||
FIVE_BITS = 0x0,
|
||||
SIX_BITS = 0x1,
|
||||
SEVEN_BITS = 0x2,
|
||||
EIGHT_BITS = 0x3
|
||||
} UartBitsNum4Char;
|
||||
|
||||
|
||||
typedef enum {
|
||||
ONE_STOP_BIT = 0x1,
|
||||
ONE_HALF_STOP_BIT = 0x2,
|
||||
TWO_STOP_BIT = 0x3
|
||||
} UartStopBitsNum;
|
||||
|
||||
|
||||
typedef enum {
|
||||
PARITY_NONE = 0x2,
|
||||
PARITY_ODD = 1,
|
||||
PARITY_EVEN = 0
|
||||
} UartParityMode;
|
||||
|
||||
|
||||
typedef enum {
|
||||
PARITY_DIS = 0,
|
||||
PARITY_EN = 1
|
||||
} UartExistParity;
|
||||
|
||||
|
||||
typedef enum {
|
||||
UART_None_Inverse = 0x0,
|
||||
UART_Rxd_Inverse = UART_RXD_INV,
|
||||
UART_CTS_Inverse = UART_CTS_INV,
|
||||
UART_Txd_Inverse = UART_TXD_INV,
|
||||
UART_RTS_Inverse = UART_RTS_INV,
|
||||
} UART_LineLevelInverse;
|
||||
|
||||
|
||||
typedef enum {
|
||||
BIT_RATE_300 = 300,
|
||||
BIT_RATE_600 = 600,
|
||||
BIT_RATE_1200 = 1200,
|
||||
BIT_RATE_2400 = 2400,
|
||||
BIT_RATE_4800 = 4800,
|
||||
BIT_RATE_9600 = 9600,
|
||||
BIT_RATE_19200 = 19200,
|
||||
BIT_RATE_38400 = 38400,
|
||||
BIT_RATE_57600 = 57600,
|
||||
BIT_RATE_74880 = 74880,
|
||||
BIT_RATE_115200 = 115200,
|
||||
BIT_RATE_230400 = 230400,
|
||||
BIT_RATE_460800 = 460800,
|
||||
BIT_RATE_921600 = 921600,
|
||||
BIT_RATE_1843200 = 1843200,
|
||||
BIT_RATE_3686400 = 3686400,
|
||||
} UartBautRate;
|
||||
|
||||
|
||||
typedef enum {
|
||||
NONE_CTRL,
|
||||
HARDWARE_CTRL,
|
||||
XON_XOFF_CTRL
|
||||
} UartFlowCtrl;
|
||||
|
||||
|
||||
typedef enum {
|
||||
USART_HWFlow_None = 0x0,
|
||||
USART_HWFlow_RTS = 0x1,
|
||||
USART_HWFlow_CTS = 0x2,
|
||||
USART_HWFlow_CTS_RTS = 0x3
|
||||
} UART_HwFlowCtrl;
|
||||
|
||||
|
||||
typedef enum {
|
||||
EMPTY,
|
||||
UNDER_WRITE,
|
||||
WRITE_OVER
|
||||
} RcvMsgBuffState;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32 RcvBuffSize;
|
||||
uint8 *pRcvMsgBuff;
|
||||
uint8 *pWritePos;
|
||||
uint8 *pReadPos;
|
||||
uint8 TrigLvl; //JLU: may need to pad
|
||||
RcvMsgBuffState BuffState;
|
||||
} RcvMsgBuff;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32 TrxBuffSize;
|
||||
uint8 *pTrxBuff;
|
||||
} TrxMsgBuff;
|
||||
|
||||
|
||||
typedef enum {
|
||||
BAUD_RATE_DET,
|
||||
WAIT_SYNC_FRM,
|
||||
SRCH_MSG_HEAD,
|
||||
RCV_MSG_BODY,
|
||||
RCV_ESC_CHAR,
|
||||
} RcvMsgState;
|
||||
|
||||
|
||||
typedef struct {
|
||||
UartBautRate baut_rate;
|
||||
UartBitsNum4Char data_bits;
|
||||
UartExistParity exist_parity;
|
||||
UartParityMode parity;
|
||||
UartStopBitsNum stop_bits;
|
||||
UartFlowCtrl flow_ctrl;
|
||||
RcvMsgBuff rcv_buff;
|
||||
TrxMsgBuff trx_buff;
|
||||
RcvMsgState rcv_state;
|
||||
int received;
|
||||
int buff_uart_no; //indicate which uart use tx/rx buffer
|
||||
} UartDevice;
|
||||
|
||||
// UartDev is defined and initialized in rom code.
|
||||
extern UartDevice UartDev;
|
||||
|
||||
|
||||
//==============================================
|
||||
|
||||
// FIFO used count
|
||||
#define UART_TxQueLen(uart_no) ((READ_PERI_REG(UART_STATUS((uart_no))) >> UART_TXFIFO_CNT_S) & UART_TXFIFO_CNT)
|
||||
#define UART_RxQueLen(uart_no) ((READ_PERI_REG(UART_STATUS((uart_no))) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT)
|
||||
|
||||
STATUS UART_WriteCharCRLF(UARTn uart_no, uint8 c, uint32 timeout_us);
|
||||
STATUS UART_WriteChar(UARTn uart_no, uint8 c, uint32 timeout_us);
|
||||
STATUS UART_WriteString(UARTn uart_no, const char *str, uint32 timeout_us);
|
||||
STATUS UART_WriteBuffer(UARTn uart_no, const uint8 *buffer, size_t len, uint32 timeout_us);
|
||||
|
||||
//==============================================
|
||||
|
||||
void UART_SetWordLength(UARTn uart_no, UartBitsNum4Char len);
|
||||
void UART_SetStopBits(UARTn uart_no, UartStopBitsNum bit_num);
|
||||
void UART_SetLineInverse(UARTn uart_no, UART_LineLevelInverse inverse_mask);
|
||||
void UART_SetParity(UARTn uart_no, UartParityMode Parity_mode);
|
||||
void UART_SetBaudrate(UARTn uart_no, uint32 baud_rate);
|
||||
void UART_SetFlowCtrl(UARTn uart_no, UART_HwFlowCtrl flow_ctrl, uint8 rx_thresh);
|
||||
void UART_WaitTxFifoEmpty(UARTn uart_no , uint32 time_out_us); //do not use if tx flow control enabled
|
||||
void UART_ResetFifo(UARTn uart_no);
|
||||
void UART_ClearIntrStatus(UARTn uart_no, uint32 clr_mask);
|
||||
void UART_SetIntrEna(UARTn uart_no, uint32 ena_mask);
|
||||
void UART_SetPrintPort(UARTn uart_no);
|
||||
bool UART_CheckOutputFinished(UARTn uart_no, uint32 time_out_us);
|
||||
|
||||
//==============================================
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
|
||||
* this notice you can do whatever you want with this stuff. If we meet some day,
|
||||
* and you think this stuff is worth it, you can buy me a beer in return.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// library headers
|
||||
#include <esp8266.h>
|
||||
#include "httpd.h"
|
||||
#include "httpdespfs.h"
|
||||
#include "cgiwifi.h"
|
||||
#include "cgiflash.h"
|
||||
#include "auth.h"
|
||||
#include "espfs.h"
|
||||
#include "captdns.h"
|
||||
#include "webpages-espfs.h"
|
||||
#include "cgiwebsocket.h"
|
||||
|
||||
// user files
|
||||
#include "cgi.h"
|
||||
#include "stdout.h"
|
||||
#include "io.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief BasicAuth name/password checking function.
|
||||
*
|
||||
* It's invoked by the authBasic() built-in route handler
|
||||
* until it returns 0. Each time it populates the provided
|
||||
* name and password buffer.
|
||||
*
|
||||
* @param connData : connection context
|
||||
* @param no : user number (incremented each time it's called)
|
||||
* @param user : user buffer
|
||||
* @param userLen : user buffer size
|
||||
* @param pass : password buffer
|
||||
* @param passLen : password buffer size
|
||||
* @return 0 to end, 1 if more users are available.
|
||||
*/
|
||||
int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen)
|
||||
{
|
||||
(void)connData;
|
||||
(void)userLen;
|
||||
(void)passLen;
|
||||
|
||||
if (no == 0) {
|
||||
os_strcpy(user, "admin");
|
||||
os_strcpy(pass, "s3cr3t");
|
||||
return 1;
|
||||
//Add more users this way. Check against incrementing no for each user added.
|
||||
// } else if (no==1) {
|
||||
// os_strcpy(user, "user1");
|
||||
// os_strcpy(pass, "something");
|
||||
// return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Some stuff for alternative ESPFS storage methods
|
||||
#ifdef ESPFS_POS
|
||||
CgiUploadFlashDef uploadParams = {
|
||||
.type = CGIFLASH_TYPE_ESPFS,
|
||||
.fw1Pos = ESPFS_POS,
|
||||
.fw2Pos = 0,
|
||||
.fwSize = ESPFS_SIZE,
|
||||
};
|
||||
#define INCLUDE_FLASH_FNS
|
||||
#endif
|
||||
#ifdef OTA_FLASH_SIZE_K
|
||||
CgiUploadFlashDef uploadParams = {
|
||||
.type = CGIFLASH_TYPE_FW,
|
||||
.fw1Pos = 0x1000,
|
||||
.fw2Pos = ((OTA_FLASH_SIZE_K * 1024) / 2) + 0x1000,
|
||||
.fwSize = ((OTA_FLASH_SIZE_K * 1024) / 2) - 0x1000,
|
||||
.tagName = OTA_TAGNAME
|
||||
};
|
||||
#define INCLUDE_FLASH_FNS
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* This is the main url->function dispatching data struct.
|
||||
*
|
||||
* In short, it's a struct with various URLs plus their handlers. The handlers can
|
||||
* be 'standard' CGI functions you wrote, or 'special' CGIs requiring an argument.
|
||||
* They can also be auth-functions. An asterisk will match any url starting with
|
||||
* everything before the asterisks; "*" matches everything. The list will be
|
||||
* handled top-down, so make sure to put more specific rules above the more
|
||||
* general ones. Authorization things (like authBasic) act as a 'barrier' and
|
||||
* should be placed above the URLs they protect.
|
||||
*/
|
||||
static HttpdBuiltInUrl builtInUrls[] = {
|
||||
{"*", cgiRedirectApClientToHostname, "esp8266.nonet"},
|
||||
{"/", cgiEspFsTemplate, (void *)tplCounter},
|
||||
|
||||
//Enable the line below to protect the WiFi configuration with an username/password combo.
|
||||
// {"/wifi/*", authBasic, (void *)myPassFn},
|
||||
|
||||
{"/wifi", cgiRedirect, "/wifi/"},
|
||||
{"/wifi/", cgiEspFsTemplate, (void *)tplWlan},
|
||||
//{"/wifi/", cgiRedirect, "/wifi/wifi.tpl"},
|
||||
{"/wifi/wifiscan.cgi", cgiWiFiScan, NULL},
|
||||
{"/wifi/connect.cgi", cgiWiFiConnect, NULL},
|
||||
{"/wifi/connstatus.cgi", cgiWiFiConnStatus, NULL},
|
||||
{"/wifi/setmode.cgi", cgiWiFiSetMode, NULL},
|
||||
|
||||
{"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
|
||||
*/
|
||||
void user_init(void)
|
||||
{
|
||||
// set up the debuging output
|
||||
stdoutInit();
|
||||
|
||||
// reset button etc
|
||||
ioInit();
|
||||
|
||||
// Start the captive portal
|
||||
captdnsInit();
|
||||
|
||||
/* --- Initialize ESPFS --- */
|
||||
|
||||
// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
|
||||
// where image is written in flash that is defined in Makefile.
|
||||
#ifdef ESPFS_POS
|
||||
espFsInit((void*)(0x40200000 + ESPFS_POS));
|
||||
#else
|
||||
espFsInit((void*)(webpages_espfs_start));
|
||||
#endif
|
||||
|
||||
/* --- Initialize the webserver --- */
|
||||
|
||||
httpdInit(builtInUrls, 80);
|
||||
|
||||
|
||||
os_printf("\nReady\n");
|
||||
}
|
||||
|
||||
|
||||
void user_rf_pre_init()
|
||||
{
|
||||
//Not needed, but some SDK versions want this defined.
|
||||
}
|
||||
Reference in New Issue
Block a user