Skip to content

Commit

Permalink
Merge pull request #67 from arduino/rp2040_final
Browse files Browse the repository at this point in the history
Adding support for Arduino RP2040 Nano Connect
  • Loading branch information
aentinger authored May 5, 2021
2 parents de7f0db + 8713b09 commit 9b4c435
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
Arduino NINA-W102 firmware ?.?.? - ????.??.??

Arduino NINA-W102 firmware 1.4.4 - 2021.04.13

* Adding support for Arduino RP2040 Nano Connect (#64)

Arduino NINA-W102 firmware 1.4.3 - 2021.01.29

* Do not immediately close connection after 1 failed write (#62)

Arduino NINA-W102 firmware 1.4.2 - 2021.01.28

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.

Arduino NINA-W102 firmware 1.4.1 - 2020.08.17

* Direct download of OTA binary to Nina storage and verifying both CRC and length (#53)
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ CFLAGS += -DUNO_WIFI_REV2
CPPFLAGS += -DUNO_WIFI_REV2
endif

ifeq ($(NANO_RP2040_CONNECT),1)
CFLAGS += -DNANO_RP2040_CONNECT
CPPFLAGS += -DNANO_RP2040_CONNECT
endif

include $(IDF_PATH)/make/project.mk

firmware: all
Expand Down
5 changes: 5 additions & 0 deletions arduino/cores/esp32/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ void pinMode(uint32_t pin, uint32_t mode)
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT);
gpio_set_pull_mode((gpio_num_t)pin, GPIO_FLOATING);
break;

case INPUT_PULLUP:
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT);
gpio_set_pull_mode((gpio_num_t)pin, GPIO_PULLUP_ONLY);
break;
}

PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], PIN_FUNC_GPIO);
Expand Down
5 changes: 3 additions & 2 deletions arduino/cores/esp32/wiring_digital.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ extern "C" {
#define LOW 0x00
#define HIGH 0x01

#define INPUT 0x00
#define OUTPUT 0x01
#define INPUT 0x00
#define OUTPUT 0x01
#define INPUT_PULLUP 0x02

extern void pinMode(uint32_t pin, uint32_t mode);

Expand Down
49 changes: 44 additions & 5 deletions main/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include "esp_log.h"

const char FIRMWARE_VERSION[6] = "1.4.4";
const char FIRMWARE_VERSION[6] = "1.4.5";

/*IPAddress*/uint32_t resolvedHostname;

Expand Down Expand Up @@ -1180,6 +1180,43 @@ int setAnalogWrite(const uint8_t command[], uint8_t response[])
return 6;
}

int getDigitalRead(const uint8_t command[], uint8_t response[])
{
uint8_t pin = command[4];

int const pin_status = digitalRead(pin);

response[2] = 1; // number of parameters
response[3] = 1; // parameter 1 length
response[4] = (uint8_t)pin_status;

return 6;
}

extern "C" {
#include <driver/adc.h>
}

int getAnalogRead(const uint8_t command[], uint8_t response[])
{
uint8_t adc_channel = command[4];

/* Initialize the ADC. */
adc_gpio_init(ADC_UNIT_1, (adc_channel_t)adc_channel);
/* Set maximum analog bit-width = 12 bit. */
adc1_config_width(ADC_WIDTH_BIT_12);
/* Configure channel attenuation. */
adc1_config_channel_atten((adc1_channel_t)adc_channel, ADC_ATTEN_DB_0);
/* Read the analog value from the pin. */
uint16_t const adc_raw = adc1_get_raw((adc1_channel_t)adc_channel);

response[2] = 1; // number of parameters
response[3] = sizeof(adc_raw); // parameter 1 length = 2 bytes
memcpy(&response[4], &adc_raw, sizeof(adc_raw));

return 7;
}

int writeFile(const uint8_t command[], uint8_t response[]) {
char filename[32 + 1];
size_t len;
Expand Down Expand Up @@ -1566,7 +1603,7 @@ const CommandHandlerType commandHandlers[] = {
setEnt, NULL, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

// 0x50 -> 0x5f
setPinMode, setDigitalWrite, setAnalogWrite, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
setPinMode, setDigitalWrite, setAnalogWrite, getDigitalRead, getAnalogRead, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

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

static const int GPIO_IRQ = 0;

void CommandHandlerClass::begin()
{
pinMode(0, OUTPUT);
pinMode(GPIO_IRQ, OUTPUT);

for (int i = 0; i < MAX_SOCKETS; i++) {
socketTypes[i] = 255;
Expand Down Expand Up @@ -1667,9 +1706,9 @@ void CommandHandlerClass::updateGpio0Pin()
}

if (available) {
digitalWrite(0, HIGH);
digitalWrite(GPIO_IRQ, HIGH);
} else {
digitalWrite(0, LOW);
digitalWrite(GPIO_IRQ, LOW);
}

vTaskDelay(1);
Expand Down
13 changes: 11 additions & 2 deletions main/sketch.ino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ void setup() {
pinMode(15, INPUT);
pinMode(21, INPUT);

#if defined(NANO_RP2040_CONNECT)
pinMode(26, OUTPUT);
pinMode(27, OUTPUT);
digitalWrite(26, HIGH);
digitalWrite(27, HIGH);
#endif

pinMode(5, INPUT);
if (digitalRead(5) == LOW) {
setupBluetooth();
Expand All @@ -111,8 +118,10 @@ void setupBluetooth() {
periph_module_enable(PERIPH_UART1_MODULE);
periph_module_enable(PERIPH_UHCI0_MODULE);

#ifdef UNO_WIFI_REV2
#if defined(UNO_WIFI_REV2)
uart_set_pin(UART_NUM_1, 1, 3, 33, 0); // TX, RX, RTS, CTS
#elif defined(NANO_RP2040_CONNECT)
uart_set_pin(UART_NUM_1, 1, 3, 33, 12); // TX, RX, RTS, CTS
#else
uart_set_pin(UART_NUM_1, 23, 12, 18, 5);
#endif
Expand All @@ -121,7 +130,7 @@ void setupBluetooth() {
esp_bt_controller_config_t btControllerConfig = BT_CONTROLLER_INIT_CONFIG_DEFAULT();

btControllerConfig.hci_uart_no = UART_NUM_1;
#ifdef UNO_WIFI_REV2
#if defined(UNO_WIFI_REV2) || defined(NANO_RP2040_CONNECT)
btControllerConfig.hci_uart_baudrate = 115200;
#else
btControllerConfig.hci_uart_baudrate = 912600;
Expand Down

0 comments on commit 9b4c435

Please sign in to comment.