8000 Add more ESP8266 WiFi compatibility wrappers (#1128) · uPesy/arduino-pico@e3f2f87 · GitHub
[go: up one dir, main page]

Skip to content

Commit e3f2f87

Browse files
Add more ESP8266 WiFi compatibility wrappers (earlephilhower#1128)
1 parent a8238cb commit e3f2f87

File tree

11 files changed

+245
-0
lines changed

11 files changed

+245
-0
lines changed

cores/rp2040/SerialUART.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class SerialUART : public HardwareSerial {
6363
bool overflow();
6464
operator bool() override;
6565

66+
// ESP8266 compat
67+
void setDebugOutput(bool unused) {
68+
(void) unused;
69+
}
70+
6671
// Not to be called by users, only from the IRQ handler. In public so that the C-language IQR callback can access it
6772
void _handleIRQ(bool inIRQ = true);
6873

cores/rp2040/SerialUSB.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class SerialUSB : public HardwareSerial {
4444
using Print::write;
4545
operator bool() override;
4646

47+
// ESP8266 compat
48+
void setDebugOutput(bool unused) {
49+
(void) unused;
50+
}
51+
4752
private:
4853
bool _running = false;
4954
};

cores/rp2040/debug_internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21+
#pragma once
22+
2123
#if !defined(DEBUG_RP2040_PORT)
2224
#define DEBUGV(...) do { } while(0)
2325
#define DEBUGCORE(...) do { } while(0)
@@ -44,3 +46,7 @@
4446
#define DEBUGSPI(...) do { } while(0)
4547
#endif
4648
#endif
49+
50+
#ifdef __cplusplus
51+
extern void hexdump(const void* mem, uint32_t len, uint8_t cols = 16);
52+
#endif

cores/rp2040/main.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,28 @@ extern "C" struct _reent *__wrap___getreent() {
170170
return _impure_ptr1;
171171
}
172172
}
173+
174+
// ESP8266 internal debug routine
175+
extern void hexdump(const void* mem, uint32_t len, uint8_t cols) __attribute__((weak));
176+
void hexdump(const void* mem, uint32_t len, uint8_t cols) {
177+
const char* src = (const char*)mem;
178+
printf("\n[HEXDUMP] Address: %p len: 0x%lX (%ld)", src, len, len);
179+
while (len > 0) {
180+
uint32_t linesize = cols > len ? len : cols;
181+
printf("\n[%p] 0x%04x: ", src, (int)(src - (const char*)mem));
182+
for (uint32_t i = 0; i < linesize; i++) {
183+
printf("%02x ", *(src + i));
184+
}
185+
printf(" ");
186+
for (uint32_t i = linesize; i < cols; i++) {
187+
printf(" ");
188+
}
189+
for (uint32_t i = 0; i < linesize; i++) {
190+
unsigned char c = *(src + i);
191+
putc(isprint(c) ? c : '.', stdout);
192+
}
193+
src += linesize;
194+
len -= linesize;
195+
}
196+
printf("\n");
197+
}

libraries/Hash/examples/sha1/sha1.ino

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
simple demo to show sha1 calculation
3+
*/
4+
#include <Arduino.h>
5+
#include <Hash.h>
6+
7+
void setup() {
8+
Serial.begin(115200);
9+
}
10+
11+
void loop() {
12+
13+
// usage as String
14+
// SHA1:a9993e364706816aba3e25717850c26c9cd0d89d
15+
16+
Serial.print("SHA1:");
17+
Serial.println(sha1("abc"));
18+
19+
// usage as ptr
20+
// SHA1:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
21+
uint8_t hash[20];
22+
sha1("test", &hash[0]);
23+
24+
Serial.print("SHA1:");
25+
for (uint16_t i = 0; i < 20; i++) { Serial.printf("%02x", hash[i]); }
26+
Serial.println();
27+
28+
delay(1000);
29+
}

libraries/Hash/keywords.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#######################################
2+
# Syntax Coloring Map For Hash
3+
#######################################
4+
5+
#######################################
6+
# Library (KEYWORD3)
7+
#######################################
8+
9+
Hash KEYWORD3 RESERVED_WORD
10+
11+
#######################################
12+
# Datatypes (KEYWORD1)
13+
#######################################
14+
15+
#######################################
16+
# Methods and Functions (KEYWORD2)
17+
#######################################
18+
19+
sha1 KEYWORD2
20+
21+
#######################################
22+
# Constants (LITERAL1)
23+
#######################################

libraries/Hash/library.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=Hash
2+
version=1.0
3+
author=Markus Sattler
4+
maintainer=Markus Sattler
5+
sentence=Generate Hash from data
6+
paragraph=
7+
category=Data Processing
8+
url=
9+
architectures=rp2040
10+
dot_a_linkage=true

libraries/Hash/src/Hash.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* @file Hash.cpp
3+
* @date 20.05.2015
4+
* @author Markus Sattler
5+
*
6+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
7+
* This file is part of the esp8266 core for Arduino environment.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*
23+
*/
24+
25+
#include <Arduino.h>
26+
#include <bearssl/bearssl_hash.h>
27+
28+
#include "Hash.h"
29+
30+
/**
31+
* create a sha1 hash from data
32+
* @param data uint8_t *
33+
* @param size uint32_t
34+
* @param hash uint8_t[20]
35+
*/
36+
void sha1(const uint8_t* data, uint32_t size, uint8_t hash[20]) {
37+
br_sha1_context ctx;
38+
39+
#ifdef DEBUG_SHA1
40+
os_printf("DATA:");
41+
for(uint16_t i = 0; i < size; i++) {
42+
os_printf("%02X", data[i]);
43+
}
44+
os_printf("\n");
45+
os_printf("DATA:");
46+
for(uint16_t i = 0; i < size; i++) {
47+
os_printf("%c", data[i]);
48+
}
49+
os_printf("\n");
50+
#endif
51+
52+
br_sha1_init(&ctx);
53+
br_sha1_update(&ctx, data, size);
54+
br_sha1_out(&ctx, hash);
55+
56+
#ifdef DEBUG_SHA1
57+
os_printf("SHA1:");
58+
for(uint16_t i = 0; i < 20; i++) {
59+
os_printf("%02X", hash[i]);
60+
}
61+
os_printf("\n\n");
62+
#endif
63+
}
64+
65+
void sha1(const char* data, uint32_t size, uint8_t hash[20]) {
66+
sha1((const uint8_t *) data, size, hash);
67+
}
68+
69+
void sha1(const String& data, uint8_t hash[20]) {
70+
sha1(data.c_str(), data.length(), hash);
71+
}
72+
73+
String sha1(const uint8_t* data, uint32_t size) {
74+
uint8_t hash[20];
75+
String hashStr((const char*)nullptr);
76+
hashStr.reserve(20 * 2 + 1);
77+
78+
sha1(&data[0], size, &hash[0]);
79+
80+
for(uint16_t i = 0; i < 20; i++) {
81+
char hex[3];
82+
snprintf(hex, sizeof(hex), "%02x", hash[i]);
83+
hashStr += hex;
84+
}
85+
86+
return hashStr;
87+
}
88+
89+
String sha1(const char* data, uint32_t size) {
90+
return sha1((const uint8_t*) data, size);
91+
}
92+
93+
String sha1(const String& data) {
94+
return sha1(data.c_str(), data.length());
95+
}
96+

libraries/Hash/src/Hash.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @file Hash.h
3+
* @date 20.05.2015
4+
* @author Markus Sattler
5+
*
6+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
7+
* This file is part of the esp8266 core for Arduino environment.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*
23+
*/
24+
25+
#ifndef HASH_H_
26+
#define HASH_H_
27+
28< CC15 /code>+
//#define DEBUG_SHA1
29+
30+
void sha1(const uint8_t* data, uint32_t size, uint8_t hash[20]);
31+
void sha1(const char* data, uint32_t size, uint8_t hash[20]);
32+
void sha1(const String& data, uint8_t hash[20]);
33+
34+
String sha1(const uint8_t* data, uint32_t size);
35+
String sha1(const char* data, uint32_t size);
36+
String sha1(const String& data);
37+
38+
#endif /* HASH_H_ */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Since things may just work, we'll redirect for now
2+
#include "WebServer.h"
3+
4+
using ESP8266WebServer = WebServer;

libraries/WiFi/src/ESP8266WiFiMulti.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Since things may just work, we'll redirect for now
2+
#include "WiFiMulti.h"
3+
4+
using ESP8266WiFiMulti = WiFiMulti;

0 commit comments

Comments
 (0)
0