Skip to content

Commit 9b4c435

Browse files
authored
Merge pull request #67 from arduino/rp2040_final
Adding support for Arduino RP2040 Nano Connect
2 parents de7f0db + 8713b09 commit 9b4c435

File tree

6 files changed

+80
-9
lines changed

6 files changed

+80
-9
lines changed

CHANGELOG

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
Arduino NINA-W102 firmware ?.?.? - ????.??.??
22

3+
Arduino NINA-W102 firmware 1.4.4 - 2021.04.13
4+
5+
* Adding support for Arduino RP2040 Nano Connect (#64)
6+
7+
Arduino NINA-W102 firmware 1.4.3 - 2021.01.29
8+
9+
* Do not immediately close connection after 1 failed write (#62)
10+
11+
Arduino NINA-W102 firmware 1.4.2 - 2021.01.28
12+
13+
Port BearSSL + crypto integration to NINA (#57). This allows to offload BearSSL for Arduino IoT Cloud applications to the nina module, drastically saving on flash/RAM.
14+
315
Arduino NINA-W102 firmware 1.4.1 - 2020.08.17
416

517
* Direct download of OTA binary to Nina storage and verifying both CRC and length (#53)

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ CFLAGS += -DUNO_WIFI_REV2
1414
CPPFLAGS += -DUNO_WIFI_REV2
1515
endif
1616

17+
ifeq ($(NANO_RP2040_CONNECT),1)
18+
CFLAGS += -DNANO_RP2040_CONNECT
19+
CPPFLAGS += -DNANO_RP2040_CONNECT
20+
endif
21+
1722
include $(IDF_PATH)/make/project.mk
1823

1924
firmware: all

arduino/cores/esp32/wiring_digital.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ void pinMode(uint32_t pin, uint32_t mode)
3333
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT);
3434
gpio_set_pull_mode((gpio_num_t)pin, GPIO_FLOATING);
3535
break;
36+
37+
case INPUT_PULLUP:
38+
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT);
39+
gpio_set_pull_mode((gpio_num_t)pin, GPIO_PULLUP_ONLY);
40+
break;
3641
}
3742

3843
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], PIN_FUNC_GPIO);

arduino/cores/esp32/wiring_digital.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ extern "C" {
2929
#define LOW 0x00
3030
#define HIGH 0x01
3131

32-
#define INPUT 0x00
33-
#define OUTPUT 0x01
32+
#define INPUT 0x00
33+
#define OUTPUT 0x01
34+
#define INPUT_PULLUP 0x02
3435

3536
extern void pinMode(uint32_t pin, uint32_t mode);
3637

main/CommandHandler.cpp

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#include "esp_log.h"
3838

39-
const char FIRMWARE_VERSION[6] = "1.4.4";
39+
const char FIRMWARE_VERSION[6] = "1.4.5";
4040

4141
/*IPAddress*/uint32_t resolvedHostname;
4242

@@ -1180,6 +1180,43 @@ int setAnalogWrite(const uint8_t command[], uint8_t response[])
11801180
return 6;
11811181
}
11821182

