/*
 *    Simple onewire library implementation
 *
 *    Copyright (C) 2006 Allied Telesis Labs
 *
 * Based on code by:
 * (c) by Alexander Neumann <alexander@bumpern.de>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License (either version 2 or
 * version 3) as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * For more information on the GPL, please go to:
 * http://www.gnu.org/copyleft/gpl.html
 */

#ifndef _W1_H_
#define _W1_H_

/* rom commands */
#define OW_ROM_SEARCH_ROM		0xF0
#define OW_ROM_READ_ROM			0x33
#define OW_ROM_MATCH_ROM		0x55
#define OW_ROM_SKIP_ROM			0xCC
#define OW_ROM_ALARM_SEARCH		0xEC

/* data commands */
#define OW_FUNC_READ_MEMORY		0xF0
#define OW_FUNC_READ_STATUS		0xAA
#define OW_FUNC_READ_DATA_CRC		0xC3

/* master configuration */
struct w1_master {
	int num_bus;
	void (*config_input)(int bus);
	void (*config_output)(int bus);
	void (*config_pullup)(int bus);
	void (*drive_low)(int bus);
	void (*drive_high)(int bus);
	int (*read_input)(int bus);
};

/* onewire API */
void w1_register_master(struct w1_master *master);
int w1_get_bus_num(void);
void w1_set_bus(int bus);
int w1_eeprom_read(uint8_t *data, int offset, int length);

/* onewire lowlevel API */
uint8_t w1_reset(void);
void w1_write_0(void);
void w1_write_1(void);
void w1_write(uint8_t value);
void w1_write_byte(uint8_t value);
uint8_t w1_read(void);
uint8_t w1_read_byte(void);

#endif /* _W1_H_ */
