1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2024-11-24 05:50:11 +01:00

Begin to work on bana protocol

This commit is contained in:
whowechina 2024-04-14 16:17:26 +08:00
parent b69e562e40
commit 6eb14a6ed1
7 changed files with 144 additions and 14 deletions

22
firmware/include/bana.h Normal file
View File

@ -0,0 +1,22 @@
/*
* Bandai Namco Protocol
* WHowe <github.com/whowechina>
*/
#ifndef BANA_H
#define BANA_H
#include <stdint.h>
#include <stdbool.h>
/* return true if accepts a byte, false if rejects */
typedef void (*bana_putc_func)(uint8_t byte);
void bana_init(bana_putc_func putc_func);
bool bana_feed(int c);
/* bana activity expires at this time */
uint64_t bana_expire_time();
#endif

View File

@ -29,5 +29,5 @@ function(make_firmware board board_def)
COMMAND cp ${board}.uf2 ${CMAKE_CURRENT_LIST_DIR}/..) COMMAND cp ${board}.uf2 ${CMAKE_CURRENT_LIST_DIR}/..)
endfunction() endfunction()
add_library(aic lib/aime.c lib/pn532.c lib/pn5180.c lib/nfc.c) add_library(aic lib/aime.c lib/bana.c lib/pn532.c lib/pn5180.c lib/nfc.c)
make_firmware(aic_pico BOARD_AIC_PICO) make_firmware(aic_pico BOARD_AIC_PICO)

View File

@ -42,7 +42,13 @@ static void handle_display()
printf(" Level: [%d ~ %d]\n", aic_cfg->light.min, aic_cfg->light.max); printf(" Level: [%d ~ %d]\n", aic_cfg->light.min, aic_cfg->light.max);
printf("[AIME]\n"); printf("[AIME]\n");
printf(" Virtual AIC: %s\n", aic_cfg->virtual_aic ? "ON" : "OFF"); printf(" Virtual AIC: %s\n", aic_cfg->virtual_aic ? "ON" : "OFF");
printf(" Mode: %d (%s)\n", aic_cfg->aime_mode, aime_get_mode_string());
printf(" Mode: %s\n", aic_cfg->mode == 0 ? "aime0" :
aic_cfg->mode == 1 ? "aime1" :
aic_cfg->mode == 0x10 ? "bana" : "not set");
if ((aic_cfg->mode & 0xf0) == 0) {
printf(" Pattern: %s\n", aime_get_mode_string());
}
} }
static void handle_save() static void handle_save()
@ -94,22 +100,36 @@ static void handle_virtual(int argc, char *argv[])
static void handle_mode(int argc, char *argv[]) static void handle_mode(int argc, char *argv[])
{ {
const char *usage = "Usage: mode <0:1>\n"; const char *usage = "Usage: mode <aime0:aime1:bana>\n"
" aime0: Sega Aime 0\n"
" aime1: Sega Aime 1\n"
" bana: Bandai Namco\n";
if (argc != 1) { if (argc != 1) {
printf("%s", usage); printf("%s", usage);
return; return;
} }
const char *commands[] = { "0", "1" }; const char *commands[] = { "aime0", "aime1", "bana" };
int match = cli_match_prefix(commands, 2, argv[0]); int match = cli_match_prefix(commands, 3, argv[0]);
if (match < 0) { switch (match) {
printf("%s", usage); case 0:
return; aic_cfg->mode = 0x00;
break;
case 1:
aic_cfg->mode = 0x01;
break;
case 2:
aic_cfg->mode = 0x10;
break;
default:
printf("%s", usage);
return;
} }
aic_cfg->aime_mode = match; if ((aic_cfg->mode & 0xf0) == 0) {
aime_set_mode(aic_cfg->mode);
}
aime_set_mode(match);
config_changed(); config_changed();
} }

View File

@ -14,7 +14,7 @@ aic_cfg_t *aic_cfg;
static aic_cfg_t default_cfg = { static aic_cfg_t default_cfg = {
.light = { .min = 24, .max = 128, .rgb = true, .led = true }, .light = { .min = 24, .max = 128, .rgb = true, .led = true },
.virtual_aic = true, .virtual_aic = true,
.aime_mode = 1, .mode = 0,
}; };
aic_runtime_t *aic_runtime; aic_runtime_t *aic_runtime;

View File

@ -17,7 +17,7 @@ typedef struct __attribute__((packed)) {
bool led; bool led;
} light; } light;
bool virtual_aic; bool virtual_aic;
uint8_t aime_mode; uint8_t mode;
uint32_t reserved; uint32_t reserved;
} aic_cfg_t; } aic_cfg_t;

79
firmware/src/lib/bana.c Normal file
View File

@ -0,0 +1,79 @@
/*
* Bandai Namco NFC Reader
* WHowe <github.com/whowechina>
*
* Use NFC Module to read BANA
*/
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "bsp/board.h"
#include "hardware/gpio.h"
#include "hardware/i2c.h"
#include "nfc.h"
#include "bana.h"
#define BANA_EXPIRE_TIME 5000000ULL
static void putc_trap(uint8_t byte)
{
}
static bana_putc_func bana_putc = putc_trap;
void bana_init(bana_putc_func putc_func)
{
bana_putc = putc_func;
}
/*
static uint8_t mifare_keys[2][6]; // 'KeyA' and 'KeyB'
static union __attribute__((packed)) {
struct {
};
uint8_t raw[256];
} response;
static union __attribute__((packed)) {
struct {
};
uint8_t raw[256];
} request;
struct {
bool active;
uint8_t len;
uint8_t check_sum;
bool escaping;
uint64_t time;
} req_ctx;
*/
typedef struct __attribute__((packed)) {
uint8_t count;
uint8_t type;
uint8_t id_len;
union {
struct {
uint8_t idm[8];
uint8_t pmm[8];
};
uint8_t uid[6];
};
} card_info_t;
static uint64_t expire_time;
bool bana_feed(int c)
{
return true;
}
uint64_t bana_expire_time()
{
return expire_time;
}

View File

@ -175,7 +175,11 @@ static void aime_run()
uint8_t buf[32]; uint8_t buf[32];
int count = tud_cdc_n_read(aime_intf, buf, sizeof(buf)); int count = tud_cdc_n_read(aime_intf, buf, sizeof(buf));
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
aime_feed(buf[i]); if ((aic_cfg->mode & 0xf0) == 0) {
aime_feed(buf[i]);
} else {
//bana_feed(buf[i]);
}
} }
} }
} }
@ -229,7 +233,12 @@ void init()
aime_init(cdc_aime_putc); aime_init(cdc_aime_putc);
aime_virtual_aic(aic_cfg->virtual_aic); aime_virtual_aic(aic_cfg->virtual_aic);
aime_set_mode(aic_cfg->aime_mode);
if ((aic_cfg->mode & 0x0f) == 0) {
aime_set_mode(aic_cfg->mode);
}
//bana_init();
cli_init("aic_pico>", "\n << AIC Pico >>\n" cli_init("aic_pico>", "\n << AIC Pico >>\n"
" https://github.com/whowechina\n\n"); " https://github.com/whowechina\n\n");