Skip to content

Commit

Permalink
fix time_t overload, begin cleaning pin-access
Browse files Browse the repository at this point in the history
  • Loading branch information
orgua committed Sep 26, 2016
1 parent 1d697cf commit be14bab
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/DS18B20.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
28 changes: 14 additions & 14 deletions src/OneWireHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
13 changes: 12 additions & 1 deletion src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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.
Expand All @@ -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)))
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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 */

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit be14bab

Please sign in to comment.