13 #include "pins_arduino.h" 27 #ifndef ONEWIRE_SEARCH 28 #define ONEWIRE_SEARCH 1 41 #ifndef ONEWIRE_CRC8_TABLE 42 #define ONEWIRE_CRC8_TABLE \ 50 #define ONEWIRE_CRC16 \ 60 #define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin))) 61 #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 62 #define IO_REG_TYPE uint8_t 63 #define IO_REG_ASM asm("r30") 64 #define DIRECT_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0) 65 #define DIRECT_MODE_INPUT(base, mask) ((*((base) + 1)) &= ~(mask)) 66 #define DIRECT_MODE_OUTPUT(base, mask) ((*((base) + 1)) |= (mask)) 67 #define DIRECT_WRITE_LOW(base, mask) ((*((base) + 2)) &= ~(mask)) 68 #define DIRECT_WRITE_HIGH(base, mask) ((*((base) + 2)) |= (mask)) 70 #elif defined(__MK20DX128__) 71 #define PIN_TO_BASEREG(pin) (portOutputRegister(pin)) 72 #define PIN_TO_BITMASK(pin) (1) 73 #define IO_REG_TYPE uint8_t 75 #define DIRECT_READ(base, mask) (*((base) + 512)) 76 #define DIRECT_MODE_INPUT(base, mask) (*((base) + 640) = 0) 77 #define DIRECT_MODE_OUTPUT(base, mask) (*((base) + 640) = 1) 78 #define DIRECT_WRITE_LOW(base, mask) (*((base) + 256) = 1) 79 #define DIRECT_WRITE_HIGH(base, mask) (*((base) + 128) = 1) 81 #elif defined(__SAM3X8E__) 86 #define PIN_TO_BASEREG(pin) (&(digitalPinToPort(pin)->PIO_PER)) 87 #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 88 #define IO_REG_TYPE uint32_t 90 #define DIRECT_READ(base, mask) (((*((base) + 15)) & (mask)) ? 1 : 0) 91 #define DIRECT_MODE_INPUT(base, mask) ((*((base) + 5)) = (mask)) 92 #define DIRECT_MODE_OUTPUT(base, mask) ((*((base) + 4)) = (mask)) 93 #define DIRECT_WRITE_LOW(base, mask) ((*((base) + 13)) = (mask)) 94 #define DIRECT_WRITE_HIGH(base, mask) ((*((base) + 12)) = (mask)) 99 #define pgm_read_byte(addr) (*(const uint8_t *)(addr)) 102 #elif defined(__PIC32MX__) 103 #define PIN_TO_BASEREG(pin) (portModeRegister(digitalPinToPort(pin))) 104 #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 105 #define IO_REG_TYPE uint32_t 107 #define DIRECT_READ(base, mask) \ 108 (((*(base + 4)) & (mask)) ? 1 : 0) // PORTX + 0x10 109 #define DIRECT_MODE_INPUT(base, mask) \ 110 ((*(base + 2)) = (mask)) // TRISXSET + 112 #define DIRECT_MODE_OUTPUT(base, mask) \ 113 ((*(base + 1)) = (mask)) // TRISXCLR + 0x04 114 #define DIRECT_WRITE_LOW(base, mask) \ 115 ((*(base + 8 + 1)) = (mask)) // LATXCLR + 0x24 116 #define DIRECT_WRITE_HIGH(base, mask) \ 117 ((*(base + 8 + 2)) = (mask)) // LATXSET + 0x28 119 #elif defined(ARDUINO_ARCH_ESP8266) 120 #define PIN_TO_BASEREG(pin) ((volatile uint32_t *)GPO) 121 #define PIN_TO_BITMASK(pin) (1 << pin) 122 #define IO_REG_TYPE uint32_t 124 #define DIRECT_READ(base, mask) ((GPI & (mask)) ? 1 : 0) // GPIO_IN_ADDRESS 125 #define DIRECT_MODE_INPUT(base, mask) \ 126 (GPE &= ~(mask)) // GPIO_ENABLE_W1TC_ADDRESS 127 #define DIRECT_MODE_OUTPUT(base, mask) \ 128 (GPE |= (mask)) // GPIO_ENABLE_W1TS_ADDRESS 129 #define DIRECT_WRITE_LOW(base, mask) (GPOC = (mask)) // GPIO_OUT_W1TC_ADDRESS 130 #define DIRECT_WRITE_HIGH(base, mask) (GPOS = (mask)) // GPIO_OUT_W1TS_ADDRESS 132 #elif defined(__SAMD21G18A__) || defined(__SAMD21E18A__) 133 #define PIN_TO_BASEREG(pin) portModeRegister(digitalPinToPort(pin)) 134 #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 135 #define IO_REG_TYPE uint32_t 137 #define DIRECT_READ(base, mask) (((*((base) + 8)) & (mask)) ? 1 : 0) 138 #define DIRECT_MODE_INPUT(base, mask) ((*((base) + 1)) = (mask)) 139 #define DIRECT_MODE_OUTPUT(base, mask) ((*((base) + 2)) = (mask)) 140 #define DIRECT_WRITE_LOW(base, mask) ((*((base) + 5)) = (mask)) 141 #define DIRECT_WRITE_HIGH(base, mask) ((*((base) + 6)) = (mask)) 143 #elif defined(__SAMD51__) 144 #define PIN_TO_BASEREG(pin) portModeRegister(digitalPinToPort(pin)) 145 #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 146 #define IO_REG_TYPE uint32_t 148 #define DIRECT_READ(base, mask) (((*((base) + 8)) & (mask)) ? 1 : 0) // IN 149 #define DIRECT_MODE_INPUT(base, mask) ((*((base) + 1)) = (mask)) // DIRCLR 150 #define DIRECT_MODE_OUTPUT(base, mask) ((*((base) + 2)) = (mask)) // DIRSET 151 #define DIRECT_WRITE_LOW(base, mask) ((*((base) + 5)) = (mask)) // OUTCLR 152 #define DIRECT_WRITE_HIGH(base, mask) ((*((base) + 6)) = (mask)) 154 #elif defined(ARDUINO_NRF52_ADAFRUIT) 155 #define PIN_TO_BASEREG(pin) (0) 156 #define PIN_TO_BITMASK(pin) digitalPinToPinName(pin) 157 #define IO_REG_TYPE uint32_t 159 #define DIRECT_READ(base, pin) nrf_gpio_pin_read(pin) 160 #define DIRECT_WRITE_LOW(base, pin) nrf_gpio_pin_clear(pin) 161 #define DIRECT_WRITE_HIGH(base, pin) nrf_gpio_pin_set(pin) 162 #define DIRECT_MODE_INPUT(base, pin) \ 163 nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL) 164 #define DIRECT_MODE_OUTPUT(base, pin) nrf_gpio_cfg_output(pin) 167 #error "Please define I/O register types here" 176 volatile IO_REG_TYPE *baseReg;
180 unsigned char ROM_NO[8];
181 uint8_t LastDiscrepancy;
182 uint8_t LastFamilyDiscrepancy;
183 uint8_t LastDeviceFlag;
205 void select(
const uint8_t rom[8]);
220 void write(uint8_t v, uint8_t power = 0);
228 void write_bytes(
const uint8_t *buf, uint16_t count,
bool power = 0);
241 void read_bytes(uint8_t *buf, uint16_t count);
289 uint8_t
search(uint8_t *newAddr);
300 static uint8_t
crc8(
const uint8_t *addr, uint8_t len);
325 static bool check_crc16(
const uint8_t *input, uint16_t len,
326 const uint8_t *inverted_crc, uint16_t crc = 0);
341 static uint16_t
crc16(
const uint8_t *input, uint16_t len, uint16_t crc = 0);
void select(const uint8_t rom[8])
Issue a 1-Wire rom select command, you do the reset first.
Definition: OneWire.cpp:271
static bool check_crc16(const uint8_t *input, uint16_t len, const uint8_t *inverted_crc, uint16_t crc=0)
Compute the 1-Wire CRC16 and compare it against the received CRC. Example usage (reading a DS2408): /...
Definition: OneWire.cpp:519
void write_bit(uint8_t v)
Write a bit. The bus is always left powered at the end, see note in write() about that...
Definition: OneWire.cpp:172
void write_bytes(const uint8_t *buf, uint16_t count, bool power=0)
Writes bytes.
Definition: OneWire.cpp:237
static uint8_t crc8(const uint8_t *addr, uint8_t len)
Compute a Dallas Semiconductor 8 bit CRC, these are used in the ROM and scratchpad registers...
Definition: OneWire.cpp:488
uint8_t read_bit(void)
Read a bit.
Definition: OneWire.cpp:199
uint8_t reset(void)
Perform a 1-Wire reset cycle. Returns 1 if a device responds with a presence pulse. Returns 0 if there is no device or the bus is shorted or otherwise held low for more than 250uS.
Definition: OneWire.cpp:138
void skip(void)
Issue a 1-Wire rom skip command, to address all on bus.
Definition: OneWire.cpp:283
uint8_t read(void)
Read a byte.
Definition: OneWire.cpp:252
void depower(void)
Stop forcing power onto the bus. You only need to do this if you used the 'power' flag to write() or ...
Definition: OneWire.cpp:287
void reset_search()
Clear the search state so that if will start from the beginning again.
Definition: OneWire.cpp:299
Stores the state and functions for Max31850 OneWire.
Definition: OneWire.h:173
void target_search(uint8_t family_code)
Setup the search to find the device type 'family_code' on the next call to search(*newAddr) if it is ...
Definition: OneWire.cpp:314
uint8_t search(uint8_t *newAddr)
Look for the next device. Returns 1 if a new address has been returned. A zero might mean that the bu...
Definition: OneWire.cpp:340
OneWire(uint8_t pin)
OneWire constructor.
Definition: OneWire.cpp:123
static uint16_t crc16(const uint8_t *input, uint16_t len, uint16_t crc=0)
Compute a Dallas Semiconductor 16 bit CRC. This is required to check the integrity of data received f...
Definition: OneWire.cpp:525
void read_bytes(uint8_t *buf, uint16_t count)
Reads bytes.
Definition: OneWire.cpp:263
void write(uint8_t v, uint8_t power=0)
Write a byte. If 'power' is one then the wire is held high at the end for parasitically powered devic...
Definition: OneWire.cpp:223