unleashed-firmware/lib/one_wire/one_wire_device.c
SG bdba15b366
[FL-2393][FL-2381] iButton, OneWire: move to plain C (#1068)
* iButton: getting started on the worker concept
* Hal delay: added global instructions_per_us variable
* iButton: one wire slave
* iButton: ibutton key setter
* iButton: one wire host, use ibutton_hal
* iButton\RFID: common pulse decoder concept
* iButton: cyfral decoder
* iButton: worker thread concept
* iButton: metakom decoder
* iButton: write key through worker
* iButton: worker mode holder
* iButton: worker improvements
* iButton: Cyfral encoder
* iButton: Metakom encoder
* lib: pulse protocol helpers
* iButton: Metakom decoder
* iButton: Cyfral decoder
* iButton worker: separate modes
* iButton: libs documentation
* HAL: iButton gpio modes
* iButton worker: rename modes file
* iButton worker, hal: move to LL
* iButton CLI: worker for reading and emulation commands
* iButton HAL: correct init and emulation sequence
* iButton cli: moved to plain C
* iButton: move to worker, small step to plain C
* Libs, one wire: move to plain C
* Libs: added forgotten files to compilation
* iButton writer: get rid of manual disable/enable irq
2022-03-29 16:01:56 +03:00

60 lines
1.3 KiB
C

#include <stdlib.h>
#include "maxim_crc.h"
#include "one_wire_device.h"
#include "one_wire_slave.h"
#include "one_wire_slave_i.h"
struct OneWireDevice {
uint8_t id_storage[8];
OneWireSlave* bus;
};
OneWireDevice* onewire_device_alloc(
uint8_t id_1,
uint8_t id_2,
uint8_t id_3,
uint8_t id_4,
uint8_t id_5,
uint8_t id_6,
uint8_t id_7,
uint8_t id_8) {
OneWireDevice* device = malloc(sizeof(OneWireDevice));
device->id_storage[0] = id_1;
device->id_storage[1] = id_2;
device->id_storage[2] = id_3;
device->id_storage[3] = id_4;
device->id_storage[4] = id_5;
device->id_storage[5] = id_6;
device->id_storage[6] = id_7;
device->id_storage[7] = id_8;
device->bus = NULL;
return device;
}
void onewire_device_free(OneWireDevice* device) {
if(device->bus != NULL) {
onewire_slave_detach(device->bus);
}
free(device);
}
void onewire_device_send_id(OneWireDevice* device) {
if(device->bus != NULL) {
onewire_slave_send(device->bus, device->id_storage, 8);
}
}
void onewire_device_attach(OneWireDevice* device, OneWireSlave* bus) {
device->bus = bus;
}
void onewire_device_detach(OneWireDevice* device) {
device->bus = NULL;
}
uint8_t* onewire_device_get_id_p(OneWireDevice* device) {
return device->id_storage;
}