Add Gitea OTA firmware update, dual-slot partition layout, and Gitea Actions release workflow
This commit is contained in:
65
components/rc522/src/rc522_helpers.c
Normal file
65
components/rc522/src/rc522_helpers.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <esp_system.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_check.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "rc522_types_internal.h"
|
||||
#include "rc522_helpers_internal.h"
|
||||
|
||||
#include <esp_timer.h>
|
||||
|
||||
RC522_LOG_DEFINE_BASE();
|
||||
|
||||
uint32_t rc522_millis()
|
||||
{
|
||||
return (uint32_t)(esp_timer_get_time() / 1000ULL);
|
||||
}
|
||||
|
||||
void rc522_delay_ms(uint32_t ms)
|
||||
{
|
||||
TickType_t ticks = pdMS_TO_TICKS(ms);
|
||||
if (ticks == 0 && ms > 0) {
|
||||
ticks = 1;
|
||||
}
|
||||
vTaskDelay(ticks);
|
||||
}
|
||||
|
||||
esp_err_t rc522_buffer_to_hex_str(
|
||||
const uint8_t *buffer, uint8_t buffer_length, char *str_buffer, uint8_t str_buffer_length)
|
||||
{
|
||||
RC522_CHECK(buffer == NULL);
|
||||
RC522_CHECK(buffer_length < 1);
|
||||
RC522_CHECK(str_buffer == NULL);
|
||||
|
||||
const char *format = "%02" RC522_X " ";
|
||||
const uint8_t formatted_length = 3;
|
||||
|
||||
RC522_CHECK(str_buffer_length < (buffer_length * formatted_length));
|
||||
|
||||
uint16_t len = 0;
|
||||
for (uint16_t i = 0; i < buffer_length; i++) {
|
||||
len += sprintf(str_buffer + len, format, buffer[i]);
|
||||
}
|
||||
|
||||
str_buffer[len - 1] = 0x00;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
inline esp_err_t rc522_nibbles(uint8_t byte, uint8_t *msb, uint8_t *lsb)
|
||||
{
|
||||
RC522_CHECK(msb == NULL && lsb == NULL);
|
||||
|
||||
if (msb) {
|
||||
*msb = byte >> 4;
|
||||
}
|
||||
|
||||
if (lsb) {
|
||||
*lsb = byte & 0x0F;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user