Merge branch 'master' into crc_compute
# Conflicts: # examples/crc_example/crc_main.c # extras/crc_generic/crc_lib
This commit is contained in:
commit
3e28e2ddef
49 changed files with 8811 additions and 6 deletions
1
extras/bearssl/BearSSL
Submodule
1
extras/bearssl/BearSSL
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit f0c00466018e4bcdaa2d965ac723d53f015cde9a
|
||||
14
extras/bearssl/component.mk
Normal file
14
extras/bearssl/component.mk
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Component makefile for BearSSL
|
||||
|
||||
BEARSSL_DIR = $(bearssl_ROOT)BearSSL/
|
||||
INC_DIRS += $(BEARSSL_DIR)inc
|
||||
|
||||
# args for passing into compile rule generation
|
||||
bearssl_INC_DIR = $(BEARSSL_DIR)inc $(BEARSSL_DIR)src
|
||||
bearssl_SRC_DIR = $(BEARSSL_DIR)src $(sort $(dir $(wildcard $(BEARSSL_DIR)src/*/)))
|
||||
|
||||
$(eval $(call component_compile_rules,bearssl))
|
||||
|
||||
# Helpful error if git submodule not initialised
|
||||
$(BEARSSL_DIR):
|
||||
$(error "bearssl git submodule not installed. Please run 'git submodule update --init'")
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit e013b431f58d916b68138b838d2a1c4584304de0
|
||||
Subproject commit a97013c72f686735889b7a0908bbbf15a104f7d0
|
||||
9
extras/httpd/component.mk
Normal file
9
extras/httpd/component.mk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Component makefile for extras/httpd
|
||||
|
||||
# expected anyone using httpd includes it as 'httpd/httpd.h'
|
||||
INC_DIRS += $(httpd_ROOT)..
|
||||
|
||||
# args for passing into compile rule generation
|
||||
httpd_SRC_DIR = $(httpd_ROOT)
|
||||
|
||||
$(eval $(call component_compile_rules,httpd))
|
||||
180
extras/httpd/fs.c
Normal file
180
extras/httpd/fs.c
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/def.h"
|
||||
#include "fs.h"
|
||||
#include "fsdata.h"
|
||||
#include <string.h>
|
||||
|
||||
/** Set this to 1 to include "fsdata_custom.c" instead of "fsdata.c" for the
|
||||
* file system (to prevent changing the file included in CVS) */
|
||||
#ifndef HTTPD_USE_CUSTOM_FSDATA
|
||||
#define HTTPD_USE_CUSTOM_FSDATA 0
|
||||
#endif
|
||||
|
||||
#if HTTPD_USE_CUSTOM_FSDATA
|
||||
#include "fsdata_custom.c"
|
||||
#else /* HTTPD_USE_CUSTOM_FSDATA */
|
||||
#include "fsdata.c"
|
||||
#endif /* HTTPD_USE_CUSTOM_FSDATA */
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
int fs_open_custom(struct fs_file *file, const char *name);
|
||||
void fs_close_custom(struct fs_file *file);
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
u8_t fs_canread_custom(struct fs_file *file);
|
||||
u8_t fs_wait_read_custom(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg);
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
err_t
|
||||
fs_open(struct fs_file *file, const char *name)
|
||||
{
|
||||
const struct fsdata_file *f;
|
||||
|
||||
if ((file == NULL) || (name == NULL)) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
if (fs_open_custom(file, name)) {
|
||||
file->is_custom_file = 1;
|
||||
return ERR_OK;
|
||||
}
|
||||
file->is_custom_file = 0;
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
|
||||
for (f = FS_ROOT; f != NULL; f = f->next) {
|
||||
if (!strcmp(name, (char *)f->name)) {
|
||||
file->data = (const char *)f->data;
|
||||
file->len = f->len;
|
||||
file->index = f->len;
|
||||
file->pextension = NULL;
|
||||
file->http_header_included = f->http_header_included;
|
||||
#if HTTPD_PRECALCULATED_CHECKSUM
|
||||
file->chksum_count = f->chksum_count;
|
||||
file->chksum = f->chksum;
|
||||
#endif /* HTTPD_PRECALCULATED_CHECKSUM */
|
||||
#if LWIP_HTTPD_FILE_STATE
|
||||
file->state = fs_state_init(file, name);
|
||||
#endif /* #if LWIP_HTTPD_FILE_STATE */
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
/* file not found */
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
fs_close(struct fs_file *file)
|
||||
{
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
if (file->is_custom_file) {
|
||||
fs_close_custom(file);
|
||||
}
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
#if LWIP_HTTPD_FILE_STATE
|
||||
fs_state_free(file, file->state);
|
||||
#endif /* #if LWIP_HTTPD_FILE_STATE */
|
||||
LWIP_UNUSED_ARG(file);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if LWIP_HTTPD_DYNAMIC_FILE_READ
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
int
|
||||
fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg)
|
||||
#else /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
int
|
||||
fs_read(struct fs_file *file, char *buffer, int count)
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
{
|
||||
int read;
|
||||
|
||||
if(file->index == file->len) {
|
||||
return FS_READ_EOF;
|
||||
}
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
if (!fs_canread_custom(file)) {
|
||||
if (fs_wait_read_custom(file, callback_fn, callback_arg)) {
|
||||
return FS_READ_DELAYED;
|
||||
}
|
||||
}
|
||||
#else /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
LWIP_UNUSED_ARG(callback_fn);
|
||||
LWIP_UNUSED_ARG(callback_arg);
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
|
||||
read = file->len - file->index;
|
||||
if(read > count) {
|
||||
read = count;
|
||||
}
|
||||
|
||||
MEMCPY(buffer, (file->data + file->index), read);
|
||||
file->index += read;
|
||||
|
||||
return(read);
|
||||
}
|
||||
#endif /* LWIP_HTTPD_DYNAMIC_FILE_READ */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
int
|
||||
fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg)
|
||||
{
|
||||
if (file != NULL) {
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
if (!fs_canread_custom(file)) {
|
||||
if (fs_wait_read_custom(file, callback_fn, callback_arg)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#else /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
LWIP_UNUSED_ARG(callback_fn);
|
||||
LWIP_UNUSED_ARG(callback_arg);
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int
|
||||
fs_bytes_left(struct fs_file *file)
|
||||
{
|
||||
return file->len - file->index;
|
||||
}
|
||||
132
extras/httpd/fs.h
Normal file
132
extras/httpd/fs.h
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
#ifndef __FS_H__
|
||||
#define __FS_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/err.h"
|
||||
|
||||
/** Set this to 1 and provide the functions:
|
||||
* - "int fs_open_custom(struct fs_file *file, const char *name)"
|
||||
* Called first for every opened file to allow opening files
|
||||
* that are not included in fsdata(_custom).c
|
||||
* - "void fs_close_custom(struct fs_file *file)"
|
||||
* Called to free resources allocated by fs_open_custom().
|
||||
*/
|
||||
#ifndef LWIP_HTTPD_CUSTOM_FILES
|
||||
#define LWIP_HTTPD_CUSTOM_FILES 0
|
||||
#endif
|
||||
|
||||
/** Set this to 1 to support fs_read() to dynamically read file data.
|
||||
* Without this (default=off), only one-block files are supported,
|
||||
* and the contents must be ready after fs_open().
|
||||
*/
|
||||
#ifndef LWIP_HTTPD_DYNAMIC_FILE_READ
|
||||
#define LWIP_HTTPD_DYNAMIC_FILE_READ 0
|
||||
#endif
|
||||
|
||||
/** Set this to 1 to include an application state argument per file
|
||||
* that is opened. This allows to keep a state per connection/file.
|
||||
*/
|
||||
#ifndef LWIP_HTTPD_FILE_STATE
|
||||
#define LWIP_HTTPD_FILE_STATE 0
|
||||
#endif
|
||||
|
||||
/** HTTPD_PRECALCULATED_CHECKSUM==1: include precompiled checksums for
|
||||
* predefined (MSS-sized) chunks of the files to prevent having to calculate
|
||||
* the checksums at runtime. */
|
||||
#ifndef HTTPD_PRECALCULATED_CHECKSUM
|
||||
#define HTTPD_PRECALCULATED_CHECKSUM 0
|
||||
#endif
|
||||
|
||||
/** LWIP_HTTPD_FS_ASYNC_READ==1: support asynchronous read operations
|
||||
* (fs_read_async returns FS_READ_DELAYED and calls a callback when finished).
|
||||
*/
|
||||
#ifndef LWIP_HTTPD_FS_ASYNC_READ
|
||||
#define LWIP_HTTPD_FS_ASYNC_READ 0
|
||||
#endif
|
||||
|
||||
#define FS_READ_EOF -1
|
||||
#define FS_READ_DELAYED -2
|
||||
|
||||
#if HTTPD_PRECALCULATED_CHECKSUM
|
||||
struct fsdata_chksum {
|
||||
u32_t offset;
|
||||
u16_t chksum;
|
||||
u16_t len;
|
||||
};
|
||||
#endif /* HTTPD_PRECALCULATED_CHECKSUM */
|
||||
|
||||
struct fs_file {
|
||||
const char *data;
|
||||
int len;
|
||||
int index;
|
||||
void *pextension;
|
||||
#if HTTPD_PRECALCULATED_CHECKSUM
|
||||
const struct fsdata_chksum *chksum;
|
||||
u16_t chksum_count;
|
||||
#endif /* HTTPD_PRECALCULATED_CHECKSUM */
|
||||
u8_t http_header_included;
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
u8_t is_custom_file;
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
#if LWIP_HTTPD_FILE_STATE
|
||||
void *state;
|
||||
#endif /* LWIP_HTTPD_FILE_STATE */
|
||||
};
|
||||
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
typedef void (*fs_wait_cb)(void *arg);
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
|
||||
err_t fs_open(struct fs_file *file, const char *name);
|
||||
void fs_close(struct fs_file *file);
|
||||
#if LWIP_HTTPD_DYNAMIC_FILE_READ
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
int fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg);
|
||||
#else /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
int fs_read(struct fs_file *file, char *buffer, int count);
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
#endif /* LWIP_HTTPD_DYNAMIC_FILE_READ */
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
int fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg);
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
int fs_bytes_left(struct fs_file *file);
|
||||
|
||||
#if LWIP_HTTPD_FILE_STATE
|
||||
/** This user-defined function is called when a file is opened. */
|
||||
void *fs_state_init(struct fs_file *file, const char *name);
|
||||
/** This user-defined function is called when a file is closed. */
|
||||
void fs_state_free(struct fs_file *file, void *state);
|
||||
#endif /* #if LWIP_HTTPD_FILE_STATE */
|
||||
|
||||
#endif /* __FS_H__ */
|
||||
50
extras/httpd/fsdata.h
Normal file
50
extras/httpd/fsdata.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
#ifndef __FSDATA_H__
|
||||
#define __FSDATA_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "fs.h"
|
||||
|
||||
struct fsdata_file {
|
||||
const struct fsdata_file *next;
|
||||
const unsigned char *name;
|
||||
const unsigned char *data;
|
||||
int len;
|
||||
u8_t http_header_included;
|
||||
#if HTTPD_PRECALCULATED_CHECKSUM
|
||||
u16_t chksum_count;
|
||||
const struct fsdata_chksum *chksum;
|
||||
#endif /* HTTPD_PRECALCULATED_CHECKSUM */
|
||||
};
|
||||
|
||||
#endif /* __FSDATA_H__ */
|
||||
2754
extras/httpd/httpd.c
Normal file
2754
extras/httpd/httpd.c
Normal file
File diff suppressed because it is too large
Load diff
263
extras/httpd/httpd.h
Normal file
263
extras/httpd/httpd.h
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* This version of the file has been modified by Texas Instruments to offer
|
||||
* simple server-side-include (SSI) and Common Gateway Interface (CGI)
|
||||
* capability.
|
||||
*/
|
||||
|
||||
#ifndef __HTTPD_H__
|
||||
#define __HTTPD_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/tcp.h"
|
||||
|
||||
|
||||
/** Set this to 1 to support CGI */
|
||||
#ifndef LWIP_HTTPD_CGI
|
||||
#define LWIP_HTTPD_CGI 0
|
||||
#endif
|
||||
|
||||
/** Set this to 1 to support SSI (Server-Side-Includes) */
|
||||
#ifndef LWIP_HTTPD_SSI
|
||||
#define LWIP_HTTPD_SSI 0
|
||||
#endif
|
||||
|
||||
/** Set this to 1 to support HTTP POST */
|
||||
#ifndef LWIP_HTTPD_SUPPORT_POST
|
||||
#define LWIP_HTTPD_SUPPORT_POST 0
|
||||
#endif
|
||||
|
||||
#if LWIP_HTTPD_CGI
|
||||
|
||||
/*
|
||||
* Function pointer for a CGI script handler.
|
||||
*
|
||||
* This function is called each time the HTTPD server is asked for a file
|
||||
* whose name was previously registered as a CGI function using a call to
|
||||
* http_set_cgi_handler. The iIndex parameter provides the index of the
|
||||
* CGI within the ppcURLs array passed to http_set_cgi_handler. Parameters
|
||||
* pcParam and pcValue provide access to the parameters provided along with
|
||||
* the URI. iNumParams provides a count of the entries in the pcParam and
|
||||
* pcValue arrays. Each entry in the pcParam array contains the name of a
|
||||
* parameter with the corresponding entry in the pcValue array containing the
|
||||
* value for that parameter. Note that pcParam may contain multiple elements
|
||||
* with the same name if, for example, a multi-selection list control is used
|
||||
* in the form generating the data.
|
||||
*
|
||||
* The function should return a pointer to a character string which is the
|
||||
* path and filename of the response that is to be sent to the connected
|
||||
* browser, for example "/thanks.htm" or "/response/error.ssi".
|
||||
*
|
||||
* The maximum number of parameters that will be passed to this function via
|
||||
* iNumParams is defined by LWIP_HTTPD_MAX_CGI_PARAMETERS. Any parameters in the incoming
|
||||
* HTTP request above this number will be discarded.
|
||||
*
|
||||
* Requests intended for use by this CGI mechanism must be sent using the GET
|
||||
* method (which encodes all parameters within the URI rather than in a block
|
||||
* later in the request). Attempts to use the POST method will result in the
|
||||
* request being ignored.
|
||||
*
|
||||
*/
|
||||
typedef const char *(*tCGIHandler)(int iIndex, int iNumParams, char *pcParam[],
|
||||
char *pcValue[]);
|
||||
|
||||
/*
|
||||
* Structure defining the base filename (URL) of a CGI and the associated
|
||||
* function which is to be called when that URL is requested.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
const char *pcCGIName;
|
||||
tCGIHandler pfnCGIHandler;
|
||||
} tCGI;
|
||||
|
||||
void http_set_cgi_handlers(const tCGI *pCGIs, int iNumHandlers);
|
||||
|
||||
|
||||
/* The maximum number of parameters that the CGI handler can be sent. */
|
||||
#ifndef LWIP_HTTPD_MAX_CGI_PARAMETERS
|
||||
#define LWIP_HTTPD_MAX_CGI_PARAMETERS 16
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_HTTPD_CGI */
|
||||
|
||||
#if LWIP_HTTPD_SSI
|
||||
|
||||
/** LWIP_HTTPD_SSI_MULTIPART==1: SSI handler function is called with 2 more
|
||||
* arguments indicating a counter for insert string that are too long to be
|
||||
* inserted at once: the SSI handler function must then set 'next_tag_part'
|
||||
* which will be passed back to it in the next call. */
|
||||
#ifndef LWIP_HTTPD_SSI_MULTIPART
|
||||
#define LWIP_HTTPD_SSI_MULTIPART 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Function pointer for the SSI tag handler callback.
|
||||
*
|
||||
* This function will be called each time the HTTPD server detects a tag of the
|
||||
* form <!--#name--> in a .shtml, .ssi or .shtm file where "name" appears as
|
||||
* one of the tags supplied to http_set_ssi_handler in the ppcTags array. The
|
||||
* returned insert string, which will be appended after the the string
|
||||
* "<!--#name-->" in file sent back to the client,should be written to pointer
|
||||
* pcInsert. iInsertLen contains the size of the buffer pointed to by
|
||||
* pcInsert. The iIndex parameter provides the zero-based index of the tag as
|
||||
* found in the ppcTags array and identifies the tag that is to be processed.
|
||||
*
|
||||
* The handler returns the number of characters written to pcInsert excluding
|
||||
* any terminating NULL or a negative number to indicate a failure (tag not
|
||||
* recognized, for example).
|
||||
*
|
||||
* Note that the behavior of this SSI mechanism is somewhat different from the
|
||||
* "normal" SSI processing as found in, for example, the Apache web server. In
|
||||
* this case, the inserted text is appended following the SSI tag rather than
|
||||
* replacing the tag entirely. This allows for an implementation that does not
|
||||
* require significant additional buffering of output data yet which will still
|
||||
* offer usable SSI functionality. One downside to this approach is when
|
||||
* attempting to use SSI within JavaScript. The SSI tag is structured to
|
||||
* resemble an HTML comment but this syntax does not constitute a comment
|
||||
* within JavaScript and, hence, leaving the tag in place will result in
|
||||
* problems in these cases. To work around this, any SSI tag which needs to
|
||||
* output JavaScript code must do so in an encapsulated way, sending the whole
|
||||
* HTML <script>...</script> section as a single include.
|
||||
*/
|
||||
typedef u16_t (*tSSIHandler)(int iIndex, char *pcInsert, int iInsertLen
|
||||
#if LWIP_HTTPD_SSI_MULTIPART
|
||||
, u16_t current_tag_part, u16_t *next_tag_part
|
||||
#endif /* LWIP_HTTPD_SSI_MULTIPART */
|
||||
#if LWIP_HTTPD_FILE_STATE
|
||||
, void *connection_state
|
||||
#endif /* LWIP_HTTPD_FILE_STATE */
|
||||
);
|
||||
|
||||
void http_set_ssi_handler(tSSIHandler pfnSSIHandler,
|
||||
const char **ppcTags, int iNumTags);
|
||||
|
||||
/* The maximum length of the string comprising the tag name */
|
||||
#ifndef LWIP_HTTPD_MAX_TAG_NAME_LEN
|
||||
#define LWIP_HTTPD_MAX_TAG_NAME_LEN 8
|
||||
#endif
|
||||
|
||||
/* The maximum length of string that can be returned to replace any given tag */
|
||||
#ifndef LWIP_HTTPD_MAX_TAG_INSERT_LEN
|
||||
#define LWIP_HTTPD_MAX_TAG_INSERT_LEN 192
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_HTTPD_SSI */
|
||||
|
||||
#if LWIP_HTTPD_SUPPORT_POST
|
||||
|
||||
/* These functions must be implemented by the application */
|
||||
|
||||
/** Called when a POST request has been received. The application can decide
|
||||
* whether to accept it or not.
|
||||
*
|
||||
* @param connection Unique connection identifier, valid until httpd_post_end
|
||||
* is called.
|
||||
* @param uri The HTTP header URI receiving the POST request.
|
||||
* @param http_request The raw HTTP request (the first packet, normally).
|
||||
* @param http_request_len Size of 'http_request'.
|
||||
* @param content_len Content-Length from HTTP header.
|
||||
* @param response_uri Filename of response file, to be filled when denying the
|
||||
* request
|
||||
* @param response_uri_len Size of the 'response_uri' buffer.
|
||||
* @param post_auto_wnd Set this to 0 to let the callback code handle window
|
||||
* updates by calling 'httpd_post_data_recved' (to throttle rx speed)
|
||||
* default is 1 (httpd handles window updates automatically)
|
||||
* @return ERR_OK: Accept the POST request, data may be passed in
|
||||
* another err_t: Deny the POST request, send back 'bad request'.
|
||||
*/
|
||||
err_t httpd_post_begin(void *connection, const char *uri, const char *http_request,
|
||||
u16_t http_request_len, int content_len, char *response_uri,
|
||||
u16_t response_uri_len, u8_t *post_auto_wnd);
|
||||
|
||||
/** Called for each pbuf of data that has been received for a POST.
|
||||
* ATTENTION: The application is responsible for freeing the pbufs passed in!
|
||||
*
|
||||
* @param connection Unique connection identifier.
|
||||
* @param p Received data.
|
||||
* @return ERR_OK: Data accepted.
|
||||
* another err_t: Data denied, http_post_get_response_uri will be called.
|
||||
*/
|
||||
err_t httpd_post_receive_data(void *connection, struct pbuf *p);
|
||||
|
||||
/** Called when all data is received or when the connection is closed.
|
||||
* The application must return the filename/URI of a file to send in response
|
||||
* to this POST request. If the response_uri buffer is untouched, a 404
|
||||
* response is returned.
|
||||
*
|
||||
* @param connection Unique connection identifier.
|
||||
* @param response_uri Filename of response file, to be filled when denying the request
|
||||
* @param response_uri_len Size of the 'response_uri' buffer.
|
||||
*/
|
||||
void httpd_post_finished(void *connection, char *response_uri, u16_t response_uri_len);
|
||||
|
||||
#ifndef LWIP_HTTPD_POST_MANUAL_WND
|
||||
#define LWIP_HTTPD_POST_MANUAL_WND 0
|
||||
#endif
|
||||
|
||||
#if LWIP_HTTPD_POST_MANUAL_WND
|
||||
void httpd_post_data_recved(void *connection, u16_t recved_len);
|
||||
#endif /* LWIP_HTTPD_POST_MANUAL_WND */
|
||||
|
||||
#endif /* LWIP_HTTPD_SUPPORT_POST */
|
||||
|
||||
enum {
|
||||
WS_TEXT_MODE = 0x01,
|
||||
WS_BIN_MODE = 0x02,
|
||||
} WS_MODE;
|
||||
|
||||
typedef void (*tWsHandler)(struct tcp_pcb *pcb, uint8_t *data, u16_t data_len, uint8_t mode);
|
||||
typedef void (*tWsOpenHandler)(struct tcp_pcb *pcb, const char *uri);
|
||||
|
||||
/**
|
||||
* Write data into a websocket.
|
||||
*
|
||||
* @param pcb tcp_pcb to send.
|
||||
* @param data data to send.
|
||||
* @param len data length.
|
||||
* @param mode WS_TEXT_MODE or WS_BIN_MODE.
|
||||
* @return ERR_OK if write succeeded.
|
||||
*/
|
||||
err_t websocket_write(struct tcp_pcb *pcb, const uint8_t *data, uint16_t len, uint8_t mode);
|
||||
|
||||
/**
|
||||
* Register websocket callback functions. Use NULL if callback is not needed.
|
||||
*
|
||||
* @param ws_open_cb called when new websocket is opened.
|
||||
* @param ws_cb called when data is received from client.
|
||||
*/
|
||||
void websocket_register_callbacks(tWsOpenHandler ws_open_cb, tWsHandler ws_cb);
|
||||
|
||||
void httpd_init(void);
|
||||
|
||||
#endif /* __HTTPD_H__ */
|
||||
125
extras/httpd/httpd_structs.h
Normal file
125
extras/httpd/httpd_structs.h
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#ifndef __HTTPD_STRUCTS_H__
|
||||
#define __HTTPD_STRUCTS_H__
|
||||
|
||||
#include "httpd.h"
|
||||
|
||||
/** This string is passed in the HTTP header as "Server: " */
|
||||
#ifndef HTTPD_SERVER_AGENT
|
||||
#define HTTPD_SERVER_AGENT "lwIP/1.3.1 (http://savannah.nongnu.org/projects/lwip)"
|
||||
#endif
|
||||
|
||||
/** Set this to 1 if you want to include code that creates HTTP headers
|
||||
* at runtime. Default is off: HTTP headers are then created statically
|
||||
* by the makefsdata tool. Static headers mean smaller code size, but
|
||||
* the (readonly) fsdata will grow a bit as every file includes the HTTP
|
||||
* header. */
|
||||
#ifndef LWIP_HTTPD_DYNAMIC_HEADERS
|
||||
#define LWIP_HTTPD_DYNAMIC_HEADERS 0
|
||||
#endif
|
||||
|
||||
|
||||
#if LWIP_HTTPD_DYNAMIC_HEADERS
|
||||
/** This struct is used for a list of HTTP header strings for various
|
||||
* filename extensions. */
|
||||
typedef struct
|
||||
{
|
||||
const char *extension;
|
||||
int headerIndex;
|
||||
} tHTTPHeader;
|
||||
|
||||
/** A list of strings used in HTTP headers */
|
||||
static const char * const g_psHTTPHeaderStrings[] =
|
||||
{
|
||||
"Content-type: text/html\r\n\r\n",
|
||||
"Content-type: text/html\r\nExpires: Fri, 10 Apr 2008 14:00:00 GMT\r\nPragma: no-cache\r\n\r\n",
|
||||
"Content-type: image/gif\r\n\r\n",
|
||||
"Content-type: image/png\r\n\r\n",
|
||||
"Content-type: image/jpeg\r\n\r\n",
|
||||
"Content-type: image/bmp\r\n\r\n",
|
||||
"Content-type: image/x-icon\r\n\r\n",
|
||||
"Content-type: application/octet-stream\r\n\r\n",
|
||||
"Content-type: application/x-javascript\r\n\r\n",
|
||||
"Content-type: application/x-javascript\r\n\r\n",
|
||||
"Content-type: text/css\r\n\r\n",
|
||||
"Content-type: application/x-shockwave-flash\r\n\r\n",
|
||||
"Content-type: text/xml\r\n\r\n",
|
||||
"Content-type: text/plain\r\n\r\n",
|
||||
"HTTP/1.0 200 OK\r\n",
|
||||
"HTTP/1.0 404 File not found\r\n",
|
||||
"HTTP/1.0 400 Bad Request\r\n",
|
||||
"HTTP/1.0 501 Not Implemented\r\n",
|
||||
"HTTP/1.1 200 OK\r\n",
|
||||
"HTTP/1.1 404 File not found\r\n",
|
||||
"HTTP/1.1 400 Bad Request\r\n",
|
||||
"HTTP/1.1 501 Not Implemented\r\n",
|
||||
"Content-Length: ",
|
||||
"Connection: Close\r\n",
|
||||
"Connection: keep-alive\r\n",
|
||||
"Server: "HTTPD_SERVER_AGENT"\r\n",
|
||||
"\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
|
||||
};
|
||||
|
||||
/* Indexes into the g_psHTTPHeaderStrings array */
|
||||
#define HTTP_HDR_HTML 0 /* text/html */
|
||||
#define HTTP_HDR_SSI 1 /* text/html Expires... */
|
||||
#define HTTP_HDR_GIF 2 /* image/gif */
|
||||
#define HTTP_HDR_PNG 3 /* image/png */
|
||||
#define HTTP_HDR_JPG 4 /* image/jpeg */
|
||||
#define HTTP_HDR_BMP 5 /* image/bmp */
|
||||
#define HTTP_HDR_ICO 6 /* image/x-icon */
|
||||
#define HTTP_HDR_APP 7 /* application/octet-stream */
|
||||
#define HTTP_HDR_JS 8 /* application/x-javascript */
|
||||
#define HTTP_HDR_RA 9 /* application/x-javascript */
|
||||
#define HTTP_HDR_CSS 10 /* text/css */
|
||||
#define HTTP_HDR_SWF 11 /* application/x-shockwave-flash */
|
||||
#define HTTP_HDR_XML 12 /* text/xml */
|
||||
#define HTTP_HDR_DEFAULT_TYPE 13 /* text/plain */
|
||||
#define HTTP_HDR_OK 14 /* 200 OK */
|
||||
#define HTTP_HDR_NOT_FOUND 15 /* 404 File not found */
|
||||
#define HTTP_HDR_BAD_REQUEST 16 /* 400 Bad request */
|
||||
#define HTTP_HDR_NOT_IMPL 17 /* 501 Not Implemented */
|
||||
#define HTTP_HDR_OK_11 18 /* 200 OK */
|
||||
#define HTTP_HDR_NOT_FOUND_11 19 /* 404 File not found */
|
||||
#define HTTP_HDR_BAD_REQUEST_11 20 /* 400 Bad request */
|
||||
#define HTTP_HDR_NOT_IMPL_11 21 /* 501 Not Implemented */
|
||||
#define HTTP_HDR_CONTENT_LENGTH 22 /* Content-Length: (HTTP 1.1)*/
|
||||
#define HTTP_HDR_CONN_CLOSE 23 /* Connection: Close (HTTP 1.1) */
|
||||
#define HTTP_HDR_CONN_KEEPALIVE 24 /* Connection: keep-alive (HTTP 1.1) */
|
||||
#define HTTP_HDR_SERVER 25 /* Server: HTTPD_SERVER_AGENT */
|
||||
#define DEFAULT_404_HTML 26 /* default 404 body */
|
||||
|
||||
/** A list of extension-to-HTTP header strings */
|
||||
const static tHTTPHeader g_psHTTPHeaders[] =
|
||||
{
|
||||
{ "html", HTTP_HDR_HTML},
|
||||
{ "htm", HTTP_HDR_HTML},
|
||||
{ "shtml",HTTP_HDR_SSI},
|
||||
{ "shtm", HTTP_HDR_SSI},
|
||||
{ "ssi", HTTP_HDR_SSI},
|
||||
{ "gif", HTTP_HDR_GIF},
|
||||
{ "png", HTTP_HDR_PNG},
|
||||
{ "jpg", HTTP_HDR_JPG},
|
||||
{ "bmp", HTTP_HDR_BMP},
|
||||
{ "ico", HTTP_HDR_ICO},
|
||||
{ "class",HTTP_HDR_APP},
|
||||
{ "cls", HTTP_HDR_APP},
|
||||
{ "js", HTTP_HDR_JS},
|
||||
{ "ram", HTTP_HDR_RA},
|
||||
{ "css", HTTP_HDR_CSS},
|
||||
{ "swf", HTTP_HDR_SWF},
|
||||
{ "xml", HTTP_HDR_XML},
|
||||
{ "xsl", HTTP_HDR_XML}
|
||||
};
|
||||
|
||||
#define NUM_HTTP_HEADERS (sizeof(g_psHTTPHeaders) / sizeof(tHTTPHeader))
|
||||
|
||||
#endif /* LWIP_HTTPD_DYNAMIC_HEADERS */
|
||||
|
||||
#if LWIP_HTTPD_SSI
|
||||
static const char * const g_pcSSIExtensions[] = {
|
||||
".shtml", ".shtm", ".ssi", ".xml"
|
||||
};
|
||||
#define NUM_SHTML_EXTENSIONS (sizeof(g_pcSSIExtensions) / sizeof(const char *))
|
||||
#endif /* LWIP_HTTPD_SSI */
|
||||
|
||||
#endif /* __HTTPD_STRUCTS_H__ */
|
||||
11
extras/httpd/readme.txt
Normal file
11
extras/httpd/readme.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
This is a basic HTTP server with WebSockets based on httpd from LwIP.
|
||||
|
||||
WebSockets implementation supports binary and text modes. Multiple sockets are supported. Continuation frames are not implemented.
|
||||
By default, a WebSocket is closed after 20 seconds of inactivity to conserve memory. This behavior can be changed by overriding `WS_TIMEOUT` option.
|
||||
|
||||
To enable debugging extra flags `-DLWIP_DEBUG=1 -DHTTPD_DEBUG=LWIP_DBG_ON` should be passed at compile-time.
|
||||
|
||||
This module expects your project to provide "fsdata.c" created with "makefsdata" utility.
|
||||
See examples/http_server.
|
||||
|
||||
Maintained by lujji (https://github.com/lujji/esp-httpd).
|
||||
80
extras/httpd/strcasestr.c
Normal file
80
extras/httpd/strcasestr.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*-
|
||||
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
#include "strcasestr.h"
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strcasestr(s, find)
|
||||
const char *s, *find;
|
||||
{
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
c = tolower((unsigned char) c);
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return (NULL);
|
||||
} while ((char) tolower((unsigned char) sc) != c);
|
||||
} while (strncasecmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return ((char *) s);
|
||||
}
|
||||
|
||||
char *
|
||||
strncasestr(s, find, slen)
|
||||
const char *s;
|
||||
const char *find;
|
||||
size_t slen;
|
||||
{
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
if ((c = *find++) != '\0') {
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if (slen-- < 1 || (sc = *s++) == '\0')
|
||||
return (NULL);
|
||||
} while (sc != c);
|
||||
if (len > slen)
|
||||
return (NULL);
|
||||
} while (strncasecmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return ((char *) s);
|
||||
}
|
||||
9
extras/httpd/strcasestr.h
Normal file
9
extras/httpd/strcasestr.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef STRCASESTR_H
|
||||
#define STRCASESTR_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
char *strcasestr(const char *s, const char *find);
|
||||
char *strncasestr(const char *s, const char * find, size_t slen);
|
||||
|
||||
#endif /* STRCASESTR_H */
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
#include "esp/iomux.h"
|
||||
#include "esp/i2s_regs.h"
|
||||
#include "esp/interrupts.h"
|
||||
#include "esp/iomux.h"
|
||||
#include "common_macros.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
7
extras/max7219/component.mk
Normal file
7
extras/max7219/component.mk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# include it as 'max7219/max7219.h'
|
||||
INC_DIRS += $(max7219_ROOT)..
|
||||
|
||||
# args for passing into compile rule generation
|
||||
max7219_SRC_DIR = $(max7219_ROOT)
|
||||
|
||||
$(eval $(call component_compile_rules,max7219))
|
||||
189
extras/max7219/max7219.c
Normal file
189
extras/max7219/max7219.c
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Driver for MAX7219/MAX7221
|
||||
* Serially Interfaced, 8-Digit LED Display Drivers
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2017 Ruslan V. Uss <unclerus@gmail.com>
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#include "max7219.h"
|
||||
#include <esp/spi.h>
|
||||
#include <esp/gpio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "max7219_priv.h"
|
||||
|
||||
#define SPI_BUS 1
|
||||
|
||||
//#define MAX7219_DEBUG
|
||||
|
||||
#ifdef MAX7219_DEBUG
|
||||
#include <stdio.h>
|
||||
#define debug(fmt, ...) printf("%s: " fmt "\n", "MAX7219", ## __VA_ARGS__)
|
||||
#else
|
||||
#define debug(fmt, ...)
|
||||
#endif
|
||||
|
||||
#define ALL_CHIPS 0xff
|
||||
#define ALL_DIGITS 8
|
||||
|
||||
#define REG_DIGIT_0 (1 << 8)
|
||||
#define REG_DECODE_MODE (9 << 8)
|
||||
#define REG_INTENSITY (10 << 8)
|
||||
#define REG_SCAN_LIMIT (11 << 8)
|
||||
#define REG_SHUTDOWN (12 << 8)
|
||||
#define REG_DISPLAY_TEST (15 << 8)
|
||||
|
||||
#define VAL_CLEAR_BCD 0x0f
|
||||
#define VAL_CLEAR_NORMAL 0x00
|
||||
|
||||
static const spi_settings_t bus_settings = {
|
||||
.mode = SPI_MODE0,
|
||||
.freq_divider = SPI_FREQ_DIV_10M,
|
||||
.msb = true,
|
||||
.minimal_pins = true,
|
||||
.endianness = SPI_BIG_ENDIAN
|
||||
};
|
||||
|
||||
static void send(const max7219_display_t *disp, uint8_t chip, uint16_t value)
|
||||
{
|
||||
uint16_t buf[MAX7219_MAX_CASCADE_SIZE] = { 0 };
|
||||
if (chip == ALL_CHIPS)
|
||||
{
|
||||
for (uint8_t i = 0; i < disp->cascade_size; i++)
|
||||
buf[i] = value;
|
||||
}
|
||||
else buf[chip] = value;
|
||||
|
||||
spi_settings_t old_settings;
|
||||
spi_get_settings(SPI_BUS, &old_settings);
|
||||
spi_set_settings(SPI_BUS, &bus_settings);
|
||||
gpio_write(disp->cs_pin, false);
|
||||
|
||||
spi_transfer(SPI_BUS, buf, NULL, disp->cascade_size, SPI_16BIT);
|
||||
|
||||
gpio_write(disp->cs_pin, true);
|
||||
spi_set_settings(SPI_BUS, &old_settings);
|
||||
}
|
||||
|
||||
bool max7219_init(max7219_display_t *disp)
|
||||
{
|
||||
if (!disp->cascade_size || disp->cascade_size > MAX7219_MAX_CASCADE_SIZE)
|
||||
{
|
||||
debug("Invalid cascade size %d", disp->cascade_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t max_digits = disp->cascade_size * ALL_DIGITS;
|
||||
if (!disp->digits || disp->digits > max_digits)
|
||||
{
|
||||
debug("Invalid digits count %d, max %d", disp->cascade_size, max_digits);
|
||||
return false;
|
||||
}
|
||||
|
||||
gpio_enable(disp->cs_pin, GPIO_OUTPUT);
|
||||
gpio_write(disp->cs_pin, true);
|
||||
|
||||
// Shutdown all chips
|
||||
max7219_set_shutdown_mode(disp, true);
|
||||
// Disable test
|
||||
send(disp, ALL_CHIPS, REG_DISPLAY_TEST);
|
||||
// Set max scan limit
|
||||
send(disp, ALL_CHIPS, REG_SCAN_LIMIT | (ALL_DIGITS - 1));
|
||||
// Set normal decode mode & clear display
|
||||
max7219_set_decode_mode(disp, false);
|
||||
// Set minimal brightness
|
||||
max7219_set_brightness(disp, 0);
|
||||
// Wake up
|
||||
max7219_set_shutdown_mode(disp, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void max7219_set_decode_mode(max7219_display_t *disp, bool bcd)
|
||||
{
|
||||
disp->bcd = bcd;
|
||||
send(disp, ALL_CHIPS, REG_DECODE_MODE | (bcd ? 0xff : 0));
|
||||
max7219_clear(disp);
|
||||
}
|
||||
|
||||
void max7219_set_brightness(const max7219_display_t *disp, uint8_t value)
|
||||
{
|
||||
send(disp, ALL_CHIPS, REG_INTENSITY | (value > MAX7219_MAX_BRIGHTNESS ? MAX7219_MAX_BRIGHTNESS : value));
|
||||
}
|
||||
|
||||
void max7219_set_shutdown_mode(const max7219_display_t *disp, bool shutdown)
|
||||
{
|
||||
send(disp, ALL_CHIPS, REG_SHUTDOWN | !shutdown);
|
||||
}
|
||||
|
||||
bool max7219_set_digit(const max7219_display_t *disp, uint8_t digit, uint8_t val)
|
||||
{
|
||||
if (digit >= disp->digits)
|
||||
{
|
||||
debug("Invalid digit: %d", digit);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (disp->mirrored)
|
||||
digit = disp->digits - digit - 1;
|
||||
|
||||
uint8_t c = digit / ALL_DIGITS;
|
||||
uint8_t d = digit % ALL_DIGITS;
|
||||
|
||||
send(disp, c, (REG_DIGIT_0 + ((uint16_t)d << 8)) | val);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void max7219_clear(const max7219_display_t *disp)
|
||||
{
|
||||
uint8_t val = disp->bcd ? VAL_CLEAR_BCD : VAL_CLEAR_NORMAL;
|
||||
for (uint8_t i = 0; i < ALL_DIGITS; i++)
|
||||
send(disp, ALL_CHIPS, (REG_DIGIT_0 + ((uint16_t)i << 8)) | val);
|
||||
}
|
||||
|
||||
inline static uint8_t get_char(const max7219_display_t *disp, char c)
|
||||
{
|
||||
if (disp->bcd)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
switch (c)
|
||||
{
|
||||
case '-':
|
||||
return 0x0a;
|
||||
case 'E':
|
||||
case 'e':
|
||||
return 0x0b;
|
||||
case 'H':
|
||||
case 'h':
|
||||
return 0x0c;
|
||||
case 'L':
|
||||
case 'l':
|
||||
return 0x0d;
|
||||
case 'P':
|
||||
case 'p':
|
||||
return 0x0e;
|
||||
}
|
||||
return VAL_CLEAR_BCD;
|
||||
}
|
||||
|
||||
return font_7seg[(c - 0x20) & 0x7f];
|
||||
}
|
||||
|
||||
void max7219_draw_text(const max7219_display_t *disp, uint8_t pos, const char *s)
|
||||
{
|
||||
while (s && pos < disp->digits)
|
||||
{
|
||||
uint8_t c = get_char(disp, *s);
|
||||
if (*(s + 1) == '.')
|
||||
{
|
||||
c |= 0x80;
|
||||
s++;
|
||||
}
|
||||
max7219_set_digit(disp, pos, c);
|
||||
pos++;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
96
extras/max7219/max7219.h
Normal file
96
extras/max7219/max7219.h
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Driver for MAX7219/MAX7221
|
||||
* Serially Interfaced, 8-Digit LED Display Drivers
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2017 Ruslan V. Uss <unclerus@gmail.com>
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#ifndef EXTRAS_MAX7219_H_
|
||||
#define EXTRAS_MAX7219_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define MAX7219_MAX_CASCADE_SIZE 8
|
||||
#define MAX7219_MAX_BRIGHTNESS 31
|
||||
|
||||
/**
|
||||
* Display descriptor
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cs_pin; //!< GPIO connected to CS/LOAD pin
|
||||
|
||||
uint8_t digits; //!< Accessible digits in 7seg. Up to cascade_size * 8
|
||||
|
||||
uint8_t cascade_size; //!< Up to 8 MAX721xx cascaded
|
||||
bool mirrored; //!< true for horizontally mirrored displays
|
||||
|
||||
bool bcd;
|
||||
} max7219_display_t;
|
||||
|
||||
/**
|
||||
* Initialize display: switch it to normal operation from shutdown mode,
|
||||
* set scan limit to the max and clear
|
||||
* @param disp Pointer to display descriptor
|
||||
* @return false if error occured
|
||||
*/
|
||||
bool max7219_init(max7219_display_t *disp);
|
||||
|
||||
/**
|
||||
* Set decode mode and clear display
|
||||
* @param disp Pointer to display descriptor
|
||||
* @param bcd true to set BCD decode mode, false to normal
|
||||
*/
|
||||
void max7219_set_decode_mode(max7219_display_t *disp, bool bcd);
|
||||
|
||||
/**
|
||||
* Set display brightness
|
||||
* @param disp Pointer to display descriptor
|
||||
* @param value Brightness value, 0..MAX7219_MAX_BRIGHTNESS
|
||||
*/
|
||||
void max7219_set_brightness(const max7219_display_t *disp, uint8_t value);
|
||||
|
||||
/**
|
||||
* Shutdown display or set it to normal mode
|
||||
* @param disp Pointer to display descriptor
|
||||
* @param shutdown Shutdown display if true
|
||||
*/
|
||||
void max7219_set_shutdown_mode(const max7219_display_t *disp, bool shutdown);
|
||||
|
||||
/**
|
||||
* Write data to display digit
|
||||
* @param disp Pointer to display descriptor
|
||||
* @param digit Digit index, 0..disp->digits - 1
|
||||
* @param val Data
|
||||
* @return false if error occured
|
||||
*/
|
||||
bool max7219_set_digit(const max7219_display_t *disp, uint8_t digit, uint8_t val);
|
||||
|
||||
/**
|
||||
* Clear display
|
||||
* @param disp Pointer to display descriptor
|
||||
*/
|
||||
void max7219_clear(const max7219_display_t *disp);
|
||||
|
||||
/**
|
||||
* Draw text.
|
||||
* Currently only 7-segment displays supported
|
||||
* @param disp Pointer to display descriptor
|
||||
* @param pos Start digit
|
||||
* @param s Text
|
||||
*/
|
||||
void max7219_draw_text(const max7219_display_t *disp, uint8_t pos, const char *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EXTRAS_MAX7219_H_ */
|
||||
36
extras/max7219/max7219_priv.h
Normal file
36
extras/max7219/max7219_priv.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Driver for MAX7219/MAX7221
|
||||
* Serially Interfaced, 8-Digit LED Display Drivers
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2017 Ruslan V. Uss <unclerus@gmail.com>
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#ifndef EXTRAS_MAX7219_PRIV_H_
|
||||
#define EXTRAS_MAX7219_PRIV_H_
|
||||
|
||||
static const uint8_t font_7seg[] = {
|
||||
/* ' ' ! " # $ % & ' ( ) */
|
||||
0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x02, 0x4e, 0x78,
|
||||
/* * + , - . / 0 1 2 3 */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x30, 0x6d, 0x79,
|
||||
/* 4 5 6 7 8 9 : ; < = */
|
||||
0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b, 0x00, 0x00, 0x0d, 0x09,
|
||||
/* > ? @ A B C D E F G */
|
||||
0x19, 0x65, 0x00, 0x77, 0x1f, 0x4e, 0x3d, 0x4f, 0x47, 0x5e,
|
||||
/* H I J K L M N O P Q */
|
||||
0x37, 0x06, 0x38, 0x57, 0x0e, 0x76, 0x15, 0x1d, 0x67, 0x73,
|
||||
/* R S T U V W X Y Z [ */
|
||||
0x05, 0x5b, 0x0f, 0x1c, 0x3e, 0x2a, 0x49, 0x3b, 0x6d, 0x4e,
|
||||
/* \ ] ^ _ ` a b c d e */
|
||||
0x00, 0x78, 0x00, 0x08, 0x02, 0x77, 0x1f, 0x4e, 0x3d, 0x4f,
|
||||
/* f g h i j k l m n o */
|
||||
0x47, 0x5e, 0x37, 0x06, 0x38, 0x57, 0x0e, 0x76, 0x15, 0x1d,
|
||||
/* p q r s t u v w x y */
|
||||
0x67, 0x73, 0x05, 0x5b, 0x0f, 0x1c, 0x3e, 0x2a, 0x49, 0x3b,
|
||||
/* z { | } ~ */
|
||||
0x6d, 0x4e, 0x06, 0x78, 0x00
|
||||
};
|
||||
|
||||
|
||||
#endif /* EXTRAS_MAX7219_PRIV_H_ */
|
||||
|
|
@ -178,7 +178,7 @@ static bool process_directory(const char *direcotry)
|
|||
{
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
char path[256];
|
||||
char path[256], *filename;
|
||||
|
||||
dp = opendir(direcotry);
|
||||
if (dp != NULL) {
|
||||
|
|
@ -187,12 +187,22 @@ static bool process_directory(const char *direcotry)
|
|||
!strcmp(ep->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
if(ep->d_type == DT_DIR) {
|
||||
char *new_dir_name = malloc(strlen(direcotry) + strlen(ep->d_name) + 2);
|
||||
sprintf(new_dir_name, "%s/%s", direcotry, ep->d_name);
|
||||
process_directory(new_dir_name);
|
||||
free(new_dir_name);
|
||||
continue;
|
||||
}
|
||||
if (ep->d_type != DT_REG) {
|
||||
continue; // not a regular file
|
||||
}
|
||||
sprintf(path, "%s/%s", direcotry, ep->d_name);
|
||||
printf("Processing file %s\n", path);
|
||||
if (!process_file(path, ep->d_name)) {
|
||||
filename = strchr(path, '/');
|
||||
filename = filename ? &filename[1] : path;
|
||||
|
||||
printf("Processing file source %s, dest: %s\n", path, filename);
|
||||
if (!process_file(path, filename)) {
|
||||
printf("Error processing file\n");
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ int ssd1306_load_frame_buffer(const ssd1306_t *dev, uint8_t buf[])
|
|||
#if (SSD1306_I2C_SUPPORT)
|
||||
case SSD1306_PROTO_I2C:
|
||||
for (i = 0; i < len; i++) {
|
||||
if(dev->screen == SH1106_SCREEN) sh1106_go_coordinate(dev,0,i/dev->width);
|
||||
if(dev->screen == SH1106_SCREEN && i%dev->width == 0) sh1106_go_coordinate(dev,0,i/dev->width);
|
||||
i2c_start();
|
||||
if (!i2c_write(dev->addr << 1)) {
|
||||
debug("Error while xmitting I2C slave address\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue