diff --git a/main.c b/main.c index a4f088a..dc96e8e 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,38 @@ #include +#include + +void mfrc522_integration_init(void) +{ + mfrc522_handle_t ctx; + + 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_DEINIT(&ctx, mfrc522_interface_reset_gpio_deinit); + DRIVER_MFRC522_LINK_RESET_GPIO_WRITE(&ctx, mfrc522_interface_reset_gpio_write); + DRIVER_MFRC522_LINK_IIC_INIT(&ctx, mfrc522_interface_iic_init); + DRIVER_MFRC522_LINK_IIC_DEINIT(&ctx, mfrc522_interface_iic_deinit); + DRIVER_MFRC522_LINK_IIC_WRITE(&ctx, mfrc522_interface_iic_write); + DRIVER_MFRC522_LINK_IIC_READ(&ctx, mfrc522_interface_iic_read); + DRIVER_MFRC522_LINK_UART_INIT(&ctx, mfrc522_interface_uart_init); + DRIVER_MFRC522_LINK_UART_DEINIT(&ctx, mfrc522_interface_uart_deinit); + DRIVER_MFRC522_LINK_UART_READ(&ctx, mfrc522_interface_uart_read); + DRIVER_MFRC522_LINK_UART_WRITE(&ctx, mfrc522_interface_uart_write); + DRIVER_MFRC522_LINK_UART_FLUSH(&ctx, mfrc522_interface_uart_flush); + DRIVER_MFRC522_LINK_SPI_INIT(&ctx, mfrc522_interface_spi_init); + DRIVER_MFRC522_LINK_SPI_DEINIT(&ctx, mfrc522_interface_spi_deinit); + DRIVER_MFRC522_LINK_SPI_READ(&ctx, mfrc522_interface_spi_read); + DRIVER_MFRC522_LINK_SPI_WRITE(&ctx, mfrc522_interface_spi_write); + DRIVER_MFRC522_LINK_DELAY_MS(&ctx, mfrc522_interface_delay_ms); + DRIVER_MFRC522_LINK_DEBUG_PRINT(&ctx, mfrc522_interface_debug_print); + DRIVER_MFRC522_LINK_RECEIVE_CALLBACK(&ctx, mfrc522_interface_receive_callback); + + uint8_t init_retval = mfrc522_init(&ctx); +} + int main(void) { printf("Hello World!\n"); + + mfrc522_integration_init(); } diff --git a/third_party/mfrc522_integration/CMakeLists.txt b/third_party/mfrc522_integration/CMakeLists.txt index 1e5536f..10b61e6 100644 --- a/third_party/mfrc522_integration/CMakeLists.txt +++ b/third_party/mfrc522_integration/CMakeLists.txt @@ -1,4 +1,9 @@ set(SRC ${CMAKE_CURRENT_SOURCE_DIR}/mfrc522/src) +set(INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/mfrc522/interface) -add_library(mfrc522 STATIC ${SRC}/driver_mfrc522.c) +add_library(mfrc522 STATIC + mfrc522_rp2040_integration.c + ${SRC}/driver_mfrc522.c +) target_include_directories(mfrc522 PUBLIC ${SRC}) +target_include_directories(mfrc522 PUBLIC ${INTERFACE}) diff --git a/third_party/mfrc522_integration/mfrc522_rp2040_integration.c b/third_party/mfrc522_integration/mfrc522_rp2040_integration.c new file mode 100644 index 0000000..6296381 --- /dev/null +++ b/third_party/mfrc522_integration/mfrc522_rp2040_integration.c @@ -0,0 +1,340 @@ +/** + * Copyright (c) 2015 - present LibDriver All rights reserved + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file driver_mfrc522_interface_template.c + * @brief driver mfrc522 interface template source file + * @version 1.0.0 + * @author Shifeng Li + * @date 2022-05-31 + * + *

history

