Add more ESP8266 WiFi compatibility wrappers (#1128)
This commit is contained in:
parent
a8238cb0d4
commit
e3f2f87e2d
11 changed files with 245 additions and 0 deletions
|
|
@ -63,6 +63,11 @@ public:
|
|||
bool overflow();
|
||||
operator bool() override;
|
||||
|
||||
// ESP8266 compat
|
||||
void setDebugOutput(bool unused) {
|
||||
(void) unused;
|
||||
}
|
||||
|
||||
// Not to be called by users, only from the IRQ handler. In public so that the C-language IQR callback can access it
|
||||
void _handleIRQ(bool inIRQ = true);
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,11 @@ public:
|
|||
using Print::write;
|
||||
operator bool() override;
|
||||
|
||||
// ESP8266 compat
|
||||
void setDebugOutput(bool unused) {
|
||||
(void) unused;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _running = false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(DEBUG_RP2040_PORT)
|
||||
#define DEBUGV(...) do { } while(0)
|
||||
#define DEBUGCORE(...) do { } while(0)
|
||||
|
|
@ -44,3 +46,7 @@
|
|||
#define DEBUGSPI(...) do { } while(0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern void hexdump(const void* mem, uint32_t len, uint8_t cols = 16);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -170,3 +170,28 @@ extern "C" struct _reent *__wrap___getreent() {
|
|||
return _impure_ptr1;
|
||||
}
|
||||
}
|
||||
|
||||
// ESP8266 internal debug routine
|
||||
extern void hexdump(const void* mem, uint32_t len, uint8_t cols) __attribute__((weak));
|
||||
void hexdump(const void* mem, uint32_t len, uint8_t cols) {
|
||||
const char* src = (const char*)mem;
|
||||
printf("\n[HEXDUMP] Address: %p len: 0x%lX (%ld)", src, len, len);
|
||||
while (len > 0) {
|
||||
uint32_t linesize = cols > len ? len : cols;
|
||||
printf("\n[%p] 0x%04x: ", src, (int)(src - (const char*)mem));
|
||||
for (uint32_t i = 0; i < linesize; i++) {
|
||||
printf("%02x ", *(src + i));
|
||||
}
|
||||
printf(" ");
|
||||
for (uint32_t i = linesize; i < cols; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
for (uint32_t i = 0; i < linesize; i++) {
|
||||
unsigned char c = *(src + i);
|
||||
putc(isprint(c) ? c : '.', stdout);
|
||||
}
|
||||
src += linesize;
|
||||
len -= linesize;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
|
|
|||
29
libraries/Hash/examples/sha1/sha1.ino
Normal file
29
libraries/Hash/examples/sha1/sha1.ino
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
simple demo to show sha1 calculation
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <Hash.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// usage as String
|
||||
// SHA1:a9993e364706816aba3e25717850c26c9cd0d89d
|
||||
|
||||
Serial.print("SHA1:");
|
||||
Serial.println(sha1("abc"));
|
||||
|
||||
// usage as ptr
|
||||
// SHA1:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
uint8_t hash[20];
|
||||
sha1("test", &hash[0]);
|
||||
|
||||
Serial.print("SHA1:");
|
||||
for (uint16_t i = 0; i < 20; i++) { Serial.printf("%02x", hash[i]); }
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
23
libraries/Hash/keywords.txt
Normal file
23
libraries/Hash/keywords.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For Hash
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Library (KEYWORD3)
|
||||
#######################################
|
||||
|
||||
Hash KEYWORD3 RESERVED_WORD
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
sha1 KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
10
libraries/Hash/library.properties
Normal file
10
libraries/Hash/library.properties
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
name=Hash
|
||||
version=1.0
|
||||
author=Markus Sattler
|
||||
maintainer=Markus Sattler
|
||||
sentence=Generate Hash from data
|
||||
paragraph=
|
||||
category=Data Processing
|
||||
url=
|
||||
architectures=rp2040
|
||||
dot_a_linkage=true
|
||||
96
libraries/Hash/src/Hash.cpp
Normal file
96
libraries/Hash/src/Hash.cpp
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* @file Hash.cpp
|
||||
* @date 20.05.2015
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. 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
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <bearssl/bearssl_hash.h>
|
||||
|
||||
#include "Hash.h"
|
||||
|
||||
/**
|
||||
* create a sha1 hash from data
|
||||
* @param data uint8_t *
|
||||
* @param size uint32_t
|
||||
* @param hash uint8_t[20]
|
||||
*/
|
||||
void sha1(const uint8_t* data, uint32_t size, uint8_t hash[20]) {
|
||||
br_sha1_context ctx;
|
||||
|
||||
#ifdef DEBUG_SHA1
|
||||
os_printf("DATA:");
|
||||
for(uint16_t i = 0; i < size; i++) {
|
||||
os_printf("%02X", data[i]);
|
||||
}
|
||||
os_printf("\n");
|
||||
os_printf("DATA:");
|
||||
for(uint16_t i = 0; i < size; i++) {
|
||||
os_printf("%c", data[i]);
|
||||
}
|
||||
os_printf("\n");
|
||||
#endif
|
||||
|
||||
br_sha1_init(&ctx);
|
||||
br_sha1_update(&ctx, data, size);
|
||||
br_sha1_out(&ctx, hash);
|
||||
|
||||
#ifdef DEBUG_SHA1
|
||||
os_printf("SHA1:");
|
||||
for(uint16_t i = 0; i < 20; i++) {
|
||||
os_printf("%02X", hash[i]);
|
||||
}
|
||||
os_printf("\n\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void sha1(const char* data, uint32_t size, uint8_t hash[20]) {
|
||||
sha1((const uint8_t *) data, size, hash);
|
||||
}
|
||||
|
||||
void sha1(const String& data, uint8_t hash[20]) {
|
||||
sha1(data.c_str(), data.length(), hash);
|
||||
}
|
||||
|
||||
String sha1(const uint8_t* data, uint32_t size) {
|
||||
uint8_t hash[20];
|
||||
String hashStr((const char*)nullptr);
|
||||
hashStr.reserve(20 * 2 + 1);
|
||||
|
||||
sha1(&data[0], size, &hash[0]);
|
||||
|
||||
for(uint16_t i = 0; i < 20; i++) {
|
||||
char hex[3];
|
||||
snprintf(hex, sizeof(hex), "%02x", hash[i]);
|
||||
hashStr += hex;
|
||||
}
|
||||
|
||||
return hashStr;
|
||||
}
|
||||
|
||||
String sha1(const char* data, uint32_t size) {
|
||||
return sha1((const uint8_t*) data, size);
|
||||
}
|
||||
|
||||
String sha1(const String& data) {
|
||||
return sha1(data.c_str(), data.length());
|
||||
}
|
||||
|
||||
38
libraries/Hash/src/Hash.h
Normal file
38
libraries/Hash/src/Hash.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* @file Hash.h
|
||||
* @date 20.05.2015
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. 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 HASH_H_
|
||||
#define HASH_H_
|
||||
|
||||
//#define DEBUG_SHA1
|
||||
|
||||
void sha1(const uint8_t* data, uint32_t size, uint8_t hash[20]);
|
||||
void sha1(const char* data, uint32_t size, uint8_t hash[20]);
|
||||
void sha1(const String& data, uint8_t hash[20]);
|
||||
|
||||
String sha1(const uint8_t* data, uint32_t size);
|
||||
String sha1(const char* data, uint32_t size);
|
||||
String sha1(const String& data);
|
||||
|
||||
#endif /* HASH_H_ */
|
||||
4
libraries/WebServer/src/ESP8266WebServer.h
Normal file
4
libraries/WebServer/src/ESP8266WebServer.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// Since things may just work, we'll redirect for now
|
||||
#include "WebServer.h"
|
||||
|
||||
using ESP8266WebServer = WebServer;
|
||||
4
libraries/WiFi/src/ESP8266WiFiMulti.h
Normal file
4
libraries/WiFi/src/ESP8266WiFiMulti.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// Since things may just work, we'll redirect for now
|
||||
#include "WiFiMulti.h"
|
||||
|
||||
using ESP8266WiFiMulti = WiFiMulti;
|
||||
Loading…
Reference in a new issue