/*
 * Copyright (c) 2020-2021, Bluetrum Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020/12/10     greedyhao    The first version
 */

/**
 * Notice!
 * All functions or data that are called during an interrupt need to be in RAM.
 * You can do it the way exception_isr() does.
 */

#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_soft_spi.h"
#include "nrf24.h"

struct rt_spi_device * spi;

int main(void)
{
    uint8_t tmp_buf[33];
    uint8_t pin = rt_pin_get("PE.1");

    rt_pin_mode(pin, PIN_MODE_OUTPUT);

  /*rt_soft_spi_device_attach("spi0", "spi0.0", RT_NULL, 19);
    spi = (struct rt_spi_device *) rt_device_find("spi0.0");
    rt_kprintf("spi0.0: %x\n", spi);
    if (spi == RT_NULL)
    {
        rt_kprintf("Can't find device on '%s'", "spi0.0");
        return -1;
    }*/

    while(NRF24L01_Init_Check())
    {
        rt_thread_mdelay(100);
    }

    NRF24L01_RX_Mode();

    while (1)
    {
        if(NRF24L01_RxPacket(tmp_buf)==0)//一旦接收到信息,则显示出来.
        {
            for(rt_uint8_t i=0;i<20;i++)
            {
                        rt_kprintf("%x ",tmp_buf[i]);
            }
            rt_pin_write(pin, PIN_LOW);
            rt_thread_mdelay(500);
            rt_pin_write(pin, PIN_HIGH);
            rt_thread_mdelay(500);
        }
        else {
            rt_thread_mdelay(500);
        }

    }
}
