Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-pico
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-pico
Commits
3bcbb246
Unverified
Commit
3bcbb246
authored
Jun 15, 2022
by
Pontus Oldberg
Committed by
GitHub
Jun 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated helper class for Challenger NB board. (#629)
parent
26752f6f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
41 deletions
+84
-41
variants/challenger_2040_wifi/ChallengerWiFi.h
variants/challenger_2040_wifi/ChallengerWiFi.h
+2
-2
variants/challenger_nb_2040_wifi/ChallengerWiFi.cpp
variants/challenger_nb_2040_wifi/ChallengerWiFi.cpp
+63
-32
variants/challenger_nb_2040_wifi/ChallengerWiFi.h
variants/challenger_nb_2040_wifi/ChallengerWiFi.h
+12
-5
variants/challenger_nb_2040_wifi/pins_arduino.h
variants/challenger_nb_2040_wifi/pins_arduino.h
+7
-2
No files found.
variants/challenger_2040_wifi/ChallengerWiFi.h
View file @
3bcbb246
...
...
@@ -20,8 +20,8 @@
#pragma once
#define DEFAULT_ESP
32_BAUDRATE
115200
#define DEFAULT_ESP_BAUDRATE DEFAULT_ESP
32
_BAUDRATE
#define DEFAULT_ESP
8285_BAUDRATE
115200
#define DEFAULT_ESP_BAUDRATE DEFAULT_ESP
8285
_BAUDRATE
class
Challenger2040WiFiClass
{
public:
...
...
variants/challenger_nb_2040_wifi/ChallengerWiFi.cpp
View file @
3bcbb246
/*
ESP8285
helper class for the Challenger RP2040 WiFi
boards
ESP8285
/ESP32C3 helper class for the Challenger RP2040 WiFi enabled
boards
Copyright (c) 2021 P. Oldberg <pontus@ilabs.se>
Copyright (c) 2021
,2022
P. Oldberg <pontus@ilabs.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
...
...
@@ -21,31 +21,33 @@
#include <Arduino.h>
#include <ChallengerWiFi.h>
Challenger2040WiFiClass
::
Challenger2040WiFiClass
()
{
pinMode
(
PIN_ESP8285_RST
,
OUTPUT
);
digitalWrite
(
PIN_ESP8285_RST
,
LOW
);
// Hold ESP8285 in reset
pinMode
(
PIN_ESP8285_MODE
,
OUTPUT
);
digitalWrite
(
PIN_ESP8285_MODE
,
HIGH
);
// Prepare for normal start
Challenger2040WiFiClass
::
Challenger2040WiFiClass
(
HardwareSerial
*
serial
)
{
_serial
=
serial
;
pinMode
(
PIN_ESP_RST
,
OUTPUT
);
digitalWrite
(
PIN_ESP_RST
,
LOW
);
// Hold ESP in reset
pinMode
(
PIN_ESP_MODE
,
OUTPUT
);
digitalWrite
(
PIN_ESP_MODE
,
HIGH
);
// Prepare for normal start
}
// Do a HW reset by applying a low pulse to the reset line for 1mSec
void
Challenger2040WiFiClass
::
doHWReset
()
{
digitalWrite
(
PIN_ESP
8285_RST
,
LOW
);
// Hold ESP8285
in reset
digitalWrite
(
PIN_ESP
_RST
,
LOW
);
// Hold ESP
in reset
delay
(
1
);
digitalWrite
(
PIN_ESP
8285_RST
,
HIGH
);
// Release ESP8285
reset
digitalWrite
(
PIN_ESP
_RST
,
HIGH
);
// Release ESP
reset
}
// Set the mode flag high to indicate normal run operation and do a HW
// reset.
void
Challenger2040WiFiClass
::
runReset
()
{
// Prepare ESP
8285
for normal op
digitalWrite
(
PIN_ESP
8285
_MODE
,
HIGH
);
// Prepare for normal start
void
Challenger2040WiFiClass
::
runReset
()
{
// Prepare ESP for normal op
digitalWrite
(
PIN_ESP_MODE
,
HIGH
);
// Prepare for normal start
doHWReset
();
}
// Set the mode flag low to indicate flash operation and do a HW
// reset.
void
Challenger2040WiFiClass
::
flashReset
()
{
// Prepare ESP
8285
for flashing
digitalWrite
(
PIN_ESP
8285
_MODE
,
LOW
);
// Prepare for normal start
void
Challenger2040WiFiClass
::
flashReset
()
{
// Prepare ESP for flashing
digitalWrite
(
PIN_ESP_MODE
,
LOW
);
// Prepare for normal start
doHWReset
();
}
...
...
@@ -55,53 +57,82 @@ void Challenger2040WiFiClass::flashReset() { // Prepare ESP8285 for flashing
bool
Challenger2040WiFiClass
::
waitForReady
()
{
int
timeout
=
20
;
// Aprox max 2 sec
Serial2
.
begin
(
DEFAULT_ESP8285_BAUDRATE
);
Serial2
.
setTimeout
(
100
);
String
rdy
=
Serial2
.
readStringUntil
(
'\n'
);
_serial
->
setTimeout
(
100
);
String
rdy
=
_serial
->
readStringUntil
(
'\n'
);
while
(
!
rdy
.
startsWith
(
"ready"
)
&&
timeout
--
)
{
rdy
=
Serial2
.
readStringUntil
(
'\n'
);
rdy
=
_serial
->
readStringUntil
(
'\n'
);
}
Serial2
.
setTimeout
(
1000
);
// Reset default timeout to 1000
_serial
->
setTimeout
(
1000
);
// Reset default timeout to 1000
if
(
timeout
)
return
true
;
return
false
;
}
// Reset the ESP
8285
and wait for the "ready" prompt to be returned.
// Reset the ESP and wait for the "ready" prompt to be returned.
bool
Challenger2040WiFiClass
::
reset
()
{
runReset
();
_serial
->
begin
(
DEFAULT_ESP_BAUDRATE
);
return
waitForReady
();
}
// Checks to see if the modem responds to the "AT" poll command.
bool
Challenger2040WiFiClass
::
isAlive
()
{
int
timeout
=
5
;
int
timeout
=
100
;
Serial2
.
setTimeout
(
250
);
Serial2
.
println
(
F
(
"AT"
));
String
rdy
=
Serial2
.
readStringUntil
(
'\n'
);
_serial
->
setTimeout
(
250
);
_serial
->
println
(
F
(
"AT"
));
String
rdy
=
_serial
->
readStringUntil
(
'\n'
);
while
(
!
rdy
.
startsWith
(
F
(
"OK"
))
&&
timeout
--
)
{
rdy
=
Serial2
.
readStringUntil
(
'\n'
);
_serial
->
println
(
F
(
"AT"
));
rdy
=
_serial
->
readStringUntil
(
'\n'
);
}
Serial2
.
setTimeout
(
1000
);
_serial
->
setTimeout
(
1000
);
if
(
timeout
)
return
true
;
return
false
;
}
// Change the baud rate of the ESP
8285
as well as the local UART.
// Change the baud rate of the ESP
device
as well as the local UART.
// No checking is done on the input baud rate so the user must know what
// baud rates are valid. The function ends by checking if the ESP
8285
is
// baud rates are valid. The function ends by checking if the ESP is
// reachable by doing an "AT" poll.
bool
Challenger2040WiFiClass
::
changeBaudRate
(
int
baud
)
{
Serial2
.
print
(
F
(
"AT+UART_CUR="
));
Serial2
.
print
(
baud
);
Serial2
.
println
(
F
(
",8,1,0,0"
));
_serial
->
print
(
F
(
"AT+UART_CUR="
));
_serial
->
print
(
baud
);
_serial
->
println
(
F
(
",8,1,0,0"
));
delay
(
100
);
Serial2
.
end
();
Serial2
.
begin
(
baud
);
_serial
->
end
();
_serial
->
begin
(
baud
);
return
isAlive
();
}
// This method should be called id the builtin object isn't needed any more
// It basically just releases the UART pins for other use.
void
Challenger2040WiFiClass
::
release
()
{
_serial
->
end
();
}
// We can assign a new hardware serial port to accommodate the ESP device here.
// The function will release the previously used serial port and assign the
// new port. The ESP will be left in a reset state ready to start normal
// operation when exiting the function.
// This function is useful for when using the PIO serial ports to communicate
// with the ESP instead of the built in hardware serial port.
void
Challenger2040WiFiClass
::
setSerial
(
HardwareSerial
*
serial
)
{
release
();
_serial
=
serial
;
pinMode
(
PIN_ESP_RST
,
OUTPUT
);
digitalWrite
(
PIN_ESP_RST
,
LOW
);
// Hold ESP in reset
pinMode
(
PIN_ESP_MODE
,
OUTPUT
);
digitalWrite
(
PIN_ESP_MODE
,
HIGH
);
// Prepare for normal start
}
// Return the current serial object
HardwareSerial
*
Challenger2040WiFiClass
::
getSerial
()
{
return
_serial
;
}
Challenger2040WiFiClass
Challenger2040WiFi
;
variants/challenger_nb_2040_wifi/ChallengerWiFi.h
View file @
3bcbb246
/*
ESP8285
helper class for the Challenger RP2040 WiFi
boards
ESP8285
/ESP32C3 helper class for the Challenger RP2040 WiFi enabled
boards
Copyright (c) 2021 P. Oldberg <pontus@ilabs.se>
Copyright (c) 2021
,2022
P. Oldberg <pontus@ilabs.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
...
...
@@ -17,20 +17,27 @@
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
#define DEFAULT_ESP8285_BAUDRATE 115200
#define DEFAULT_ESP8285_BAUDRATE 115200
#define DEFAULT_ESP_BAUDRATE DEFAULT_ESP8285_BAUDRATE
class
Challenger2040WiFiClass
{
public:
Challenger2040WiFiClass
();
Challenger2040WiFiClass
(
HardwareSerial
*
=
&
ESP_SERIAL_PORT
);
void
doHWReset
();
void
runReset
();
void
flashReset
();
bool
waitForReady
();
bool
reset
();
bool
isAlive
();
bool
changeBaudRate
(
int
baud
);
bool
changeBaudRate
(
int
);
void
release
();
void
setSerial
(
HardwareSerial
*
);
HardwareSerial
*
getSerial
();
private:
HardwareSerial
*
_serial
;
};
extern
Challenger2040WiFiClass
Challenger2040WiFi
;
variants/challenger_nb_2040_wifi/pins_arduino.h
View file @
3bcbb246
#pragma once
#include <ChallengerWiFi.h>
#define PINS_COUNT (24u)
#define NUM_DIGITAL_PINS (24u)
#define NUM_ANALOG_INPUTS (4u)
...
...
@@ -20,6 +18,13 @@
#define PIN_SERIAL2_RX (5u)
#define PIN_ESP8285_RST (19u)
#define PIN_ESP8285_MODE (13u)
#define ESP8285_SERIAL Serial2
// Uart define esp serial abstraction pins
#define PIN_ESP_TX PIN_SERIAL2_TX
#define PIN_ESP_RX PIN_SERIAL2_RX
#define PIN_ESP_RST PIN_ESP8285_RST
#define PIN_ESP_MODE PIN_ESP8285_MODE
#define ESP_SERIAL_PORT ESP8285_SERIAL
// SPI
#define PIN_SPI0_MISO (24u)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment