Commit aace3b4b authored by TMRh20's avatar TMRh20

Merge pull request #40 from spaniakos/master

intel galileo support added.
parents deef592b e13b238b
...@@ -594,8 +594,7 @@ void RF24::printDetails(void) ...@@ -594,8 +594,7 @@ void RF24::printDetails(void)
print_byte_register(PSTR("RF_SETUP"),RF_SETUP); print_byte_register(PSTR("RF_SETUP"),RF_SETUP);
print_byte_register(PSTR("CONFIG"),CONFIG); print_byte_register(PSTR("CONFIG"),CONFIG);
print_byte_register(PSTR("DYNPD/FEATURE"),DYNPD,2); print_byte_register(PSTR("DYNPD/FEATURE"),DYNPD,2);
#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__)
#if defined(__arm__) || defined (RF24_LINUX)
printf_P(PSTR("Data Rate\t = %s\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()])); printf_P(PSTR("Data Rate\t = %s\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));
printf_P(PSTR("Model\t\t = %s\r\n"),pgm_read_word(&rf24_model_e_str_P[isPVariant()])); printf_P(PSTR("Model\t\t = %s\r\n"),pgm_read_word(&rf24_model_e_str_P[isPVariant()]));
printf_P(PSTR("CRC Length\t = %s\r\n"),pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()])); printf_P(PSTR("CRC Length\t = %s\r\n"),pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()]));
...@@ -650,6 +649,9 @@ void RF24::begin(void) ...@@ -650,6 +649,9 @@ void RF24::begin(void)
_SPI.begin(); _SPI.begin();
ce(LOW); ce(LOW);
csn(HIGH); csn(HIGH);
#if defined (__ARDUINO_X86__)
delay(100);
#endif
#endif #endif
#endif //Linux #endif //Linux
...@@ -735,9 +737,7 @@ void RF24::startListening(void) ...@@ -735,9 +737,7 @@ void RF24::startListening(void)
} }
// Go! // Go!
#if defined (RF24_LINUX) || defined (__arm__) delayMicroseconds(100);
delayMicroseconds(100);
#endif
listeningStarted = 1; listeningStarted = 1;
} }
...@@ -750,7 +750,7 @@ static const uint8_t child_pipe_enable[] PROGMEM = ...@@ -750,7 +750,7 @@ static const uint8_t child_pipe_enable[] PROGMEM =
void RF24::stopListening(void) void RF24::stopListening(void)
{ {
ce(LOW); ce(LOW);
#if defined (RF24_LINUX) #if defined (RF24_LINUX) || defined (__ARDUINO_X86__)
delayMicroseconds(370); delayMicroseconds(370);
#elif defined(__arm__) #elif defined(__arm__)
delayMicroseconds(300); delayMicroseconds(300);
...@@ -1067,7 +1067,7 @@ bool RF24::available(void) ...@@ -1067,7 +1067,7 @@ bool RF24::available(void)
bool RF24::available(uint8_t* pipe_num) bool RF24::available(uint8_t* pipe_num)
{ {
//Check the FIFO buffer to see if data is waiting to be read //Check the FIFO buffer to see if data is waiting to be read
#if defined (RF24_LINUX) // This seems to prevent faster devices like RPi from saturating the RF24 module with SPI requests #if defined (RF24_LINUX) || defined (__ARDUINO_X86__) // This seems to prevent faster devices like RPi from saturating the RF24 module with SPI requests
while(millis() - lastAvailableCheck < 1){} while(millis() - lastAvailableCheck < 1){}
lastAvailableCheck = millis(); lastAvailableCheck = millis();
#else #else
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define __RF24_H__ #define __RF24_H__
#include "RF24_config.h" #include "RF24_config.h"
#if defined (__linux) || defined (LINUX) #if (defined (__linux) || defined (LINUX)) && !defined (__ARDUINO_X86__)
#include "RPi/bcm2835.h" #include "RPi/bcm2835.h"
#elif defined SOFTSPI #elif defined SOFTSPI
#include <DigitalIO.h> #include <DigitalIO.h>
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
Added Arduino Due support from https://github.com/mcrosson/ Added Arduino Due support from https://github.com/mcrosson/
*/ */
/* spaniakos <spaniakos@gmail.com>
Added __ARDUINO_X86__ support
*/
#ifndef __RF24_CONFIG_H__ #ifndef __RF24_CONFIG_H__
#define __RF24_CONFIG_H__ #define __RF24_CONFIG_H__
...@@ -20,8 +24,7 @@ ...@@ -20,8 +24,7 @@
//#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO //#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO
/**********************/ /**********************/
#if defined (__linux) || defined (linux) #if (defined (__linux) || defined (linux)) && !defined (__ARDUINO_X86__)
#define RF24_LINUX #define RF24_LINUX
#include <stdint.h> #include <stdint.h>
...@@ -67,7 +70,7 @@ ...@@ -67,7 +70,7 @@
// Define _BV for non-Arduino platforms and for Arduino DUE // Define _BV for non-Arduino platforms and for Arduino DUE
#if defined (ARDUINO) && !defined (__arm__) #if defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
#define RF24_TINY #define RF24_TINY
#define _SPI SPI #define _SPI SPI
...@@ -95,13 +98,13 @@ ...@@ -95,13 +98,13 @@
#include <string.h> #include <string.h>
#if defined(__arm__) || defined (CORE_TEENSY) #if defined(__arm__) || defined (CORE_TEENSY) || defined (__ARDUINO_X86__)
#include <SPI.h> #include <SPI.h>
#endif #endif
#if !defined(CORE_TEENSY) #if !defined(CORE_TEENSY)
#define _BV(x) (1<<(x)) #define _BV(x) (1<<(x))
#if !defined(__arm__) #if !defined(__arm__) && !defined (__ARDUINO_X86__)
extern HardwareSPI SPI; extern HardwareSPI SPI;
#endif #endif
#else #else
...@@ -120,7 +123,12 @@ ...@@ -120,7 +123,12 @@
#define printf_P(...) #define printf_P(...)
#endif #endif
#endif #endif
#if defined (__ARDUINO_X86__)
#define printf_P printf
#define _BV(bit) (1<<(bit))
#endif
// Avoid spurious warnings // Avoid spurious warnings
// Arduino DUE is arm and uses traditional PROGMEM constructs // Arduino DUE is arm and uses traditional PROGMEM constructs
#if 1 #if 1
...@@ -134,7 +142,7 @@ ...@@ -134,7 +142,7 @@
// Progmem is Arduino-specific // Progmem is Arduino-specific
// Arduino DUE is arm and does not include avr/pgmspace // Arduino DUE is arm and does not include avr/pgmspace
#if defined(ARDUINO) && ! defined(__arm__) #if defined(ARDUINO) && ! defined(__arm__) && !defined (__ARDUINO_X86__)
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#define PRIPSTR "%S" #define PRIPSTR "%S"
#else #else
...@@ -144,7 +152,6 @@ ...@@ -144,7 +152,6 @@
#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#endif #endif
#if !defined ( CORE_TEENSY ) #if !defined ( CORE_TEENSY )
typedef uint16_t prog_uint16_t; typedef uint16_t prog_uint16_t;
#define PSTR(x) (x) #define PSTR(x) (x)
......
This diff is collapsed.
#!/usr/bin/env python
from distutils.core import setup, Extension
module_RF24 = Extension('RF24',
libraries = ['rf24-bcm', 'boost_python'],
sources = ['pyRF24.cpp'])
setup(name='RF24',
version='1.0',
ext_modules=[module_RF24]
)
#!/usr/bin/env python
#
# Example using Dynamic Payloads
#
# This is an example of how to use payloads of a varying (dynamic) size.
#
import time
from RF24 import *
# CE Pin, CSN Pin, SPI Speed
# Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz
#radio = radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ)
# Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
#radio = RF24(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ)
# Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
#radio = RF24(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ)
# Setup for GPIO 22 CE and CE0 CSN for RPi B+ with SPI Speed @ 8Mhz
radio = RF24(RPI_BPLUS_GPIO_J8_22, RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ)
pipes = [0xF0F0F0F0E1, 0xF0F0F0F0D2]
min_payload_size = 4
max_payload_size = 32
payload_size_increments_by = 1
next_payload_size = min_payload_size
inp_role = 'none'
send_payload = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ789012'
millis = lambda: int(round(time.time() * 1000))
print 'pyRF24/examples/pingpair_dyn/'
radio.begin()
radio.enableDynamicPayloads()
radio.setRetries(5,15)
radio.printDetails()
print ' ************ Role Setup *********** '
while (inp_role !='0') and (inp_role !='1'):
inp_role = raw_input('Choose a role: Enter 0 for receiver, 1 for transmitter (CTRL+C to exit) ')
if inp_role == '0':
print 'Role: Pong Back, awaiting transmission'
radio.openWritingPipe(pipes[1])
radio.openReadingPipe(1,pipes[0])
radio.startListening()
else:
print 'Role: Ping Out, starting transmission'
radio.openWritingPipe(pipes[0])
radio.openReadingPipe(1,pipes[1])
# forever loop
while 1:
if inp_role == '1': # ping out
# The payload will always be the same, what will change is how much of it we send.
# First, stop listening so we can talk.
radio.stopListening()
# Take the time, and send it. This will block until complete
print 'Now sending length ', next_payload_size, ' ... ',
radio.write(send_payload[:next_payload_size])
# Now, continue listening
radio.startListening()
# Wait here until we get a response, or timeout
started_waiting_at = millis()
timeout = False
while (not radio.available()) and (not timeout):
if (millis() - started_waiting_at) > 500:
timeout = True
# Describe the results
if timeout:
print 'failed, response timed out.'
else:
# Grab the response, compare, and send to debugging spew
len = radio.getDynamicPayloadSize()
receive_payload = radio.read(len)
# Spew it
print 'got response size=', len, ' value="', receive_payload, '"'
# Update size for next time.
next_payload_size += payload_size_increments_by
if next_payload_size > max_payload_size:
next_payload_size = min_payload_size
time.sleep(0.1)
else:
# Pong back role. Receive each packet, dump it out, and send it back
# if there is data ready
if radio.available():
while radio.available():
# Fetch the payload, and see if this was the last one.
len = radio.getDynamicPayloadSize()
receive_payload = radio.read(len)
# Spew it
print 'Got payload size=', len, ' value="', receive_payload, '"'
# First, stop listening so we can talk
radio.stopListening()
# Send the final one back.
radio.write(receive_payload)
print 'Sent response.'
# Now, resume listening so we catch the next packets.
radio.startListening()
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation. version 2 as published by the Free Software Foundation.
*/ */
/* Galileo support from spaniakos <spaniakos@gmail.com> */
/** /**
* @file printf.h * @file printf.h
...@@ -16,7 +17,7 @@ ...@@ -16,7 +17,7 @@
#ifndef __PRINTF_H__ #ifndef __PRINTF_H__
#define __PRINTF_H__ #define __PRINTF_H__
#if defined (ARDUINO) && !defined (__arm__) #if defined (ARDUINO) && !defined (__arm__) && !defined(__ARDUINO_X86__)
int serial_putc( char c, FILE * ) int serial_putc( char c, FILE * )
{ {
...@@ -34,6 +35,23 @@ void printf_begin(void) ...@@ -34,6 +35,23 @@ void printf_begin(void)
void printf_begin(void){} void printf_begin(void){}
#elif defined(__ARDUINO_X86__)
int serial_putc( char c, FILE * )
{
Serial.write( c );
return c;
}
void printf_begin(void)
{
//JESUS - For reddirect stdout to /dev/ttyGS0 (Serial Monitor port)
stdout = freopen("/dev/ttyGS0","w",stdout);
delay(500);
printf("redirecting to Serial...");
//JESUS -----------------------------------------------------------
}
#else #else
#error This example is only for use on Arduino. #error This example is only for use on Arduino.
#endif // ARDUINO #endif // ARDUINO
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment