GPIO setup, IRQ handler setup, blink keepalive LED, delay serial usb setup.
This commit is contained in:
46
main.c
46
main.c
@@ -1,11 +1,28 @@
|
|||||||
#include <stdio.h>
|
#include "pico/stdlib.h"
|
||||||
|
#include "hardware/gpio.h"
|
||||||
|
#include "driver_mfrc522_interface.h"
|
||||||
|
|
||||||
#include <driver_mfrc522_interface.h>
|
#define MFRC522_CFG_IRQ_GPIO 14
|
||||||
|
|
||||||
|
static mfrc522_handle_t ctx = {0};
|
||||||
|
|
||||||
|
static void mfrc522_integration_irq_handler(uint gpio, uint32_t event_mask)
|
||||||
|
{
|
||||||
|
(void) gpio;
|
||||||
|
(void) event_mask;
|
||||||
|
|
||||||
|
// Dump return value for now, we cannot do anything at the moment.
|
||||||
|
(void) mfrc522_irq_handler(&ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mfrc522_integration_irq_init(void)
|
||||||
|
{
|
||||||
|
gpio_set_irq_enabled_with_callback(MFRC522_CFG_IRQ_GPIO, GPIO_IRQ_EDGE_RISE, true,
|
||||||
|
mfrc522_integration_irq_handler);
|
||||||
|
}
|
||||||
|
|
||||||
void mfrc522_integration_init(void)
|
void mfrc522_integration_init(void)
|
||||||
{
|
{
|
||||||
mfrc522_handle_t ctx;
|
|
||||||
|
|
||||||
DRIVER_MFRC522_LINK_INIT(&ctx, mfrc522_handle_t);
|
DRIVER_MFRC522_LINK_INIT(&ctx, mfrc522_handle_t);
|
||||||
DRIVER_MFRC522_LINK_RESET_GPIO_INIT(&ctx, mfrc522_interface_reset_gpio_init);
|
DRIVER_MFRC522_LINK_RESET_GPIO_INIT(&ctx, mfrc522_interface_reset_gpio_init);
|
||||||
DRIVER_MFRC522_LINK_RESET_GPIO_DEINIT(&ctx, mfrc522_interface_reset_gpio_deinit);
|
DRIVER_MFRC522_LINK_RESET_GPIO_DEINIT(&ctx, mfrc522_interface_reset_gpio_deinit);
|
||||||
@@ -27,12 +44,33 @@ void mfrc522_integration_init(void)
|
|||||||
DRIVER_MFRC522_LINK_DEBUG_PRINT(&ctx, mfrc522_interface_debug_print);
|
DRIVER_MFRC522_LINK_DEBUG_PRINT(&ctx, mfrc522_interface_debug_print);
|
||||||
DRIVER_MFRC522_LINK_RECEIVE_CALLBACK(&ctx, mfrc522_interface_receive_callback);
|
DRIVER_MFRC522_LINK_RECEIVE_CALLBACK(&ctx, mfrc522_interface_receive_callback);
|
||||||
|
|
||||||
|
mfrc522_set_interface(&ctx, MFRC522_INTERFACE_SPI);
|
||||||
uint8_t init_retval = mfrc522_init(&ctx);
|
uint8_t init_retval = mfrc522_init(&ctx);
|
||||||
|
|
||||||
|
if (init_retval == 0) {
|
||||||
|
mfrc522_integration_irq_init();
|
||||||
|
} else {
|
||||||
|
printf("ERR: %s failed: %d\n", __FUNCTION__, init_retval);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
stdio_init_all();
|
||||||
|
sleep_ms(2500);
|
||||||
|
|
||||||
printf("Hello World!\n");
|
printf("Hello World!\n");
|
||||||
|
|
||||||
mfrc522_integration_init();
|
mfrc522_integration_init();
|
||||||
|
|
||||||
|
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||||
|
gpio_init(LED_PIN);
|
||||||
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
|
while (true) {
|
||||||
|
gpio_put(LED_PIN, 1);
|
||||||
|
sleep_ms(250);
|
||||||
|
gpio_put(LED_PIN, 0);
|
||||||
|
sleep_ms(250);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,12 @@
|
|||||||
|
|
||||||
#include "driver_mfrc522_interface.h"
|
#include "driver_mfrc522_interface.h"
|
||||||
|
|
||||||
#define MFRC522_CFG_N_GPIO 5
|
#define MFRC522_CFG_RST_GPIO 9
|
||||||
|
#define MFRC522_CFG_SPI_MISO_GPIO 12
|
||||||
|
#define MFRC522_CFG_SPI_MOSI_GPIO 11
|
||||||
|
#define MFRC522_CFG_SPI_CLK_GPIO 10
|
||||||
|
#define MFRC522_CFG_SPI_SS_GPIO 13
|
||||||
|
#define MFRC522_CFG_SPI_SPEED_MHZ (1000 * 1000)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief interface reset gpio init
|
* @brief interface reset gpio init
|
||||||
@@ -55,8 +60,8 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t mfrc522_interface_reset_gpio_init(void)
|
uint8_t mfrc522_interface_reset_gpio_init(void)
|
||||||
{
|
{
|
||||||
gpio_init(MFRC522_CFG_N_GPIO);
|
gpio_init(MFRC522_CFG_RST_GPIO);
|
||||||
gpio_set_dir(MFRC522_CFG_N_GPIO, GPIO_OUT);
|
gpio_set_dir(MFRC522_CFG_RST_GPIO, GPIO_OUT);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +74,7 @@ uint8_t mfrc522_interface_reset_gpio_init(void)
|
|||||||
*/
|
*/
|
||||||
uint8_t mfrc522_interface_reset_gpio_deinit(void)
|
uint8_t mfrc522_interface_reset_gpio_deinit(void)
|
||||||
{
|
{
|
||||||
gpio_deinit(MFRC522_CFG_N_GPIO);
|
gpio_deinit(MFRC522_CFG_RST_GPIO);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +88,7 @@ uint8_t mfrc522_interface_reset_gpio_deinit(void)
|
|||||||
*/
|
*/
|
||||||
uint8_t mfrc522_interface_reset_gpio_write(uint8_t value)
|
uint8_t mfrc522_interface_reset_gpio_write(uint8_t value)
|
||||||
{
|
{
|
||||||
gpio_put(MFRC522_CFG_N_GPIO, !!value);
|
gpio_put(MFRC522_CFG_RST_GPIO, !!value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +161,13 @@ uint8_t mfrc522_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uin
|
|||||||
*/
|
*/
|
||||||
uint8_t mfrc522_interface_spi_init(void)
|
uint8_t mfrc522_interface_spi_init(void)
|
||||||
{
|
{
|
||||||
return 0;
|
gpio_set_function(MFRC522_CFG_SPI_MISO_GPIO, GPIO_FUNC_SPI);
|
||||||
|
gpio_set_function(MFRC522_CFG_SPI_MOSI_GPIO, GPIO_FUNC_SPI);
|
||||||
|
gpio_set_function(MFRC522_CFG_SPI_CLK_GPIO, GPIO_FUNC_SPI);
|
||||||
|
gpio_set_function(MFRC522_CFG_SPI_SS_GPIO, GPIO_FUNC_SPI);
|
||||||
|
|
||||||
|
uint baudrate = MFRC522_CFG_SPI_SPEED_MHZ;
|
||||||
|
return (baudrate == spi_init(spi0, baudrate)) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user