diff --git a/README.md b/README.md index f1cb27f..296c708 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Note: **Bold printed devices are feature-complete and were mostly tested with a - documentation, numerous examples, easy interface for hub and sensors ### Recent development (latest at the top): +- fix and clean pin access, fix a portability issue (time_t) - prepare hub for overdrive-mode - added or extended the ds2431, ds2431, ds2501, ds2502 (also tested) - hub is more resilient to odd master-behaviour (lazy timings and subsequent resets are handled now), extended in 0.9.3 and 0.9.4 diff --git a/library.properties b/library.properties index eb7b637..02e06ef 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=OneWireHub -version=0.9.7 +version=0.9.8 author=Ingmar Splitt, orgua, MarkusLange, Shagrat2 maintainer=orgua sentence=OneWire slave device emulator with support for up to 32 simultaneous 1wire devices. diff --git a/src/DS18B20.h b/src/DS18B20.h index a2d28a0..3ba1d95 100644 --- a/src/DS18B20.h +++ b/src/DS18B20.h @@ -17,6 +17,7 @@ class DS18B20 : public OneWireItem bool ds18s20_mode; public: + static constexpr uint8_t family_code = 0x28; // is compatible to ds1822 (0x22) and ds18S20 (0x10) DS18B20(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7); diff --git a/src/OneWireHub.h b/src/OneWireHub.h index 29f5c35..b6a6c8b 100644 --- a/src/OneWireHub.h +++ b/src/OneWireHub.h @@ -35,7 +35,7 @@ using mask_t = uint8_t; #error "Slavelimit is set to zero (why?)" #endif -using time_t = uint32_t; +using timeOW_t = uint32_t; enum class Error : uint8_t { NO_ERROR = 0, @@ -87,24 +87,24 @@ class OneWireHub static constexpr uint16_t ONEWIRE_TIME_WRITE_ZERO_LOW_STD = 35; // // TODO: use #define to switch to overdrive mode - time_t LOOPS_BUS_CHANGE_MAX; - time_t LOOPS_RESET_MIN; - time_t LOOPS_RESET_MAX; - time_t LOOPS_PRESENCE_SAMPLE_MIN; - time_t LOOPS_PRESENCE_LOW_STD; - time_t LOOPS_PRESENCE_LOW_MAX; - time_t LOOPS_PRESENCE_HIGH_MAX; - time_t LOOPS_SLOT_MAX; - time_t LOOPS_READ_ONE_LOW_MAX; - time_t LOOPS_READ_STD; - time_t LOOPS_WRITE_ZERO_LOW_STD; + timeOW_t LOOPS_BUS_CHANGE_MAX; + timeOW_t LOOPS_RESET_MIN; + timeOW_t LOOPS_RESET_MAX; + timeOW_t LOOPS_PRESENCE_SAMPLE_MIN; + timeOW_t LOOPS_PRESENCE_LOW_STD; + timeOW_t LOOPS_PRESENCE_LOW_MAX; + timeOW_t LOOPS_PRESENCE_HIGH_MAX; + timeOW_t LOOPS_SLOT_MAX; + timeOW_t LOOPS_READ_ONE_LOW_MAX; + timeOW_t LOOPS_READ_STD; + timeOW_t LOOPS_WRITE_ZERO_LOW_STD; Error _error; uint8_t _error_cmd; - uint8_t pin_bitMask; - volatile uint8_t *pin_baseReg; + io_reg_t pin_bitMask; + volatile io_reg_t *pin_baseReg; uint8_t extend_timeslot_detection; uint8_t skip_reset_detection; diff --git a/src/platform.h b/src/platform.h index 7875451..4acb7da 100644 --- a/src/platform.h +++ b/src/platform.h @@ -3,6 +3,8 @@ #ifndef ONEWIREHUB_PLATFORM_H #define ONEWIREHUB_PLATFORM_H +// NOTE: added io_reg_t, don't use IO_REG_TYPE and IO_REG_ASM anymore +// TODO: sync with onewireLib // Platform specific I/O definitions #if defined(__AVR__) @@ -15,6 +17,7 @@ #define DIRECT_MODE_OUTPUT(base, mask) ((*((base)+1)) |= (mask)) #define DIRECT_WRITE_LOW(base, mask) ((*((base)+2)) &= ~(mask)) #define DIRECT_WRITE_HIGH(base, mask) ((*((base)+2)) |= (mask)) +using io_reg_t = uint8_t; // define special datatype for register-access #elif defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK66FX1M0__) || defined(__MK64FX512__) #define PIN_TO_BASEREG(pin) (portOutputRegister(pin)) @@ -26,6 +29,7 @@ #define DIRECT_MODE_OUTPUT(base, mask) (*((base)+640) = 1) #define DIRECT_WRITE_LOW(base, mask) (*((base)+256) = 1) #define DIRECT_WRITE_HIGH(base, mask) (*((base)+128) = 1) +using io_reg_t = uint8_t; // define special datatype for register-access #elif defined(__MKL26Z64__) #define PIN_TO_BASEREG(pin) (portOutputRegister(pin)) @@ -37,6 +41,7 @@ #define DIRECT_MODE_OUTPUT(base, mask) (*((base)+20) |= (mask)) #define DIRECT_WRITE_LOW(base, mask) (*((base)+8) = (mask)) #define DIRECT_WRITE_HIGH(base, mask) (*((base)+4) = (mask)) +using io_reg_t = uint8_t; // define special datatype for register-access #elif defined(__SAM3X8E__) // Arduino 1.5.1 may have a bug in delayMicroseconds() on Arduino Due. @@ -58,6 +63,7 @@ #ifndef pgm_read_byte #define pgm_read_byte(address) (*(const uint8_t *)(address)) #endif +using io_reg_t = uint32_t; // define special datatype for register-access #elif defined(__PIC32MX__) #define PIN_TO_BASEREG(pin) (portModeRegister(digitalPinToPort(pin))) @@ -69,6 +75,7 @@ #define DIRECT_MODE_OUTPUT(base, mask) ((*(base+1)) = (mask)) //TRISXCLR + 0x04 #define DIRECT_WRITE_LOW(base, mask) ((*(base+8+1)) = (mask)) //LATXCLR + 0x24 #define DIRECT_WRITE_HIGH(base, mask) ((*(base+8+2)) = (mask)) //LATXSET + 0x28 +using io_reg_t = uint32_t; // define special datatype for register-access #elif defined(ARDUINO_ARCH_ESP8266) #define PIN_TO_BASEREG(pin) ((volatile uint32_t*) GPO) @@ -80,6 +87,7 @@ #define DIRECT_MODE_OUTPUT(base, mask) (GPE |= (mask)) //GPIO_ENABLE_W1TS_ADDRESS #define DIRECT_WRITE_LOW(base, mask) (GPOC = (mask)) //GPIO_OUT_W1TC_ADDRESS #define DIRECT_WRITE_HIGH(base, mask) (GPOS = (mask)) //GPIO_OUT_W1TS_ADDRESS +using io_reg_t = uint32_t; // define special datatype for register-access #elif defined(__SAMD21G18A__) #define PIN_TO_BASEREG(pin) portModeRegister(digitalPinToPort(pin)) @@ -91,6 +99,7 @@ #define DIRECT_MODE_OUTPUT(base, mask) ((*((base)+2)) = (mask)) #define DIRECT_WRITE_LOW(base, mask) ((*((base)+5)) = (mask)) #define DIRECT_WRITE_HIGH(base, mask) ((*((base)+6)) = (mask)) +using io_reg_t = uint32_t; // define special datatype for register-access #elif defined(RBL_NRF51822) #define PIN_TO_BASEREG(pin) (0) @@ -102,6 +111,7 @@ #define DIRECT_WRITE_HIGH(base, pin) nrf_gpio_pin_set(pin) #define DIRECT_MODE_INPUT(base, pin) nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL) #define DIRECT_MODE_OUTPUT(base, pin) nrf_gpio_cfg_output(pin) +using io_reg_t = uint32_t; // define special datatype for register-access #elif defined(__arc__) /* Arduino101/Genuino101 specifics */ @@ -122,6 +132,7 @@ #define PIN_TO_BITMASK(pin) pin #define IO_REG_TYPE uint32_t #define IO_REG_ASM +using io_reg_t = uint32_t; // define special datatype for register-access static inline __attribute__((always_inline)) IO_REG_TYPE directRead(volatile IO_REG_TYPE *base, IO_REG_TYPE pin) @@ -197,7 +208,7 @@ void directWriteHigh(volatile IO_REG_TYPE *base, IO_REG_TYPE pin) #define DIRECT_MODE_INPUT(base, pin) pinMode(pin,INPUT) #define DIRECT_MODE_OUTPUT(base, pin) pinMode(pin,OUTPUT) #warning "OneWire. Fallback mode. Using API calls for pinMode,digitalRead and digitalWrite. Operation of this library is not guaranteed on this architecture." - +using io_reg_t = uint32_t; // define special datatype for register-access /////////////////////////////////////////// EXTRA PART ///////////////////////////////////////// // this part is loaded if no proper arduino-environment is found (good for external testing)