mirror of
				https://github.com/thelsing/knx.git
				synced 2025-10-26 10:26:25 +01:00 
			
		
		
		
	added support for RP2040 (Raspberry Pi Pico) (#145)
This commit is contained in:
		
							parent
							
								
									6254fc9b67
								
							
						
					
					
						commit
						4f6c837b78
					
				| @ -5,7 +5,7 @@ | |||||||
| 
 | 
 | ||||||
| #if defined(__linux__) | #if defined(__linux__) | ||||||
| #include <arpa/inet.h> | #include <arpa/inet.h> | ||||||
| #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || defined (DeviceFamily_CC13X0) | #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32) || defined (DeviceFamily_CC13X0) | ||||||
| #define getbyte(x,n) (*(((uint8_t*)&(x))+n)) | #define getbyte(x,n) (*(((uint8_t*)&(x))+n)) | ||||||
| #define htons(x)  ( (getbyte(x,0)<<8) | getbyte(x,1) )  | #define htons(x)  ( (getbyte(x,0)<<8) | getbyte(x,1) )  | ||||||
| #define htonl(x) ( (getbyte(x,0)<<24) | (getbyte(x,1)<<16) | (getbyte(x,2)<<8) | getbyte(x,3) ) | #define htonl(x) ( (getbyte(x,0)<<24) | (getbyte(x,1)<<16) | (getbyte(x,2)<<8) | getbyte(x,3) ) | ||||||
| @ -25,7 +25,7 @@ | |||||||
| #define ABS(x)    ((x > 0) ? (x) : (-x)) | #define ABS(x)    ((x > 0) ? (x) : (-x)) | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) | #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32) | ||||||
| #include <Arduino.h> | #include <Arduino.h> | ||||||
| #elif defined(ARDUINO_ARCH_ESP8266) | #elif defined(ARDUINO_ARCH_ESP8266) | ||||||
| #include <Arduino.h> | #include <Arduino.h> | ||||||
|  | |||||||
| @ -20,7 +20,7 @@ enum ComFlag | |||||||
| class GroupObject; | class GroupObject; | ||||||
| 
 | 
 | ||||||
| #ifndef HAS_FUNCTIONAL | #ifndef HAS_FUNCTIONAL | ||||||
| # if defined(__linux__) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32) || defined (ARDUINO_ARCH_SAMD) | # if defined(__linux__) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_RP2040) | ||||||
| #  define HAS_FUNCTIONAL    1 | #  define HAS_FUNCTIONAL    1 | ||||||
| # else | # else | ||||||
| #  define HAS_FUNCTIONAL   0 | #  define HAS_FUNCTIONAL   0 | ||||||
|  | |||||||
| @ -7,7 +7,8 @@ | |||||||
|     #if (defined(ARDUINO_ARCH_STM32) || \ |     #if (defined(ARDUINO_ARCH_STM32) || \ | ||||||
|         defined(ARDUINO_ARCH_ESP32) || \ |         defined(ARDUINO_ARCH_ESP32) || \ | ||||||
|         defined(ARDUINO_ARCH_ESP8266) || \ |         defined(ARDUINO_ARCH_ESP8266) || \ | ||||||
|         defined(ARDUINO_ARCH_SAMD)) |         defined(ARDUINO_ARCH_SAMD) || \ | ||||||
|  | 		defined(ARDUINO_ARCH_RP2040)) | ||||||
| 
 | 
 | ||||||
|         // Only ESP8266 and ESP32 have this define. For all other platforms this is just empty.
 |         // Only ESP8266 and ESP32 have this define. For all other platforms this is just empty.
 | ||||||
|         #ifndef ICACHE_RAM_ATTR |         #ifndef ICACHE_RAM_ATTR | ||||||
| @ -35,6 +36,17 @@ | |||||||
|         #else |         #else | ||||||
|             #error "Mask version not supported on ARDUINO_ARCH_SAMD" |             #error "Mask version not supported on ARDUINO_ARCH_SAMD" | ||||||
|         #endif |         #endif | ||||||
|  |     #elif defined(ARDUINO_ARCH_RP2040) | ||||||
|  |         // predefined global instance for TP or RF or TP/RF coupler
 | ||||||
