Update startup logic

This commit is contained in:
Edith Boles
2026-03-19 21:29:07 -07:00
parent 703e019d73
commit ed2ad9bcea
4 changed files with 916 additions and 27 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@
typedef void (*nfc_cb)(uint8_t status, uint8_t *version, uint16_t version_size,
uint8_t *data, uint16_t data_size);
void nfc_reset(const char *path);
void nfc_init(const char *path);
void *nfc_handle(void *data);
#endif /* end of include guard: NFC_H_3196CYAP */

View File

@@ -1,51 +1,45 @@
#include "cvend.h"
#include <asm-generic/ioctls.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <poll.h>
#include <sys/ioctl.h>
#include "nfc.h"
FILE *nfc_stream = NULL;
const char *nfc_path = NULL;
void nfc_reset(const char *path)
void nfc_init(const char *path)
{
uint8_t desfire_enable[] = { 0x00, CTYPE_DESFIRE, 0x01, FUNC_ENABLE };
cvend_packet *packet;
struct pollfd stream_poll;
if (nfc_stream)
fclose(nfc_stream);
nfc_stream = fopen(path, "wb+");
stream_poll.fd = fileno(nfc_stream);
stream_poll.events = POLLIN;
cvend_init();
printf("[INFO] checking for signs of life\n");
printf("[INFO] starting system...\n");
cvend_write(nfc_stream, MTYPE_STATUS, NULL, 0);
int status = poll(&stream_poll, 1, 1);
if (status) {
printf("[INFO] buffer active, checking status\n");
packet = cvend_read_type(nfc_stream, MTYPE_STATUS_REPLY);
if (!packet) {
printf("[ERROR] failed reading status\n");
exit(1);
while (1) {
packet = cvend_read(nfc_stream);
if (packet->msg_type == MTYPE_STATUS_REPLY) {
printf("[INFO] system already started\n");
break;
}
printf("[INFO] cvend seems to be working\n");
cvend_free(packet);
} else {
printf("[INFO] waiting for startup\n");
packet = cvend_read_type(nfc_stream, MTYPE_STARTUP);
if (!packet) {
printf("[ERROR] stream closed before startup\n");
exit(1);
if (packet->msg_type == MTYPE_STARTUP) {
printf("[INFO] system startup complete\n");
sleep(1);
if (nfc_stream)
fclose(nfc_stream);
nfc_stream = fopen(path, "wb+");
break;
}
printf("[INFO] startup complete\n");
cvend_free(packet);
}
printf("[INFO] enabling desfire\n");
cvend_write(nfc_stream, MTYPE_PROX_CARD_FUNCTION, desfire_enable, 4);
packet = cvend_read_type(nfc_stream, MTYPE_PROX_CARD_FUNCTION_REPLY);
@@ -118,7 +112,7 @@ void *nfc_handle(void *data)
goto cleanup;
reset:
nfc_reset("/dev/ttymxc3");
nfc_init("/dev/ttymxc3");
cleanup:
cvend_free(packet);

View File

@@ -45,6 +45,8 @@ void read_card(uint8_t status, uint8_t *version, uint16_t version_size,
int main(int argc, char *argv[])
{
printf("[INFO] Starting pm3-lvgl...\n");
result = ma_engine_init(NULL, &engine);
if (result != MA_SUCCESS) {
return -1;
@@ -57,7 +59,7 @@ int main(int argc, char *argv[])
lv_linux_fbdev_set_file(display, "/dev/fb0");
pthread_t nfc_thread;
nfc_reset("/dev/ttymxc3");
nfc_init("/dev/ttymxc3");
pthread_create(&nfc_thread, NULL, nfc_handle, read_card);
#else
display = lv_x11_window_create("LVGL X11 Simulation", 800, 480);