PaulStoffregen / OneWire

Library for Dallas/Maxim 1-Wire Chips
http://www.pjrc.com/teensy/td_libs_OneWire.html
595 stars 390 forks source link

It is desirable to support new AVR controllers. #128

Closed mikrocoder closed 1 year ago

mikrocoder commented 1 year ago

Hi Paul,

would you please include support for the new AVR controllers in your OneWire? For everything concerning the AVR, only this small change is necessary.

#if defined(__AVR__)
    #define PIN_TO_BITMASK(pin)                (digitalPinToBitMask(pin))
    #define IO_REG_TYPE uint8_t
    #define IO_REG_BASE_ATTR asm("r30")
    #define IO_REG_MASK_ATTR

    #if ((__AVR_ARCH__ == 102) || (__AVR_ARCH__ == 103) || (__AVR_ARCH__ == 104))
        #define PIN_TO_BASEREG(pin)             ((volatile uint8_t*)((digitalPinToPort(pin))<<2)) // VPORT Base = VPORT.DIR
        #define DIRECT_READ(base, mask)         ((*((base)+2) & (mask)) ? 1 : 0)                  // VPORT.IN
        #define DIRECT_MODE_INPUT(base, mask)   ((*(base))     &= ~(mask))                        // VPORT.DIR
        #define DIRECT_MODE_OUTPUT(base, mask)  ((*(base))     |=  (mask))                        // VPORT.DIR
        #define DIRECT_WRITE_LOW(base, mask)    ((*((base)+1)) &= ~(mask))                        // VPORT.OUT
        #define DIRECT_WRITE_HIGH(base, mask)   ((*((base)+1)) |=  (mask))                        // VPORT.OUT
    #else
        #define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
        #define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
        #define DIRECT_MODE_INPUT(base, mask)   ((*((base)+1)) &= ~(mask))
        #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))
    #endif

Tested with AVR128DB64, Nano Every (ATmega4809) and Arduino Mega2560. You can use the completely revised and better readable formatted file directly. I have labeled it v2.3.8 for better distinction. OneWire_direct_gpio_v2.3.8.zip It would be very kind of you.

PaulStoffregen commented 1 year ago

This is too soon to ask again. Wait until next week.

mikrocoder commented 1 year ago

I thought I should close the old issue and I should open a new issue with clear wording?

PaulStoffregen commented 1 year ago

Stop right now. Do not write another word, no more replies today. Wait until next week.