|  |         #if MASK_VERSION == 0x07B0 | ||||||
|  |             KnxFacade<RP2040ArduinoPlatform, Bau07B0> knx(buttonUp); | ||||||
|  |         #elif MASK_VERSION == 0x27B0 | ||||||
|  |             KnxFacade<RP2040ArduinoPlatform, Bau27B0> knx(buttonUp); | ||||||
|  |         #elif MASK_VERSION == 0x2920 | ||||||
|  |             KnxFacade<RP2040ArduinoPlatform, Bau2920> knx(buttonUp); | ||||||
|  |         #else | ||||||
|  |             #error "Mask version not supported on ARDUINO_ARCH_RP2040" | ||||||
|  |         #endif | ||||||
| 
 | 
 | ||||||
|     #elif defined(ARDUINO_ARCH_ESP8266) |     #elif defined(ARDUINO_ARCH_ESP8266) | ||||||
|         // predefined global instance for TP or IP or TP/IP coupler
 |         // predefined global instance for TP or IP or TP/IP coupler
 | ||||||
|  | |||||||
| @ -17,6 +17,11 @@ | |||||||
|     #ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE |     #ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE | ||||||
|         void buttonUp(); |         void buttonUp(); | ||||||
|     #endif |     #endif | ||||||
|  | #elif defined(ARDUINO_ARCH_RP2040) | ||||||
|  |     #include "rp2040_arduino_platform.h" | ||||||
|  |     #ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE | ||||||
|  |         void buttonUp(); | ||||||
|  |     #endif | ||||||
| #elif defined(ARDUINO_ARCH_ESP8266) | #elif defined(ARDUINO_ARCH_ESP8266) | ||||||
|     #include "esp_platform.h" |     #include "esp_platform.h" | ||||||
|     #ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE |     #ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE | ||||||
| @ -387,6 +392,17 @@ template <class P, class B> class KnxFacade : private SaveRestore | |||||||
|         #else |         #else | ||||||
|             #error "Mask version not supported on ARDUINO_ARCH_SAMD" |             #error "Mask version not supported on ARDUINO_ARCH_SAMD" | ||||||
|         #endif |         #endif | ||||||
|  |     #elif defined(ARDUINO_ARCH_RP2040) | ||||||
|  |         // predefined global instance for TP or RF or TP/RF coupler
 | ||||||
|  |         #if MASK_VERSION == 0x07B0 | ||||||
|  |             extern KnxFacade<RP2040ArduinoPlatform, Bau07B0> knx; | ||||||
|  |         #elif MASK_VERSION == 0x27B0 | ||||||
|  |             extern KnxFacade<RP2040ArduinoPlatform, Bau27B0> knx; | ||||||
|  |         #elif MASK_VERSION == 0x2920 | ||||||
|  |             extern KnxFacade<RP2040ArduinoPlatform, Bau2920> knx; | ||||||
|  |         #else | ||||||
|  |             #error "Mask version not supported on ARDUINO_ARCH_RP2040" | ||||||
|  |         #endif | ||||||
|     #elif defined(ARDUINO_ARCH_ESP8266) |     #elif defined(ARDUINO_ARCH_ESP8266) | ||||||
|         // predefined global instance for TP or IP or TP/IP coupler
 |         // predefined global instance for TP or IP or TP/IP coupler
 | ||||||
|         #if MASK_VERSION == 0x07B0 |         #if MASK_VERSION == 0x07B0 | ||||||
|  | |||||||
							
								
								
									
										82
									
								
								src/rp2040_arduino_platform.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								src/rp2040_arduino_platform.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,82 @@ | |||||||
