2017-03-28 12:38:43 +02:00
|
|
|
/* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-07-11 08:10:25 +02:00
|
|
|
/** library for 1-wire protocol as master
|
|
|
|
* @file
|
2017-03-28 12:38:43 +02:00
|
|
|
* @author King Kévin <kingkevin@cuvoodoo.info>
|
2018-05-09 21:27:00 +02:00
|
|
|
* @date 2017-2018
|
2017-03-28 12:38:43 +02:00
|
|
|
* @note peripherals used: timer @ref onewire_master_timer, GPIO @ref onewire_master_gpio
|
2017-08-02 13:44:49 +02:00
|
|
|
* @note overdrive mode is not provided
|
2017-03-28 12:38:43 +02:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-05-09 21:27:00 +02:00
|
|
|
/** @defgroup onewire_master_gpio GPIO used for 1-wire signal
|
|
|
|
* @note external pull-up resistor on pin is required (< 5 kOhm)
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define ONEWIRE_MASTER_PORT C /**< GPIO port */
|
|
|
|
#define ONEWIRE_MASTER_PIN 9 /**< GPIO pin */
|
|
|
|
/** @} */
|
|
|
|
|
2017-08-02 13:44:49 +02:00
|
|
|
/** setup 1-wire peripheral
|
|
|
|
*/
|
2018-05-09 21:27:00 +02:00
|
|
|
void onewire_master_setup(void);
|
|
|
|
/** release 1-wire peripheral
|
|
|
|
*/
|
|
|
|
void onewire_master_release(void);
|
2017-03-28 12:38:43 +02:00
|
|
|
/** send reset pulse
|
|
|
|
* @return if slaves have indicated their presence
|
|
|
|
*/
|
|
|
|
bool onewire_master_reset(void);
|
|
|
|
/** compute CRC for 1-Wire
|
|
|
|
* @note this CRC-8 uses normal polynomial 0x31, reverse polynomial 0x8C, start value 0x00
|
|
|
|
* @param[in] data bytes on which to calculate CRC checksum on
|
2017-08-01 19:17:22 +02:00
|
|
|
* @param[in] length number of bytes in data
|
2017-03-28 12:38:43 +02:00
|
|
|
* @return computed CRC checksum
|
|
|
|
*/
|
2017-08-01 19:17:22 +02:00
|
|
|
uint8_t onewire_master_crc(uint8_t* data, uint32_t length);
|
|
|
|
/** send READ ROM command and read ROM code response
|
2017-03-28 12:38:43 +02:00
|
|
|
* @note user needs to send reset pulse before
|
|
|
|
* @return ROM code read
|
|
|
|
*/
|
|
|
|
uint64_t onewire_master_rom_read(void);
|
|
|
|
/** send SEARCH ROM command
|
|
|
|
* @note user needs to send reset pulse before
|
|
|
|
* @warning undefined behaviour if a ROM code different than the last found is provided
|
|
|
|
* @param[in,out] code use 0 to start search ROM code from scratch, or last know value to search next; writes back next ROM code found, or 0 if error occurred
|
|
|
|
* @param[in] alarm search only for ROM codes for slaves with an alarm flag set
|
|
|
|
* @return if an additional slave has been detected
|
2018-06-16 11:05:12 +02:00
|
|
|
* @warning when the code found is 0 it very probably means that the 1-wire line is not pulled up instead of actually having found a slave with ROM code 0
|
2017-03-28 12:38:43 +02:00
|
|
|
*/
|
|
|
|
bool onewire_master_rom_search(uint64_t* code, bool alarm);
|
|
|
|
/** send SKIP ROM command (all slaves on the bus will be selected)
|
|
|
|
* @note user needs to send reset pulse before
|
|
|
|
* @return if operation succeeded
|
|
|
|
*/
|
|
|
|
bool onewire_master_rom_skip(void);
|
|
|
|
/** send MATCH ROM command to select a specific slave
|
|
|
|
* @note user needs to send reset pulse before
|
|
|
|
* @param[in] code ROM code of slave to select
|
|
|
|
* @return if operation succeeded
|
|
|
|
*/
|
|
|
|
bool onewire_master_rom_match(uint64_t code);
|
2018-05-09 21:27:00 +02:00
|
|
|
/** read data byte
|
|
|
|
* @note it is up to the user to send the reset pulse
|
|
|
|
* @param[out] data buffer to save data read
|
|
|
|
* @return if operation succeeded
|
|
|
|
*/
|
|
|
|
bool onewire_master_read_byte(uint8_t* data);
|
|
|
|
/** write data byte
|
|
|
|
* @note it is up to the user to send the reset pulse
|
|
|
|
* @param[in] data byte to write
|
|
|
|
* @return if operation succeeded
|
|
|
|
*/
|
|
|
|
bool onewire_master_write_byte(uint8_t data);
|
2017-03-28 12:38:43 +02:00
|
|
|
/** issue function and read data
|
|
|
|
* @note user needs to send a ROM command before
|
|
|
|
* @param[in] function function command to send
|
|
|
|
* @param[out] data buffer to save read bits (NULL if only the function command should be sent)
|
|
|
|
* @param[in] bits number of bits to read (0 if only the function command should be sent)
|
|
|
|
* @return if operation succeeded
|
|
|
|
*/
|
2017-08-01 19:17:22 +02:00
|
|
|
bool onewire_master_function_read(uint8_t function, uint8_t* data, uint32_t bits);
|
2017-03-28 12:38:43 +02:00
|
|
|
/** issue function and write data
|
|
|
|
* @note user needs to send a ROM command before
|
|
|
|
* @param[in] function function command to send
|
|
|
|
* @param[out] data data to write (NULL if only the function command should be sent)
|
|
|
|
* @param[in] bits number of bits to write (0 if only the function command should be sent)
|
|
|
|
* @return if operation succeeded
|
|
|
|
*/
|
2017-08-01 19:17:22 +02:00
|
|
|
bool onewire_master_function_write(uint8_t function, uint8_t* data, uint32_t bits);
|