diff --git a/_Boards/raspberry_pico2.png b/_Boards/raspberry_pico2.png new file mode 100644 index 00000000..69f7d1e3 Binary files /dev/null and b/_Boards/raspberry_pico2.png differ diff --git a/_Boards/raspberrypi_pico2.board.json b/_Boards/raspberrypi_pico2.board.json new file mode 100644 index 00000000..08c444d0 --- /dev/null +++ b/_Boards/raspberrypi_pico2.board.json @@ -0,0 +1,202 @@ +{ + "$schema": "./mfboard.schema.json", + "UsbDriveSettings": { + "VolumeLabel": "RP2350", + "VerificationFileName": "INFO_UF2.TXT" + }, + "Connection": { + "ConnectionDelay": 1250, + "DelayAfterFirmwareUpdate": 1250, + "DtrEnable": true, + "EEPROMSize": 1496, + "ExtraConnectionRetry": false, + "ForceResetOnFirmwareUpdate": true, + "MessageSize": 96 + }, + "HardwareIds": ["^VID_2E8A&PID_F00A"], + "Info": { + "CanInstallFirmware": true, + "CanResetBoard": true, + "FirmwareBaseName": "mobiflight_raspberrypico2", + "FirmwareExtension": "uf2", + "FriendlyName": "Raspberry Pico2", + "LatestFirmwareVersion": "0.0.1", + "MobiFlightType": "MobiFlight RaspiPico2", + "ResetFirmwareFile": "reset.raspberry_pico2_1_0_2.uf2" + }, + "ModuleLimits": { + "MaxAnalogInputs": 3, + "MaxInputShifters": 6, + "MaxButtons": 26, + "MaxEncoders": 13, + "MaxLcdI2C": 2, + "MaxLedSegments": 6, + "MaxOutputs": 26, + "MaxServos": 8, + "MaxShifters": 6, + "MaxSteppers": 6, + "MaxInputMultiplexer": 6, + "MaxCustomDevices": 0 + }, + "Pins": [ + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 0 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 1 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 2 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 3 + }, + { + "isAnalog": false, + "isI2C": true, + "isPWM": true, + "Pin": 4 + }, + { + "isAnalog": false, + "isI2C": true, + "isPWM": true, + "Pin": 5 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 6 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 7 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 8 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 9 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 10 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 11 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 12 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 13 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 14 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 15 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": false, + "Pin": 16 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": false, + "Pin": 17 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": false, + "Pin": 18 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": false, + "Pin": 19 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": false, + "Pin": 20 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": false, + "Pin": 21 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": false, + "Pin": 22 + }, + { + "isAnalog": true, + "isI2C": false, + "isPWM": false, + "Name": "A0", + "Pin": 26 + }, + { + "isAnalog": true, + "isI2C": false, + "isPWM": false, + "Name": "A1", + "Pin": 27 + }, + { + "isAnalog": true, + "isI2C": false, + "isPWM": false, + "Name": "A2", + "Pin": 28 + } + ] +} diff --git a/_Boards/reset.raspberry_pico2_1_0_2.uf2 b/_Boards/reset.raspberry_pico2_1_0_2.uf2 new file mode 100644 index 00000000..d6bf1b4e Binary files /dev/null and b/_Boards/reset.raspberry_pico2_1_0_2.uf2 differ diff --git a/platformio.ini b/platformio.ini index 53af38cf..e77f784b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -25,7 +25,6 @@ lib_deps = custom_lib_deps_Atmel = arduino-libraries/Servo @ 1.1.8 custom_lib_deps_Pico = - ricaun/ArduinoUniqueID @ ^1.3.0 build_flags = -DMF_REDUCE_FUNCT_LEDCONTROL -DMAXCALLBACKS=35 @@ -187,3 +186,34 @@ lib_deps = monitor_speed = 115200 extra_scripts = ${env.extra_scripts} + +; Build settings for the Raspberry Pico2 original +[env:mobiflight_raspberrypico2] +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = rpipico2 +framework = arduino +board_build.core = earlephilhower ; select new core +board_build.filesystem_size = 0M ; configure filesystem size. Default 0 Mbyte. +lib_ldf_mode = chain+ +upload_protocol = mbed ; for debugging upoading can be changed to picoprobe +;debug_tool = picoprobe ; and uncomment this for debugging w/ picoprobe +;board_build.arduino.earlephilhower.usb_manufacturer = Custom Manufacturer +;board_build.arduino.earlephilhower.usb_product = Ultra Cool Product +;board_build.arduino.earlephilhower.usb_vid = 0x2E8A +board_build.arduino.earlephilhower.usb_pid = 0xF00A +build_flags = + ${env.build_flags} + '-DMOBIFLIGHT_TYPE="MobiFlight RaspiPico2"' + '-DMOBIFLIGHT_NAME="MobiFlight RaspiPico2"' + -DMEMLEN_CONFIG=1496 ; max. size for config which wil be stored in EEPROM + -DMEMLEN_NAMES_BUFFER=1000 ; max. size for configBuffer, contains only names from inputs + -DMF_MAX_DEVICEMEM=1000 ; max. memory size for devices + -I./_Boards/RaspberryPi/Pico +build_src_filter = + ${env.build_src_filter} +lib_deps = + ${env.lib_deps} + ${env.custom_lib_deps_Pico} +monitor_speed = 115200 +extra_scripts = + ${env.extra_scripts} diff --git a/src/Config.cpp b/src/Config.cpp index b6cfae44..670ca2ee 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -11,9 +11,12 @@ #include "Button.h" #include "Encoder.h" #include "Output.h" -#if !defined(ARDUINO_ARCH_AVR) +#if !defined(ARDUINO_ARCH_AVR) && !defined(ARDUINO_ARCH_RP2040) #include "ArduinoUniqueID.h" #endif +#ifdef ARDUINO_ARCH_RP2040 +#include +#endif #ifdef MF_ANALOG_SUPPORT #include "Analog.h" @@ -69,10 +72,13 @@ const uint8_t MEM_OFFSET_SERIAL = MEM_OFFSET_NAME + MEM_LEN_NAME; const uint8_t MEM_LEN_SERIAL = 11; const uint8_t MEM_OFFSET_CONFIG = MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL; +// 3 characters for "SN-", n characters for uniqueID plus terminating NULL #ifdef ARDUINO_ARCH_AVR -char serial[11]; // 3 characters for "SN-",7 characters for "xyz-zyx" plus terminating NULL +char serial[11] = {0}; +#elif ARDUINO_ARCH_RP2040 +char serial[3 + (PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2) + 1] = {0}; #else -char serial[3 + UniqueIDsize * 2 + 1]; // 3 characters for "SN-", UniqueID as HEX String, terminating NULL +char serial[3 + UniqueIDsize * 2 + 1] = {0}; #endif char name[MEM_LEN_NAME] = MOBIFLIGHT_NAME; const int MEM_LEN_CONFIG = MEMLEN_CONFIG; @@ -654,11 +660,7 @@ void generateRandomSerial() // and getting the command to send the info's to the connector is always the same. // additional double check if it's really a new board, should reduce Jaimes problem randomSeed(millis()); - serial[0] = 'S'; - serial[1] = 'N'; - serial[2] = '-'; - serial[6] = '-'; - serial[10] = 0x00; + strcpy(serial, "SN-000-000"); uint16_t randomSerial = random(4095); for (uint8_t i = 3; i < 6; i++) { serial[i] = (randomSerial & 0x000F) + 48; // convert from 4bit to HEX string @@ -676,14 +678,16 @@ void generateRandomSerial() cmdMessenger.sendCmd(kDebug, F("Serial number generated")); #endif } -#endif - -#if !defined(ARDUINO_ARCH_AVR) +#elif ARDUINO_ARCH_RP2040 +void readUniqueSerial() +{ + strcpy(serial, "SN-"); + pico_get_unique_board_id_string(serial + 3, sizeof(serial) - 3); +} +#else void readUniqueSerial() { - serial[0] = 'S'; - serial[1] = 'N'; - serial[2] = '-'; + strcpy(serial, "SN-"); for (size_t i = 0; i < UniqueIDsize; i++) { serial[3 + i * 2] = (UniqueID[i] >> 4) + 48; if (serial[3 + i * 2] >= 58) serial[3 + i * 2] += 7; diff --git a/src/MF_InputShifter/MFInputShifter.cpp b/src/MF_InputShifter/MFInputShifter.cpp index d8bdfb9c..641278b4 100644 --- a/src/MF_InputShifter/MFInputShifter.cpp +++ b/src/MF_InputShifter/MFInputShifter.cpp @@ -5,6 +5,7 @@ // #include "MFInputShifter.h" +#include "MFShiftData.h" #include "allocateMem.h" inputShifterEvent MFInputShifter::_inputHandler = NULL; @@ -61,12 +62,12 @@ void MFInputShifter::poll(uint8_t doTrigger) digitalWrite(_clockPin, HIGH); // Preset clock to retrieve first bit digitalWrite(_latchPin, HIGH); // Disable input latching and enable shifting - // Multiple chained modules are handled one at a time. As shiftIn() keeps getting + // Multiple chained modules are handled one at a time. As shiftInData() keeps getting // called it will pull in the data from each chained module. for (uint8_t module = 0; module < _moduleCount; module++) { uint8_t currentState; - currentState = shiftIn(_dataPin, _clockPin, MSBFIRST); + currentState = shiftInData(_dataPin, _clockPin, MSBFIRST); // If an input changed on the current module from the last time it was read // then hand it off to figure out which bits specifically changed. diff --git a/src/MF_Modules/MFShiftData.cpp b/src/MF_Modules/MFShiftData.cpp new file mode 100644 index 00000000..53799af6 --- /dev/null +++ b/src/MF_Modules/MFShiftData.cpp @@ -0,0 +1,41 @@ +#include "MFShiftData.h" + +uint8_t shiftInData(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) +{ + uint8_t value = 0; + uint8_t i; + + for (i = 0; i < 8; ++i) { + if (bitOrder == LSBFIRST) + value |= digitalRead(dataPin) << i; + else + value |= digitalRead(dataPin) << (7 - i); + digitalWrite(clockPin, HIGH); + digitalWrite(clockPin, LOW); +#if !defined(ARDUINO_ARCH_AVR) && !defined(ARDUINO_ARCH_RP2040) + delayMicroseconds(1); +#endif + } + return value; +} + +void shiftOutData(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) +{ + uint8_t i; + + for (i = 0; i < 8; i++) { + if (bitOrder == LSBFIRST) { + digitalWrite(dataPin, val & 1); + val >>= 1; + } else { + digitalWrite(dataPin, (val & 128) != 0); + val <<= 1; + } + + digitalWrite(clockPin, HIGH); + digitalWrite(clockPin, LOW); +#if !defined(ARDUINO_ARCH_AVR) && !defined(ARDUINO_ARCH_RP2040) + delayMicroseconds(1); +#endif + } +} diff --git a/src/MF_Modules/MFShiftData.h b/src/MF_Modules/MFShiftData.h new file mode 100644 index 00000000..bfe5644a --- /dev/null +++ b/src/MF_Modules/MFShiftData.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +uint8_t shiftInData(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); +void shiftOutData(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); diff --git a/src/MF_OutputShifter/MFOutputShifter.cpp b/src/MF_OutputShifter/MFOutputShifter.cpp index 59cf0566..b7e2af7f 100644 --- a/src/MF_OutputShifter/MFOutputShifter.cpp +++ b/src/MF_OutputShifter/MFOutputShifter.cpp @@ -5,6 +5,7 @@ // #include "MFOutputShifter.h" +#include "MFShiftData.h" #include "allocateMem.h" MFOutputShifter::MFOutputShifter() @@ -79,7 +80,7 @@ void MFOutputShifter::update() { digitalWrite(_latchPin, LOW); for (uint8_t i = _moduleCount; i > 0; i--) { - shiftOut(_dataPin, _clockPin, MSBFIRST, _lastState[i - 1]); // LSBFIRST, MSBFIRST, + shiftOutData(_dataPin, _clockPin, MSBFIRST, _lastState[i - 1]); // LSBFIRST, MSBFIRST, } digitalWrite(_latchPin, HIGH); } @@ -89,7 +90,7 @@ void MFOutputShifter::powerSavingMode(bool state) if (state) { digitalWrite(_latchPin, LOW); for (uint8_t i = _moduleCount; i > 0; i--) { - shiftOut(_dataPin, _clockPin, MSBFIRST, 0xFF * MF_LOW); + shiftOutData(_dataPin, _clockPin, MSBFIRST, 0xFF * MF_LOW); } digitalWrite(_latchPin, HIGH); } else {