|  | /*-----------------------------------------------------
 | ||||||
|  | 
 | ||||||
|  | Plattform for Raspberry Pi Pico and other RP2040 boards | ||||||
|  | 
 | ||||||
|  | made to work with arduino-pico - "Raspberry Pi Pico Arduino core, for all RP2040 boards" | ||||||
|  | by Earl E. Philhower III https://github.com/earlephilhower/arduino-pico
 | ||||||
|  | tested with V1.9.1 | ||||||
|  | 
 | ||||||
|  | by SirSydom <com@sirsydom.de> 2021 | ||||||
|  | 
 | ||||||
|  | A maximum of 4kB emulated EEPROM is supported. | ||||||
|  | For more, use or own emulation (maybe with littlefs) | ||||||
|  | 
 | ||||||
|  | ----------------------------------------------------*/ | ||||||
|  | 
 | ||||||
|  | #include "rp2040_arduino_platform.h" | ||||||
|  | 
 | ||||||
|  | #ifdef ARDUINO_ARCH_RP2040 | ||||||
|  | #include <knx/bits.h> | ||||||
|  | 
 | ||||||
|  | #include <Arduino.h> | ||||||
|  | 
 | ||||||
|  | //Pi Pico specific libs
 | ||||||
|  | #include <EEPROM.h>             // EEPROM emulation in flash, part of Earl E Philhowers Pi Pico Arduino support 
 | ||||||
|  | #include <pico/unique_id.h>     // from Pico SDK
 | ||||||
|  | #include <hardware/watchdog.h>  // from Pico SDK
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | RP2040ArduinoPlatform::RP2040ArduinoPlatform() | ||||||
|  | #ifndef KNX_NO_DEFAULT_UART | ||||||
|  |     : ArduinoPlatform(&Serial1) | ||||||
|  | #endif | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | RP2040ArduinoPlatform::RP2040ArduinoPlatform( HardwareSerial* s) : ArduinoPlatform(s) | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint32_t RP2040ArduinoPlatform::uniqueSerialNumber() | ||||||
|  | { | ||||||
|  |     pico_unique_board_id_t id;      // 64Bit unique serial number from the QSPI flash
 | ||||||
|  |     pico_get_unique_board_id(&id); | ||||||
|  | 
 | ||||||
|  |     // use lower 4 byte and convert to unit32_t
 | ||||||
|  |     uint32_t uid = ((uint32_t)(id.id[4]) << 24) | ((uint32_t)(id.id[5]) << 16) | ((uint32_t)(id.id[6]) << 8) | (uint32_t)(id.id[7]); | ||||||
|  | 
 | ||||||
|  |     return uid; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void RP2040ArduinoPlatform::restart() | ||||||
|  | { | ||||||
|  |     println("restart"); | ||||||
|  |     watchdog_reboot(0,0,0); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint16_t size) | ||||||
|  | { | ||||||
|  |     if(size > 4096) | ||||||
|  |     { | ||||||
|  |         println("KNX_FLASH_SIZE to big for EEPROM emulation (max. 4kB)"); | ||||||
|  |         fatalError(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     uint8_t * eepromptr = EEPROM.getDataPtr(); | ||||||
|  | 
 | ||||||
|  |     if(eepromptr == nullptr) | ||||||
|  |     { | ||||||
|  |         EEPROM.begin(4096); | ||||||
|  |         eepromptr = EEPROM.getDataPtr(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     return eepromptr; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void RP2040ArduinoPlatform::commitToEeprom() | ||||||
|  | { | ||||||
|  |     EEPROM.commit(); | ||||||
|  | } | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
							
								
								
									
										21
									
								
								src/rp2040_arduino_platform.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/rp2040_arduino_platform.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | |||||||
|  | #include "arduino_platform.h" | ||||||
|  | 
 | ||||||
|  | #include "Arduino.h" | ||||||
|  | 
 | ||||||
|  | #ifdef ARDUINO_ARCH_RP2040 | ||||||
|  | 
 | ||||||
|  | class RP2040ArduinoPlatform : public ArduinoPlatform | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     RP2040ArduinoPlatform(); | ||||||
|  |     RP2040ArduinoPlatform( HardwareSerial* s); | ||||||
|  | 
 | ||||||
|  |     // unique serial number
 | ||||||
|  |     uint32_t uniqueSerialNumber() override; | ||||||
|  | 
 | ||||||
|  |     void restart(); | ||||||
|  |     uint8_t* getEepromBuffer(uint16_t size); | ||||||
|  |     void commitToEeprom(); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user