Revision 168:bfc84ee2839b analog_exp/onewire_hal_bitbang.c

b/analog_exp/onewire_hal_bitbang.c
5 5
#include "board.h"
6 6
#include "onewire_hal.h"
7 7

  
8
#define 1W_LOW()  1W_DDR |=  (1<<1W)
9
#define 1W_HIGH() 1W_DDR &= ~(1<<1W)
10
#define 1W_IN     ((1W_PIN & (1<<1W)) >> 1W)
8
#define ONEWIRE_LOW()  ONEWIRE_DDR |=  (1<<ONEWIRE)
9
#define ONEWIRE_HIGH() ONEWIRE_DDR &= ~(1<<ONEWIRE)
10
#define ONEWIRE_IN     ((ONEWIRE_PIN & (1<<ONEWIRE)) >> ONEWIRE)
11 11

  
12 12
bool onewire_reset(void) {
13 13
    bool presence;
14 14
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
15
        1W_PORT &= ~(1<<1W);
16
        1W_LOW();
15
        ONEWIRE_PORT &= ~(1<<ONEWIRE);
16
        ONEWIRE_LOW();
17 17
        _delay_us(480);
18
        1W_HIGH();
18
        ONEWIRE_HIGH();
19 19
        _delay_us(70);
20
        presence = (1W_IN == 0);
21
        __delay_us(410);
20
        presence = (ONEWIRE_IN == 0);
21
        _delay_us(410);
22 22
    }
23 23
    return presence;
24 24
}
25 25

  
26 26
inline void onewire_tx1(void) {
27 27
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
28
        1W_LOW();
28
        ONEWIRE_LOW();
29 29
        _delay_us(6);
30
        1W_HIGH();
30
        ONEWIRE_HIGH();
31 31
        _delay_us(64);
32 32
    }
33 33
}
34 34

  
35 35
inline void onewire_tx0(void) {
36 36
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
37
        1W_LOW();
37
        ONEWIRE_LOW();
38 38
        _delay_us(60);
39
        1W_HIGH();
39
        ONEWIRE_HIGH();
40 40
        _delay_us(10);
41 41
    }
42 42
}
......
44 44
inline uint8_t onewire_rx(void) {
45 45
    uint8_t bit;
46 46
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
47
        1W_LOW();
47
        ONEWIRE_LOW();
48 48
        _delay_us(6);
49
        1W_HIGH();
49
        ONEWIRE_HIGH();
50 50
        _delay_us(9);
51
        bit = 1W_IN;
51
        bit = ONEWIRE_IN;
52 52
        _delay_us(55);
53 53
    }
54 54
    return bit;

Also available in: Unified diff