Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 2384153

Browse files
authored
v1.0.0 for hardware-PWM on nRF52 boards
### Initial Releases v1.0.0 1. Initial coding to support **nRF52-based boards, such as AdaFruit Itsy-Bitsy nRF52840, Feather nRF52840 Express, Seeed XIAO nRF52840, Seeed XIAO nRF52840 Sense**, etc. using [`Adafruit nRF52 core`](https://github.com/adafruit/Adafruit_nRF52_Arduino) or [`Seeeduino nRF52 core`](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino)
1 parent 2017789 commit 2384153

File tree

55 files changed

+10023
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+10023
-0
lines changed

Packages_Patches/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Print.cpp

Lines changed: 466 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
Copyright (c) 2016 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#pragma once
20+
21+
#include <inttypes.h>
22+
#include <stdio.h> // for size_t
23+
24+
#include "WString.h"
25+
#include "Printable.h"
26+
27+
#define DEC 10
28+
#define HEX 16
29+
#define OCT 8
30+
#define BIN 2
31+
32+
class Print
33+
{
34+
private:
35+
int write_error;
36+
size_t printNumber(unsigned long, uint8_t);
37+
size_t printULLNumber(unsigned long long, uint8_t);
38+
size_t printFloat(double, int);
39+
protected:
40+
void setWriteError(int err = 1)
41+
{
42+
write_error = err;
43+
}
44+
public:
45+
Print() : write_error(0) {}
46+
47+
int getWriteError()
48+
{
49+
return write_error;
50+
}
51+
void clearWriteError()
52+
{
53+
setWriteError(0);
54+
}
55+
56+
virtual size_t write(uint8_t) = 0;
57+
size_t write(const char *str)
58+
{
59+
if (str == NULL)
60+
return 0;
61+
62+
return write((const uint8_t *)str, strlen(str));
63+
}
64+
virtual size_t write(const uint8_t *buffer, size_t size);
65+
size_t write(const char *buffer, size_t size)
66+
{
67+
return write((const uint8_t *)buffer, size);
68+
}
69+
70+
// default to zero, meaning "a single write may block"
71+
// should be overridden by subclasses with buffering
72+
virtual int availableForWrite()
73+
{
74+
return 0;
75+
}
76+
77+
size_t print(const __FlashStringHelper *);
78+
size_t print(const String &);
79+
size_t print(const char[]);
80+
size_t print(char);
81+
size_t print(unsigned char, int = DEC);
82+
size_t print(int, int = DEC);
83+
size_t print(unsigned int, int = DEC);
84+
size_t print(long, int = DEC);
85+
size_t print(unsigned long, int = DEC);
86+
size_t print(long long, int = DEC);
87+
size_t print(unsigned long long, int = DEC);
88+
size_t print(double, int = 2);
89+
size_t print(const Printable&);
90+
91+
size_t println(const __FlashStringHelper *);
92+
size_t println(const String &s);
93+
size_t println(const char[]);
94+
size_t println(char);
95+
size_t println(unsigned char, int = DEC);
96+
size_t println(int, int = DEC);
97+
size_t println(unsigned int, int = DEC);
98+
size_t println(long, int = DEC);
99+
size_t println(unsigned long, int = DEC);
100+
size_t println(long long, int = DEC);
101+
size_t println(unsigned long long, int = DEC);
102+
size_t println(double, int = 2);
103+
size_t println(const Printable&);
104+
size_t println(void);
105+
106+
size_t printf(const char * format, ...);
107+
108+
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
109+
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
110+
{
111+
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
112+
}
113+
114+
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
115+
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
116+
{
117+
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
118+
}
119+
120+
virtual void flush() { /* Empty implementation for backward compatibility */ }
121+
};
122+
123+
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Udp.cpp: Library to send/receive UDP packets.
3+
4+
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
5+
1) UDP does not guarantee the order in which assembled UDP packets are received. This
6+
might not happen often in practice, but in larger network topologies, a UDP
7+
packet can be received out of sequence.
8+
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
9+
aware of it. Again, this may not be a concern in practice on small local networks.
10+
For more information, see http://www.cafeaulait.org/course/week12/35.html
11+
12+
MIT License:
13+
Copyright (c) 2008 Bjoern Hartmann
14+
Permission is hereby granted, free of charge, to any person obtaining a copy
15+
of this software and associated documentation files (the "Software"), to deal
16+
in the Software without restriction, including without limitation the rights
17+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
copies of the Software, and to permit persons to whom the Software is
19+
furnished to do so, subject to the following conditions:
20+
21+
The above copyright notice and this permission notice shall be included in
22+
all copies or substantial portions of the Software.
23+
24+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30+
THE SOFTWARE.
31+
32+
[email protected] 12/30/2008
33+
*/
34+
35+
#ifndef udp_h
36+
#define udp_h
37+
38+
#include <Stream.h>
39+
#include <IPAddress.h>
40+
41+
class UDP : public Stream
42+
{
43+
44+
public:
45+
virtual uint8_t begin(uint16_t) =
46+
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
47+
48+
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
49+
virtual uint8_t beginMulticast(IPAddress, uint16_t)
50+
{
51+
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
52+
}
53+
54+
virtual void stop() = 0; // Finish with the UDP socket
55+
56+
// Sending UDP packets
57+
58+
// Start building up a packet to send to the remote host specific in ip and port
59+
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
60+
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
61+
// Start building up a packet to send to the remote host specific in host and port
62+
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
63+
virtual int beginPacket(const char *host, uint16_t port) = 0;
64+
// Finish off this packet and send it
65+
// Returns 1 if the packet was sent successfully, 0 if there was an error
66+
virtual int endPacket() = 0;
67+
// Write a single byte into the packet
68+
virtual size_t write(uint8_t) = 0;
69+
// Write size bytes from buffer into the packet
70+
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
71+
72+
// Start processing the next available incoming packet
73+
// Returns the size of the packet in bytes, or 0 if no packets are available
74+
virtual int parsePacket() = 0;
75+
// Number of bytes remaining in the current packet
76+
virtual int available() = 0;
77+
// Read a single byte from the current packet
78+
virtual int read() = 0;
79+
// Read up to len bytes from the current packet and place them into buffer
80+
// Returns the number of bytes read, or 0 if none are available
81+
virtual int read(unsigned char* buffer, size_t len) = 0;
82+
// Read up to len characters from the current packet and place them into buffer
83+
// Returns the number of characters read, or 0 if none are available
84+
virtual int read(char* buffer, size_t len) = 0;
85+
// Return the next byte from the current packet without moving on to the next byte
86+
virtual int peek() = 0;
87+
virtual void flush() = 0; // Finish reading the current packet
88+
89+
// Return the IP address of the host who sent the current incoming packet
90+
virtual IPAddress remoteIP() = 0;
91+
// Return the port of the host who sent the current incoming packet
92+
virtual uint16_t remotePort() = 0;
93+
protected:
94+
uint8_t* rawIPAddress(IPAddress& addr)
95+
{
96+
return addr.raw_address();
97+
};
98+
};
99+
100+
#endif

0 commit comments

Comments
 (0)