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, typedef void (*nfc_cb)(uint8_t status, uint8_t *version, uint16_t version_size,
uint8_t *data, uint16_t data_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); void *nfc_handle(void *data);
#endif /* end of include guard: NFC_H_3196CYAP */ #endif /* end of include guard: NFC_H_3196CYAP */

View File

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