Minor header/directrory cleanup (#802)
This commit is contained in:
parent
257db5ac7d
commit
064dd4794f
32 changed files with 1226 additions and 1116 deletions
|
|
@ -71,8 +71,6 @@ static int __usb_task_irq;
|
|||
|
||||
#define EPNUM_HID 0x83
|
||||
|
||||
#define EPNUM_MIDI 0x01
|
||||
|
||||
|
||||
const uint8_t *tud_descriptor_device_cb(void) {
|
||||
static tusb_desc_device_t usbd_desc_device = {
|
||||
|
|
@ -91,7 +89,7 @@ const uint8_t *tud_descriptor_device_cb(void) {
|
|||
.iSerialNumber = USBD_STR_SERIAL,
|
||||
.bNumConfigurations = 1
|
||||
};
|
||||
if (__USBInstallSerial && !__USBInstallKeyboard && !__USBInstallMouse && !__USBInstallJoystick && !__USBInstallMIDI) {
|
||||
if (__USBInstallSerial && !__USBInstallKeyboard && !__USBInstallMouse && !__USBInstallJoystick) {
|
||||
// Can use as-is, this is the default USB case
|
||||
return (const uint8_t *)&usbd_desc_device;
|
||||
}
|
||||
|
|
@ -105,9 +103,6 @@ const uint8_t *tud_descriptor_device_cb(void) {
|
|||
if (__USBInstallJoystick) {
|
||||
usbd_desc_device.idProduct |= 0x0100;
|
||||
}
|
||||
if (__USBInstallMIDI) {
|
||||
usbd_desc_device.idProduct |= 0x2000;
|
||||
}
|
||||
// Set the device class to 0 to indicate multiple device classes
|
||||
usbd_desc_device.bDeviceClass = 0;
|
||||
usbd_desc_device.bDeviceSubClass = 0;
|
||||
|
|
@ -228,7 +223,7 @@ void __SetupUSBDescriptor() {
|
|||
if (!usbd_desc_cfg) {
|
||||
bool hasHID = __USBInstallKeyboard || __USBInstallMouse || __USBInstallJoystick;
|
||||
|
||||
uint8_t interface_count = (__USBInstallSerial ? 2 : 0) + (hasHID ? 1 : 0) + (__USBInstallMIDI ? 2 : 0);
|
||||
uint8_t interface_count = (__USBInstallSerial ? 2 : 0) + (hasHID ? 1 : 0);
|
||||
|
||||
uint8_t cdc_desc[TUD_CDC_DESC_LEN] = {
|
||||
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
|
||||
|
|
@ -243,13 +238,7 @@ void __SetupUSBDescriptor() {
|
|||
TUD_HID_DESCRIPTOR(hid_itf, 0, HID_ITF_PROTOCOL_NONE, hid_report_len, EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10)
|
||||
};
|
||||
|
||||
uint8_t midi_itf = hid_itf + (hasHID ? 1 : 0);
|
||||
uint8_t midi_desc[TUD_MIDI_DESC_LEN] = {
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MIDI_DESCRIPTOR(midi_itf, 0, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64)
|
||||
};
|
||||
|
||||
int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof(cdc_desc) : 0) + (hasHID ? sizeof(hid_desc) : 0) + (__USBInstallMIDI ? sizeof(midi_desc) : 0);
|
||||
int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof(cdc_desc) : 0) + (hasHID ? sizeof(hid_desc) : 0);
|
||||
|
||||
uint8_t tud_cfg_desc[TUD_CONFIG_DESC_LEN] = {
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
|
|
@ -271,9 +260,6 @@ void __SetupUSBDescriptor() {
|
|||
memcpy(ptr, hid_desc, sizeof(hid_desc));
|
||||
ptr += sizeof(hid_desc);
|
||||
}
|
||||
if (__USBInstallMIDI) {
|
||||
memcpy(ptr, midi_desc, sizeof(midi_desc));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ extern void __USBInstallSerial() __attribute__((weak));
|
|||
extern void __USBInstallKeyboard() __attribute__((weak));
|
||||
extern void __USBInstallJoystick() __attribute__((weak));
|
||||
extern void __USBInstallMouse() __attribute__((weak));
|
||||
extern void __USBInstallMIDI() __attribute__((weak));
|
||||
|
||||
// Big, global USB mutex, shared with all USB devices to make sure we don't
|
||||
// have multiple cores updating the TUSB state in parallel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,24 @@
|
|||
/*
|
||||
Arduino OTA.cpp - Simple Arduino IDE OTA handler
|
||||
Modified 2022 Earle F. Philhower, III. All rights reserved.
|
||||
|
||||
Taken from the ESP8266 core libraries, (c) various authors.
|
||||
|
||||
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 <functional>
|
||||
#include <WiFiUdp.h>
|
||||
#include "ArduinoOTA.h"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,24 @@
|
|||
/*
|
||||
Arduino OTA.h - Simple Arduino IDE OTA handler
|
||||
Modified 2022 Earle F. Philhower, III. All rights reserved.
|
||||
|
||||
Taken from the ESP8266 core libraries, (c) various authors.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WiFi.h>
|
||||
|
|
|
|||
|
|
@ -133,7 +133,9 @@ void loop() {
|
|||
WiFi.disconnect();
|
||||
}
|
||||
}
|
||||
if (s == WL_CONNECTED) { MDNS.update(); }
|
||||
if (s == WL_CONNECTED) {
|
||||
MDNS.update();
|
||||
}
|
||||
}
|
||||
// Do work:
|
||||
// DNS
|
||||
|
|
|
|||
|
|
@ -71,7 +71,9 @@ void handleWifi() {
|
|||
int n = WiFi.scanNetworks();
|
||||
Serial.println("scan done");
|
||||
if (n > 0) {
|
||||
for (int i = 0; i < n; i++) { Page += String(F("\r\n<tr><td>SSID ")) + WiFi.SSID(i) + ((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? F(" ") : F(" *")) + F(" (") + WiFi.RSSI(i) + F(")</td></tr>"); }
|
||||
for (int i = 0; i < n; i++) {
|
||||
Page += String(F("\r\n<tr><td>SSID ")) + WiFi.SSID(i) + ((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? F(" ") : F(" *")) + F(" (") + WiFi.RSSI(i) + F(")</td></tr>");
|
||||
}
|
||||
} else {
|
||||
Page += F("<tr><td>No WLAN found</td></tr>");
|
||||
}
|
||||
|
|
@ -114,7 +116,9 @@ void handleNotFound() {
|
|||
message += server.args();
|
||||
message += F("\n");
|
||||
|
||||
for (uint8_t i = 0; i < server.args(); i++) { message += String(F(" ")) + server.argName(i) + F(": ") + server.arg(i) + F("\n"); }
|
||||
for (uint8_t i = 0; i < server.args(); i++) {
|
||||
message += String(F(" ")) + server.argName(i) + F(": ") + server.arg(i) + F("\n");
|
||||
}
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server.sendHeader("Pragma", "no-cache");
|
||||
server.sendHeader("Expires", "-1");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
boolean isIp(String str) {
|
||||
for (size_t i = 0; i < str.length(); i++) {
|
||||
int c = str.charAt(i);
|
||||
if (c != '.' && (c < '0' || c > '9')) { return false; }
|
||||
if (c != '.' && (c < '0' || c > '9')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -10,7 +12,9 @@ boolean isIp(String str) {
|
|||
/** IP to String? */
|
||||
String toStringIp(IPAddress ip) {
|
||||
String res = "";
|
||||
for (int i = 0; i < 3; i++) { res += String((ip >> (8 * i)) & 0xFF) + "."; }
|
||||
for (int i = 0; i < 3; i++) {
|
||||
res += String((ip >> (8 * i)) & 0xFF) + ".";
|
||||
}
|
||||
res += String(((ip >> 8 * 3)) & 0xFF);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,29 @@
|
|||
/*
|
||||
DNSServer.cpp - Simple DNS server for the Pico
|
||||
Modified 2022 Earle F. Philhower, III. All rights reserved.
|
||||
|
||||
Taken from the ESP8266 core libraries, (c) various authors.
|
||||
|
||||
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 "WiFi.h"
|
||||
#include "DNSServer.h"
|
||||
#include <lwip/def.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
extern struct rst_info resetInfo;
|
||||
|
||||
#ifdef DEBUG_ESP_PORT
|
||||
#define CONSOLE DEBUG_ESP_PORT
|
||||
#else
|
||||
|
|
@ -49,8 +68,7 @@ extern struct rst_info resetInfo;
|
|||
// Want to keep IDs unique across restarts and continquious
|
||||
static uint32_t _ids __attribute__((section(".noinit")));
|
||||
|
||||
DNSServer::DNSServer()
|
||||
{
|
||||
DNSServer::DNSServer() {
|
||||
// I have observed that using 0 for captive and non-zero (600) when
|
||||
// forwarding, will help Android devices recognize the change in connectivity.
|
||||
// They will then report connected.
|
||||
|
|
@ -62,8 +80,7 @@ DNSServer::DNSServer()
|
|||
_errorReplyCode = DNSReplyCode::NonExistentDomain;
|
||||
}
|
||||
|
||||
void DNSServer::disableForwarder(const String &domainName, bool freeResources)
|
||||
{
|
||||
void DNSServer::disableForwarder(const String &domainName, bool freeResources) {
|
||||
_forwarder = false;
|
||||
if (domainName != "") {
|
||||
_domainName = domainName;
|
||||
|
|
@ -86,8 +103,7 @@ void DNSServer::disableForwarder(const String &domainName, bool freeResources)
|
|||
}
|
||||
}
|
||||
|
||||
bool DNSServer::enableForwarder(const String &domainName, const IPAddress &dns)
|
||||
{
|
||||
bool DNSServer::enableForwarder(const String &domainName, const IPAddress &dns) {
|
||||
disableForwarder(domainName, false); // Just happens to have the same logic needed here.
|
||||
|
||||
if (dns.isSet()) {
|
||||
|
|
@ -114,8 +130,7 @@ bool DNSServer::enableForwarder(const String &domainName, const IPAddress &dns)
|
|||
}
|
||||
|
||||
bool DNSServer::start(const uint16_t &port, const String &domainName,
|
||||
const IPAddress &resolvedIP, const IPAddress &dns)
|
||||
{
|
||||
const IPAddress &resolvedIP, const IPAddress &dns) {
|
||||
_port = (port) ? port : IANA_DNS_PORT;
|
||||
|
||||
_resolvedIP[0] = resolvedIP[0];
|
||||
|
|
@ -130,36 +145,31 @@ bool DNSServer::start(const uint16_t &port, const String &domainName,
|
|||
return _udp.begin(_port) == 1;
|
||||
}
|
||||
|
||||
void DNSServer::setErrorReplyCode(const DNSReplyCode &replyCode)
|
||||
{
|
||||
void DNSServer::setErrorReplyCode(const DNSReplyCode &replyCode) {
|
||||
_errorReplyCode = replyCode;
|
||||
}
|
||||
|
||||
void DNSServer::setTTL(const uint32_t &ttl)
|
||||
{
|
||||
void DNSServer::setTTL(const uint32_t &ttl) {
|
||||
_ttl = lwip_htonl(ttl);
|
||||
}
|
||||
|
||||
uint32_t DNSServer::getTTL()
|
||||
{
|
||||
uint32_t DNSServer::getTTL() {
|
||||
return lwip_ntohl(_ttl);
|
||||
}
|
||||
|
||||
void DNSServer::stop()
|
||||
{
|
||||
void DNSServer::stop() {
|
||||
_udp.stop();
|
||||
disableForwarder("", true);
|
||||
}
|
||||
|
||||
void DNSServer::downcaseAndRemoveWwwPrefix(String &domainName)
|
||||
{
|
||||
void DNSServer::downcaseAndRemoveWwwPrefix(String &domainName) {
|
||||
domainName.toLowerCase();
|
||||
if (domainName.startsWith("www."))
|
||||
if (domainName.startsWith("www.")) {
|
||||
domainName.remove(0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
void DNSServer::forwardReply(uint8_t *buffer, size_t length)
|
||||
{
|
||||
void DNSServer::forwardReply(uint8_t *buffer, size_t length) {
|
||||
if (!_forwarder || !_que) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -186,8 +196,7 @@ void DNSServer::forwardReply(uint8_t *buffer, size_t length)
|
|||
_que[i].ip = 0; // This gets used to detect duplicate packets and overflow
|
||||
}
|
||||
|
||||
void DNSServer::forwardRequest(uint8_t *buffer, size_t length)
|
||||
{
|
||||
void DNSServer::forwardRequest(uint8_t *buffer, size_t length) {
|
||||
if (!_forwarder || !_dns.isSet() || !_que) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -209,8 +218,7 @@ void DNSServer::forwardRequest(uint8_t *buffer, size_t length)
|
|||
DEBUG_PRINTLN2("Forward request ID: 0x", (String(dnsHeader->ID, HEX) + F(" to ") + _dns.toString()));
|
||||
}
|
||||
|
||||
bool DNSServer::respondToRequest(uint8_t *buffer, size_t length)
|
||||
{
|
||||
bool DNSServer::respondToRequest(uint8_t *buffer, size_t length) {
|
||||
DNSHeader *dnsHeader;
|
||||
uint8_t *query, *start;
|
||||
const char *matchString;
|
||||
|
|
@ -309,8 +317,9 @@ bool DNSServer::respondToRequest(uint8_t *buffer, size_t length)
|
|||
start = query;
|
||||
|
||||
// If there's a leading 'www', skip it
|
||||
if (*start == 3 && strncasecmp("www", (char *) start + 1, 3) == 0)
|
||||
if (*start == 3 && strncasecmp("www", (char *) start + 1, 3) == 0) {
|
||||
start += 4;
|
||||
}
|
||||
|
||||
while (*start != 0) {
|
||||
labelLength = *start;
|
||||
|
|
@ -344,48 +353,48 @@ bool DNSServer::respondToRequest(uint8_t *buffer, size_t length)
|
|||
return false;
|
||||
}
|
||||
|
||||
void DNSServer::processNextRequest()
|
||||
{
|
||||
void DNSServer::processNextRequest() {
|
||||
size_t currentPacketSize;
|
||||
|
||||
currentPacketSize = _udp.parsePacket();
|
||||
if (currentPacketSize == 0)
|
||||
if (currentPacketSize == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The DNS RFC requires that DNS packets be less than 512 bytes in size,
|
||||
// so just discard them if they are larger
|
||||
if (currentPacketSize > MAX_DNS_PACKETSIZE)
|
||||
if (currentPacketSize > MAX_DNS_PACKETSIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the packet size is smaller than the DNS header, then someone is
|
||||
// messing with us
|
||||
if (currentPacketSize < DNS_HEADER_SIZE)
|
||||
if (currentPacketSize < DNS_HEADER_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<uint8_t[]> buffer(new (std::nothrow) uint8_t[currentPacketSize]);
|
||||
if (buffer == nullptr)
|
||||
if (buffer == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
_udp.read(buffer.get(), currentPacketSize);
|
||||
if (_dns.isSet() && _udp.remoteIP() == _dns) {
|
||||
// _forwarder may have been set to false; however, for now allow in-flight
|
||||
// replies to finish. //??
|
||||
forwardReply(buffer.get(), currentPacketSize);
|
||||
} else
|
||||
if (respondToRequest(buffer.get(), currentPacketSize)) {
|
||||
} else if (respondToRequest(buffer.get(), currentPacketSize)) {
|
||||
forwardRequest(buffer.get(), currentPacketSize);
|
||||
}
|
||||
}
|
||||
|
||||
void DNSServer::writeNBOShort(uint16_t value)
|
||||
{
|
||||
void DNSServer::writeNBOShort(uint16_t value) {
|
||||
_udp.write((unsigned char *)&value, 2);
|
||||
}
|
||||
|
||||
void DNSServer::replyWithIP(DNSHeader *dnsHeader,
|
||||
unsigned char * query,
|
||||
size_t queryLength)
|
||||
{
|
||||
size_t queryLength) {
|
||||
uint16_t value;
|
||||
|
||||
dnsHeader->QR = DNS_QR_RESPONSE;
|
||||
|
|
@ -421,27 +430,27 @@ void DNSServer::replyWithIP(DNSHeader *dnsHeader,
|
|||
void DNSServer::replyWithError(DNSHeader *dnsHeader,
|
||||
DNSReplyCode rcode,
|
||||
unsigned char *query,
|
||||
size_t queryLength)
|
||||
{
|
||||
size_t queryLength) {
|
||||
dnsHeader->QR = DNS_QR_RESPONSE;
|
||||
dnsHeader->RCode = (unsigned char) rcode;
|
||||
if (query)
|
||||
if (query) {
|
||||
dnsHeader->QDCount = lwip_htons(1);
|
||||
else
|
||||
} else {
|
||||
dnsHeader->QDCount = 0;
|
||||
}
|
||||
dnsHeader->ANCount = 0;
|
||||
dnsHeader->NSCount = 0;
|
||||
dnsHeader->ARCount = 0;
|
||||
|
||||
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
|
||||
_udp.write((unsigned char *)dnsHeader, sizeof(DNSHeader));
|
||||
if (query != NULL)
|
||||
if (query != NULL) {
|
||||
_udp.write(query, queryLength);
|
||||
}
|
||||
_udp.endPacket();
|
||||
}
|
||||
|
||||
void DNSServer::replyWithError(DNSHeader *dnsHeader,
|
||||
DNSReplyCode rcode)
|
||||
{
|
||||
DNSReplyCode rcode) {
|
||||
replyWithError(dnsHeader, rcode, NULL, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,25 @@
|
|||
#ifndef DNSServer_h
|
||||
#define DNSServer_h
|
||||
/*
|
||||
DNSServer.cwhcpp - Simple DNS server for the Pico
|
||||
Modified 2022 Earle F. Philhower, III. All rights reserved.
|
||||
|
||||
Taken from the ESP8266 core libraries, (c) various authors.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <WiFiUdp.h>
|
||||
|
|
@ -25,8 +45,7 @@ constexpr inline uint16_t kIanaDnsPort = IANA_DNS_PORT;
|
|||
#define MAX_DNSNAME_LENGTH 253
|
||||
#define MAX_DNS_PACKETSIZE 512
|
||||
|
||||
enum class DNSReplyCode
|
||||
{
|
||||
enum class DNSReplyCode {
|
||||
NoError = 0,
|
||||
FormError = 1,
|
||||
ServerFailure = 2,
|
||||
|
|
@ -38,8 +57,7 @@ enum class DNSReplyCode
|
|||
NXRRSet = 8
|
||||
};
|
||||
|
||||
struct DNSHeader
|
||||
{
|
||||
struct DNSHeader {
|
||||
uint16_t ID; // identification number
|
||||
unsigned char RD : 1; // recursion desired
|
||||
unsigned char TC : 1; // truncated message
|
||||
|
|
@ -64,9 +82,8 @@ struct DNSS_REQUESTER {
|
|||
uint16_t id;
|
||||
};
|
||||
|
||||
class DNSServer
|
||||
{
|
||||
public:
|
||||
class DNSServer {
|
||||
public:
|
||||
DNSServer();
|
||||
~DNSServer() {
|
||||
stop();
|
||||
|
|
@ -79,8 +96,8 @@ class DNSServer
|
|||
Returns `true` on success.
|
||||
|
||||
Returns `false`,
|
||||
* when forwarding `dns` is not set, or
|
||||
* unable to allocate resources for managing the DNS forward function.
|
||||
when forwarding `dns` is not set, or
|
||||
unable to allocate resources for managing the DNS forward function.
|
||||
*/
|
||||
bool enableForwarder(const String &domainName = String(""), const IPAddress &dns = (uint32_t)0);
|
||||
/*
|
||||
|
|
@ -89,16 +106,26 @@ class DNSServer
|
|||
Optionally, resources used for the DNS forward function can be freed.
|
||||
*/
|
||||
void disableForwarder(const String &domainName = String(""), bool freeResources = false);
|
||||
bool isForwarding() { return _forwarder && _dns.isSet(); }
|
||||
void setDNS(const IPAddress& dns) { _dns = dns; }
|
||||
IPAddress getDNS() { return _dns; }
|
||||
bool isDNSSet() { return _dns.isSet(); }
|
||||
bool isForwarding() {
|
||||
return _forwarder && _dns.isSet();
|
||||
}
|
||||
void setDNS(const IPAddress& dns) {
|
||||
_dns = dns;
|
||||
}
|
||||
IPAddress getDNS() {
|
||||
return _dns;
|
||||
}
|
||||
bool isDNSSet() {
|
||||
return _dns.isSet();
|
||||
}
|
||||
|
||||
void processNextRequest();
|
||||
void setErrorReplyCode(const DNSReplyCode &replyCode);
|
||||
void setTTL(const uint32_t &ttl);
|
||||
uint32_t getTTL();
|
||||
String getDomainName() { return _domainName; }
|
||||
String getDomainName() {
|
||||
return _domainName;
|
||||
}
|
||||
|
||||
// Returns true if successful, false if there are no sockets available
|
||||
bool start(const uint16_t &port,
|
||||
|
|
@ -108,7 +135,7 @@ class DNSServer
|
|||
// stops the DNS server
|
||||
void stop();
|
||||
|
||||
private:
|
||||
private:
|
||||
WiFiUDP _udp;
|
||||
String _domainName;
|
||||
IPAddress _dns;
|
||||
|
|
@ -141,4 +168,3 @@ class DNSServer
|
|||
void forwardReply(uint8_t *buffer, size_t length);
|
||||
void writeNBOShort(uint16_t value);
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef EEPROM_h
|
||||
#define EEPROM_h
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
|
@ -85,6 +84,3 @@ protected:
|
|||
};
|
||||
|
||||
extern EEPROMClass EEPROM;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,3 +1,24 @@
|
|||
/*
|
||||
HTTPUpdateServer - Support simple web based OTA
|
||||
Modified 2022 Earle F. Philhower, III. All rights reserved.
|
||||
|
||||
Ported from the ESP8266 Arduino core, (c) copyright multiple authors
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,24 @@
|
|||
/*
|
||||
HTTPUpdateServer - Support simple web based OTA
|
||||
Modified 2022 Earle F. Philhower, III. All rights reserved.
|
||||
|
||||
Ported from the ESP8266 Arduino core, (c) copyright multiple authors
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WebServer.h>
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifndef MDNS_PRIV_H
|
||||
#define MDNS_PRIV_H
|
||||
#pragma once
|
||||
|
||||
namespace esp8266 {
|
||||
|
||||
|
|
@ -186,5 +185,3 @@ namespace MDNSImplementation {
|
|||
|
||||
// Include the main header, so the submodlues only need to include this header
|
||||
#include "LEAmDNS.h"
|
||||
|
||||
#endif // MDNS_PRIV_H
|
||||
|
|
|
|||
|
|
@ -22,9 +22,6 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifndef MDNS_LWIPDEFS_H
|
||||
#define MDNS_LWIPDEFS_H
|
||||
#pragma once
|
||||
|
||||
#include <lwip/prot/dns.h> // DNS_RRTYPE_xxx, DNS_MQUERY_PORT
|
||||
|
||||
#endif // MDNS_LWIPDEFS_H
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __LITTLEFS_H
|
||||
#define __LITTLEFS_H
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <FS.h>
|
||||
|
|
@ -681,6 +679,3 @@ protected:
|
|||
extern FS LittleFS;
|
||||
using littlefs_impl::LittleFSConfig;
|
||||
#endif // ARDUINO
|
||||
|
||||
|
||||
#endif // !defined(__LITTLEFS_H)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ void loop() {
|
|||
|
||||
// Print samples to the serial monitor or plotter
|
||||
for (int i = 0; i < samplesRead; i++) {
|
||||
if(channels == 2) {
|
||||
if (channels == 2) {
|
||||
Serial.print("L:");
|
||||
Serial.print(sampleBuffer[i]);
|
||||
Serial.print(" R:");
|
||||
|
|
@ -67,9 +67,9 @@ void loop() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Callback function to process the data from the PDM microphone.
|
||||
* NOTE: This callback is executed as part of an ISR.
|
||||
* Therefore using `Serial` to print messages inside this function isn't supported.
|
||||
Callback function to process the data from the PDM microphone.
|
||||
NOTE: This callback is executed as part of an ISR.
|
||||
Therefore using `Serial` to print messages inside this function isn't supported.
|
||||
* */
|
||||
void onPDMdata() {
|
||||
// Query the number of available bytes
|
||||
|
|
|
|||
|
|
@ -16,16 +16,14 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _PDM_H_INCLUDED
|
||||
#define _PDM_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
//#include <pinDefinitions.h>
|
||||
|
||||
#include "utility/PDMDoubleBuffer.h"
|
||||
|
||||
class PDMClass
|
||||
{
|
||||
class PDMClass {
|
||||
public:
|
||||
PDMClass(int dinPin, int clkPin, int pwrPin);
|
||||
virtual ~PDMClass();
|
||||
|
|
@ -44,7 +42,7 @@ public:
|
|||
void setBufferSize(int bufferSize);
|
||||
size_t getBufferSize();
|
||||
|
||||
// private:
|
||||
// private:
|
||||
void IrqHandler(bool halftranfer);
|
||||
|
||||
private:
|
||||
|
|
@ -58,7 +56,7 @@ private:
|
|||
int _gain;
|
||||
int _init;
|
||||
|
||||
// Hardware peripherals used
|
||||
// Hardware peripherals used
|
||||
uint _dmaChannel;
|
||||
PIO _pio;
|
||||
int _smIdx;
|
||||
|
|
@ -68,7 +66,7 @@ private:
|
|||
|
||||
void (*_onReceive)(void);
|
||||
};
|
||||
|
||||
#ifdef PIN_PDM_DIN
|
||||
extern PDMClass PDM;
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
/**
|
||||
*******************************************************************************
|
||||
* @file OpenPDMFilter.c
|
||||
* @author CL
|
||||
* @version V1.0.0
|
||||
* @date 9-September-2015
|
||||
* @brief Open PDM audio software decoding Library.
|
||||
* This Library is used to decode and reconstruct the audio signal
|
||||
* produced by ST MEMS microphone (MP45Dxxx, MP34Dxxx).
|
||||
@file OpenPDMFilter.c
|
||||
@author CL
|
||||
@version V1.0.0
|
||||
@date 9-September-2015
|
||||
@brief Open PDM audio software decoding Library.
|
||||
This Library is used to decode and reconstruct the audio signal
|
||||
produced by ST MEMS microphone (MP45Dxxx, MP34Dxxx).
|
||||
*******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2018 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
@attention
|
||||
|
||||
<h2><center>© COPYRIGHT 2018 STMicroelectronics</center></h2>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*******************************************************************************
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
|
@ -48,8 +48,7 @@ int32_t lut[256][DECIMATION_MAX / 8][SINCN];
|
|||
/* Functions -----------------------------------------------------------------*/
|
||||
|
||||
#ifdef USE_LUT
|
||||
int32_t filter_table_mono_64(uint8_t *data, uint8_t sincn)
|
||||
{
|
||||
int32_t filter_table_mono_64(uint8_t *data, uint8_t sincn) {
|
||||
return (int32_t)
|
||||
lut[data[0]][0][sincn] +
|
||||
lut[data[1]][1][sincn] +
|
||||
|
|
@ -60,8 +59,7 @@ int32_t filter_table_mono_64(uint8_t *data, uint8_t sincn)
|
|||
lut[data[6]][6][sincn] +
|
||||
lut[data[7]][7][sincn];
|
||||
}
|
||||
int32_t filter_table_stereo_64(uint8_t *data, uint8_t sincn)
|
||||
{
|
||||
int32_t filter_table_stereo_64(uint8_t *data, uint8_t sincn) {
|
||||
return (int32_t)
|
||||
lut[data[0]][0][sincn] +
|
||||
lut[data[2]][1][sincn] +
|
||||
|
|
@ -72,8 +70,7 @@ int32_t filter_table_stereo_64(uint8_t *data, uint8_t sincn)
|
|||
lut[data[12]][6][sincn] +
|
||||
lut[data[14]][7][sincn];
|
||||
}
|
||||
int32_t filter_table_mono_128(uint8_t *data, uint8_t sincn)
|
||||
{
|
||||
int32_t filter_table_mono_128(uint8_t *data, uint8_t sincn) {
|
||||
return (int32_t)
|
||||
lut[data[0]][0][sincn] +
|
||||
lut[data[1]][1][sincn] +
|
||||
|
|
@ -92,8 +89,7 @@ int32_t filter_table_mono_128(uint8_t *data, uint8_t sincn)
|
|||
lut[data[14]][14][sincn] +
|
||||
lut[data[15]][15][sincn];
|
||||
}
|
||||
int32_t filter_table_stereo_128(uint8_t *data, uint8_t sincn)
|
||||
{
|
||||
int32_t filter_table_stereo_128(uint8_t *data, uint8_t sincn) {
|
||||
return (int32_t)
|
||||
lut[data[0]][0][sincn] +
|
||||
lut[data[2]][1][sincn] +
|
||||
|
|
@ -112,11 +108,10 @@ int32_t filter_table_stereo_128(uint8_t *data, uint8_t sincn)
|
|||
lut[data[28]][14][sincn] +
|
||||
lut[data[30]][15][sincn];
|
||||
}
|
||||
int32_t (* filter_tables_64[2]) (uint8_t *data, uint8_t sincn) = {filter_table_mono_64, filter_table_stereo_64};
|
||||
int32_t (* filter_tables_128[2]) (uint8_t *data, uint8_t sincn) = {filter_table_mono_128, filter_table_stereo_128};
|
||||
int32_t (* filter_tables_64[2])(uint8_t *data, uint8_t sincn) = {filter_table_mono_64, filter_table_stereo_64};
|
||||
int32_t (* filter_tables_128[2])(uint8_t *data, uint8_t sincn) = {filter_table_mono_128, filter_table_stereo_128};
|
||||
#else
|
||||
int32_t filter_table(uint8_t *data, uint8_t sincn, TPDMFilter_InitStruct *param)
|
||||
{
|
||||
int32_t filter_table(uint8_t *data, uint8_t sincn, TPDMFilter_InitStruct *param) {
|
||||
uint8_t c, i;
|
||||
uint16_t data_index = 0;
|
||||
uint32_t *coef_p = &coef[sincn][0];
|
||||
|
|
@ -126,14 +121,14 @@ int32_t filter_table(uint8_t *data, uint8_t sincn, TPDMFilter_InitStruct *param)
|
|||
|
||||
for (i = 0; i < decimation; i += 8) {
|
||||
c = data[data_index];
|
||||
F += ((c >> 7) ) * coef_p[i ] +
|
||||
F += ((c >> 7)) * coef_p[i ] +
|
||||
((c >> 6) & 0x01) * coef_p[i + 1] +
|
||||
((c >> 5) & 0x01) * coef_p[i + 2] +
|
||||
((c >> 4) & 0x01) * coef_p[i + 3] +
|
||||
((c >> 3) & 0x01) * coef_p[i + 4] +
|
||||
((c >> 2) & 0x01) * coef_p[i + 5] +
|
||||
((c >> 1) & 0x01) * coef_p[i + 6] +
|
||||
((c ) & 0x01) * coef_p[i + 7];
|
||||
((c) & 0x01) * coef_p[i + 7];
|
||||
data_index += channels;
|
||||
}
|
||||
return F;
|
||||
|
|
@ -142,12 +137,10 @@ int32_t filter_table(uint8_t *data, uint8_t sincn, TPDMFilter_InitStruct *param)
|
|||
|
||||
void convolve(uint32_t Signal[/* SignalLen */], unsigned short SignalLen,
|
||||
uint32_t Kernel[/* KernelLen */], unsigned short KernelLen,
|
||||
uint32_t Result[/* SignalLen + KernelLen - 1 */])
|
||||
{
|
||||
uint32_t Result[/* SignalLen + KernelLen - 1 */]) {
|
||||
uint16_t n;
|
||||
|
||||
for (n = 0; n < SignalLen + KernelLen - 1; n++)
|
||||
{
|
||||
for (n = 0; n < SignalLen + KernelLen - 1; n++) {
|
||||
unsigned short kmin, kmax, k;
|
||||
|
||||
Result[n] = 0;
|
||||
|
|
@ -161,8 +154,7 @@ void convolve(uint32_t Signal[/* SignalLen */], unsigned short SignalLen,
|
|||
}
|
||||
}
|
||||
|
||||
void Open_PDM_Filter_Init(TPDMFilter_InitStruct *Param)
|
||||
{
|
||||
void Open_PDM_Filter_Init(TPDMFilter_InitStruct *Param) {
|
||||
uint16_t i, j;
|
||||
int64_t sum = 0;
|
||||
|
||||
|
|
@ -177,15 +169,15 @@ void Open_PDM_Filter_Init(TPDMFilter_InitStruct *Param)
|
|||
}
|
||||
|
||||
Param->OldOut = Param->OldIn = Param->OldZ = 0;
|
||||
Param->LP_ALFA = (Param->LP_HZ != 0 ? (uint16_t) (Param->LP_HZ * 256 / (Param->LP_HZ + Param->Fs / (2 * 3.14159))) : 0);
|
||||
Param->HP_ALFA = (Param->HP_HZ != 0 ? (uint16_t) (Param->Fs * 256 / (2 * 3.14159 * Param->HP_HZ + Param->Fs)) : 0);
|
||||
Param->LP_ALFA = (Param->LP_HZ != 0 ? (uint16_t)(Param->LP_HZ * 256 / (Param->LP_HZ + Param->Fs / (2 * 3.14159))) : 0);
|
||||
Param->HP_ALFA = (Param->HP_HZ != 0 ? (uint16_t)(Param->Fs * 256 / (2 * 3.14159 * Param->HP_HZ + Param->Fs)) : 0);
|
||||
|
||||
Param->FilterLen = decimation * SINCN;
|
||||
sinc[0] = 0;
|
||||
sinc[decimation * SINCN - 1] = 0;
|
||||
convolve(sinc1, decimation, sinc1, decimation, sinc2);
|
||||
convolve(sinc2, decimation * 2 - 1, sinc1, decimation, &sinc[1]);
|
||||
for(j = 0; j < SINCN; j++) {
|
||||
for (j = 0; j < SINCN; j++) {
|
||||
for (i = 0; i < decimation; i++) {
|
||||
coef[j][i] = sinc[j * decimation + i];
|
||||
sum += sinc[j * decimation + i];
|
||||
|
|
@ -199,25 +191,23 @@ void Open_PDM_Filter_Init(TPDMFilter_InitStruct *Param)
|
|||
#ifdef USE_LUT
|
||||
/* Look-Up Table. */
|
||||
uint16_t c, d, s;
|
||||
for (s = 0; s < SINCN; s++)
|
||||
{
|
||||
for (s = 0; s < SINCN; s++) {
|
||||
uint32_t *coef_p = &coef[s][0];
|
||||
for (c = 0; c < 256; c++)
|
||||
for (d = 0; d < decimation / 8; d++)
|
||||
lut[c][d][s] = ((c >> 7) ) * coef_p[d * 8 ] +
|
||||
lut[c][d][s] = ((c >> 7)) * coef_p[d * 8 ] +
|
||||
((c >> 6) & 0x01) * coef_p[d * 8 + 1] +
|
||||
((c >> 5) & 0x01) * coef_p[d * 8 + 2] +
|
||||
((c >> 4) & 0x01) * coef_p[d * 8 + 3] +
|
||||
((c >> 3) & 0x01) * coef_p[d * 8 + 4] +
|
||||
((c >> 2) & 0x01) * coef_p[d * 8 + 5] +
|
||||
((c >> 1) & 0x01) * coef_p[d * 8 + 6] +
|
||||
((c ) & 0x01) * coef_p[d * 8 + 7];
|
||||
((c) & 0x01) * coef_p[d * 8 + 7];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Open_PDM_Filter_64(uint8_t* data, int16_t* dataOut, uint16_t volume, TPDMFilter_InitStruct *Param)
|
||||
{
|
||||
void Open_PDM_Filter_64(uint8_t* data, int16_t* dataOut, uint16_t volume, TPDMFilter_InitStruct *Param) {
|
||||
uint8_t i, data_out_index;
|
||||
uint8_t channels = Param->In_MicChannels;
|
||||
uint8_t data_inc = ((DECIMATION_MAX >> 4) * channels);
|
||||
|
|
@ -264,8 +254,7 @@ void Open_PDM_Filter_64(uint8_t* data, int16_t* dataOut, uint16_t volume, TPDMFi
|
|||
Param->OldZ = OldZ;
|
||||
}
|
||||
|
||||
void Open_PDM_Filter_128(uint8_t* data, int16_t* dataOut, uint16_t volume, TPDMFilter_InitStruct *Param)
|
||||
{
|
||||
void Open_PDM_Filter_128(uint8_t* data, int16_t* dataOut, uint16_t volume, TPDMFilter_InitStruct *Param) {
|
||||
uint8_t i, data_out_index;
|
||||
uint8_t channels = Param->In_MicChannels;
|
||||
uint8_t data_inc = ((DECIMATION_MAX >> 3) * channels);
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
/**
|
||||
*******************************************************************************
|
||||
* @file OpenPDMFilter.h
|
||||
* @author CL
|
||||
* @version V1.0.0
|
||||
* @date 9-September-2015
|
||||
* @brief Header file for Open PDM audio software decoding Library.
|
||||
* This Library is used to decode and reconstruct the audio signal
|
||||
* produced by ST MEMS microphone (MP45Dxxx, MP34Dxxx).
|
||||
@file OpenPDMFilter.h
|
||||
@author CL
|
||||
@version V1.0.0
|
||||
@date 9-September-2015
|
||||
@brief Header file for Open PDM audio software decoding Library.
|
||||
This Library is used to decode and reconstruct the audio signal
|
||||
produced by ST MEMS microphone (MP45Dxxx, MP34Dxxx).
|
||||
*******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2018 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
@attention
|
||||
|
||||
<h2><center>© COPYRIGHT 2018 STMicroelectronics</center></h2>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*******************************************************************************
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
#define __OPENPDMFILTER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -45,10 +45,10 @@
|
|||
/* Definitions ---------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Enable to use a Look-Up Table to improve performances while using more FLASH
|
||||
* and RAM memory.
|
||||
* Note: Without Look-Up Table up to stereo@16KHz configuration is supported.
|
||||
*/
|
||||
Enable to use a Look-Up Table to improve performances while using more FLASH
|
||||
and RAM memory.
|
||||
Note: Without Look-Up Table up to stereo@16KHz configuration is supported.
|
||||
*/
|
||||
#define USE_LUT
|
||||
|
||||
#define SINCN 3
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ int16_t* volatile finalBuffer;
|
|||
TPDMFilter_InitStruct filter;
|
||||
|
||||
extern "C" {
|
||||
__attribute__((__used__)) void dmaHandler(void)
|
||||
{
|
||||
__attribute__((__used__)) void dmaHandler(void) {
|
||||
PDM.IrqHandler(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -49,16 +48,13 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
|
|||
_dmaChannel(0),
|
||||
_pio(nullptr),
|
||||
_smIdx(-1),
|
||||
_pgmOffset(-1)
|
||||
{
|
||||
_pgmOffset(-1) {
|
||||
}
|
||||
|
||||
PDMClass::~PDMClass()
|
||||
{
|
||||
PDMClass::~PDMClass() {
|
||||
}
|
||||
|
||||
int PDMClass::begin(int channels, int sampleRate)
|
||||
{
|
||||
int PDMClass::begin(int channels, int sampleRate) {
|
||||
//_channels = channels; // only one channel available
|
||||
|
||||
// clear the final buffers
|
||||
|
|
@ -76,12 +72,12 @@ int PDMClass::begin(int channels, int sampleRate)
|
|||
/* Initialize Open PDM library */
|
||||
filter.Fs = sampleRate;
|
||||
filter.nSamples = rawBufferLength;
|
||||
filter.LP_HZ = sampleRate/2;
|
||||
filter.LP_HZ = sampleRate / 2;
|
||||
filter.HP_HZ = 10;
|
||||
filter.In_MicChannels = 1;
|
||||
filter.Out_MicChannels = 1;
|
||||
filter.Decimation = decimation;
|
||||
if(_gain == -1) {
|
||||
if (_gain == -1) {
|
||||
_gain = FILTER_GAIN;
|
||||
}
|
||||
filter.filterGain = _gain;
|
||||
|
|
@ -127,14 +123,12 @@ int PDMClass::begin(int channels, int sampleRate)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void PDMClass::end()
|
||||
{
|
||||
void PDMClass::end() {
|
||||
dma_channel_abort(_dmaChannel);
|
||||
pinMode(_clkPin, INPUT);
|
||||
}
|
||||
|
||||
int PDMClass::available()
|
||||
{
|
||||
int PDMClass::available() {
|
||||
//NVIC_DisableIRQ(DMA_IRQ_0n);
|
||||
//uint32_t interrupts = save_and_disable_interrupts();
|
||||
irq_set_enabled(DMA_IRQ_0, false);
|
||||
|
|
@ -145,35 +139,30 @@ int PDMClass::available()
|
|||
return avail;
|
||||
}
|
||||
|
||||
int PDMClass::read(void* buffer, size_t size)
|
||||
{
|
||||
int PDMClass::read(void* buffer, size_t size) {
|
||||
irq_set_enabled(DMA_IRQ_0, false);
|
||||
int read = _doubleBuffer.read(buffer, size);
|
||||
irq_set_enabled(DMA_IRQ_0, true);
|
||||
return read;
|
||||
}
|
||||
|
||||
void PDMClass::onReceive(void(*function)(void))
|
||||
{
|
||||
void PDMClass::onReceive(void(*function)(void)) {
|
||||
_onReceive = function;
|
||||
}
|
||||
|
||||
void PDMClass::setGain(int gain)
|
||||
{
|
||||
void PDMClass::setGain(int gain) {
|
||||
_gain = gain;
|
||||
if(_init == 1) {
|
||||
if (_init == 1) {
|
||||
filter.filterGain = _gain;
|
||||
Open_PDM_Filter_Init(&filter);
|
||||
}
|
||||
}
|
||||
|
||||
void PDMClass::setBufferSize(int bufferSize)
|
||||
{
|
||||
void PDMClass::setBufferSize(int bufferSize) {
|
||||
_doubleBuffer.setSize(bufferSize);
|
||||
}
|
||||
|
||||
void PDMClass::IrqHandler(bool halftranfer)
|
||||
{
|
||||
void PDMClass::IrqHandler(bool halftranfer) {
|
||||
static int cutSamples = 100;
|
||||
|
||||
// Clear the interrupt request.
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ static inline void pdm_pio_program_init(PIO pio, uint sm, uint offset, uint clkP
|
|||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, dataPin, 1, false);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, clkPin, 1, true);
|
||||
pio_sm_set_pins_with_mask(pio, sm, 0, (1u << clkPin) );
|
||||
pio_sm_set_pins_with_mask(pio, sm, 0, (1u << clkPin));
|
||||
//pio_gpio_init(pio, dataPin);
|
||||
pio_gpio_init(pio, clkPin);
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
|
|
|
|||
|
|
@ -22,28 +22,23 @@
|
|||
#include "PDMDoubleBuffer.h"
|
||||
|
||||
PDMDoubleBuffer::PDMDoubleBuffer() :
|
||||
_size(DEFAULT_PDM_BUFFER_SIZE)
|
||||
{
|
||||
_size(DEFAULT_PDM_BUFFER_SIZE) {
|
||||
reset();
|
||||
}
|
||||
|
||||
PDMDoubleBuffer::~PDMDoubleBuffer()
|
||||
{
|
||||
PDMDoubleBuffer::~PDMDoubleBuffer() {
|
||||
}
|
||||
|
||||
void PDMDoubleBuffer::setSize(int size)
|
||||
{
|
||||
void PDMDoubleBuffer::setSize(int size) {
|
||||
_size = size;
|
||||
reset();
|
||||
}
|
||||
|
||||
size_t PDMDoubleBuffer::getSize()
|
||||
{
|
||||
size_t PDMDoubleBuffer::getSize() {
|
||||
return _size;
|
||||
}
|
||||
|
||||
void PDMDoubleBuffer::reset()
|
||||
{
|
||||
void PDMDoubleBuffer::reset() {
|
||||
_buffer[0] = (uint8_t*)realloc(_buffer[0], _size);
|
||||
_buffer[1] = (uint8_t*)realloc(_buffer[1], _size);
|
||||
|
||||
|
|
@ -57,13 +52,11 @@ void PDMDoubleBuffer::reset()
|
|||
_readOffset[1] = 0;
|
||||
}
|
||||
|
||||
size_t PDMDoubleBuffer::availableForWrite()
|
||||
{
|
||||
size_t PDMDoubleBuffer::availableForWrite() {
|
||||
return (_size - (_length[_index] - _readOffset[_index]));
|
||||
}
|
||||
|
||||
size_t PDMDoubleBuffer::write(const void *buffer, size_t size)
|
||||
{
|
||||
size_t PDMDoubleBuffer::write(const void *buffer, size_t size) {
|
||||
size_t space = availableForWrite();
|
||||
|
||||
if (size > space) {
|
||||
|
|
@ -81,8 +74,7 @@ size_t PDMDoubleBuffer::write(const void *buffer, size_t size)
|
|||
return size;
|
||||
}
|
||||
|
||||
size_t PDMDoubleBuffer::read(void *buffer, size_t size)
|
||||
{
|
||||
size_t PDMDoubleBuffer::read(void *buffer, size_t size) {
|
||||
size_t avail = available();
|
||||
|
||||
if (size > avail) {
|
||||
|
|
@ -99,8 +91,7 @@ size_t PDMDoubleBuffer::read(void *buffer, size_t size)
|
|||
return size;
|
||||
}
|
||||
|
||||
size_t PDMDoubleBuffer::peek(void *buffer, size_t size)
|
||||
{
|
||||
size_t PDMDoubleBuffer::peek(void *buffer, size_t size) {
|
||||
size_t avail = available();
|
||||
|
||||
if (size > avail) {
|
||||
|
|
@ -116,18 +107,15 @@ size_t PDMDoubleBuffer::peek(void *buffer, size_t size)
|
|||
return size;
|
||||
}
|
||||
|
||||
void* PDMDoubleBuffer::data()
|
||||
{
|
||||
void* PDMDoubleBuffer::data() {
|
||||
return (void*)_buffer[_index];
|
||||
}
|
||||
|
||||
size_t PDMDoubleBuffer::available()
|
||||
{
|
||||
size_t PDMDoubleBuffer::available() {
|
||||
return _length[_index] - _readOffset[_index];
|
||||
}
|
||||
|
||||
void PDMDoubleBuffer::swap(int length)
|
||||
{
|
||||
void PDMDoubleBuffer::swap(int length) {
|
||||
if (_index == 0) {
|
||||
_index = 1;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@
|
|||
|
||||
#define DEFAULT_PDM_BUFFER_SIZE 512
|
||||
|
||||
class PDMDoubleBuffer
|
||||
{
|
||||
class PDMDoubleBuffer {
|
||||
public:
|
||||
PDMDoubleBuffer();
|
||||
virtual ~PDMDoubleBuffer();
|
||||
|
|
@ -44,7 +43,7 @@ public:
|
|||
void swap(int length = 0);
|
||||
|
||||
private:
|
||||
uint8_t* _buffer[2] __attribute__((aligned (16)));
|
||||
uint8_t* _buffer[2] __attribute__((aligned(16)));
|
||||
int _size;
|
||||
volatile int _length[2];
|
||||
volatile int _readOffset[2];
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __SD_H__
|
||||
#define __SD_H__
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <FS.h>
|
||||
|
|
@ -218,5 +217,3 @@ static inline uint8_t FAT_SECOND(uint16_t fatTime) {
|
|||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SD)
|
||||
extern SDClass SD;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
#ifndef SDFS_H
|
||||
#define SDFS_H
|
||||
|
||||
/*
|
||||
SDFS.h - file system wrapper for SdLib
|
||||
Copyright (c) 2019 Earle F. Philhower, III. All rights reserved.
|
||||
|
|
@ -27,6 +24,9 @@
|
|||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <assert.h>
|
||||
#include "FS.h"
|
||||
|
|
@ -508,5 +508,3 @@ protected:
|
|||
extern FS SDFS;
|
||||
using sdfs::SDFSConfig;
|
||||
#endif
|
||||
|
||||
#endif // SDFS.h
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@
|
|||
detach() - Stops an attached servos from pulsing its i/o pin.
|
||||
*/
|
||||
|
||||
#ifndef Servo_h
|
||||
#define Servo_h
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <hardware/pio.h>
|
||||
|
|
@ -89,5 +88,3 @@ private:
|
|||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,22 @@
|
|||
/*
|
||||
StackThunk - Implements a simple 2nd stack for BSSL and others
|
||||
Copyright (c) 2022 Earle F. Philhower, III. All rights reserved.
|
||||
|
||||
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 <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,22 @@
|
|||
/*
|
||||
StackThunk - Implements a simple 2nd stack for BSSL and others
|
||||
Copyright (c) 2022 Earle F. Philhower, III. All rights reserved.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
|
|
|||
|
|
@ -72,8 +72,7 @@
|
|||
}
|
||||
*/
|
||||
|
||||
#ifndef __ADDRLIST_H
|
||||
#define __ADDRLIST_H
|
||||
#pragma once
|
||||
|
||||
#include <IPAddress.h>
|
||||
#include <api/String.h>
|
||||
|
|
@ -254,6 +253,3 @@ inline AddressList::const_iterator end(const AddressList& a) {
|
|||
} // esp8266
|
||||
|
||||
extern esp8266::AddressListImplementation::AddressList addrList;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,25 @@
|
|||
/*
|
||||
LwipEthernet.h
|
||||
|
||||
Arduino interface for lwIP generic callbacks and functions
|
||||
|
||||
Original Copyright (c) 2020 esp8266 Arduino All rights reserved.
|
||||
|
||||
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 <ESP8266WiFi.h> // tcp API
|
||||
//#include <debug.h>
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
for dir in ./cores/rp2040 ./libraries/EEPROM ./libraries/I2S \
|
||||
./libraries/LittleFS/src ./libraries/LittleFS/examples \
|
||||
./libraries/rp2040 ./libraries/SD ./libraries/ESP8266SdFat \
|
||||
./libraries/Servo ./libraries/SPI ./libraries/Wire \
|
||||
./libraries/Servo ./libraries/SPI ./libraries/Wire ./libraries/PDM \
|
||||
./libraries/WiFi ./libraries/lwIP_Ethernet ./libraries/lwIP_CYW43 \
|
||||
./libraries/FreeRTOS/src ./libraries/LEAmDNS ./libraries/MD5Builder \
|
||||
./libraries/PicoOTA ./libraries/SDFS ./libraries/ArduinoOTA \
|
||||
./libraries/Updater ./libraries/HTTPClient ./libraries/HTTPUpdate \
|
||||
./libraries/WebServer ./libraries/HTTPUpdateServer ; do
|
||||
./libraries/WebServer ./libraries/HTTPUpdateServer ./libraries/DNSServer ; do
|
||||
find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" \) -a \! -path '*api*' -exec astyle --suffix=none --options=./tests/astyle_core.conf \{\} \;
|
||||
find $dir -type f -name "*.ino" -exec astyle --suffix=none --options=./tests/astyle_examples.conf \{\} \;
|
||||
done
|
||||
|
|
|
|||
Loading…
Reference in a new issue