generated from Embedded_Projects/NUC200_Template
80 lines
1.6 KiB
C
80 lines
1.6 KiB
C
#include "FreeRTOS.h"
|
|
#include "NUC200Series.h"
|
|
#include "pn512.h"
|
|
#include "task.h"
|
|
|
|
#define NFC_RESET_GPIO PA
|
|
#define NFC_RESET_PIN BIT15
|
|
|
|
/* PN512 has a strange SPI timing, see DS § 9.2 */
|
|
/* **Stop it, Get some help.** */
|
|
|
|
pn512_ret_t nfc_impl_reset_ops(void *handle) {
|
|
/* Clear nRSTPD */
|
|
NFC_RESET_GPIO->DOUT &= ~(NFC_RESET_PIN);
|
|
|
|
/* ..Sleep for a while */
|
|
vTaskDelay(pdMS_TO_TICKS(5));
|
|
|
|
/* Set nRSTPD */
|
|
NFC_RESET_GPIO->DOUT |= NFC_RESET_PIN;
|
|
|
|
return PN512_OK;
|
|
}
|
|
|
|
pn512_ret_t nfc_impl_delay_ops(void *handle, uint32_t msec) {
|
|
/* .. */
|
|
vTaskDelay(pdMS_TO_TICKS(msec));
|
|
|
|
return PN512_OK;
|
|
}
|
|
|
|
pn512_ret_t nfc_impl_read_ops(void *handle, uint8_t reg, uint8_t *data, uint16_t len) {
|
|
/*
|
|
* SPI Read sequence(len + 1 bytes in total):
|
|
* CS->LOW
|
|
* MOSI send 1st address byte, ignore MISO data.
|
|
* MISO receive `len` bytes, while MOSI repeats 1st byte data.
|
|
* CS->HIGH
|
|
*/
|
|
|
|
/* .. */
|
|
|
|
return PN512_OK;
|
|
}
|
|
|
|
pn512_ret_t nfc_impl_write_ops(void *handle, uint8_t reg, uint8_t *data, uint16_t len) {
|
|
/*
|
|
* SPI Write sequence(len + 1 bytes in total):
|
|
* CS->LOW
|
|
* MOSI send 1st address byte, data payload follows.
|
|
* CS->HIGH
|
|
*/
|
|
|
|
/* .. */
|
|
|
|
return PN512_OK;
|
|
}
|
|
|
|
pn512_ret_t pn512_poll_irq_ops(void *handle, uint32_t max_timeout) {
|
|
/*
|
|
* Poll for GPIO interrupt
|
|
* (Get Semaphore)
|
|
*
|
|
*/
|
|
|
|
/* .. */
|
|
|
|
return PN512_OK;
|
|
}
|
|
|
|
/* <-- SPI0_IRQHandler --> */
|
|
void SPI0_IRQHandler(void) {
|
|
/* DMA or FIFO xfer flags. */
|
|
/* .. */
|
|
}
|
|
|
|
/* <-- EXTI --> */
|
|
void GPAB_IRQHandler(void) {
|
|
/* ??? Sasuga Nuvoton */
|
|
} |