Example #1
0
struct rf24* radio_init(void)
{
	spi_init_pins();
	spi_init();

	rf24_init(&nrf);

	return &nrf;
}
Example #2
0
uchar   usbFunctionSetup(uchar data[8])
{
	usbRequest_t    *rq = (void *)data;
	switch (rq->bRequest) 
	{
	case RQ_SET_CONFIG:
		rf24_init(g_radio);
		rf24_enable_dynamic_payloads(g_radio);
		rf24_set_channel(g_radio,   rq->wValue.bytes[0]);
		rf24_set_data_rate(g_radio, rq->wValue.bytes[1]);
		rf24_set_pa_level(g_radio,  rq->wIndex.bytes[0]);
		break;
	case RQ_OPEN_PIPES:
		
		break;
	case RQ_LISTEN:
		if (rq->wValue.bytes[0]) {
			rf24_open_reading_pipe(g_radio, 1, local_addr);
			rf24_start_listening(g_radio);
		} else {
			rf24_stop_listening(g_radio);
			rf24_open_writing_pipe(g_radio, remote_addr);
		}
		break;
	case RQ_READ:
	{
		uint8_t pipe;
		uint8_t retries=50;
		uint8_t len =0; 
		do { 
			if (rf24_available(g_radio, &pipe)) {
				PORTC ^= 1<<2;
				len = rf24_get_dynamic_payload_size(g_radio);
				have_moar = !rf24_read(g_radio, msg, len);
				usbMsgPtr = msg;
				return len;
			}
			delay_ms(10);
		} while (retries--);
		
	}
		return 0;	
		break;
		
	case RQ_NOP:
		/* Shit out dbg buffer */
		usbMsgPtr = msg;
		return strlen(msg)+1;
		break;
	}
	last_rq = rq->bRequest;
	rq_len = rq->wLength.word;
	pos = 0;
	return USB_NO_MSG;		

}
Example #3
0
int main() {

	//
	// Disable the watchdog
	//
	WDTimerDisable();

	xSysCtlClockSet32KhzFLLExt(); //48mhz from 32768khz external clock

	xSysTickPeriodSet(xSysCtlClockGet()/SYSTICKS_PER_SECOND); //1ms
	xSysTickIntEnable();
	xSysTickEnable(); // End of SysTick init
	ulClockMS = xSysCtlClockGet() / (3 * 1000);

	pwmInit();

	// Setup and configure rf radio
	RF24 radio = RF24();
	rf24_init(radio);

	while (1) {

		// if there is data ready
		report_t gamepad_report;
		if (!getNRF24report(&radio, &gamepad_report))
		{

			drive(&gamepad_report);

			//			if (gamepad_report.reportid == 1) {
			//				// Delay just a little bit to let the other unit
			//				// make the transition to receiver
			//				xSysCtlDelay(ulClockMS * 10);
			//
			//				radio.stopListening();
			//				uint8_t response = 0;
			//				radio.write(&response, sizeof(uint8_t));
			//				radio.startListening();
			//			}


			timeoutcounter = millis();

		} else {
			if ((millis() - timeoutcounter) > TIMEOUT) {
				stopall();
				xSysCtlDelay(ulClockMS * 10);
			}
		}
	}

	return 0;
}
Example #4
0
int main()
{
	uint8_t payload[3];

	QM_PRINTF("Simple nRF24L01 receive example\r\n");

#if defined(RF24_SPI_MULTIBYTE)
	QM_PRINTF("Using multibyte SPI transfers\r\n");
#else
	QM_PRINTF("Using single byte SPI transfers\r\n");
#endif

	if (rf24_init()) {
		QM_PRINTF("Failed to initialize nRF24L01\r\n");
	} else {
		QM_PRINTF("Initialized nRF24L01 radio. ");
		if (rf24_is_plus()) {
			QM_PRINTF("Detected nRF24L01+\r\n");
		} else {
			QM_PRINTF("Detected nRF24L01\r\n");
		}
	}


    rf24_set_retries(15,15);

    rf24_open_reading_pipe_uint64(0, 0xAA55AA55AA);

    rf24_start_listening();

    clk_sys_udelay(1000);

    while(1) {

    	if (rf24_available()) {
    		rf24_read(payload, 3);

    		QM_PRINTF("Received data ... %d,%d,%d\r\n",payload[0],payload[1],payload[2]);

#if !defined (RF24_MINIMAL)
    		rf24_print_details();
#endif
    	}
    }

    return 0;
}
Example #5
0
int main(int argc, char *argv[])
{
	struct nrf24_drv *pdrv;
	struct rf24 *pnrf;
	struct rf24 nrf;

	struct cfg_platform pconf = {0};
	struct cfg_radio rconf = {0};
	char *config_name = DEFAULT_CONFIG;

	char *cmd;
	int rc;
	int i;

	int opt;
	const char opts[] = "c:h";
	const struct option longopts[] = {
		{"config", required_argument, NULL, 'c'},
		{"help", no_argument, NULL, 'h'},
		{NULL,}
	};

	/* use sane config defaults */

	cfg_radio_init(&rconf);
	cfg_platform_init(&pconf);


	/* parse command line */

	while (opt = getopt_long(argc, argv, opts, longopts, &opt), opt > 0) {
		switch (opt) {
		case 'c':
			config_name = strdup(optarg);
			break;
		case 'h':
		default:
			nrf24_dump_usage(argv[0]);
			exit(0);
		}
	}

	if (argc - optind + 1 <= 1) {
		nrf24_dump_usage(argv[0]);
		exit(0);
	}

	/* read and validate config */

	rc = cfg_from_file(config_name);
	if (rc < 0) {
		printf("ERR: failed to parse config\n");
		exit(-1);
	}

	rc = cfg_radio_read(&rconf);
	if (rc < 0) {
		printf("ERR: failed to get radio config\n");
		exit(-1);
	}

	rc = cfg_platform_read(&pconf);
	if (rc < 0) {
		printf("ERR: failed to get platform config\n");
		exit(-1);
	}

	cfg_platform_dump(&pconf);
	cfg_radio_dump(&rconf);

	rc = cfg_radio_validate(&rconf);
	if (rc < 0) {
		printf("ERR: invalid radio config\n");
		exit(-1);
	}

	/* setup nRF24L01 */

	pnrf = &nrf;
	memset(pnrf, 0x0, sizeof(*pnrf));

	pdrv = nrf24_driver_setup(pnrf, (void *)&pconf);
	if (!pdrv) {
		printf("ERR: can't setup gpio\n");
		exit(-1);
	}

	rf24_init(pnrf);

	/* execute command */

	for (i = 0; i < sizeof(commands) / sizeof(struct cmd_handler); i++) {
		cmd = commands[i].cmd;
		if (0 == strncmp(cmd, argv[optind], strlen(cmd))) {
			commands[i].handler(pnrf, argc - optind - 1, &argv[optind + 1]);
			break;
		}
	}

	return 0;
}
Example #6
0
int main(int argc, char *argv[])
{
	struct nrf24_drv *pdrv;
	bool parse_message = false;

	uint8_t recv_buffer[32];
	enum rf24_rx_status ret;
	int recv_length = 32;
	struct rf24 *pnrf;
	int pipe;
	int rc;
	int i;

	struct cfg_platform pconf = {0};
	struct cfg_radio rconf = {0};
	char *config_name = DEFAULT_CONFIG;

	/* command line options */

	int opt;
	const char opts[] = "c:ph";
	const struct option longopts[] = {
		{"config", required_argument, NULL, 'c'},
		{"parse-message", no_argument, NULL, 'p'},
		{"help", optional_argument, NULL, 'h'},
		{NULL,}
	};

	/* use sane config defaults */

	cfg_radio_init(&rconf);
	cfg_platform_init(&pconf);

	while (opt = getopt_long(argc, argv, opts, longopts, &opt), opt > 0) {
		switch (opt) {
		case 'c':
			config_name = strdup(optarg);
			break;
		case 'p':
			parse_message = true;
			break;
		case 'h':
		default:
			nrf24_test_usage(argv[0]);
			exit(0);
		}
	}

	/* read and validate config */

	rc = cfg_from_file(config_name);
	if (rc < 0) {
		printf("ERR: failed to parse config\n");
		exit(-1);
	}

	rc = cfg_radio_read(&rconf);
	if (rc < 0) {
		printf("ERR: failed to get radio config\n");
		exit(-1);
	}

	rc = cfg_platform_read(&pconf);
	if (rc < 0) {
		printf("ERR: failed to get platform config\n");
		exit(-1);
	}

	cfg_platform_dump(&pconf);
	cfg_radio_dump(&rconf);

	rc = cfg_radio_validate(&rconf);
	if (rc < 0) {
		printf("ERR: invalid radio config\n");
		exit(-1);
	}

	/* setup nRF24 driver */

	pnrf = &nrf;
	memset(pnrf, 0x0, sizeof(*pnrf));

	pdrv = nrf24_driver_setup(pnrf, (void *)&pconf);
	if (!pdrv) {
		printf("ERR: can't setup driver for nrf24 radio\n");
		exit(-1);
	}

	/* setup nRF24L01 */

	rf24_init(pnrf);
	rf24_print_status(pnrf);

	/* */

	if (cfg_payload_is_dynamic(&rconf))
		rf24_enable_dyn_payload(pnrf);
	else
		rf24_set_payload_size(pnrf, rconf.payload);

	rf24_set_channel(pnrf, rconf.channel);
	rf24_set_data_rate(pnrf, rconf.rate);
	rf24_set_crc_mode(pnrf, rconf.crc);
	rf24_set_pa_level(pnrf, rconf.pwr);

	for (i = 0; i < PIPE_MAX_NUM; i++) {
		if (rconf.pipe[i])
			rf24_setup_prx(pnrf, i, rconf.pipe[i]);
	}

	rf24_start_prx(pnrf);
	rf24_print_status(pnrf);

	/* */

	while (1) {
		/* block for driver 'ready' event */
		ret = nrf24_driver_wait_for(pdrv);
		if (ret < 0) {
			printf("ERR: driver wait failure\n");
			exit(-1);
		} else if (ret == 0) {
			/* some interruption: try again */
			continue;
		} else {
			/* ready to go */
		}

		if (!rf24_rx_ready(pnrf, &pipe))
			continue;

		ret = rf24_rx_pipe_check(pnrf, pipe);
		if (ret != RF24_RX_OK) {
			printf("WARN: pipe check error 0x%02x\n", (int)pipe);
			rf24_flush_rx(pnrf);
			continue;
		}

		printf("INFO: data ready in pipe 0x%02x\n", pipe);
		memset(recv_buffer, 0x0, sizeof(recv_buffer));

		if (rf24_is_dyn_payload(pnrf)) {
			recv_length = (int)rf24_get_dyn_payload_size(pnrf);
			if (recv_length == 0xff) {
				printf("WARN: failed to get dynamic payload length\n");
				rf24_flush_rx(pnrf);
				continue;
			}
		}

		ret = rf24_recv(pnrf, recv_buffer, recv_length);
		if (ret != RF24_RX_OK) {
			printf("WARN: failed to receive rx data: 0x%02x\n", ret);
			rf24_flush_rx(pnrf);
			continue;
		}

		if (parse_message)
			decode_data(recv_buffer, recv_length);
		else
			dump_data(recv_buffer, recv_length);
	}
}