+ * + *
Date Version Author Description + *
2022/05/31 1.0 Shifeng Li first upload + *
+ */ + +#include "driver_mfrc522_interface.h" + +/** + * @brief interface reset gpio init + * @return status code + * - 0 success + * - 1 reset gpio init failed + * @note none + */ +uint8_t mfrc522_interface_reset_gpio_init(void) +{ + return 0; +} + +/** + * @brief interface reset gpio deinit + * @return status code + * - 0 success + * - 1 reset gpio deinit failed + * @note none + */ +uint8_t mfrc522_interface_reset_gpio_deinit(void) +{ + return 0; +} + +/** + * @brief interface reset gpio write + * @param[in] value is the written value + * @return status code + * - 0 success + * - 1 reset gpio write failed + * @note none + */ +uint8_t mfrc522_interface_reset_gpio_write(uint8_t value) +{ + return 0; +} + +/** + * @brief interface iic bus init + * @return status code + * - 0 success + * - 1 iic init failed + * @note none + */ +uint8_t mfrc522_interface_iic_init(void) +{ + return 0; +} + +/** + * @brief interface iic bus deinit + * @return status code + * - 0 success + * - 1 iic deinit failed + * @note none + */ +uint8_t mfrc522_interface_iic_deinit(void) +{ + return 0; +} + +/** + * @brief interface iic bus read + * @param[in] addr is the iic device write address + * @param[in] reg is the iic register address + * @param[out] *buf points to a data buffer + * @param[in] len is the length of the data buffer + * @return status code + * - 0 success + * - 1 read failed + * @note none + */ +uint8_t mfrc522_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len) +{ + return 0; +} + +/** + * @brief interface iic bus write + * @param[in] addr is the iic device write address + * @param[in] reg is the iic register address + * @param[in] *buf points to a data buffer + * @param[in] len is the length of the data buffer + * @return status code + * - 0 success + * - 1 write failed + * @note none + */ +uint8_t mfrc522_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len) +{ + return 0; +} + +/** + * @brief interface spi bus init + * @return status code + * - 0 success + * - 1 spi init failed + * @note none + */ +uint8_t mfrc522_interface_spi_init(void) +{ + return 0; +} + +/** + * @brief interface spi bus deinit + * @return status code + * - 0 success + * - 1 spi deinit failed + * @note none + */ +uint8_t mfrc522_interface_spi_deinit(void) +{ + return 0; +} + +/** + * @brief interface spi bus read + * @param[in] reg is the register address + * @param[out] *buf points to a data buffer + * @param[in] len is the length of data buffer + * @return status code + * - 0 success + * - 1 read failed + * @note none + */ +uint8_t mfrc522_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len) +{ + return 0; +} + +/** + * @brief interface spi bus write + * @param[in] reg is the register address + * @param[in] *buf points to a data buffer + * @param[in] len is the length of data buffer + * @return status code + * - 0 success + * - 1 write failed + * @note none + */ +uint8_t mfrc522_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len) +{ + return 0; +} + +/** + * @brief interface uart init + * @return status code + * - 0 success + * - 1 uart init failed + * @note none + */ +uint8_t mfrc522_interface_uart_init(void) +{ + return 0; +} + +/** + * @brief interface uart deinit + * @return status code + * - 0 success + * - 1 uart deinit failed + * @note none + */ +uint8_t mfrc522_interface_uart_deinit(void) +{ + return 0; +} + +/** + * @brief interface uart read + * @param[out] *buf points to a data buffer + * @param[in] len is the length of the data buffer + * @return status code + * - 0 success + * - 1 read failed + * @note none + */ +uint16_t mfrc522_interface_uart_read(uint8_t *buf, uint16_t len) +{ + return 0; +} + +/** + * @brief interface uart write + * @param[in] *buf points to a data buffer + * @param[in] len is the length of the data buffer + * @return status code + * - 0 success + * - 1 write failed + * @note none + */ +uint8_t mfrc522_interface_uart_write(uint8_t *buf, uint16_t len) +{ + return 0; +} + +/** + * @brief interface uart flush + * @return status code + * - 0 success + * - 1 uart flush failed + * @note none + */ +uint8_t mfrc522_interface_uart_flush(void) +{ + return 0; +} + +/** + * @brief interface delay ms + * @param[in] ms + * @note none + */ +void mfrc522_interface_delay_ms(uint32_t ms) +{ + +} + +/** + * @brief interface print format data + * @param[in] fmt is the format data + * @note none + */ +void mfrc522_interface_debug_print(const char *const fmt, ...) +{ + +} + +/** + * @brief interface receive callback + * @param[in] type is the irq type + * @note none + */ +void mfrc522_interface_receive_callback(uint16_t type) +{ + switch (type) + { + case MFRC522_INTERRUPT_MFIN_ACT : + { + mfrc522_interface_debug_print("mfrc522: irq mfin act.\n"); + + break; + } + case MFRC522_INTERRUPT_CRC : + { + mfrc522_interface_debug_print("mfrc522: irq crc.\n"); + + break; + } + case MFRC522_INTERRUPT_TX : + { + mfrc522_interface_debug_print("mfrc522: irq tx.\n"); + + break; + } + case MFRC522_INTERRUPT_RX : + { + mfrc522_interface_debug_print("mfrc522: irq rx.\n"); + + break; + } + case MFRC522_INTERRUPT_IDLE : + { + mfrc522_interface_debug_print("mfrc522: irq idle.\n"); + + break; + } + case MFRC522_INTERRUPT_HI_ALERT : + { + mfrc522_interface_debug_print("mfrc522: irq hi alert.\n"); + + break; + } + case MFRC522_INTERRUPT_LO_ALERT : + { + mfrc522_interface_debug_print("mfrc522: irq lo alert.\n"); + + break; + } + case MFRC522_INTERRUPT_ERR : + { + mfrc522_interface_debug_print("mfrc522: irq err.\n"); + + break; + } + case MFRC522_INTERRUPT_TIMER : + { + mfrc522_interface_debug_print("mfrc522: irq timer.\n"); + + break; + } + default : + { + mfrc522_interface_debug_print("mfrc522: irq unknown code.\n"); + + break; + } + } +}