1183+
int getDigitalRead(const uint8_t command[], uint8_t response[])
1184+
{
1185+
uint8_t pin = command[4];
1186+
1187+
int const pin_status = digitalRead(pin);
1188+
1189+
response[2] = 1; // number of parameters
1190+
response[3] = 1; // parameter 1 length
1191+
response[4] = (uint8_t)pin_status;
1192+
1193+
return 6;
1194+
}
1195+
1196+
extern "C" {
1197+
#include <driver/adc.h>
1198+
}
1199+
1200+
int getAnalogRead(const uint8_t command[], uint8_t response[])
1201+
{
1202+
uint8_t adc_channel = command[4];
1203+
1204+
/* Initialize the ADC. */
1205+
adc_gpio_init(ADC_UNIT_1, (adc_channel_t)adc_channel);
1206+
/* Set maximum analog bit-width = 12 bit. */
1207+
adc1_config_width(ADC_WIDTH_BIT_12);
1208+
/* Configure channel attenuation. */
1209+
adc1_config_channel_atten((adc1_channel_t)adc_channel, ADC_ATTEN_DB_0);
1210+
/* Read the analog value from the pin. */
1211+
uint16_t const adc_raw = adc1_get_raw((adc1_channel_t)adc_channel);
1212+
1213+
response[2] = 1; // number of parameters
1214+
response[3] = sizeof(adc_raw); // parameter 1 length = 2 bytes
1215+
memcpy(&response[4], &adc_raw, sizeof(adc_raw));
1216+
1217+
return 7;
1218+
}
1219+
11831220
int writeFile(const uint8_t command[], uint8_t response[]) {
11841221
char filename[32 + 1];
11851222
size_t len;
@@ -1566,7 +1603,7 @@ const CommandHandlerType commandHandlers[] = {
15661603
setEnt, NULL, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
15671604

15681605
// 0x50 -> 0x5f
1569-
setPinMode, setDigitalWrite, setAnalogWrite, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1606+
setPinMode, setDigitalWrite, setAnalogWrite, getDigitalRead, getAnalogRead, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
15701607

15711608
// 0x60 -> 0x6f
15721609
writeFile, readFile, deleteFile, existsFile, downloadFile, applyOTA, renameFile, downloadOTA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -1578,9 +1615,11 @@ CommandHandlerClass::CommandHandlerClass()
15781615
{
15791616
}
15801617

1618+
static const int GPIO_IRQ = 0;
1619+
15811620
void CommandHandlerClass::begin()
15821621
{
1583-
pinMode(0, OUTPUT);
1622+
pinMode(GPIO_IRQ, OUTPUT);
15841623

15851624
for (int i = 0; i < MAX_SOCKETS; i++) {
15861625
socketTypes[i] = 255;
@@ -1667,9 +1706,9 @@ void CommandHandlerClass::updateGpio0Pin()
16671706
}
16681707

16691708
if (available) {
1670-
digitalWrite(0, HIGH);
1709+
digitalWrite(GPIO_IRQ, HIGH);
16711710
} else {
1672-
digitalWrite(0, LOW);
1711+
digitalWrite(GPIO_IRQ, LOW);
16731712
}
16741713

16751714
vTaskDelay(1);

main/sketch.ino.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ void setup() {
9797
pinMode(15, INPUT);
9898
pinMode(21, INPUT);
9999

100+
#if defined(NANO_RP2040_CONNECT)
101+
pinMode(26, OUTPUT);
102+
pinMode(27, OUTPUT);
103+
digitalWrite(26, HIGH);
104+
digitalWrite(27, HIGH);
105+
#endif
106+
100107
pinMode(5, INPUT);
101108
if (digitalRead(5) == LOW) {
102109
setupBluetooth();
@@ -111,8 +118,10 @@ void setupBluetooth() {
111118
periph_module_enable(PERIPH_UART1_MODULE);
112119
periph_module_enable(PERIPH_UHCI0_MODULE);
113120

114-
#ifdef UNO_WIFI_REV2
121+
#if defined(UNO_WIFI_REV2)
115122
uart_set_pin(UART_NUM_1, 1, 3, 33, 0); // TX, RX, RTS, CTS
123+
#elif defined(NANO_RP2040_CONNECT)
124+
uart_set_pin(UART_NUM_1, 1, 3, 33, 12); // TX, RX, RTS, CTS
116125
#else
117126
uart_set_pin(UART_NUM_1, 23, 12, 18, 5);
118127
#endif
@@ -121,7 +130,7 @@ void setupBluetooth() {
121130
esp_bt_controller_config_t btControllerConfig = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
122131

123132
btControllerConfig.hci_uart_no = UART_NUM_1;
124-
#ifdef UNO_WIFI_REV2
133+
#if defined(UNO_WIFI_REV2) || defined(NANO_RP2040_CONNECT)
125134
btControllerConfig.hci_uart_baudrate = 115200;
126135
#else
127136
btControllerConfig.hci_uart_baudrate = 912600;

0 commit comments

Comments
 (0)