Subversion Repositories HomeAutomation

Rev

Rev 777 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #ifndef _1wire_h_
  2. #define _1wire_h_
  3.  
  4. #include <inttypes.h>
  5.  
  6. /*******************************************/
  7. /* Hardware connection                     */
  8. /*******************************************/
  9.  
  10. /* Define OW_ONE_BUS if only one 1-Wire-Bus is used
  11.    in the application -> shorter code.
  12.    If not defined make sure to call ow_set_bus() before using
  13.    a bus. Runtime bus-select increases code size by around 300
  14.    bytes so use OW_ONE_BUS if possible */
  15. #define OW_ONE_BUS
  16.  
  17. #ifdef OW_ONE_BUS
  18.  
  19. #ifndef OW_PIN
  20.  
  21. #define OW_PIN  PD6
  22. #define OW_IN   PIND
  23. #define OW_OUT  PORTD
  24. #define OW_DDR  DDRD
  25.  
  26. #endif
  27.  
  28. #define OW_CONF_DELAYOFFSET 0
  29.  
  30. #else
  31. #if F_CPU<1843200
  32.  #warning | experimental multi-bus-mode is not tested for
  33.  #warning | frequencies below 1,84MHz - use OW_ONE_WIRE or
  34.  #warning | faster clock-source (i.e. internal 2MHz R/C-Osc.)
  35. #endif
  36. #define OW_CONF_CYCLESPERACCESS 13
  37. #define OW_CONF_DELAYOFFSET ( (uint16_t)( ((OW_CONF_CYCLESPERACCESS)*1000000L) / F_CPU  ) )
  38. #endif
  39.  
  40. /*******************************************/
  41.  
  42. // #define OW_SHORT_CIRCUIT  0x01
  43.  
  44. #define OW_MATCH_ROM    0x55
  45. #define OW_SKIP_ROM     0xCC
  46. #define OW_SEARCH_ROM   0xF0
  47.  
  48. #define OW_SEARCH_FIRST 0xFF        // start new search
  49. #define OW_PRESENCE_ERR 0xFF
  50. #define OW_DATA_ERR     0xFE
  51. #define OW_LAST_DEVICE  0x00        // last device found
  52. //          0x01 ... 0x40: continue searching
  53.  
  54. // rom-code size including CRC
  55. #define OW_ROMCODE_SIZE 8
  56.  
  57. extern uint8_t ow_reset(void);
  58.  
  59. extern uint8_t ow_bit_io( uint8_t b );
  60. extern uint8_t ow_byte_wr( uint8_t b );
  61. extern uint8_t ow_byte_rd( void );
  62.  
  63. extern uint8_t ow_rom_search( uint8_t diff, uint8_t *id );
  64.  
  65. extern void ow_command( uint8_t command, uint8_t *id );
  66.  
  67. extern void ow_parasite_enable(void);
  68. extern void ow_parasite_disable(void);
  69. extern uint8_t ow_input_pin_state(void);
  70.  
  71. #ifndef OW_ONE_BUS
  72. extern void ow_set_bus(volatile uint8_t* in,
  73.     volatile uint8_t* out,
  74.     volatile uint8_t* ddr,
  75.     uint8_t pin);
  76. #endif
  77.  
  78. #endif
  79.  
  80.