Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RF24
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
RF24
Commits
e78893bf
Commit
e78893bf
authored
Feb 18, 2015
by
Anton Sabadash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Memory handling with MRAA device contexts
parent
c0848cb1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
23 deletions
+62
-23
RF24.h
RF24.h
+3
-0
arch/MRAA/RF24_arch_config.h
arch/MRAA/RF24_arch_config.h
+6
-4
arch/MRAA/gpio.cpp
arch/MRAA/gpio.cpp
+26
-5
arch/MRAA/gpio.h
arch/MRAA/gpio.h
+6
-7
arch/MRAA/spi.cpp
arch/MRAA/spi.cpp
+18
-6
arch/MRAA/spi.h
arch/MRAA/spi.h
+3
-1
No files found.
RF24.h
View file @
e78893bf
...
...
@@ -114,6 +114,9 @@ public:
RF24
(
uint8_t
_cepin
,
uint8_t
_cspin
,
uint32_t
spispeed
);
//#endif
virtual
~
RF24
()
{};
/**
* Begin operation of the chip
*
...
...
arch/MRAA/RF24_arch_config.h
View file @
e78893bf
...
...
@@ -4,7 +4,8 @@
#include "mraa.h"
#include "spi.h"
#include "gpio.h"
#include "compatibility.h"
//#include "compatibility.h"
#include <UtilTime.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
...
...
@@ -30,6 +31,7 @@
//typedef uint16_t prog_uint16_t;
#define PSTR(x) (x)
#define printf_P printf
#define sprintf_P sprintf
#define strlen_P strlen
#define PROGMEM
#define PRIPSTR "%s"
...
...
@@ -44,9 +46,9 @@
#define digitalWrite(pin, value) gpio.write(pin, value)
#define digitalRead(pin) GPIO::read(pin)
#define pinMode(pin, direction) gpio.open(pin, direction)
#define delay(milisec) __msleep(milisec)
#define delayMicroseconds(usec) __usleep(usec)
#define millis() __millis()
//
#define delay(milisec) __msleep(milisec)
//
#define delayMicroseconds(usec) __usleep(usec)
//
#define millis() __millis()
#define INPUT mraa::DIR_IN
#define OUTPUT mraa::DIR_OUT
...
...
arch/MRAA/gpio.cpp
View file @
e78893bf
...
...
@@ -6,9 +6,17 @@
#include "gpio.h"
GPIO
::
GPIO
()
{
// Prophet: basic members initialization
gpio_ce_pin
=
-
1
;
gpio_cs_pin
=
-
1
;
gpio_0
=
NULL
;
gpio_1
=
NULL
;
}
GPIO
::~
GPIO
()
{
// Prophet: this should free memory, and unexport pins when RF24 and/or GPIO gets deleted or goes out of scope
this
->
close
(
gpio_ce_pin
);
this
->
close
(
gpio_cs_pin
);
}
void
GPIO
::
begin
(
uint8_t
ce_pin
,
uint8_t
cs_pin
)
...
...
@@ -16,9 +24,10 @@ void GPIO::begin(uint8_t ce_pin, uint8_t cs_pin)
gpio_ce_pin
=
ce_pin
;
gpio_cs_pin
=
cs_pin
;
gpio_0
=
new
mraa
::
Gpio
(
ce_pin
,
0
);
gpio_1
=
new
mraa
::
Gpio
(
cs_pin
,
0
);
// Prophet: owner can be set here, because we use our pins exclusively, and are making mraa:Gpio context persistent
// so pins will be unexported only if close is called, or on destruction
gpio_0
=
new
mraa
::
Gpio
(
ce_pin
/*,0*/
);
gpio_1
=
new
mraa
::
Gpio
(
cs_pin
/*,0*/
);
}
void
GPIO
::
open
(
int
port
,
int
DDR
)
{
...
...
@@ -36,8 +45,20 @@ void GPIO::open(int port, int DDR)
void
GPIO
::
close
(
int
port
)
{
delete
gpio_0
;
delete
gpio_1
;
// Prophet: using same theme of working with port numbers as with GPIO::open,
// checking for mraa::Gpio context existence to be sure, that GPIO::begin was called
if
(
port
==
gpio_ce_pin
)
{
if
(
gpio_0
!=
NULL
)
{
delete
gpio_0
;
}
}
if
(
port
==
gpio_cs_pin
)
{
if
(
gpio_1
!=
NULL
)
{
delete
gpio_1
;
}
}
}
int
GPIO
::
read
(
int
port
)
...
...
arch/MRAA/gpio.h
View file @
e78893bf
...
...
@@ -3,8 +3,8 @@
*
*/
#ifndef H
#define H
#ifndef
RF24_ARCH_GPIO_
H
#define
RF24_ARCH_GPIO_
H
#include <cstdio>
#include <stdio.h>
...
...
@@ -16,7 +16,8 @@ public:
/* Constants */
GPIO
();
GPIO
();
virtual
~
GPIO
();
/**
* Sets up GPIO on the CE & CS pins
...
...
@@ -48,9 +49,7 @@ public:
* @param value
*/
void
write
(
int
port
,
int
value
);
virtual
~
GPIO
();
private:
int
gpio_ce_pin
;
/** ce_pin value of the RF24 device **/
int
gpio_cs_pin
;
/** cs_pin value of the RF24 device **/
...
...
@@ -58,5 +57,5 @@ private:
mraa
::
Gpio
*
gpio_1
;
/** gpio object for cs_pin **/
};
#endif
/* H */
#endif
/*
RF24_ARCH_GPIO_
H */
arch/MRAA/spi.cpp
View file @
e78893bf
...
...
@@ -3,21 +3,32 @@
#include "spi.h"
SPI
::
SPI
()
{
mspi
=
NULL
;
}
void
SPI
::
begin
(
)
{
void
SPI
::
begin
(
void
)
{
mspi
=
new
mraa
::
Spi
(
0
);
mspi
->
mode
(
mraa
::
SPI_MODE0
);
mspi
->
bitPerWord
(
8
);
mspi
->
frequency
(
8000000
);
mspi
->
frequency
(
4000000
);
}
// Prophet: this is only a suggestion, but can be useful for devices with multiple SPI ports
void
SPI
::
begin
(
int
bus
,
int
frequency
)
{
mspi
=
new
mraa
::
Spi
(
bus
);
mspi
->
mode
(
mraa
::
SPI_MODE0
);
mspi
->
bitPerWord
(
8
);
mspi
->
frequency
(
frequency
);
}
void
SPI
::
end
()
{
delete
mspi
;
// Prophet: we should check for existence of mspi before deleting it
if
(
mspi
!=
NULL
)
delete
mspi
;
}
void
SPI
::
setBitOrder
(
uint8_t
bit_order
)
{
...
...
@@ -37,5 +48,6 @@ void SPI::chipSelect(int csn_pin){
}
SPI
::~
SPI
()
{
}
\ No newline at end of file
// Prophet: we should call end here to free used memory and unexport SPI interface
this
->
end
();
}
arch/MRAA/spi.h
View file @
e78893bf
...
...
@@ -21,7 +21,9 @@ public:
inline
void
transfernb
(
char
*
tbuf
,
char
*
rbuf
,
uint32_t
len
);
inline
void
transfern
(
char
*
buf
,
uint32_t
len
);
void
begin
();
void
begin
(
void
);
// Prophet: A customized SPI::begin can be used with parameters defined as macro in RF24_arch_config.h
void
begin
(
int
bus
,
int
frequency
);
void
end
();
void
setBitOrder
(
uint8_t
bit_order
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment