mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
Api Symbols: replace asserts with checks (#3507)
* Api Symbols: replace asserts with checks * Api Symbols: replace asserts with checks part 2 * Update no args function signatures with void, to help compiler to track incorrect usage * More unavoidable void * Update PVS config and code to make it happy * Format sources * nfc: fix checks * dead code cleanup & include fixes Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "maxim_crc.h"
|
||||
#include <furi.h>
|
||||
|
||||
uint8_t maxim_crc8(const uint8_t* data, const uint8_t data_size, const uint8_t crc_init) {
|
||||
furi_check(data);
|
||||
|
||||
uint8_t crc = crc_init;
|
||||
|
||||
for(uint8_t index = 0; index < data_size; ++index) {
|
||||
|
||||
@@ -56,19 +56,26 @@ struct OneWireHost {
|
||||
};
|
||||
|
||||
OneWireHost* onewire_host_alloc(const GpioPin* gpio_pin) {
|
||||
furi_check(gpio_pin);
|
||||
|
||||
OneWireHost* host = malloc(sizeof(OneWireHost));
|
||||
host->gpio_pin = gpio_pin;
|
||||
onewire_host_reset_search(host);
|
||||
onewire_host_set_overdrive(host, false);
|
||||
|
||||
return host;
|
||||
}
|
||||
|
||||
void onewire_host_free(OneWireHost* host) {
|
||||
furi_check(host);
|
||||
|
||||
onewire_host_stop(host);
|
||||
free(host);
|
||||
}
|
||||
|
||||
bool onewire_host_reset(OneWireHost* host) {
|
||||
furi_check(host);
|
||||
|
||||
uint8_t r;
|
||||
uint8_t retries = 125;
|
||||
|
||||
@@ -100,6 +107,8 @@ bool onewire_host_reset(OneWireHost* host) {
|
||||
}
|
||||
|
||||
bool onewire_host_read_bit(OneWireHost* host) {
|
||||
furi_check(host);
|
||||
|
||||
bool result;
|
||||
|
||||
const OneWireHostTimings* timings = host->timings;
|
||||
@@ -120,6 +129,8 @@ bool onewire_host_read_bit(OneWireHost* host) {
|
||||
}
|
||||
|
||||
uint8_t onewire_host_read(OneWireHost* host) {
|
||||
furi_check(host);
|
||||
|
||||
uint8_t result = 0;
|
||||
|
||||
for(uint8_t bitMask = 0x01; bitMask; bitMask <<= 1) {
|
||||
@@ -132,12 +143,17 @@ uint8_t onewire_host_read(OneWireHost* host) {
|
||||
}
|
||||
|
||||
void onewire_host_read_bytes(OneWireHost* host, uint8_t* buffer, uint16_t count) {
|
||||
furi_check(host);
|
||||
furi_check(buffer);
|
||||
|
||||
for(uint16_t i = 0; i < count; i++) {
|
||||
buffer[i] = onewire_host_read(host);
|
||||
}
|
||||
}
|
||||
|
||||
void onewire_host_write_bit(OneWireHost* host, bool value) {
|
||||
furi_check(host);
|
||||
|
||||
const OneWireHostTimings* timings = host->timings;
|
||||
|
||||
if(value) {
|
||||
@@ -160,6 +176,8 @@ void onewire_host_write_bit(OneWireHost* host, bool value) {
|
||||
}
|
||||
|
||||
void onewire_host_write(OneWireHost* host, uint8_t value) {
|
||||
furi_check(host);
|
||||
|
||||
uint8_t bitMask;
|
||||
|
||||
for(bitMask = 0x01; bitMask; bitMask <<= 1) {
|
||||
@@ -168,22 +186,31 @@ void onewire_host_write(OneWireHost* host, uint8_t value) {
|
||||
}
|
||||
|
||||
void onewire_host_write_bytes(OneWireHost* host, const uint8_t* buffer, uint16_t count) {
|
||||
furi_check(host);
|
||||
furi_check(buffer);
|
||||
|
||||
for(uint16_t i = 0; i < count; ++i) {
|
||||
onewire_host_write(host, buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void onewire_host_start(OneWireHost* host) {
|
||||
furi_check(host);
|
||||
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_gpio_init(host->gpio_pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void onewire_host_stop(OneWireHost* host) {
|
||||
furi_check(host);
|
||||
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_gpio_init(host->gpio_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void onewire_host_reset_search(OneWireHost* host) {
|
||||
furi_check(host);
|
||||
|
||||
host->last_discrepancy = 0;
|
||||
host->last_device_flag = false;
|
||||
host->last_family_discrepancy = 0;
|
||||
@@ -194,6 +221,8 @@ void onewire_host_reset_search(OneWireHost* host) {
|
||||
}
|
||||
|
||||
void onewire_host_target_search(OneWireHost* host, uint8_t family_code) {
|
||||
furi_check(host);
|
||||
|
||||
host->saved_rom[0] = family_code;
|
||||
for(uint8_t i = 1; i < 8; i++) host->saved_rom[i] = 0;
|
||||
host->last_discrepancy = 64;
|
||||
@@ -202,6 +231,8 @@ void onewire_host_target_search(OneWireHost* host, uint8_t family_code) {
|
||||
}
|
||||
|
||||
bool onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSearchMode mode) {
|
||||
furi_check(host);
|
||||
|
||||
uint8_t id_bit_number;
|
||||
uint8_t last_zero, rom_byte_number, search_result;
|
||||
uint8_t id_bit, cmp_id_bit;
|
||||
@@ -317,5 +348,7 @@ bool onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSearch
|
||||
}
|
||||
|
||||
void onewire_host_set_overdrive(OneWireHost* host, bool set) {
|
||||
furi_check(host);
|
||||
|
||||
host->timings = set ? &onewire_host_timings_overdrive : &onewire_host_timings_normal;
|
||||
}
|
||||
|
||||
@@ -205,6 +205,7 @@ static void onewire_slave_exti_callback(void* context) {
|
||||
/*********************** PUBLIC ***********************/
|
||||
|
||||
OneWireSlave* onewire_slave_alloc(const GpioPin* gpio_pin) {
|
||||
furi_check(gpio_pin);
|
||||
OneWireSlave* bus = malloc(sizeof(OneWireSlave));
|
||||
|
||||
bus->gpio_pin = gpio_pin;
|
||||
@@ -215,17 +216,23 @@ OneWireSlave* onewire_slave_alloc(const GpioPin* gpio_pin) {
|
||||
}
|
||||
|
||||
void onewire_slave_free(OneWireSlave* bus) {
|
||||
furi_check(bus);
|
||||
|
||||
onewire_slave_stop(bus);
|
||||
free(bus);
|
||||
}
|
||||
|
||||
void onewire_slave_start(OneWireSlave* bus) {
|
||||
furi_check(bus);
|
||||
|
||||
furi_hal_gpio_add_int_callback(bus->gpio_pin, onewire_slave_exti_callback, bus);
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
furi_hal_gpio_init(bus->gpio_pin, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void onewire_slave_stop(OneWireSlave* bus) {
|
||||
furi_check(bus);
|
||||
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
furi_hal_gpio_init(bus->gpio_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_remove_int_callback(bus->gpio_pin);
|
||||
@@ -235,6 +242,7 @@ void onewire_slave_set_reset_callback(
|
||||
OneWireSlave* bus,
|
||||
OneWireSlaveResetCallback callback,
|
||||
void* context) {
|
||||
furi_check(bus);
|
||||
bus->reset_callback = callback;
|
||||
bus->reset_callback_context = context;
|
||||
}
|
||||
@@ -243,6 +251,8 @@ void onewire_slave_set_command_callback(
|
||||
OneWireSlave* bus,
|
||||
OneWireSlaveCommandCallback callback,
|
||||
void* context) {
|
||||
furi_check(bus);
|
||||
|
||||
bus->command_callback = callback;
|
||||
bus->command_callback_context = context;
|
||||
}
|
||||
@@ -251,11 +261,14 @@ void onewire_slave_set_result_callback(
|
||||
OneWireSlave* bus,
|
||||
OneWireSlaveResultCallback result_cb,
|
||||
void* context) {
|
||||
furi_check(bus);
|
||||
bus->result_callback = result_cb;
|
||||
bus->result_callback_context = context;
|
||||
}
|
||||
|
||||
bool onewire_slave_receive_bit(OneWireSlave* bus) {
|
||||
furi_check(bus);
|
||||
|
||||
const OneWireSlaveTimings* timings = bus->timings;
|
||||
// wait while bus is low
|
||||
if(!onewire_slave_wait_while_gpio_is(bus, timings->tslot_max, false)) {
|
||||
@@ -274,6 +287,8 @@ bool onewire_slave_receive_bit(OneWireSlave* bus) {
|
||||
}
|
||||
|
||||
bool onewire_slave_send_bit(OneWireSlave* bus, bool value) {
|
||||
furi_check(bus);
|
||||
|
||||
const OneWireSlaveTimings* timings = bus->timings;
|
||||
// wait while bus is low
|
||||
if(!onewire_slave_wait_while_gpio_is(bus, timings->tslot_max, false)) {
|
||||
@@ -305,6 +320,8 @@ bool onewire_slave_send_bit(OneWireSlave* bus, bool value) {
|
||||
}
|
||||
|
||||
bool onewire_slave_send(OneWireSlave* bus, const uint8_t* data, size_t data_size) {
|
||||
furi_check(bus);
|
||||
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
|
||||
size_t bytes_sent = 0;
|
||||
@@ -324,6 +341,8 @@ bool onewire_slave_send(OneWireSlave* bus, const uint8_t* data, size_t data_size
|
||||
}
|
||||
|
||||
bool onewire_slave_receive(OneWireSlave* bus, uint8_t* data, size_t data_size) {
|
||||
furi_check(bus);
|
||||
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
|
||||
size_t bytes_received = 0;
|
||||
@@ -347,6 +366,7 @@ bool onewire_slave_receive(OneWireSlave* bus, uint8_t* data, size_t data_size) {
|
||||
}
|
||||
|
||||
void onewire_slave_set_overdrive(OneWireSlave* bus, bool set) {
|
||||
furi_check(bus);
|
||||
const OneWireSlaveTimings* new_timings = set ? &onewire_slave_timings_overdrive :
|
||||
&onewire_slave_timings_normal;
|
||||
if(bus->timings != new_timings) {
|
||||
|
||||
Reference in New Issue
Block a user