Commit d1925371 authored by Nicolas Pouillon's avatar Nicolas Pouillon

Update NFC test

parent 64bc3fc2
......@@ -51,6 +51,7 @@
CONFIG_DRIVER_NRF5X_GPIO_PWM
CONFIG_DRIVER_NRF5X_GPIO_PWM_CHANNEL_COUNT 1
CONFIG_DRIVER_HD44780
CONFIG_DRIVER_HD44780_TERM
CONFIG_DRIVER_HD44780_4BIT
CONFIG_DRIVER_HD44780_4BIT_SWAPPED
%end
......
......@@ -66,8 +66,8 @@ DEV_DECLARE_STATIC(spi_dev, "spi0", 0, nrf5x_spi_drv,
DEV_STATIC_RES_DEV_IOMUX("/gpio"),
DEV_STATIC_RES_IOMUX("clk", 0, 29, 0, 0),
DEV_STATIC_RES_IOMUX("mosi", 0, 28, 0, 0),
// DEV_STATIC_RES_IOMUX("miso", 0, 27, 0, 0)
DEV_STATIC_RES_IOMUX("miso", 0, 12, 0, 0)
DEV_STATIC_RES_IOMUX("miso", 0, 27, 0, 0)
// DEV_STATIC_RES_IOMUX("miso", 0, 12, 0, 0)
);
# if defined(CONFIG_DRIVER_NFC_MICORE2)
......
......@@ -8,4 +8,8 @@ CONFIG_MUTEK_CONTEXT_SCHED
%inherit bmaaa-pinky
%inherit nfc
%inherit lcd
%include bmaaa.build
CONFIG_HEXO_CPU_STACK_SIZE 0x1000
CONFIG_PTHREAD_STACK_SIZE 0x1000
#include <mutek/startup.h>
#include <mutek/thread.h>
#include <mutek/printk.h>
#include <stdio.h>
#include <device/class/nfc.h>
#include <device/class/char.h>
#include <device/class/timer.h>
#include <device/class/pwm.h>
#define BACKLIGHT 12
static CONTEXT_ENTRY(nfc_main)
{
error_t err;
struct device_char_s lcd;
struct device_timer_s timer;
struct device_pwm_s pwm;
dev_timer_delay_t sec;
struct dev_pwm_config_s pwm_config;
struct device_nfc_s nfc;
struct dev_nfc_rq_s req;
struct dev_nfc_peer_s peer;
char buffer[64];
pwm_config.freq.num = 16000;
pwm_config.freq.denom = 1;
pwm_config.duty.num = 0;
pwm_config.duty.denom = 16;
pwm_config.pol = DEV_PWM_POL_HIGH;
req.peer = &peer;
peer.side = DEV_NFC_PASSIVE_PICC;
......@@ -19,19 +37,53 @@ static CONTEXT_ENTRY(nfc_main)
err = device_get_accessor_by_path(&nfc.base, NULL, "/nfc0", DRIVER_CLASS_NFC);
assert(!err);
req.type = DEV_NFC_WRITE;
err = dev_nfc_wait_request(&nfc, &req);
err = device_get_accessor_by_path(&lcd.base, NULL, "/lcd*", DRIVER_CLASS_CHAR);
assert(!err);
req.type = DEV_NFC_READ;
err = dev_nfc_wait_request(&nfc, &req);
err = device_get_accessor_by_path(&pwm.base, NULL, "/pwm*", DRIVER_CLASS_PWM);
assert(!err);
err = device_get_accessor_by_path(&timer.base, NULL, "/rtc* /timer*", DRIVER_CLASS_TIMER);
assert(!err);
device_start(&pwm.base);
dev_pwm_wait_config(&pwm, &pwm_config,
DEV_PWM_MASK_DUTY|DEV_PWM_MASK_FREQ|DEV_PWM_MASK_POL);
dev_timer_init_sec(&timer, &sec, 0, 1, 10);
while (1) {
size_t n;
req.type = DEV_NFC_FIND_ANY;
err = dev_nfc_wait_request(&nfc, &req);
n = snprintf(buffer, sizeof(buffer), "\x1b[2J" "\x1b[0;0H" "Please put a tag",
peer.uid, peer.uid_size, peer.sak, peer.atqa);
dev_char_wait_op(&lcd, DEV_CHAR_WRITE_FLUSH, (void *)buffer, n);
if (err == 0) {
pwm_config.duty.num = 16;
dev_pwm_wait_config(&pwm, &pwm_config, DEV_PWM_MASK_DUTY);
n = snprintf(buffer, sizeof(buffer),
"\x1b[2J" "\x1b[0;0H" "UID %08x"
"\x1b[1;0H" "SAK %02x ATQA %04x",
endian_le32_na_load(peer.uid),
peer.sak,
peer.atqa);
dev_char_wait_op(&lcd, DEV_CHAR_WRITE_FLUSH, (void *)buffer, n);
dev_timer_wait_delay(&timer, sec, 0);
} else {
pwm_config.duty.num = 1;
dev_pwm_wait_config(&pwm, &pwm_config, DEV_PWM_MASK_DUTY);
}
}
}
void app_start(void)
{
struct thread_attr_s attr = {
.stack_size = 1024,
.stack_size = 2048,
};
thread_create(nfc_main, 0, &attr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment