10#define ONEWIRE_CMD_SEARCH_ROM 0xF0U
11#define ONEWIRE_CMD_MATCH_ROM 0x55U
12#define ONEWIRE_CMD_SKIP_ROM 0xCCU
32 if ((driver == 0) || (pin_config == 0)) {
36 driver->
pin = *pin_config;
52 bool presence_detected =
false;
67 return presence_detected;
91 bool bit_value =
false;
110 uint8_t bit_index = 0U;
116 for (bit_index = 0U; bit_index < 8U; ++bit_index) {
124 uint8_t bit_index = 0U;
131 for (bit_index = 0U; bit_index < 8U; ++bit_index) {
133 value |= (uint8_t) (1U << bit_index);
151 uint8_t byte_index = 0U;
153 if ((driver == 0) || (rom_code == 0) || !driver->
initialized) {
168 uint8_t device_count = 0U;
170 uint8_t last_discrepancy = 0U;
171 bool last_device_flag =
false;
173 if ((driver == 0) || (rom_codes == 0) || (max_devices == 0U) || !driver->
initialized) {
177 while (!last_device_flag && (device_count < max_devices)) {
178 uint8_t rom_byte_index = 0U;
179 uint8_t rom_bit_mask = 0x01U;
180 uint8_t bit_number = 1U;
181 uint8_t last_zero = 0U;
182 bool search_failed =
false;
190 while (bit_number <= 64U) {
193 bool search_direction =
false;
195 if (id_bit && cmp_id_bit) {
196 search_failed =
true;
200 if (id_bit != cmp_id_bit) {
201 search_direction = id_bit;
203 if (bit_number < last_discrepancy) {
204 search_direction = ((current_rom[rom_byte_index] & rom_bit_mask) != 0U);
206 search_direction = (bit_number == last_discrepancy);
209 if (!search_direction) {
210 last_zero = bit_number;
214 if (search_direction) {
215 current_rom[rom_byte_index] |= rom_bit_mask;
217 current_rom[rom_byte_index] &= (uint8_t) ~rom_bit_mask;
224 if (rom_bit_mask == 0U) {
226 rom_bit_mask = 0x01U;
230 if (search_failed || (bit_number <= 64U)) {
235 rom_codes[device_count][rom_byte_index] = current_rom[rom_byte_index];
239 last_discrepancy = last_zero;
240 if (last_discrepancy == 0U) {
241 last_device_flag =
true;
void driver_delay_us(uint32_t microseconds)
Realiza una espera bloqueante expresada en microsegundos.
void driver_delay_init(void)
Inicializa la base de tiempos usada por los delays bloqueantes.
Interfaz comun de delays bloqueantes basada en stopwatch de LPCOpen.
bool onewire_init(onewire_driver_t *driver, const onewire_pin_config_t *pin_config)
Inicializa un bus 1-Wire sobre el pin indicado.
static void onewire_release_line(const onewire_driver_t *driver)
static void onewire_drive_low(const onewire_driver_t *driver)
#define ONEWIRE_CMD_SKIP_ROM
#define ONEWIRE_CMD_MATCH_ROM
void onewire_write_byte(const onewire_driver_t *driver, uint8_t value)
Escribe un byte en el bus 1-Wire.
bool onewire_reset(const onewire_driver_t *driver)
Emite un reset 1-Wire y detecta presencia de dispositivos.
uint8_t onewire_search_roms(const onewire_driver_t *driver, uint8_t rom_codes[][ONEWIRE_ROM_CODE_SIZE], uint8_t max_devices)
Busca dispositivos presentes en el bus mediante el comando Search ROM.
uint8_t onewire_read_byte(const onewire_driver_t *driver)
Lee un byte desde el bus 1-Wire.
void onewire_skip_rom(const onewire_driver_t *driver)
Emite el comando Skip ROM sobre el bus.
static bool onewire_read_line(const onewire_driver_t *driver)
void onewire_write_bit(const onewire_driver_t *driver, bool bit_value)
Escribe un bit en el bus 1-Wire.
bool onewire_read_bit(const onewire_driver_t *driver)
Lee un bit desde el bus 1-Wire.
#define ONEWIRE_CMD_SEARCH_ROM
void onewire_match_rom(const onewire_driver_t *driver, const uint8_t rom_code[ONEWIRE_ROM_CODE_SIZE])
Selecciona un dispositivo concreto por su codigo ROM.
Interfaz del driver para bus 1-Wire por bit-banging.
#define ONEWIRE_ROM_CODE_SIZE
Tamano del codigo ROM de un dispositivo 1-Wire.
Estado del driver 1-Wire para un bus individual.
Configuracion fisica del pin usado por el bus 1-Wire.