Compare commits

..

32 Commits

Author SHA1 Message Date
d878a5cf1a upm: update to 0.1.7
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-08-18 16:03:13 +01:00
428f4e5bfc upm: remove flag setting, move node to target only
* Fixes issue with swig and sysroots

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-08-18 15:56:38 +01:00
050c134664 lpd8806: Added new module - digital led strip (NOT TESTED)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-08-18 11:21:48 +00:00
ffdd6d2f00 nrf8001: added helloworld example (communicating with nrf UART application
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-08-13 11:49:33 +00:00
044037b892 nrf8001: added new BLE module with broadcasting example
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-08-12 23:40:47 +00:00
ad87704c19 grovelight.cxx: add grovelight sample code
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-08-12 16:53:16 +01:00
00114f69d2 grove: add documentation for grove module
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-08-11 14:12:23 +01:00
c99821ad26 CMakeLists.txt: fix python builds and doc building
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-08-11 11:31:32 +01:00
a9939d6352 max31723: use new prefixed spi MODE enum
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-08-08 09:52:52 +01:00
5ed36a37f9 sm130: fix std::min call having issues with template argument dedudction
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-08-07 20:38:45 +01:00
03b9cf89a0 CMakeLists.txt: fix builds without swig
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-08-07 19:23:29 +01:00
9c9b273b5a lcd: overhaul documentation for lcd module
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-08-07 19:15:49 +01:00
586acf7502 contributions.md: add rules for documentation
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-08-07 19:15:32 +01:00
d0e83d7076 max31723: made it work with SPI but the data looks like incorrect
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-08-06 16:41:40 +00:00
1747fbbe19 max5487: added new sensor with example (TESTED AND WORKING)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-08-05 20:16:05 +00:00
45f85e9944 max31723 :: added new temperature sensor (HAVE ISSUES WITH SPI)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-08-04 18:01:21 +00:00
b31e88c233 maxds3231m :: added working example (set/get date and temperature)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-08-04 11:44:07 +00:00
58b80f6b58 maxds3231m :: fix to getTemperature method
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-08-04 12:00:58 +03:00
574a39d3c1 maxds3231m: Added new sensor support get/set data&time and get temperature (NOT TESTED YET)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-07-31 19:16:23 +03:00
bb38b35b32 sm130: Added new sensor (basic function was implemented and not tested)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-07-04 15:10:09 +00:00
d15bf22536 Fix some dosctrings errors and trailing whitespaces
Signed-off-by: Kirill Luchikhin <kirill.luchikhin@intel.com>
2014-07-29 21:46:48 +04:00
731704eaac Jhd1313m1: add basic scroll functionality
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-07-14 15:25:12 +01:00
00170bea97 my9221: return mraa_error_t when method says it does
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-07-14 13:59:56 +01:00
8cfb3d3dab my9221: add direction for setBarLevel
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-07-14 13:59:19 +01:00
d2e2682f0e building.md: Adding doc on building a simple example with g++ and using pkg-config
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-07-14 10:55:17 +01:00
22ad93956c building.md: add information to rebuild only one scripting module in doc
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-07-14 10:49:17 +01:00
86a3be4517 jhd1313m1: add setColor method call to control backlight
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-07-14 10:48:55 +01:00
8a67c143bf mic: add carrays for uint16_t as used by mic module
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-07-03 13:42:46 +01:00
7dc8ec6244 oled-1308.cxx: replace Seed logo with Intel logo
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-27 04:38:20 +01:00
0d544dadeb make_oled_pic.py: script can transform an image into correct format for oled-13xx displays
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-27 04:37:50 +01:00
9f66c10b26 upm.i: add stdint.i to add uinstd typemaps
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-26 19:20:10 +01:00
2822d63c9c upm.i: add top level interface file which includes std_string.i
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-25 14:16:28 +01:00
143 changed files with 9186 additions and 254 deletions

View File

@ -20,7 +20,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND")
message (WARNING " - Install git to compile a production libmraa!")
set (VERSION "v0.1.5-dirty")
set (VERSION "v0.1.7-dirty")
endif ()
message (INFO " - UPM Version ${VERSION}")

View File

@ -29,3 +29,31 @@ Building debug build:
Using clang instead of gcc:
-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang
Often developers are only interested in building one module or even just the
python/node module to do some quick testing using scripting. In order to do
this you need to use the target name for the python or node module you want to
rebuild. For example the lcd module target name is i2clcd. Therfore the python
module target name will be prefixed by _pyupm_. Just do the following to build
only that module. Modules not using the UPM cmake macros may have different
naming.
~~~~~~~~~~~~~
make _pyupm_i2clcd
~~~~~~~~~~~~~
Sometimes you want to build a small C++ example against an installed library.
This is fairly easy if installed systemwide. Just link against the correct
librar (in this case libupm-tm1637) and then add /usr/include/upm to the loader
path:
~~~~~~~~~~~~
g++ test.cxx -lupm_tm1637 -I/usr/include/upm
~~~~~~~~~~~~
You can also use pkg-config to return the information to you, which is
considered the correct way if including UPM in a build system like cmake or
autotools on linux.
~~~~~~~~~~~
pkg-config --cflags --libs upm-tm1637
~~~~~~~~~~~

View File

@ -2,10 +2,10 @@ Contributing a module {#contributions}
=====================
Here are the rules of contribution:
- Try not to break master. In any commit.
- Your module must have an example that builds against your UPM library
- Commits must have a sign-off line by everyone who reviewed them
- Commits must be named <file/module>: Some decent description
- You must license your module under an FOSS license. The recommended license
- You must license your module under a FOSS license. The recommended license
is MIT but any permissive license is fine. Please consider that people using
UPM may want to write proprietary programs with your sensors so we like to
avoid GPL. (LGPL is fine). If your license is not MIT please include a
@ -13,4 +13,22 @@ Here are the rules of contribution:
- Please test your module builds before contributing and make sure it works on
the latest version of mraa. If you tested on a specific board/platform please
tell us what this was in your PR.
- Try not to break master. In any commit.
- Attempt to have some decent API documentation below are the explicit rules on documentation:
Documentation
=============
- Try to have no warnings in doxygen, this is generally fairly easy
- Have the specific sensor manufacturer/model & version that you used, if you
support multiple versions please list
- Comments do not need full stops
- Stick to <80 chars per line even in comments
- No text is allowed on the same line as the start or end of a comment /** */
- All classes should have a "@brief" and a "@snippet"
The example should have an 'Interesting' section which will be highlighted as a
code sample in doxygen. Everything in between such tags will show up in the
class documentation when the following is put at the end of a class docstring
as show above.

View File

@ -31,7 +31,8 @@ change between the javascript & node.js one is the argument to %module.
The %include parameter defines which functions will be available to the
node/python module created, Whilst the headers inside %{} will be explicitly
required during compilation. Typically only the top level header is required in
either of those args.
either of those args. The upm.i is just a shortcut to include some commonly
used swig wrappers for UPM sensors, it's not obligatory but recommended.
### API

View File

@ -21,6 +21,12 @@ add_executable (stepmotor-example stepmotor.cxx)
add_executable (pulsensor-example pulsensor.cxx)
add_executable (mic-example mic-example.cxx)
add_executable (mpu9150-example mpu9150-example.cxx)
add_executable (maxds3231m-example maxds3231m.cxx)
add_executable (max31723-example max31723.cxx)
add_executable (max5487-example max5487.cxx)
add_executable (nrf8001-broadcast-example nrf8001_broadcast.cxx)
add_executable (nrf8001-helloworld-example nrf8001_helloworld.cxx)
add_executable (lpd8806-example lpd8806-example.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -40,6 +46,11 @@ include_directories (${PROJECT_SOURCE_DIR}/src/stepmotor)
include_directories (${PROJECT_SOURCE_DIR}/src/pulsensor)
include_directories (${PROJECT_SOURCE_DIR}/src/mic)
include_directories (${PROJECT_SOURCE_DIR}/src/mpu9150)
include_directories (${PROJECT_SOURCE_DIR}/src/maxds3231m)
include_directories (${PROJECT_SOURCE_DIR}/src/max31723)
include_directories (${PROJECT_SOURCE_DIR}/src/max5487)
include_directories (${PROJECT_SOURCE_DIR}/src/nrf8001)
include_directories (${PROJECT_SOURCE_DIR}/src/lpd8806)
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
@ -64,3 +75,9 @@ target_link_libraries (stepmotor-example stepmotor ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (pulsensor-example pulsensor ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mic-example mic ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mpu9150-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (maxds3231m-example maxds3231m ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (max31723-example max31723 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (max5487-example max5487 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf8001-broadcast-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf8001-helloworld-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lpd8806-example lpd8806 ${CMAKE_THREAD_LIBS_INIT})

View File

@ -29,7 +29,7 @@
int
main(int argc, char **argv)
{
// Use i2c device 0 all the time
//! [Interesting]
upm::GroveLed* led = new upm::GroveLed(2);
std::cout << led->name() << std::endl;
for (int i=0; i < 10; i++) {
@ -38,6 +38,7 @@ main(int argc, char **argv)
led->off();
sleep(1);
}
//! [Interesting]
return 0;
}

40
examples/grovelight.cxx Normal file
View File

@ -0,0 +1,40 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <unistd.h>
#include <iostream>
#include "grove.h"
int
main(int argc, char **argv)
{
// This example uses AIO 0
//! [Interesting]
upm::GroveLight* light = new upm::GroveLight(0);
int lightValue = light->value();
delete light;
//! [Interesting]
return 0;
}

View File

@ -29,13 +29,14 @@
int
main(int argc, char **argv)
{
// Use i2c device 0 all the time
//! [Interesting]
upm::GroveTemp* s = new upm::GroveTemp(0);
std::cout << s->name() << std::endl;
for (int i=0; i < 10; i++) {
std::cout << s->value() << std::endl;
sleep(1);
}
//! [Interesting]
return 0;
}

View File

@ -27,9 +27,11 @@
int
main(int argc, char **argv)
{
//! [Interesting]
upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
lcd->setCursor(0,0);
lcd->write("Hello World");
//! [Interesting]
lcd->setCursor(1,2);
lcd->write("Hello World");
lcd->setCursor(2,4);

View File

@ -0,0 +1,104 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <unistd.h>
#include <iostream>
#include "lpd8806.h"
#include <signal.h>
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
int doWork = 0;
upm::LPD8806 *sensor = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
doWork = 1;
}
}
int
main(int argc, char **argv)
{
//! [Interesting]
sensor = new upm::LPD8806(10, 7);
usleep (1000000);
sensor->show ();
while (!doWork) {
// Back-and-forth lights
scanner(127, 0, 0, 30); // red, slow
scanner(0, 0, 127, 15); // blue, fast
usleep (1000000);
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
int i, j, pos, dir;
pos = 0;
dir = 1;
for(i=0; i < ((sensor->getStripLength() - 1) * 8); i++) {
// Draw 5 pixels centered on pos. setPixelColor() will clip
// any pixels off the ends of the strip, no worries there.
// we'll make the colors dimmer at the edges for a nice pulse
// look
sensor->setPixelColor(pos - 2, r/4, g/4, b/4);
sensor->setPixelColor(pos - 1, r/2, g/2, b/2);
sensor->setPixelColor(pos, r, g, b);
sensor->setPixelColor(pos + 1, r/2, g/2, b/2);
sensor->setPixelColor(pos + 2, r/4, g/4, b/4);
sensor->show();
usleep (wait * 1000);
// If we wanted to be sneaky we could erase just the tail end
// pixel, but it's much easier just to erase the whole thing
// and draw a new one next time.
for(j=-2; j<= 2; j++) {
sensor->setPixelColor(pos+j, 0,0,0);
}
// Bounce off ends of strip
pos += dir;
if(pos < 0) {
pos = 1;
dir = -dir;
} else if (pos >= sensor->getStripLength()) {
pos = sensor->getStripLength() - 2;
dir = -dir;
}
}
}

61
examples/max31723.cxx Normal file
View File

@ -0,0 +1,61 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <unistd.h>
#include <iostream>
#include "max31723.h"
#include <signal.h>
int doWork = 0;
upm::MAX31723 *sensor = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
doWork = 1;
}
}
int
main(int argc, char **argv)
{
//! [Interesting]
sensor = new upm::MAX31723(7);
usleep (1000000);
while (!doWork) {
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
usleep (1000000);
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

66
examples/max5487.cxx Normal file
View File

@ -0,0 +1,66 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <unistd.h>
#include <iostream>
#include "max5487.h"
#include <signal.h>
upm::MAX5487 *sensor = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
}
}
int
main(int argc, char **argv)
{
//! [Interesting]
sensor = new upm::MAX5487(7);
// Power LED UP
for (int i = 0; i < 255; i++) {
sensor->setWiperA(i);
usleep (5000);
}
// Power LED DOWN
for (int i = 0; i < 255; i++) {
sensor->setWiperA(255 - i);
usleep (5000);
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

75
examples/maxds3231m.cxx Normal file
View File

@ -0,0 +1,75 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <unistd.h>
#include <iostream>
#include "maxds3231m.h"
#include <signal.h>
int doWork = 0;
upm::MAXDS3231M *sensor = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
doWork = 1;
}
}
int
main(int argc, char **argv)
{
//! [Interesting]
upm::Time3231 t;
sensor = new upm::MAXDS3231M(0, ADDR);
t.second = 1;
t.minute = 3;
t.hour = 3;
t.day = 3;
t.month = 3;
t.year = 3;
t.weekDay = 3;
sensor->setDate (t); // Note, second should be set to 1.
usleep (500000);
while (!doWork) {
if (sensor->getDate (t)) {
std::cout << (int)t.hour << ":" << (int)t.minute << ":" << (int)t.second << std::endl;
}
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
usleep (1000000);
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

View File

@ -0,0 +1,177 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <unistd.h>
#include <iostream>
#include "nrf8001.h"
#include "nrf8001_broadcast.h"
#include <lib_aci.h>
#include <aci_setup.h>
#include <signal.h>
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
static services_pipe_type_mapping_t
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
#else
#define NUMBER_OF_PIPES 0
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
#endif
/**
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
*/
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
/**
* aci_struct that will contain
* total initial credits
* current credit
* current state of the aci (setup/standby/active/sleep)
* open remote pipe pending
* close remote pipe pending
* Current pipe available bitmap
* Current pipe closed bitmap
* Current connection interval, slave latency and link supervision timeout
* Current State of the the GATT client (Service Discovery)
* Status of the bond (R) Peer address
*/
static struct aci_state_t aci_state;
/**
* Temporary buffers for sending ACI commands
*/
static hal_aci_evt_t aci_data;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
}
}
void
init_aci_setup () {
/**
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
*/
if (NULL != services_pipe_type_mapping) {
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
} else {
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
}
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
aci_state.aci_setup_info.setup_msgs = setup_msgs;
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
}
int
main(int argc, char **argv)
{
//! [Interesting]
init_aci_setup ();
init_local_interfaces (&aci_state, 10, 8, 4);
while (1) {
static bool setup_required = false;
if (lib_aci_event_get (&aci_state, &aci_data)) {
aci_evt_t * aci_evt;
aci_evt = &aci_data.evt;
switch(aci_evt->evt_opcode) {
/**
As soon as you reset the nRF8001 you will get an ACI Device Started Event
*/
case ACI_EVT_DEVICE_STARTED: {
aci_state.data_credit_available = aci_evt->params.device_started.credit_available;
switch(aci_evt->params.device_started.device_mode) {
case ACI_DEVICE_SETUP:
/**
When the device is in the setup mode
*/
printf ("Evt Device Started: Setup\n");
setup_required = true;
break;
case ACI_DEVICE_STANDBY:
printf ("Evt Device Started: Standby\n");
lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */);
printf ("Broadcasting started\n");
break;
}
}
break; //ACI Device Started Event
case ACI_EVT_CMD_RSP:
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
printf ("ACI_EVT_CMD_RSP\n");
while (1);
}
break;
case ACI_EVT_CONNECTED:
printf ("ACI_EVT_CONNECTED\n");
break;
case ACI_EVT_PIPE_STATUS:
printf ("ACI_EVT_PIPE_STATUS\n");
break;
case ACI_EVT_DISCONNECTED:
if (ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status) {
printf ("Broadcasting timed out\n");
} else {
printf ("Evt Disconnected. Link Loss\n");
}
break;
case ACI_EVT_DATA_RECEIVED:
printf ("ACI_EVT_DATA_RECEIVED\n");
break;
case ACI_EVT_HW_ERROR:
printf ("ACI_EVT_HW_ERROR\n");
break;
}
}
if (setup_required) {
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
setup_required = false;
}
}
usleep (100);
}
close_local_interfaces (&aci_state);
//! [Interesting]
std::cout << "exiting application" << std::endl;
return 0;
}

View File

@ -0,0 +1,93 @@
#include "hal_platform.h"
#include "aci.h"
#pragma once
#define PIPE_GAP_DEVICE_NAME_SET 1
#define NUMBER_OF_PIPES 1
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
{ACI_STORE_LOCAL, ACI_SET}, \
}
#define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
#define GAP_PPCP_MIN_CONN_INT 0xffff /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific maximum*/
#define GAP_PPCP_SLAVE_LATENCY 0
#define GAP_PPCP_CONN_TIMEOUT 0xffff /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
#define NB_SETUP_MESSAGES 13
#define SETUP_MESSAGES_CONTENT {\
{0x00,\
{\
0x07,0x06,0x00,0x00,0x03,0x02,0x41,0xd7,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x10,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0x64,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x10,0x38,0x02,0xff,0x02,0x58,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
},\
},\
{0x00,\
{\
0x05,0x06,0x10,0x54,0x00,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
0x02,0x28,0x03,0x01,0x0e,0x03,0x00,0x00,0x2a,0x04,0x14,0x0b,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x62,0x63,0x61,0x73,0x74,0x63,0x73,0x65,0x6d,0x69,\
0x2e,0x04,0x04,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x38,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x00,0x00,0x04,0x04,\
0x05,0x05,0x00,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x54,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,0x04,0x01,0xff,0xff,0xff,0xff,0x00,0x00,0xff,\
0xff,0x04,0x04,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,\
},\
},\
{0x00,\
{\
0x04,0x06,0x20,0x70,0x00,\
},\
},\
{0x00,\
{\
0x0d,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,\
},\
},\
{0x00,\
{\
0x06,0x06,0x60,0x00,0x00,0x00,0x00,\
},\
},\
{0x00,\
{\
0x06,0x06,0xf0,0x00,0x03,0x4c,0xf2,\
},\
},\
}

View File

@ -0,0 +1,362 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <unistd.h>
#include <iostream>
#include "nrf8001.h"
#include "nrf8001_helloworld.h"
#include <lib_aci.h>
#include <aci_setup.h>
#include <signal.h>
#include "uart_over_ble.h"
/*
* You can use the nRF UART app in the Apple iOS app store and Google Play for Android 4.3 for Samsung Galaxy S4
* with this helloworld application
*/
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
static services_pipe_type_mapping_t
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
#else
#define NUMBER_OF_PIPES 0
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
#endif
/**
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
*/
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
/**
* aci_struct that will contain
* total initial credits
* current credit
* current state of the aci (setup/standby/active/sleep)
* open remote pipe pending
* close remote pipe pending
* Current pipe available bitmap
* Current pipe closed bitmap
* Current connection interval, slave latency and link supervision timeout
* Current State of the the GATT client (Service Discovery)
* Status of the bond (R) Peer address
*/
static struct aci_state_t aci_state;
/**
* Temporary buffers for sending ACI commands
*/
static hal_aci_evt_t aci_data;
/*
Timing change state variable
*/
static bool timing_change_done = false;
/*
Used to test the UART TX characteristic notification
*/
static uart_over_ble_t uart_over_ble;
static uint8_t uart_buffer[20];
static uint8_t uart_buffer_len = 0;
static uint8_t dummychar = 0;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
}
}
void
init_aci_setup () {
/**
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
*/
if (NULL != services_pipe_type_mapping) {
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
} else {
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
}
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
aci_state.aci_setup_info.setup_msgs = setup_msgs;
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
}
void
uart_over_ble_init (void) {
uart_over_ble.uart_rts_local = true;
}
bool
uart_tx (uint8_t *buffer, uint8_t buffer_len) {
bool status = false;
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) &&
(aci_state.data_credit_available >= 1)) {
status = lib_aci_send_data(PIPE_UART_OVER_BTLE_UART_TX_TX, buffer, buffer_len);
if (status) {
aci_state.data_credit_available--;
}
}
return status;
}
bool
uart_process_control_point_rx(uint8_t *byte, uint8_t length) {
bool status = false;
aci_ll_conn_params_t *conn_params;
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX) ) {
switch (*byte) {
/*
Queues a ACI Disconnect to the nRF8001 when this packet is received.
May cause some of the UART packets being sent to be dropped
*/
case UART_OVER_BLE_DISCONNECT:
/*
Parameters:
None
*/
lib_aci_disconnect(&aci_state, ACI_REASON_TERMINATE);
status = true;
break;
/*
Queues an ACI Change Timing to the nRF8001
*/
case UART_OVER_BLE_LINK_TIMING_REQ:
/*
Parameters:
Connection interval min: 2 bytes
Connection interval max: 2 bytes
Slave latency: 2 bytes
Timeout: 2 bytes
Same format as Peripheral Preferred Connection Parameters (See nRFgo studio -> nRF8001 Configuration -> GAP Settings
Refer to the ACI Change Timing Request in the nRF8001 Product Specifications
*/
conn_params = (aci_ll_conn_params_t *)(byte+1);
lib_aci_change_timing( conn_params->min_conn_interval,
conn_params->max_conn_interval,
conn_params->slave_latency,
conn_params->timeout_mult);
status = true;
break;
/*
Clears the RTS of the UART over BLE
*/
case UART_OVER_BLE_TRANSMIT_STOP:
/*
Parameters:
None
*/
uart_over_ble.uart_rts_local = false;
status = true;
break;
/*
Set the RTS of the UART over BLE
*/
case UART_OVER_BLE_TRANSMIT_OK:
/*
Parameters:
None
*/
uart_over_ble.uart_rts_local = true;
status = true;
break;
}
}
return status;
}
int
main(int argc, char **argv)
{
//! [Interesting]
init_aci_setup ();
init_local_interfaces (&aci_state, 10, 8, 4);
while (1) {
static bool setup_required = false;
// We enter the if statement only when there is a ACI event available to be processed
if (lib_aci_event_get(&aci_state, &aci_data)) {
aci_evt_t * aci_evt;
aci_evt = &aci_data.evt;
switch(aci_evt->evt_opcode) {
/**
As soon as you reset the nRF8001 you will get an ACI Device Started Event
*/
case ACI_EVT_DEVICE_STARTED: {
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
switch(aci_evt->params.device_started.device_mode) {
case ACI_DEVICE_SETUP:
/**
When the device is in the setup mode
*/
printf ("Evt Device Started: Setup \n");
setup_required = true;
break;
case ACI_DEVICE_STANDBY:
printf ("Evt Device Started: Standby \n");
// Looking for an iPhone by sending radio advertisements
// When an iPhone connects to us we will get an ACI_EVT_CONNECTED event from the nRF8001
if (aci_evt->params.device_started.hw_error) {
usleep (20000); //Handle the HW error event correctly.
} else {
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
printf ("Advertising started \n");
}
break;
}
}
break; // ACI Device Started Event
case ACI_EVT_CMD_RSP:
//If an ACI command response event comes with an error -> stop
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
//ACI ReadDynamicData and ACI WriteDynamicData will have status codes of
//TRANSACTION_CONTINUE and TRANSACTION_COMPLETE
//all other ACI commands will have status code of ACI_STATUS_SCUCCESS for a successful command
printf ("ACI_EVT_CMD_RSP \n");
}
if (ACI_CMD_GET_DEVICE_VERSION == aci_evt->params.cmd_rsp.cmd_opcode) {
//Store the version and configuration information of the nRF8001 in the Hardware Revision String Characteristic
lib_aci_set_local_data(&aci_state, PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET,
(uint8_t *)&(aci_evt->params.cmd_rsp.params.get_device_version), sizeof(aci_evt_cmd_rsp_params_get_device_version_t));
}
break;
case ACI_EVT_CONNECTED:
printf ("ACI_EVT_CONNECTED");
uart_over_ble_init ();
timing_change_done = false;
aci_state.data_credit_available = aci_state.data_credit_total;
/*
Get the device version of the nRF8001 and store it in the Hardware Revision String
*/
lib_aci_device_version();
break;
case ACI_EVT_PIPE_STATUS:
printf ("ACI_EVT_PIPE_STATUS \n");
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) && (false == timing_change_done)) {
lib_aci_change_timing_GAP_PPCP(); // change the timing on the link as specified in the nRFgo studio -> nRF8001 conf. -> GAP.
// Used to increase or decrease bandwidth
timing_change_done = true;
char hello[]="Hello World, works";
uart_tx((uint8_t *)&hello[0], strlen(hello));
}
break;
case ACI_EVT_TIMING:
printf ("Evt link connection interval changed \n");
lib_aci_set_local_data(&aci_state,
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET,
(uint8_t *)&(aci_evt->params.timing.conn_rf_interval), /* Byte aligned */
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE);
break;
case ACI_EVT_DISCONNECTED:
printf ("ACI_EVT_DISCONNECTED \n");
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
printf ("Advertising started \n");
break;
case ACI_EVT_DATA_RECEIVED:
if (PIPE_UART_OVER_BTLE_UART_RX_RX == aci_evt->params.data_received.rx_data.pipe_number) {
for(int i=0; i<aci_evt->len - 2; i++) {
uart_buffer[i] = aci_evt->params.data_received.rx_data.aci_data[i];
}
uart_buffer_len = aci_evt->len - 2;
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX)) {
}
}
if (PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX == aci_evt->params.data_received.rx_data.pipe_number) {
//Subtract for Opcode and Pipe number
uart_process_control_point_rx(&aci_evt->params.data_received.rx_data.aci_data[0], aci_evt->len - 2);
}
printf ("Incomming data - %s\n", uart_buffer);
break;
case ACI_EVT_DATA_CREDIT:
printf ("ACI_EVT_DATA_CREDIT \n");
aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit;
break;
case ACI_EVT_PIPE_ERROR:
printf ("ACI_EVT_PIPE_ERROR \n");
//Increment the credit available as the data packet was not sent.
//The pipe error also represents the Attribute protocol Error Response sent from the peer and that should not be counted
//for the credit.
if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code) {
aci_state.data_credit_available++;
}
break;
case ACI_EVT_HW_ERROR:
printf ("ACI_EVT_HW_ERROR \n");
lib_aci_connect(0/* in seconds, 0 means forever */, 0x0050 /* advertising interval 50ms*/);
printf ("Advertising started \n");
break;
}
}
/* setup_required is set to true when the device starts up and enters setup mode.
* It indicates that do_aci_setup() should be called. The flag should be cleared if
* do_aci_setup() returns ACI_STATUS_TRANSACTION_COMPLETE.
*/
if(setup_required) {
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
setup_required = false;
}
}
usleep (100);
}
close_local_interfaces (&aci_state);
//! [Interesting]
std::cout << "exiting application" << std::endl;
return 0;
}

View File

@ -0,0 +1,254 @@
#include "hal_platform.h"
#include "aci.h"
#pragma once
#define SETUP_ID 0
#define SETUP_FORMAT 2 /** nRF8001 Cx */
#define ACI_DYNAMIC_DATA_SIZE 263
/* Service: GATT - Characteristic: Service Changed - Pipe: TX_ACK */
#define PIPE_GATT_SERVICE_CHANGED_TX_ACK 1
#define PIPE_GATT_SERVICE_CHANGED_TX_ACK_MAX_SIZE 4
/* Service: Device Information - Characteristic: Hardware Revision String - Pipe: SET */
#define PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET 2
#define PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET_MAX_SIZE 9
/* Service: Device Information - Characteristic: Manufacturer Name String - Pipe: SET */
#define PIPE_DEVICE_INFORMATION_MANUFACTURER_NAME_STRING_SET 3
#define PIPE_DEVICE_INFORMATION_MANUFACTURER_NAME_STRING_SET_MAX_SIZE 20
/* Service: Device Information - Characteristic: Model Number String - Pipe: SET */
#define PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_SET 4
#define PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_SET_MAX_SIZE 8
/* Service: Device Information - Characteristic: Firmware Revision String - Pipe: SET */
#define PIPE_DEVICE_INFORMATION_FIRMWARE_REVISION_STRING_SET 5
#define PIPE_DEVICE_INFORMATION_FIRMWARE_REVISION_STRING_SET_MAX_SIZE 4
/* Service: Device Information - Characteristic: PNP_ID - Pipe: SET */
#define PIPE_DEVICE_INFORMATION_PNP_ID_SET 6
#define PIPE_DEVICE_INFORMATION_PNP_ID_SET_MAX_SIZE 7
/* Service: UART over BTLE - Characteristic: UART RX - Pipe: RX */
#define PIPE_UART_OVER_BTLE_UART_RX_RX 7
#define PIPE_UART_OVER_BTLE_UART_RX_RX_MAX_SIZE 20
/* Service: UART over BTLE - Characteristic: UART TX - Pipe: TX */
#define PIPE_UART_OVER_BTLE_UART_TX_TX 8
#define PIPE_UART_OVER_BTLE_UART_TX_TX_MAX_SIZE 20
/* Service: UART over BTLE - Characteristic: UART Control Point - Pipe: TX */
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX 9
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX_MAX_SIZE 9
/* Service: UART over BTLE - Characteristic: UART Control Point - Pipe: RX */
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX 10
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX_MAX_SIZE 9
/* Service: UART over BTLE - Characteristic: UART Link Timing Current - Pipe: SET */
#define PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET 11
#define PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE 6
#define NUMBER_OF_PIPES 11
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
{ACI_STORE_LOCAL, ACI_TX_ACK}, \
{ACI_STORE_LOCAL, ACI_SET}, \
{ACI_STORE_LOCAL, ACI_SET}, \
{ACI_STORE_LOCAL, ACI_SET}, \
{ACI_STORE_LOCAL, ACI_SET}, \
{ACI_STORE_LOCAL, ACI_SET}, \
{ACI_STORE_LOCAL, ACI_RX}, \
{ACI_STORE_LOCAL, ACI_TX}, \
{ACI_STORE_LOCAL, ACI_TX}, \
{ACI_STORE_LOCAL, ACI_RX}, \
{ACI_STORE_LOCAL, ACI_SET}, \
}
#define GAP_PPCP_MAX_CONN_INT 0x12 /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
#define GAP_PPCP_MIN_CONN_INT 0xa /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
#define GAP_PPCP_SLAVE_LATENCY 0
#define GAP_PPCP_CONN_TIMEOUT 0xa /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
#define NB_SETUP_MESSAGES 30
#define SETUP_MESSAGES_CONTENT {\
{0x00,\
{\
0x07,0x06,0x00,0x00,0x02,0x02,0x41,0xfe,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x0b,0x01,0x01,0x00,0x00,0x06,0x00,0x00,\
0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
},\
},\
{0x00,\
{\
0x1e,0x06,0x10,0x1c,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x14,0x03,0x90,0x01,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
0x02,0x28,0x03,0x01,0x02,0x03,0x00,0x00,0x2a,0x04,0x04,0x14,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x48,0x65,0x6c,0x6c,0x6f,0x63,0x73,0x65,0x6d,0x69,\
0x2e,0x63,0x6f,0x6d,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x38,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,\
0x00,0x05,0x2a,0x01,0x01,0x80,0x00,0x04,0x04,0x05,0x05,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x54,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,\
0x04,0x01,0x0a,0x00,0x12,0x00,0x00,0x00,0x0a,0x00,0x04,0x04,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x70,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,0x04,0x04,0x05,0x05,0x00,0x09,0x28,\
0x03,0x01,0x22,0x0a,0x00,0x05,0x2a,0x26,0x04,0x05,0x04,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0x8c,0x0a,0x2a,0x05,0x01,0x00,0x00,0x00,0x00,0x46,0x14,0x03,0x02,0x00,0x0b,0x29,0x02,\
0x01,0x00,0x00,0x04,0x04,0x02,0x02,0x00,0x0c,0x28,0x00,0x01,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0xa8,0x0a,0x18,0x04,0x04,0x05,0x05,0x00,0x0d,0x28,0x03,0x01,0x02,0x0e,0x00,0x27,0x2a,\
0x04,0x04,0x09,0x01,0x00,0x0e,0x2a,0x27,0x01,0x0a,0x00,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0xc4,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x0f,0x28,0x03,0x01,0x02,\
0x10,0x00,0x29,0x2a,0x04,0x04,0x14,0x02,0x00,0x10,0x2a,0x29,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0xe0,0x01,0x30,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x11,0x28,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x20,0xfc,0x03,0x01,0x02,0x12,0x00,0x24,0x2a,0x04,0x04,0x08,0x02,0x00,0x12,0x2a,0x24,0x01,\
0x31,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0x18,0x00,0x13,0x28,0x03,0x01,0x02,0x14,0x00,0x26,0x2a,0x04,0x04,0x04,0x02,0x00,0x14,\
0x2a,0x26,0x01,0x33,0x34,0x00,0x00,0x04,0x04,0x05,0x05,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0x34,0x15,0x28,0x03,0x01,0x02,0x16,0x00,0x50,0x2a,0x06,0x04,0x08,0x07,0x00,0x16,0x2a,\
0x50,0x01,0x02,0x00,0x00,0xaa,0xaa,0xcc,0xcc,0x04,0x04,0x10,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0x50,0x10,0x00,0x17,0x28,0x00,0x01,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,\
0xa3,0xb5,0x01,0x00,0x40,0x6e,0x04,0x04,0x13,0x13,0x00,0x18,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0x6c,0x28,0x03,0x01,0x04,0x19,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,\
0xa3,0xb5,0x02,0x00,0x40,0x6e,0x44,0x10,0x14,0x00,0x00,0x19,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0x88,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x13,0x13,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0xa4,0x1a,0x28,0x03,0x01,0x10,0x1b,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,\
0xf3,0xa3,0xb5,0x03,0x00,0x40,0x6e,0x14,0x00,0x14,0x00,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0xc0,0x1b,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,0x02,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0xdc,0x00,0x1c,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x1d,0x28,0x03,0x01,\
0x14,0x1e,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x21,0xf8,0xf3,0xa3,0xb5,0x04,0x00,0x40,0x6e,0x54,0x10,0x09,0x00,0x00,0x1e,0x00,0x04,0x02,\
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x22,0x14,0x02,0x00,0x1f,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x20,0x28,0x03,\
0x01,0x02,0x21,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,\
},\
},\
{0x00,\
{\
0x1b,0x06,0x22,0x30,0x93,0xf3,0xa3,0xb5,0x05,0x00,0x40,0x6e,0x06,0x04,0x07,0x06,0x00,0x21,0x00,0x05,\
0x02,0xff,0xff,0xff,0xff,0xff,0xff,0x00,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x40,0x00,0x2a,0x05,0x01,0x00,0x04,0x04,0x00,0x0a,0x00,0x0b,0x2a,0x27,0x01,0x00,0x80,0x04,\
0x00,0x0e,0x00,0x00,0x2a,0x29,0x01,0x00,0x80,0x04,0x00,0x10,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x40,0x1c,0x00,0x00,0x2a,0x24,0x01,0x00,0x80,0x04,0x00,0x12,0x00,0x00,0x2a,0x26,0x01,0x00,\
0x80,0x04,0x00,0x14,0x00,0x00,0x2a,0x50,0x01,0x00,0x80,0x04,\
},\
},\
{0x00,\
{\
0x1f,0x06,0x40,0x38,0x00,0x16,0x00,0x00,0x00,0x02,0x02,0x00,0x08,0x04,0x00,0x19,0x00,0x00,0x00,0x03,\
0x02,0x00,0x02,0x04,0x00,0x1b,0x00,0x1c,0x00,0x04,0x02,0x00,\
},\
},\
{0x00,\
{\
0x13,0x06,0x40,0x54,0x0a,0x04,0x00,0x1e,0x00,0x1f,0x00,0x05,0x02,0x00,0x80,0x04,0x00,0x21,0x00,0x00,\
},\
},\
{0x00,\
{\
0x13,0x06,0x50,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,0xa3,0xb5,0x00,0x00,0x40,0x6e,\
},\
},\
{0x00,\
{\
0x06,0x06,0xf0,0x00,0x02,0xb2,0xd1,\
},\
},\
}

View File

@ -27,90 +27,72 @@
#define DEVICE_ADDRESS 0x3C
#define BUS_NUMBER 0x0
static uint8_t SeeedLogo[] ={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x60, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0xff, 0xfc, 0x00, 0x00, 0x00, 0x80, 0xf0, 0x20, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0x60, 0xe0, 0xc0,
0xc0, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x80, 0xc0,
0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0,
0x80, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0xc0, 0xf0, 0xf0, 0xf0, 0xc0, 0x00, 0xc0,
0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0,
0xf8, 0xf8, 0x00, 0xd8, 0xd8, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00,
0x00, 0x03, 0x0f, 0x1e, 0x3c, 0x70, 0xe3, 0xcf, 0x9f, 0x30, 0x00, 0x00, 0x00, 0x00, 0x70, 0xbf,
0xcf, 0xe3, 0x70, 0x78, 0x3e, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x33, 0x77, 0x66, 0x66, 0x66, 0x6c,
0x7d, 0x18, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37, 0x07, 0x00, 0x0f, 0x3f, 0x7f,
0x66, 0x66, 0x66, 0x66, 0x77, 0x27, 0x07, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37,
0x07, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x11, 0x37, 0x67, 0x66, 0x66, 0x6c, 0x7d, 0x38, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00, 0x00, 0x1f,
0x3f, 0x70, 0x60, 0x60, 0x70, 0x7f, 0x7f, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31,
0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x06, 0x1f, 0x3b, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3f, 0x1f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0xb0, 0x00, 0xc0, 0x20,
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00,
0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0xf8, 0x08,
0x08, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0x20, 0xa0,
0xa0, 0xa0, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0x08, 0x00, 0x20, 0x40, 0x80, 0x40,
0x20, 0x00, 0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0xe0, 0x00,
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x01, 0x00, 0x01, 0x02,
0x02, 0x02, 0x01, 0x00, 0x01, 0x02, 0x02, 0x02, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00,
0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x02,
0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x01, 0x02,
0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x82, 0x02, 0x00, 0x02, 0x01, 0x01, 0x01,
0x02, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x03, 0x00,
0x00, 0x00, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x82, 0x8c, 0x60, 0x1c, 0x02, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x1e,
0x20, 0x20, 0x00, 0x3e, 0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x1c, 0x2a, 0x2a, 0x2a, 0x0c, 0x00, 0x12, 0x2a, 0x2a,
0x2a, 0x1c, 0x20, 0x1c, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3f, 0x00, 0x02, 0x02, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static uint8_t intel_logo[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 192, 192, 192, 224,
224, 224, 224, 240, 240, 248, 248, 120, 120, 120, 120, 60, 60, 60, 60, 60,
62, 30, 30, 30, 30, 30, 30, 30, 31, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 31, 31, 31, 31, 31,
30, 62, 62, 62, 62, 126, 126, 124, 124, 252, 252, 248, 248, 240, 240, 240,
224, 224, 224, 192, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128,
128, 0, 56, 56, 28, 30, 14, 15, 15, 7, 7, 7, 7, 3, 3, 1, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 192, 193, 195, 195,
195, 7, 15, 15, 63, 127, 255, 255, 255, 254, 252, 252, 240, 192, 0, 0, 0,
0, 0, 0, 0, 0, 128, 192, 192, 240, 248, 124, 124, 60, 0, 0, 0, 0, 159, 159,
159, 159, 159, 159, 159, 159, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0,
0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 128, 128, 128, 128,
128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 192, 192, 192, 192, 192, 192, 128,
128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255,
0, 0, 0, 0, 3, 7, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1, 255, 255, 255, 255, 255,
255, 255, 0, 0, 224, 248, 252, 252, 255, 127, 15, 15, 3, 1, 0, 0, 0, 0, 0,
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
255, 255, 255, 255, 255, 15, 15, 15, 15, 15, 15, 255, 255, 255, 255, 255,
255, 255, 252, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 15, 15,
15, 15, 15, 224, 224, 252, 254, 255, 255, 255, 255, 159, 159, 143, 143,
135, 135, 143, 159, 255, 255, 255, 255, 255, 255, 252, 248, 0, 0, 0, 255,
255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,
224, 248, 248, 255, 255, 255, 255, 255, 127, 15, 255, 255, 255, 255, 255,
255, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0,
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
255, 255, 255, 255, 255, 192, 192, 192, 192, 192, 31, 31, 255, 255, 255,
255, 255, 255, 231, 231, 199, 199, 199, 199, 199, 199, 199, 199, 231, 231,
231, 231, 199, 135, 0, 0, 0, 63, 255, 255, 255, 255, 255, 255, 255, 0, 0,
0, 0, 224, 240, 248, 248, 252, 254, 255, 255, 255, 127, 63, 63, 31, 15, 7,
7, 1, 0, 0, 63, 63, 255, 255, 255, 255, 255, 240, 192, 192, 128, 0, 0, 0,
0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7,
0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 3, 3, 7, 7, 7,
7, 7, 7, 7, 7, 7, 0, 0, 0, 1, 3, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7,
7, 7, 3, 3, 3, 1, 0, 0, 0, 0, 1, 3, 3, 7, 135, 135, 135, 192, 192, 0, 0, 7,
7, 3, 3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 15,
31, 127, 127, 127, 255, 255, 252, 252, 252, 248, 240, 240, 240, 224, 224,
224, 192, 192, 192, 192, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 192, 192, 192, 192, 192,
224, 224, 224, 224, 240, 240, 240, 240, 248, 248, 248, 248, 252, 252, 252,
254, 254, 255, 255, 255, 255, 255, 255, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
3, 3, 3, 7, 7, 7, 15, 15, 31, 31, 31, 63, 63, 63, 63, 63, 127, 127, 127,
127, 127, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254, 254, 254, 254,
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
255, 255, 255, 255, 255, 255, 255, 127, 127, 127, 127, 127, 127, 127, 127,
63, 63, 63, 63, 63, 31, 31, 31, 31, 31, 15, 15, 15, 15, 7, 7, 7, 7, 3, 3,
3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0 };
int
main(int argc, char **argv)
{
upm::SSD1308 *lcd = new upm::SSD1308 (BUS_NUMBER, DEVICE_ADDRESS);
//! [Interesting]
upm::SSD1308 *lcd = new upm::SSD1308(BUS_NUMBER, DEVICE_ADDRESS);
/*
* Simple print hello world
*/
// lcd->setCursor (0, 0);
// lcd->write ("Hello World");
lcd->clear();
lcd->draw(intel_logo, 1024);
/*
* Simple print hello world
*/
lcd->clear ();
lcd->draw (SeeedLogo, 1024);
lcd->close ();
lcd->close();
//! [Interesting]
}

View File

@ -106,21 +106,19 @@ static uint8_t SeeedLogo[] ={
int
main(int argc, char **argv)
{
upm::SSD1327 *lcd = new upm::SSD1327 (BUS_NUMBER, 0x3C);
//! [Interesting]
upm::SSD1327 *lcd = new upm::SSD1327(BUS_NUMBER, 0x3C);
/*
* Simple print hello world
*/
for(uint8_t i = 0; i < 12 ; i++) {
lcd->setCursor (i, 0);
lcd->setGrayLevel (i);
lcd->write ("Hello World");
// Simple print hello world
for (uint8_t i = 0; i < 12; i++) {
lcd->setCursor(i, 0);
lcd->setGrayLevel(i);
lcd->write("Hello World");
}
/*
* Simple print hello world
*/
lcd->draw (SeeedLogo, 96 * 96 / 8);
// Simple print hello world
lcd->draw(SeeedLogo, 96 * 96 / 8);
lcd->close ();
lcd->close();
//! [Interesting]
}

View File

@ -0,0 +1,74 @@
#!/usr/bin/env python
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
# Copyright (c) 2014 Intel Corporation.
#
# 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
from __future__ import print_function
from PIL import Image
import sys
# Pixels are arranged in one byte for 8 vertical pixels and not addressed individually
# We convert the image to greysacle and end up making it monochrome where we
# consider that every pixel that is '40' is black.
width = 128
height = 64
if len(sys.argv) != 2:
print('Please specify an image to use as the only argument')
exit(1)
im = Image.open(sys.argv[1])
im = im.convert('L').resize((width, height))
data = list(im.getdata())
byteblock = [0 for i in range(width)]
widthblock = [list(byteblock) for i in range(int(height/8))]
numblock = 0
pixcount = 0
i = 0
# we split the list by width * 8, to create data chunks of 8rows
datachunks=[data[x:x+(width*8)] for x in range(0, len(data), (width*8))]
# grab every pixel of image (or datachunk)
while i < len(widthblock):
pixcount = 0
for y in datachunks[i]:
xcoor = pixcount % width
ycoor = int(pixcount/width)
blknum = xcoor % len(widthblock)
blkycoor = ycoor
# 40 is what we consider 'black'
if y > 40:
widthblock[i][xcoor] |= (1 << blkycoor)
pixcount += 1
i += 1
flatlist = [y for x in widthblock for y in x]
carray = 'static uint8_t image[] = {\n' + ', '.join(str(x) for x in flatlist)
print(carray + '\n};')

View File

@ -0,0 +1,31 @@
#!/usr/bin/env python
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
# Copyright (c) 2014 Intel Corporation.
#
# 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
import pyupm_mic
mymic = pyupm_mic.Microphone(1)
# careful this is an unitialised array with no bounds checking!
x = pyupm_mic.uint16Array(3)
mymic.getSampledWindow(100, 3, x)

View File

@ -27,6 +27,7 @@
int
main(int argc, char **argv)
{
//! [Interesting]
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
lcd->setCursor(0,0);
@ -34,4 +35,5 @@ main(int argc, char **argv)
lcd->setCursor(1,2);
lcd->write("Hello World");
lcd->close();
//! [Interesting]
}

View File

@ -16,8 +16,7 @@ macro (upm_CREATE_INSTALL_PKGCONFIG generated_file install_location)
endmacro (upm_CREATE_INSTALL_PKGCONFIG)
macro(upm_SWIG_PYTHON)
if(BUILDSWIGPYTHON)
set (CMAKE_C_FLAGS -DSWIGPYTHON=${SWIG_FOUND})
if (BUILDSWIGPYTHON AND BUILDSWIG)
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES})
@ -34,8 +33,7 @@ macro(upm_SWIG_PYTHON)
endmacro()
macro(upm_SWIG_NODE)
if(BUILDSWIGNODE)
set (CMAKE_CXX_FLAGS -DBUILDING_NODE_EXTENSION)
if (BUILDSWIGNODE AND BUILDSWIG)
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
@ -45,6 +43,7 @@ macro(upm_SWIG_NODE)
"${NODE_INCLUDE_DIRS}"
)
set_target_properties (jsupm_${libname} PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION"
PREFIX ""
SUFFIX ".node"
)
@ -65,7 +64,11 @@ macro(upm_doxygen)
)
add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i)
add_dependencies (${libname}doc_i doc)
add_dependencies (${SWIG_MODULE_pyupm_${libname}_REAL_NAME} ${libname}doc_i)
if (BUILDSWIG)
add_dependencies (_pyupm_${libname} ${libname}doc_i)
else ()
add_dependencies (${libname} doc)
endif ()
endif ()
endmacro()
@ -107,6 +110,8 @@ macro(upm_module_init)
if (SWIG_FOUND)
upm_swig_python()
upm_swig_node()
endif()
if (BUILDDOC)
upm_doxygen()
endif()
install (TARGETS ${libname} DESTINATION lib COMPONENT ${libname})

View File

@ -49,7 +49,7 @@ class Buzzer {
/**
* Instanciates a Buzzer object
*
* @param pin Buzzer pin number
* @param pinNumber Buzzer pin number
*/
Buzzer (int pinNumber);

View File

@ -1,4 +1,5 @@
%module jsupm_buzzer
%include "../upm.i"
%{
#include "buzzer.h"

View File

@ -1,4 +1,5 @@
%module pyupm_buzzer
%include "../upm.i"
%feature("autodoc", "3");

3
src/carrays_uint16_t.i Normal file
View File

@ -0,0 +1,3 @@
%include "stdint.i"
%include "carrays.i"
%array_class(uint16_t, uint16Array);

View File

@ -40,6 +40,13 @@ class Grove {
std::string m_name;
};
/**
* @brief C++ API for Grove LED
*
* Very basic UPM module for grove LED, or any LED for that matter
*
* @snippet groveled.cxx Interesting
*/
class GroveLed: public Grove {
public:
GroveLed(int pin);
@ -51,21 +58,55 @@ class GroveLed: public Grove {
mraa_gpio_context m_gpio;
};
/**
* @brief C++ API for Grove Temperature sensor
*
* Very basic UPM module for grove temperature sensor on analog
*
* @snippet grovetemp.cxx Interesting
*/
class GroveTemp: public Grove {
public:
GroveTemp(unsigned int pin);
~GroveTemp();
/**
* Get raw value from AIO pin
*
* @return the raw value from the ADC
*/
float raw_value();
/**
* Get the temperature from the sensor
*
* @return the normalised temperature
*/
int value();
private:
mraa_aio_context m_aio;
};
/**
* @brief C++ API for Grove light sensor
*
* Very basic UPM module for grove Light sensor on analog
*
* @snippet grovelight.cxx Interesting
*/
class GroveLight: public Grove {
public:
GroveLight(unsigned int pin);
~GroveLight();
/**
* Get raw value from AIO pin
*
* @return the raw value from the ADC
*/
float raw_value();
/**
* Get the light value from the sensor
*
* @return the normalised light reading
*/
int value();
private:
mraa_aio_context m_aio;

View File

@ -1,4 +1,5 @@
%module jsupm_grove
%include "../upm.i"
%{
#include "grove.h"

View File

@ -1,4 +1,5 @@
%module pyupm_grove
%include "../upm.i"
%feature("autodoc", "3");

View File

@ -73,7 +73,8 @@ class GY65 {
* Instanciates a GY65 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
* @param devAddr address of used i2c device
* @param mode BMP085 mode
*/
GY65 (int bus, int devAddr, uint8_t mode = BMP085_ULTRAHIGHRES);

View File

@ -1,4 +1,5 @@
%module jsupm_gy65
%include "../upm.i"
%{
#include "gy65.h"

View File

@ -1,4 +1,5 @@
%module pyupm_gy65
%include "../upm.i"
%include "stdint.i"

View File

@ -1,4 +1,5 @@
%module jsupm_hcsr04
%include "../upm.i"
%{
#include "hcsr04.h"

View File

@ -1,4 +1,5 @@
%module pyupm_hcsr04
%include "../upm.i"
%feature("autodoc", "3");

View File

@ -29,19 +29,38 @@
namespace upm {
/**
* @brief C++ API for HMC5883l (3-axis digital compass)
*
* This file defines the HMC5883l C++ interface for libhmc5883l
*
* @snippet hmc5883l.cxx Interesting
*
*/
class Hmc5883l {
public:
/// Creates a Hmc5883l object
/**
* Creates a Hmc5883l object
*
* @param bus number of used i2c bus
*
*/
Hmc5883l(int bus);
/// Returns the direction
/*
* Returns the direction
*/
float direction();
/// Returns the heading
/*
* Returns the heading
*/
float heading();
/**
* Returns a pointer to an int[3] that contains the coordinates as ints
*
* @return *int to an int[3]
*/
int* coordinates();

View File

@ -1,4 +1,5 @@
%module jsupm_hmc5883l
%include "../upm.i"
%{
#include "hmc5883l.h"

View File

@ -1,4 +1,5 @@
%module pyupm_hmc5883l
%include "../upm.i"
%feature("autodoc", "3");

View File

@ -55,6 +55,11 @@ namespace upm {
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
@ -71,7 +76,7 @@ class I2CLcd {
public:
I2CLcd (int bus, int lcdAddress);
mraa_result_t write (int x, int y, std::string msg);
virtual mraa_result_t write (std::string msg) = 0;
virtual mraa_result_t setCursor (int row, int column) = 0;
virtual mraa_result_t clear () = 0;
@ -79,7 +84,7 @@ class I2CLcd {
virtual mraa_result_t i2Cmd (mraa_i2c_context ctx, uint8_t value);
virtual mraa_result_t i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
virtual mraa_result_t i2cData (mraa_i2c_context ctx, uint8_t value);
mraa_result_t close();
std::string name()
{

View File

@ -52,7 +52,7 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcd
i2Cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
clear ();
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
LCD_ENTRYLEFT |
LCD_ENTRYSHIFTDECREMENT);
@ -67,7 +67,29 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcd
}
Jhd1313m1::~Jhd1313m1() {
}
mraa_result_t
Jhd1313m1::setColor(uint8_t r, uint8_t g, uint8_t b)
{
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, r);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, g);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, b);
return MRAA_SUCCESS;
}
mraa_result_t
Jhd1313m1::scroll(bool direction)
{
if (direction)
return i2Cmd (m_i2c_lcd_control, (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT));
return i2Cmd (m_i2c_lcd_control, (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT));
}
/*

View File

@ -28,14 +28,70 @@
namespace upm {
/**
* @brief C++ API for Jhd1313m1 i2c controller for HD44780 based displays with
* an RGB backlight such as the Grove RGB i2c LCD display
*
* @snippet rgb-lcd.cxx Interesting
*/
class Jhd1313m1 : public I2CLcd {
public:
Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
~Jhd1313m1 ();
mraa_result_t write (std::string msg);
mraa_result_t setCursor (int row, int column);
mraa_result_t clear ();
mraa_result_t home ();
/**
* Jhd1313m1 constructor
*
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on
* @param address the slave address the rgb backlight is on
*/
Jhd1313m1(int bus, int lcdAddress, int rgbAddress);
/**
* Jhd1313m1 destructor
*/
~Jhd1313m1();
/**
* Make the LCD scroll text
*
* @param direction, true is typical scrolling to the right
* @return Result of operation
*/
mraa_result_t scroll (bool direction);
/**
* Set the color of the backlight
*
* @param r 0-255 value for red
* @param g 0-255 value for green
* @param b 0-255 value for blue
* @return Result of operation
*/
mraa_result_t setColor(uint8_t r, uint8_t g, uint8_t b);
/**
* Write a string to LCD
*
* @param msg The std::string to write to display, note only ascii
* chars are supported
* @return Result of operation
*/
mraa_result_t write(std::string msg);
/**
* Set cursor to a coordinate
*
* @param row The row to set cursor to
* @param column The column to set cursor to
* @return Result of operation
*/
mraa_result_t setCursor(int row, int column);
/**
* Clear display from characters
*
* @return Result of operatio
*/
mraa_result_t clear();
/**
* Return to coordinate 0,0
*
* @return Result of operation
*/
mraa_result_t home();
private:
int m_rgb_address;

View File

@ -1,4 +1,5 @@
%module jsupm_i2clcd
%include "../upm.i"
%include "i2clcd.h"
%{

View File

@ -61,7 +61,7 @@ Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
}
Lcm1602::~Lcm1602 () {
}
/*

View File

@ -32,22 +32,59 @@
namespace upm {
/**
* @brief C++ API for LCM1602 i2c controller for HD44780 based displays
*
* This supports all sizes of HD44780 displays from 16x2 to 4x20, the
* controller has no idea of the actual display hardware so will let you write
* further than you can see
*
* @snippet lcm-lcd.cxx Interesting
*/
class Lcm1602 : public I2CLcd {
public:
/** LCM1602 Constructor.
* Calls MRAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
/**
* Lcm1602 Constructor, calls libmraa initialisation functions
*
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on
*/
Lcm1602(int bus, int address);
/**
* Lcm1602 Destructor
*/
~Lcm1602();
mraa_result_t write (std::string msg);
mraa_result_t setCursor (int row, int column);
mraa_result_t clear ();
mraa_result_t home ();
/**
* Write a string to LCD
*
* @param msg The std::string to write to display, note only ascii
* chars are supported
* @return Result of operation
*/
mraa_result_t write(std::string msg);
/**
* Set cursor to a coordinate
*
* @param row The row to set cursor to
* @param column The column to set cursor to
* @return Result of operation
*/
mraa_result_t setCursor(int row, int column);
/**
* Clear display from characters
*
* @return Result of operatio
*/
mraa_result_t clear();
/**
* Return to coordinate 0,0
*
* @return Result of operation
*/
mraa_result_t home();
private :
mraa_result_t send (uint8_t value, int mode);
mraa_result_t send(uint8_t value, int mode);
mraa_result_t write4bits(uint8_t value);
mraa_result_t expandWrite(uint8_t value);
mraa_result_t pulseEnable(uint8_t value);

View File

@ -1,4 +1,5 @@
%module pyupm_i2clcd
%include "../upm.i"
%feature("autodoc", "3");

View File

@ -29,7 +29,7 @@
namespace upm {
#define DISPLAY_CMD_OFF 0xAE
#define DISPLAY_CMD_OFF 0xAE
#define DISPLAY_CMD_ON 0xAF
#define BASE_LOW_COLUMN_ADDR 0x00
@ -145,23 +145,61 @@ typedef enum {
PAGE = 2
} displayAddressingMode;
/**
* @brief C++ API for SSD1308 i2c controlled OLED displays
*
* @snippet lcm-lcd.cxx Interesting
*/
class SSD1308 : public I2CLcd {
public:
/** SSD1308 Constructor.
* Calls MRAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
/**
* SSD1308 Constructor, calls libmraa initialisation functions
*
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on
*/
SSD1308 (int bus, int address);
/**
* SSD1308 Destructor
*/
~SSD1308 ();
/**
* Draw an image, see examples/python/make_oled_pic.py for an
* explanation on how the pixels are mapped to bytes
*
* @param data the buffer to read
* @param bytes the amount of bytes to read from the pointer
* @return Result of operation
*/
mraa_result_t draw(uint8_t *data, int bytes);
// pure virtual methods
mraa_result_t write (std::string msg);
mraa_result_t setCursor (int row, int column);
mraa_result_t clear ();
mraa_result_t home ();
/**
* Write a string to LCD
*
* @param msg The std::string to write to display, note only ascii
* chars are supported
* @return Result of operation
*/
mraa_result_t write(std::string msg);
/**
* Set cursor to a coordinate
*
* @param row The row to set cursor to
* @param column The column to set cursor to
* @return Result of operation
*/
mraa_result_t setCursor(int row, int column);
/**
* Clear display from characters
*
* @return Result of operatio
*/
mraa_result_t clear();
/**
* Return to coordinate 0,0
*
* @return Result of operation
*/
mraa_result_t home();
private:
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);
mraa_result_t setNormalDisplay ();

View File

@ -147,21 +147,61 @@ typedef enum {
class SSD1327 : public I2CLcd {
public:
/** SSD1308 Constructor.
* Calls MRAA initialisation functions.
/**
* SSD1308 Constructor, calls libmraa initialisation functions
*
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
* @param address the slave address the lcd is registered on
*/
SSD1327 (int bus, int address);
/**
* SSD1327 destructor
*/
~SSD1327 ();
/**
* Draw an image, see examples/python/make_oled_pic.py for an
* explanation on how the pixels are mapped to bytes
*
* @param data the buffer to read
* @param bytes the amount of bytes to read from the pointer
* @return Result of operation
*/
mraa_result_t draw(uint8_t *data, int bytes);
// virtual methods
mraa_result_t write (std::string msg);
mraa_result_t setCursor (int row, int column);
mraa_result_t clear ();
mraa_result_t home ();
/**
* Set gray level for LCD panel
*
* @param gray level from 0-255
* @return Result of operation
*/
mraa_result_t setGrayLevel (uint8_t level);
/**
* Write a string to LCD
*
* @param msg The std::string to write to display, note only ascii
* chars are supported
* @return Result of operation
*/
mraa_result_t write(std::string msg);
/**
* Set cursor to a coordinate
*
* @param row The row to set cursor to
* @param column The column to set cursor to
* @return Result of operation
*/
mraa_result_t setCursor(int row, int column);
/**
* Clear display from characters
*
* @return Result of operatio
*/
mraa_result_t clear();
/**
* Return to coordinate 0,0
*
* @return Result of operation
*/
mraa_result_t home();
private:
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);

BIN
src/lpd8806/.DS_Store vendored Normal file

Binary file not shown.

BIN
src/lpd8806/._.DS_Store Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,5 @@
set (libname "lpd8806")
set (libdescription “Digital RGB LED strip”)
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,8 @@
%module jsupm_lpd8806
%include "../upm.i"
%{
#include "lpd8806.h"
%}
%include "lpd8806.h"

146
src/lpd8806/lpd8806.cxx Normal file
View File

@ -0,0 +1,146 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <cstring>
#include "lpd8806.h"
using namespace upm;
struct LPD8806Exception : public std::exception {
std::string message;
LPD8806Exception (std::string msg) : message (msg) { }
~LPD8806Exception () throw () { }
const char* what() const throw () { return message.c_str(); }
};
LPD8806::LPD8806 (uint16_t pixelCount, uint8_t csn) {
mraa_result_t error = MRAA_SUCCESS;
m_name = "LPD8806";
m_pixels = NULL;
m_csnPinCtx = mraa_gpio_init (csn);
if (m_csnPinCtx == NULL) {
throw LPD8806Exception ("GPIO failed to initilize");
}
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
throw LPD8806Exception ("GPIO failed to initilize");
}
CSOff ();
m_spi = mraa_spi_init (0);
if (m_spi == NULL) {
throw LPD8806Exception ("SPI failed to initilize");
}
// set spi mode to mode2 (CPOL = 0, CPHA = 0)
mraa_spi_mode (m_spi, MRAA_SPI_MODE0);
CSOn ();
// issue initial latch/reset to strip:
for (uint16_t i = ((pixelCount + 31) / 32); i > 0; i--) {
mraa_spi_write (m_spi, 0);
}
CSOff ();
m_pixelsCount = pixelCount;
uint8_t latchBytes;
uint16_t dataBytes, totalBytes;
uint16_t numBytes = 0;
dataBytes = m_pixelsCount * 3;
latchBytes = (m_pixelsCount + 31) / 32;
totalBytes = dataBytes + latchBytes;
if ((m_pixels = (uint8_t *) malloc(totalBytes))) {
numBytes = totalBytes;
memset ( m_pixels , 0x80, dataBytes); // Init to RGB 'off' state
memset (&m_pixels[dataBytes], 0 , latchBytes); // Clear latch bytes
}
}
LPD8806::~LPD8806() {
mraa_result_t error = MRAA_SUCCESS;
if (m_pixels) {
free(m_pixels);
}
error = mraa_spi_stop(m_spi);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close (m_csnPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
}
void
LPD8806::setPixelColor (uint16_t pixelOffset, uint8_t r, uint8_t g, uint8_t b) {
if (pixelOffset < m_pixelsCount) { // Arrays are 0-indexed, thus NOT '<='
uint8_t *ptr = &m_pixels[pixelOffset * 3];
*ptr++ = g | 0x80; // Strip color order is GRB,
*ptr++ = r | 0x80; // not the more common RGB,
*ptr++ = b | 0x80; // so the order here is intentional; don't "fix"
}
}
void
LPD8806::show (void) {
uint8_t *ptr = m_pixels;
uint16_t byte = (m_pixelsCount * 3) + ((m_pixelsCount + 31) / 32);
while (byte--) {
mraa_spi_write (m_spi, *ptr++);
}
}
uint16_t
LPD8806::getStripLength (void) {
return m_pixelsCount;
}
/*
* **************
* private area
* **************
*/
mraa_result_t
LPD8806::CSOn () {
return mraa_gpio_write (m_csnPinCtx, HIGH);
}
mraa_result_t
LPD8806::CSOff () {
return mraa_gpio_write (m_csnPinCtx, LOW);
}

105
src/lpd8806/lpd8806.h Normal file
View File

@ -0,0 +1,105 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
#include <mraa/gpio.h>
#include <mraa/spi.h>
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for LPD8806
*
* This file defines the LPD8806 C++ interface for liblpd8806
*
*/
class LPD8806 {
public:
/**
* Instanciates a LPD8806 object
*
* @param pixelCount number of pixels in the strip
* @param csn chip slect pin
*/
LPD8806 (uint16_t pixelCount, uint8_t csn);
/**
* LPD8806 object destructor, basicaly it close SPI and the GPIO.
*/
~LPD8806 ();
/**
* @param pixelOffset pixel offset in the strip of pixel
* @param r red led
* @param g green led
* @param b blue led
*/
void setPixelColor (uint16_t pixelOffset, uint8_t r, uint8_t g, uint8_t b);
/**
* Write the data stored in array of pixels to the chip
*/
void show (void);
/**
* Return length of the led strip
*/
uint16_t getStripLength (void);
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
std::string m_name;
mraa_spi_context m_spi;
mraa_gpio_context m_csnPinCtx;
uint8_t* m_pixels;
uint8_t m_pixelsCount;
uint8_t readRegister (uint8_t reg);
void writeRegister (uint8_t reg, uint8_t data);
/**
* Set chip select pin LOW
*/
mraa_result_t CSOn ();
/**
* Set chip select pin HIGH
*/
mraa_result_t CSOff ();
};
}

View File

@ -0,0 +1,9 @@
%module pyupm_lpd8806
%include "../upm.i"
%feature("autodoc", "3");
%include "lpd8806.h"
%{
#include "lpd8806.h"
%}

View File

@ -0,0 +1,5 @@
set (libname "max31723")
set (libdescription "Very accurate temperature sensor")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,8 @@
%module jsupm_max31723
%include "../upm.i"
%{
#include "max31723.h"
%}
%include "max31723.h"

139
src/max31723/max31723.cxx Normal file
View File

@ -0,0 +1,139 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include "max31723.h"
using namespace upm;
struct MAX31723Exception : public std::exception {
std::string message;
MAX31723Exception (std::string msg) : message (msg) { }
~MAX31723Exception () throw () { }
const char* what() const throw () { return message.c_str(); }
};
MAX31723::MAX31723 (int csn) {
mraa_result_t error = MRAA_SUCCESS;
m_name = "MAX31723";
m_csnPinCtx = mraa_gpio_init (csn);
if (m_csnPinCtx == NULL) {
throw MAX31723Exception ("GPIO failed to initilize");
}
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
throw MAX31723Exception ("GPIO failed to initilize");
}
CSOff ();
m_spi = mraa_spi_init (0);
if (m_spi == NULL) {
throw MAX31723Exception ("SPI failed to initilize");
}
// set spi mode to mode2 (CPOL = 1, CPHA = 0)
mraa_spi_mode (m_spi, MRAA_SPI_MODE2);
// set ontinuously perform temperature conversions
writeRegister (R_STS_WRITE_CMD, B_CONT_READING);
}
MAX31723::~MAX31723() {
mraa_result_t error = MRAA_SUCCESS;
error = mraa_spi_stop(m_spi);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close (m_csnPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
}
short
MAX31723::getTemperature () {
uint8_t lsb = 0;
uint8_t msb = 0;
short temperature = 0;
lsb = readRegister (R_TEMPERATURE_LSB);
msb = readRegister (R_TEMPERATURE_MSB);
if ((msb & 0x80) != 0) {
msb &= 0x7F;
temperature = 0 - msb;
} else {
temperature = msb;
}
return temperature;
}
/*
* **************
* private area
* **************
*/
uint8_t
MAX31723::readRegister (uint8_t reg) {
uint8_t data[2] = { 0x00, 0x00 };
uint8_t* sensorData = NULL;
CSOn ();
data[0] = reg;
sensorData = mraa_spi_write_buf(m_spi, data, 2);
CSOff ();
return sensorData[1];
}
void
MAX31723::writeRegister (uint8_t reg, uint8_t data) {
uint8_t buffer[2] = { 0x00, 0x00 };
uint8_t* sensorData = NULL;
CSOn ();
buffer[0] = reg;
buffer[1] = data;
sensorData = mraa_spi_write_buf(m_spi, buffer, 2);
CSOff ();
}
mraa_result_t
MAX31723::CSOn () {
return mraa_gpio_write (m_csnPinCtx, HIGH);
}
mraa_result_t
MAX31723::CSOff () {
return mraa_gpio_write (m_csnPinCtx, LOW);
}

95
src/max31723/max31723.h Normal file
View File

@ -0,0 +1,95 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
#include <mraa/gpio.h>
#include <mraa/spi.h>
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for MAX31723 chip (Temperature sensor)
*
* This file defines the MAX31723 C++ interface for libmax31723
*
*/
class MAX31723 {
public:
static const uint8_t R_STS_READ_CMD = 0x00;
static const uint8_t R_STS_WRITE_CMD = 0x80;
static const uint8_t R_TEMPERATURE_LSB = 0x01;
static const uint8_t R_TEMPERATURE_MSB = 0x02;
static const uint8_t B_CONT_READING = 0x00;
/**
* Instanciates a MAX31723 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
MAX31723 (int csn);
/**
* MAXDS3231M object destructor, basicaly it close i2c connection.
*/
~MAX31723 ();
/**
* Get on board temperature.
*/
short getTemperature ();
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
std::string m_name;
mraa_spi_context m_spi;
mraa_gpio_context m_csnPinCtx;
uint8_t readRegister (uint8_t reg);
void writeRegister (uint8_t reg, uint8_t data);
/**
* Set chip select pin LOW
*/
mraa_result_t CSOn ();
/**
* Set chip select pin HIGH
*/
mraa_result_t CSOff ();
};
}

View File

@ -0,0 +1,9 @@
%module pyupm_max31723
%include "../upm.i"
%feature("autodoc", "3");
%include "max31723.h"
%{
#include "max31723.h"
%}

View File

@ -1,5 +1,6 @@
//! [Interesting]
%module jsupm_max31855
%include "../upm.i"
%{
#include "max31855.h"

View File

@ -1,4 +1,5 @@
%module pyupm_max31855
%include "../upm.i"
%include "stdint.i"

View File

@ -1,4 +1,5 @@
%module jsupm_max44000
%include "../upm.i"
%{
#include "max44000.h"

View File

@ -1,4 +1,5 @@
%module pyupm_max44000
%include "../upm.i"
%include "stdint.i"

View File

@ -0,0 +1,5 @@
set (libname "max5487")
set (libdescription "Digital potentiometer")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,8 @@
%module jsupm_max5487
%include "../upm.i"
%{
#include "max5487.h"
%}
%include "max5487.h"

117
src/max5487/max5487.cxx Normal file
View File

@ -0,0 +1,117 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include "max5487.h"
using namespace upm;
struct MAX5487Exception : public std::exception {
std::string message;
MAX5487Exception (std::string msg) : message (msg) { }
~MAX5487Exception () throw () { }
const char* what() const throw () { return message.c_str(); }
};
MAX5487::MAX5487 (int csn) {
mraa_result_t error = MRAA_SUCCESS;
m_name = "MAX5487";
m_csnPinCtx = mraa_gpio_init (csn);
if (m_csnPinCtx == NULL) {
throw MAX5487Exception ("GPIO failed to initilize");
}
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
throw MAX5487Exception ("GPIO failed to initilize");
}
m_spi = mraa_spi_init (0);
if (m_spi == NULL) {
throw MAX5487Exception ("SPI failed to initilize");
}
CSOff ();
}
MAX5487::~MAX5487() {
mraa_result_t error = MRAA_SUCCESS;
error = mraa_spi_stop(m_spi);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close (m_csnPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
}
void
MAX5487::setWiperA (uint8_t wiper) {
uint8_t data[2] = { 0x00, 0x00};
CSOn ();
data[0] = R_WR_WIPER_A;
data[1] = wiper;
uint8_t* retData = mraa_spi_write_buf(m_spi, data, 2);
CSOff ();
}
void
MAX5487::setWiperB (uint8_t wiper) {
uint8_t data[2] = { 0x00, 0x00};
CSOn ();
data[0] = R_WR_WIPER_B;
data[1] = wiper;
uint8_t* retData = mraa_spi_write_buf(m_spi, data, 2);
CSOff ();
}
/*
* **************
* private area
* **************
*/
mraa_result_t
MAX5487::CSOn () {
return mraa_gpio_write (m_csnPinCtx, LOW);
}
mraa_result_t
MAX5487::CSOff () {
return mraa_gpio_write (m_csnPinCtx, HIGH);
}

93
src/max5487/max5487.h Normal file
View File

@ -0,0 +1,93 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
#include <mraa/gpio.h>
#include <mraa/spi.h>
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for MAX5487 chip (Temperature sensor)
*
* This file defines the MAX5487 C++ interface for libmax5487
*
*/
class MAX5487 {
public:
static const uint8_t R_WR_WIPER_A = 0x01;
static const uint8_t R_WR_WIPER_B = 0x02;
/**
* Instanciates a MAX5487 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
MAX5487 (int csn);
/**
* MAX5487 object destructor, basicaly it close SPI connection and GPIO.
*/
~MAX5487 ();
/**
* Set wiper for port A.
*/
void setWiperA (uint8_t wiper);
/**
* Set wiper for port B.
*/
void setWiperB (uint8_t wiper);
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
std::string m_name;
mraa_spi_context m_spi;
mraa_gpio_context m_csnPinCtx;
/**
* Set chip select pin LOW
*/
mraa_result_t CSOn ();
/**
* Set chip select pin HIGH
*/
mraa_result_t CSOff ();
};
}

View File

@ -0,0 +1,9 @@
%module pyupm_max5487
%include "../upm.i"
%feature("autodoc", "3");
%include "max5487.h"
%{
#include "max5487.h"
%}

View File

@ -0,0 +1,5 @@
set (libname "maxds3231m")
set (libdescription "realtime clock sensor from MAX family")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,8 @@
%module jsupm_maxds3231m
%include "../upm.i"
%{
#include "maxds3231m.h"
%}
%include "maxds3231m.h"

View File

@ -0,0 +1,146 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include "maxds3231m.h"
using namespace upm;
struct DS3231Exception : public std::exception {
std::string message;
DS3231Exception (std::string msg) : message (msg) { }
~DS3231Exception () throw () { }
const char* what() const throw () { return message.c_str(); }
};
MAXDS3231M::MAXDS3231M (int bus, int devAddr) {
m_name = "MAXDS3231M";
m_i2cAddr = devAddr;
m_bus = bus;
m_i2Ctx = mraa_i2c_init(m_bus);
mraa_result_t ret = mraa_i2c_address(m_i2Ctx, m_i2cAddr);
if (ret != MRAA_SUCCESS) {
throw DS3231Exception ("Couldn't initilize I2C.");
}
}
MAXDS3231M::~MAXDS3231M() {
mraa_i2c_stop(m_i2Ctx);
}
void
MAXDS3231M::setDate (Time3231 &time) {
uint8_t *data = (uint8_t *)&time;
i2cWriteReg_N (TIME_CAL_ADDR, 7, data);
}
bool
MAXDS3231M::getDate (Time3231 &time) {
uint8_t buffer[7];
// We need 7 bytes of data.
if (i2cReadReg_N (TIME_CAL_ADDR, 7, buffer) > 6) {
uint8_t century = (buffer[5] & 0x80) >> 7;
time.second = BCDtoDEC(buffer[0]);
time.minute = BCDtoDEC(buffer[1]);
time.hour = BCDtoDEC(buffer[2]);
time.day = BCDtoDEC(buffer[4]);
time.month = BCDtoDEC(buffer[5] & 0x1F);
time.year = (century == 1) ? 2000 + BCDtoDEC(buffer[6]) : 1900 + BCDtoDEC(buffer[6]);
time.weekDay = BCDtoDEC(buffer[3]);
return true;
}
return false;
}
uint16_t
MAXDS3231M::getTemperature () {
uint8_t buffer[2];
uint8_t msb = 0;
uint8_t lsb = 0;
i2cReadReg_N (TEMPERATURE_ADDR, 2, buffer);
msb = buffer[0];
lsb = buffer[1] >> 6;
if ((msb & 0x80) != 0)
msb |= ~((1 << 8) - 1); // if negative get two's complement
return 0.25 * lsb + msb;
}
/*
* **************
* private area
* **************
*/
uint16_t
MAXDS3231M::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
int readByte = 0;
if (m_i2Ctx == NULL) {
throw DS3231Exception ("Couldn't find initilized I2C.");
}
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
mraa_i2c_write_byte(m_i2Ctx, reg);
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
readByte = mraa_i2c_read(m_i2Ctx, buffer, len);
return readByte;
}
mraa_result_t
MAXDS3231M::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) {
mraa_result_t error = MRAA_SUCCESS;
if (m_i2Ctx == NULL) {
throw DS3231Exception ("Couldn't find initilized I2C.");
}
error = mraa_i2c_address (m_i2Ctx, m_i2cAddr);
error = mraa_i2c_write (m_i2Ctx, buffer, len);
return error;
}
uint8_t
MAXDS3231M::DECtoBSD(uint8_t data) {
return ((data / 10 * 16) + (data % 10));
}
uint8_t
MAXDS3231M::BCDtoDEC(uint8_t data) {
return ((data / 16 * 10) + (data % 16));
}

125
src/maxds3231m/maxds3231m.h Normal file
View File

@ -0,0 +1,125 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* 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.
*/
#pragma once
#include <string>
#include <mraa/i2c.h>
#define ADDR 0x68 // device address
// timekeeping registers
#define TIME_CAL_ADDR 0x00
#define ALARM1_ADDR 0x07
#define ALARM2_ADDR 0x0B
#define CONTROL_ADDR 0x0E
#define STATUS_ADDR 0x0F
#define AGING_OFFSET_ADDR 0x10
#define TEMPERATURE_ADDR 0x11
// control register bits
#define A1IE 0x1
#define A2IE 0x2
#define INTCN 0x4
// status register bits
#define A1F 0x1
#define A2F 0x2
#define OSF 0x80
#define HIGH 1
#define LOW 0
namespace upm {
struct Time3231 {
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t day;
uint8_t month;
int16_t year;
uint8_t weekDay;
};
/**
* @brief C++ API for MAXDS3231M chip (Ambient and Infrared Proximity Sensor)
*
* This file defines the MAXDS3231M C++ interface for libmax44000
*
*/
class MAXDS3231M {
public:
/**
* Instanciates a MAXDS3231M object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
MAXDS3231M (int bus, int devAddr);
/**
* MAXDS3231M object destructor, basicaly it close i2c connection.
*/
~MAXDS3231M ();
/**
* Set date and time on the chip.
*
* @param time staracture
*/
void setDate (Time3231 &time);
/**
* Get date and time located on the chip.
*
* @param time staracture
*/
bool getDate (Time3231 &time);
/**
* Get on board temperature.
*/
uint16_t getTemperature ();
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
std::string m_name;
int m_i2cAddr;
int m_bus;
mraa_i2c_context m_i2Ctx;
uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
mraa_result_t i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
uint8_t DECtoBSD (uint8_t data);
uint8_t BCDtoDEC (uint8_t data);
};
}

View File

@ -0,0 +1,9 @@
%module pyupm_maxds3231m
%include "../upm.i"
%feature("autodoc", "3");
%include "maxds3231m.h"
%{
#include "maxds3231m.h"
%}

View File

@ -1,4 +1,6 @@
%module jsupm_mic
%include "../upm.i"
%include "../carrays_uint16_t.i"
%{
#include "mic.h"

View File

@ -61,9 +61,9 @@ class Microphone {
* Get samples from microphone according to provided window and
* number of samples
*
* @return freqMS time between each sample (in microseconds)
* @return numberOfSamples number of sample to sample for this window
* @return buffer bufer with sampled data
* @param freqMS time between each sample (in microseconds)
* @param numberOfSamples number of sample to sample for this window
* @param buffer bufer with sampled data
*/
int getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples, uint16_t * buffer);
@ -71,12 +71,19 @@ class Microphone {
* Given sampled buffer this method will return TRUE/FALSE if threshold
* was reached
*
* @return threshold sample threshold
* @return buffer buffer with samples
* @return len bufer len
* @param ctx threshold context
* @param threshold sample threshold
* @param buffer buffer with samples
* @param len bufer len
*/
int findThreshold (thresholdContext* ctx, unsigned int threshold, uint16_t * buffer, unsigned int len);
/**
*
* Print running average of threshold context
*
* @param ctx threshold context
*/
void printGraph (thresholdContext* ctx);
private:

View File

@ -1,4 +1,6 @@
%module pyupm_mic
%include "../upm.i"
%include "../carrays_uint16_t.i"
%include "stdint.i"

View File

@ -1,4 +1,5 @@
%module jsupm_mma7455
%include "../upm.i"
%{
#include "mma7455.h"

View File

@ -36,7 +36,7 @@ using namespace upm;
MMA7455::MMA7455 (int bus, int devAddr) {
unsigned char data = 0;
int nBytes = 0;
m_name = "MMA7455";
m_controlAddr = devAddr;
@ -49,7 +49,7 @@ MMA7455::MMA7455 (int bus, int devAddr) {
fprintf(stderr, "Messed up i2c bus\n");
return;
}
// setting GLVL 0x1 (64LSB/g) and MODE 0x1 (Measurement Mode)
data = (BIT (MMA7455_GLVL0) | BIT (MMA7455_MODE0));
error = ic2WriteReg (MMA7455_MCTL, &data, 0x1);
@ -57,7 +57,7 @@ MMA7455::MMA7455 (int bus, int devAddr) {
std::cout << "ERROR :: MMA7455 instance wan not created (Mode)" << std::endl;
return;
}
if (MRAA_SUCCESS != calibrate ()) {
std::cout << "ERROR :: MMA7455 instance wan not created (Calibrate)" << std::endl;
return;
@ -68,63 +68,63 @@ MMA7455::~MMA7455() {
mraa_i2c_stop(m_i2ControlCtx);
}
mraa_result_t
mraa_result_t
MMA7455::calibrate () {
mraa_result_t error = MRAA_SUCCESS;
int i = 0;
accelData xyz;
xyz.value.x = xyz.value.y = xyz.value.z = 0;
do {
error = readData (&xyz.value.x, &xyz.value.y, &xyz.value.z);
if (MRAA_SUCCESS != error) {
return error;
}
xyz.value.x += 2 * -xyz.value.x;
xyz.value.y += 2 * -xyz.value.y;
xyz.value.z += 2 * -(xyz.value.z - 64);
error = ic2WriteReg (MMA7455_XOFFL, (unsigned char *) &xyz, 0x6);
if (error != MRAA_SUCCESS) {
return error;
}
} while ( ++i < 3 );
return error;
}
mraa_result_t
mraa_result_t
MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
accelData xyz;
unsigned char data = 0;
int nBytes = 0;
/*do {
nBytes = ic2ReadReg (MMA7455_STATUS, &data, 0x1);
} while ( !(data & MMA7455_DRDY) && nBytes == MRAA_SUCCESS);
if (nBytes == MRAA_SUCCESS) {
std::cout << "NO_GDB :: 1" << std::endl;
return MRAA_SUCCESS;
}*/
nBytes = ic2ReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
if (nBytes == 0) {
std::cout << "NO_GDB :: 2" << std::endl;
return MRAA_ERROR_UNSPECIFIED;
}
if (xyz.reg.x_msb & 0x02) {
xyz.reg.x_msb |= 0xFC;
}
if (xyz.reg.y_msb & 0x02) {
xyz.reg.y_msb |= 0xFC;
}
if (xyz.reg.z_msb & 0x02) {
xyz.reg.z_msb |= 0xFC;
}
@ -133,16 +133,16 @@ MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
*ptrX = xyz.value.x;
*ptrY = xyz.value.y;
*ptrZ = xyz.value.z;
return MRAA_SUCCESS;
}
int
int
MMA7455::ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size) {
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
return 0;
}
if (MRAA_SUCCESS != mraa_i2c_write_byte(m_i2ControlCtx, reg)) {
return 0;
}
@ -150,11 +150,11 @@ MMA7455::ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size)
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
return 0;
}
return (int) mraa_i2c_read(m_i2ControlCtx, buf, size);
}
mraa_result_t
mraa_result_t
MMA7455::ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size) {
mraa_result_t error = MRAA_SUCCESS;
@ -173,4 +173,3 @@ MMA7455::ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size
return error;
}

View File

@ -53,7 +53,7 @@
#define MMA7455_YOFFH 0x13 // Read/Write, Offset Drift Y MSB
#define MMA7455_ZOFFL 0x14 // Read/Write, Offset Drift Z LSB
#define MMA7455_ZOFFH 0x15 // Read/Write, Offset Drift Z MSB
#define MMA7455_MCTL 0x16 // Read/Write, Mode Control Register
#define MMA7455_MCTL 0x16 // Read/Write, Mode Control Register
#define MMA7455_INTRST 0x17 // Read/Write, Interrupt Latch Reset
#define MMA7455_CTL1 0x18 // Read/Write, Control 1 Register
#define MMA7455_CTL2 0x19 // Read/Write, Control 2 Register
@ -64,11 +64,11 @@
#define MMA7455_TW 0x1E // Read/Write, Time Window for Second Pulse Value
#define MMA7455_RESERVED2 0x1F // Reserved
// Defines for the bits, to be able to change
// Defines for the bits, to be able to change
// between bit number and binary definition.
// By using the bit number, programming the MMA7455
// By using the bit number, programming the MMA7455
// is like programming an AVR microcontroller.
// But instead of using "(1<<X)", or "_BV(X)",
// But instead of using "(1<<X)", or "_BV(X)",
// the Arduino "bit(X)" is used.
#define MMA7455_D0 0
#define MMA7455_D1 1
@ -129,7 +129,7 @@
#define LOW 0
namespace upm {
union accelData {
struct {
unsigned char x_lsb;
@ -139,7 +139,7 @@ union accelData {
unsigned char z_lsb;
unsigned char z_msb;
} reg;
struct {
short x;
short y;
@ -179,12 +179,12 @@ class MMA7455 {
{
return m_name;
}
/**
* Calibrate the sensor
*/
mraa_result_t calibrate ();
/**
* Read X, Y and Z acceleration data
*
@ -193,21 +193,21 @@ class MMA7455 {
* @param ptrZ Z axis
*/
mraa_result_t readData (short * ptrX, short * ptrY, short * ptrZ);
/**
*
*
*
* @param reg register address
* @param buf register data buffer
* @param size buffer size
*/
int ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size);
/**
*
*
*
* @param reg register address
* @param buf register data buffer
* @param buf register data buffer
* @param size buffer size
*/
mraa_result_t ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);

View File

@ -1,4 +1,5 @@
%module pyupm_mma7455
%include "../upm.i"
%feature("autodoc", "3");

View File

@ -1,4 +1,5 @@
%module jsupm_mpu9150
%include "../upm.i"
%{
#include "mpu9150.h"

View File

@ -1,4 +1,5 @@
%module pyupm_mpu9150
%include "../upm.i"
%include "stdint.i"

View File

@ -1,4 +1,5 @@
%module jsupm_my9221
%include "../upm.i"
%{
#include "my9221.h"

View File

@ -46,7 +46,7 @@ MY9221::MY9221 (uint8_t di, uint8_t dcki) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
exit(1);
}
// set direction (out)
error = mraa_gpio_dir(m_clkPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
@ -73,17 +73,25 @@ MY9221::~MY9221() {
}
mraa_result_t
MY9221::setBarLevel (uint8_t level) {
MY9221::setBarLevel (uint8_t level, bool direction) {
if (level > 10) {
return MRAA_ERROR_INVALID_PARAMETER;
}
send16bitBlock (CMDMODE);
for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
if (direction) {
level += 3;
for(uint8_t block_idx = 12; block_idx > 0; block_idx--) {
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
}
} else {
for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
}
}
lockData ();
return lockData ();
}
mraa_result_t
@ -91,11 +99,12 @@ MY9221::lockData () {
mraa_result_t error = MRAA_SUCCESS;
error = mraa_gpio_write (m_dataPinCtx, LOW);
usleep(100);
for(int idx = 0; idx < 4; idx++) {
error = mraa_gpio_write (m_dataPinCtx, HIGH);
error = mraa_gpio_write (m_dataPinCtx, LOW);
}
return error;
}
mraa_result_t
@ -116,4 +125,5 @@ MY9221::send16bitBlock (short data) {
data <<= 1;
}
return error;
}

View File

@ -63,8 +63,9 @@ class MY9221 {
* Set the level bar
*
* @param level selected level for the bar (1 - 10)
* @param direction up or down, true is up and is the default
*/
mraa_result_t setBarLevel (uint8_t level);
mraa_result_t setBarLevel (uint8_t level, bool direction=true);
/**
* Return name of the component

View File

@ -1,4 +1,5 @@
%module pyupm_my9221
%include "../upm.i"
%feature("autodoc", "3");

View File

@ -1,4 +1,5 @@
%module jsupm_nrf24l01
%include "../upm.i"
%{
#include "nrf24l01.h"

View File

@ -317,4 +317,3 @@ NRF24l01::nrfListenForChannel() {
dataRecievedHandler(); /* let know that data arrived */
}
}

View File

@ -164,7 +164,7 @@ class NRF24l01 {
/**
* Send the buffer data
*
* @param *value pointer to the buffer
* @param value pointer to the buffer
*/
void nrfSend (uint8_t *value);
@ -226,7 +226,7 @@ class NRF24l01 {
/**
* Sink all arrived data into the provided buffer
*
* @param load size of the payload (MAX 32)
* @param data pointer to buffer of data
*/
void nrfGetData (uint8_t * data);
@ -238,7 +238,7 @@ class NRF24l01 {
/**
* Transmit provided data to the chip
*
* @param *dataout pointer to the buffer with data
* @param dataout pointer to the buffer with data
* @param len length of the buffer
*/
void nrfTransmitSync (uint8_t *dataout, uint8_t len);
@ -246,8 +246,8 @@ class NRF24l01 {
/**
* Recieve data from the chip
*
* @param *dataout pointer to the buffer with data
* @param *datain pointer to the buffer where the arrived data
* @param dataout pointer to the buffer with data
* @param datain pointer to the buffer where the arrived data
* will be sinked
* @param len length of the buffer
*/
@ -265,7 +265,7 @@ class NRF24l01 {
* Read continues data from register
*
* @param reg register address
* @param *value pointer to the buffer
* @param value pointer to the buffer
* @param len length of the buffer
*/
void nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len);
@ -274,7 +274,7 @@ class NRF24l01 {
* Write continues data to register
*
* @param reg register address
* @param *value pointer to the buffer
* @param value pointer to the buffer
* @param len length of the buffer
*/
void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);

View File

@ -1,4 +1,5 @@
%module pyupm_nrf24l01
%include "../upm.i"
%feature("autodoc", "3");

View File

@ -0,0 +1,5 @@
set (libname "nrf8001")
set (libdescription "BLE module from NordicSemiconductor family")
set (module_src hal_aci_tl.cpp aci_setup.cpp aci_queue.cpp acilib.cpp lib_aci.cpp ${libname}.cxx)
set (module_h hal_aci_tl.h aci_setup.h aci_queue.h acilib.h lib_aci.h ${libname}.h)
upm_module_init()

669
src/nrf8001/aci.h Normal file
View File

@ -0,0 +1,669 @@
/* Copyright (c) 2014, Nordic Semiconductor ASA
*
* 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
*
* @defgroup aci aci
* @{
* @ingroup lib
*
* @brief Definitions for the ACI (Application Control Interface)
* @remarks
*
* Flow control from application mcu to nRF8001
*
* Data flow control:
* The flow control is credit based and the credit is initally given using the "device started" event.
* A credit of more than 1 is given to the application mcu.
* These credits are used only after the "ACI Connected Event" is sent to the application mcu.
*
* every send_data that is used decrements the credit available by 1. This is to be tracked by the application mcu.
* When the credit available reaches 0, the application mcu shall not send any more send_data.
* Credit is returned using the "credit event", this returned credit can then be used to send more send_data.
* This flow control is not necessary and not available for Broadcast.
* The entire credit available with the external mcu expires when a "disconnected" event arrives.
*
* Command flow control:
* When a command is sent over the ACI, the next command shall not be sent until after a response
* for the command sent has arrived.
*
*/
#ifndef ACI_H__
#define ACI_H__
/**
* Define an _aci_packed_ macro we can use in structure and enumerated type
* declarations so that the types are sized consistently across different
* platforms. In particular Arduino platforms using the GCC compiler and the
* Nordic processors using the Keil compiler.
*
* It's really the GNU compiler platforms that need a special keyword to get
* tight packing of values. On GNU platforms we can use the keyword:
* __attribute__((__packed__))
* The thing is that while this keyword does the right thing with old and new
* versions of the gcc (C) compiler it only works right with g++ (C++) compiler
* versions that are version 4 or newer.
*/
#ifdef __GNUC__
# if __GNUC__ >= 4
# define _aci_packed_ __attribute__((__packed__))
# else
# error "older g++ versions don't handle packed attribute in typedefs"
# endif
#else
# define _aci_packed_
#endif
#include <stdint.h>
#include <cstddef>
#include <string.h>
#include <unistd.h>
/*
* Define a macro that compares the size of the first parameter to the integer
* value of the second parameter. If they do not match, a compile time error
* for negative array size occurs (even gnu chokes on negative array size).
*
* This compare is done by creating a typedef for an array. No variables are
* created and no memory is consumed with this check. The created type is
* used for checking only and is not for use by any other code. The value
* of 10 in this macro is arbitrary, it just needs to be a value larger
* than one to result in a positive number for the array size.
*/
#define ACI_ASSERT_SIZE(x,y) typedef char x ## _assert_size_t[-1+10*(sizeof(x) == (y))]
/**
* @def ACI_VERSION
* @brief Current ACI protocol version. 0 means a device that is not yet released.
* A numer greater than 0 refers to a specific ACI version documented and released.
* The ACI consists of the ACI commands, ACI events and error codes.
*/
#define ACI_VERSION (0x02)
/**
* @def BTLE_DEVICE_ADDRESS_SIZE
* @brief Size in bytes of a Bluetooth Address
*/
#define BTLE_DEVICE_ADDRESS_SIZE (6)
/**
* @def ACI_PACKET_MAX_LEN
* @brief Maximum length in bytes of a full ACI packet, including length prefix, opcode and payload
*/
#define ACI_PACKET_MAX_LEN (32)
/**
* @def ACI_ECHO_DATA_MAX_LEN
* @brief Maximum length in bytes of the echo data portion
*/
#define ACI_ECHO_DATA_MAX_LEN (ACI_PACKET_MAX_LEN - 3)
/**
* @def ACI_DEVICE_MAX_PIPES
* @brief Maximum number of ACI pipes
*/
#define ACI_DEVICE_MAX_PIPES (62)
/**
* @def ACI_PIPE_TX_DATA_MAX_LEN
* @brief Maximum length in bytes of a transmission data pipe packet
*/
#define ACI_PIPE_TX_DATA_MAX_LEN (20)
/**
* @def ACI_PIPE_RX_DATA_MAX_LEN
* @brief Maximum length in bytes of a reception data pipe packet
*/
#define ACI_PIPE_RX_DATA_MAX_LEN (22)
/**
* @def ACI_GAP_DEVNAME_MAX_LEN
* @brief Maximum length in bytes of the GAP device name
*/
#define ACI_GAP_DEVNAME_MAX_LEN (20)
/**
* @def ACI_AD_PACKET_MAX_LEN
* @brief Maximum length in bytes of an AD packet
*/
#define ACI_AD_PACKET_MAX_LEN (31)
/**
* @def ACI_AD_PACKET_MAX_USER_LEN
* @brief Maximum usable length in bytes of an AD packet
*/
#define ACI_AD_PACKET_MAX_USER_LEN (31 - 3)
/**
* @def ACI_PIPE_INVALID
* @brief Invalid pipe number
*/
#define ACI_PIPE_INVALID (0xFF)
/**
* @enum aci_pipe_store_t
* @brief Storage type identifiers: local and remote
*/
typedef enum
{
ACI_STORE_INVALID = 0x0,
ACI_STORE_LOCAL= 0x01,
ACI_STORE_REMOTE= 0x02
} _aci_packed_ aci_pipe_store_t;
/**
* @enum aci_pipe_type_t
* @brief Pipe types
*/
typedef enum
{
ACI_TX_BROADCAST = 0x0001,
ACI_TX = 0x0002,
ACI_TX_ACK = 0x0004,
ACI_RX = 0x0008,
ACI_RX_ACK = 0x0010,
ACI_TX_REQ = 0x0020,
ACI_RX_REQ = 0x0040,
ACI_SET = 0x0080,
ACI_TX_SIGN = 0x0100,
ACI_RX_SIGN = 0x0200,
ACI_RX_ACK_AUTO = 0x0400
} _aci_packed_ aci_pipe_type_t;
ACI_ASSERT_SIZE(aci_pipe_type_t, 2);
/**
* @enum aci_bd_addr_type_t
* @brief Bluetooth Address types
*/
typedef enum
{
ACI_BD_ADDR_TYPE_INVALID = 0x00,
ACI_BD_ADDR_TYPE_PUBLIC = 0x01,
ACI_BD_ADDR_TYPE_RANDOM_STATIC = 0x02,
ACI_BD_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE = 0x03,
ACI_BD_ADDR_TYPE_RANDOM_PRIVATE_UNRESOLVABLE = 0x04
} _aci_packed_ aci_bd_addr_type_t;
/**
* @enum aci_device_output_power_t
* @brief Radio output power levels
*/
typedef enum
{
ACI_DEVICE_OUTPUT_POWER_MINUS_18DBM = 0x00, /**< Output power set to -18dBm */
ACI_DEVICE_OUTPUT_POWER_MINUS_12DBM = 0x01, /**< Output power set to -12dBm */
ACI_DEVICE_OUTPUT_POWER_MINUS_6DBM = 0x02, /**< Output power set to -6dBm */
ACI_DEVICE_OUTPUT_POWER_0DBM = 0x03 /**< Output power set to 0dBm - DEFAULT*/
} _aci_packed_ aci_device_output_power_t;
/**
* @enum aci_device_operation_mode_t
* @brief Device operation modes
*/
typedef enum
{
ACI_DEVICE_INVALID =0x00,
ACI_DEVICE_TEST =0x01,
ACI_DEVICE_SETUP =0x02,
ACI_DEVICE_STANDBY =0x03,
ACI_DEVICE_SLEEP =0x04
} _aci_packed_ aci_device_operation_mode_t;
/**
* @enum aci_disconnect_reason_t
* @brief Reason enumeration for ACI_CMD_DISCONNECT
*/
typedef enum
{
ACI_REASON_TERMINATE =0x01, /**< Use this to disconnect (does a terminate request), you need to wait for the "disconnected" event */
ACI_REASON_BAD_TIMING =0x02 /*<Use this to disconnect and inform the peer, that the timing on the link is not acceptable for the device, you need to wait for the "disconnected" event */
} _aci_packed_ aci_disconnect_reason_t;
/**
* @enum aci_test_mode_change_t
* @brief Device test mode control
*/
typedef enum
{
ACI_TEST_MODE_DTM_UART = 0x01,
ACI_TEST_MODE_DTM_ACI = 0x02,
ACI_TEST_MODE_EXIT = 0xFF
} _aci_packed_ aci_test_mode_change_t;
ACI_ASSERT_SIZE(aci_test_mode_change_t, 1);
/**
* @enum aci_permissions_t
* @brief Data store permissions
*/
typedef enum
{
ACI_PERMISSIONS_NONE =0x00,
ACI_PERMISSIONS_LINK_AUTHENTICATED =0x01
} _aci_packed_ aci_permissions_t;
/**
* @def ACI_VS_UUID_128_MAX_COUNT
* @brief Maximum number of 128-bit Vendor Specific
* UUIDs that can be set
*/
#define ACI_VS_UUID_128_MAX_COUNT 64 /** #0 reserved for invalid, #1 reservered for BT SIG and a maximum of 1024 bytes (16*64) */
/**
* @struct aci_ll_conn_params_t
* @brief Link Layer Connection Parameters
*/
typedef struct
{
uint16_t min_conn_interval; /**< Minimum connection interval requested from peer */
#define ACI_PPCP_MIN_CONN_INTVL_NONE 0xFFFF
#define ACI_PPCP_MIN_CONN_INTVL_MIN 0x0006
#define ACI_PPCP_MIN_CONN_INTVL_MAX 0x0C80
uint16_t max_conn_interval; /**< Maximum connection interval requested from peer */
#define ACI_PPCP_MAX_CONN_INTVL_NONE 0xFFFF
#define ACI_PPCP_MAX_CONN_INTVL_MIN 0x0006
#define ACI_PPCP_MAX_CONN_INTVL_MAX 0x0C80
uint16_t slave_latency; /**< Connection interval latency requested from peer */
#define ACI_PPCP_SLAVE_LATENCY_MAX 0x03E8
uint16_t timeout_mult; /**< Link supervisor timeout multiplier requested from peer */
#define ACI_PPCP_TIMEOUT_MULT_NONE 0xFFFF
#define ACI_PPCP_TIMEOUT_MULT_MIN 0x000A
#define ACI_PPCP_TIMEOUT_MULT_MAX 0x0C80
} _aci_packed_ aci_ll_conn_params_t;
/**
* @def aci_gap_ppcp_t
* @brief GAP Peripheral Preferred Connection Parameters
*/
#define aci_gap_ppcp_t aci_ll_conn_params_t
/**
* @def ACI_AD_LOC_SVCUUID_16_MAX_COUNT
* @brief Maximum number of 16-bit UUIDs that can
* be inserted in the Services tag of AD
*/
#define ACI_AD_LOC_SVCUUID_16_MAX_COUNT 5
/**
* @def ACI_AD_LOC_SVCUUID_128_MAX_COUNT
* @brief Maximum number of 128-bit UUIDs that can
* be inserted in the Services tag of AD
*/
#define ACI_AD_LOC_SVCUUID_128_MAX_COUNT 1
/**
* @def ACI_AD_SOL_SVCUUID_16_MAX_COUNT
* @brief Maximum number of UUIDs that can
* be inserted in the Solicited Services tag of AD
*/
#define ACI_AD_SOL_SVCUUID_16_MAX_COUNT 5
/**
* @def ACI_AD_SOL_SVCUUID_128_MAX_COUNT
* @brief Maximum number of UUIDs that can
* be inserted in the Solicited Services tag of AD
*/
#define ACI_AD_SOL_SVCUUID_128_MAX_COUNT 1
/**
* @def ACI_SEC_ENCKEY_SIZE_MIN
* @brief Minimum encryption key size
*/
#define ACI_SEC_ENCKEY_SIZE_MIN 7
/**
* @def ACI_SEC_ENCKEY_SIZE_MAX
* @brief Maximum encryption key size
*/
#define ACI_SEC_ENCKEY_SIZE_MAX 16
/**
* @def ACI_CUSTOM_AD_TYPE_MAX_COUNT
* @brief Maximum number of custom ad types
*/
#define ACI_CUSTOM_AD_TYPE_MAX_COUNT 8
/**
* @def ACI_CUSTOM_AD_TYPE_MAX_DATA_LENGTH
* @brief Maximum custom ad type data size
*/
#define ACI_CUSTOM_AD_TYPE_MAX_DATA_LENGTH 20
/**
* @struct aci_tx_data_t
* @brief Generic ACI transmit data structure
*/
typedef struct
{
uint8_t pipe_number;
uint8_t aci_data[ACI_PIPE_TX_DATA_MAX_LEN];
} _aci_packed_ aci_tx_data_t;
ACI_ASSERT_SIZE(aci_tx_data_t, ACI_PIPE_TX_DATA_MAX_LEN + 1);
/**
* @struct aci_rx_data_t
* @brief Generic ACI receive data structure
*/
typedef struct
{
uint8_t pipe_number;
uint8_t aci_data[ACI_PIPE_RX_DATA_MAX_LEN];
} _aci_packed_ aci_rx_data_t;
ACI_ASSERT_SIZE(aci_rx_data_t, ACI_PIPE_RX_DATA_MAX_LEN + 1);
/**
* @enum aci_hw_error_t
* @brief Hardware Error codes
*/
typedef enum
{
ACI_HW_ERROR_NONE = 0x00,
ACI_HW_ERROR_FATAL = 0x01
} _aci_packed_ aci_hw_error_t;
/**
* @enum aci_clock_accuracy_t
* @brief Bluetooth Low Energy Clock Accuracy
*/
typedef enum
{
ACI_CLOCK_ACCURACY_500_PPM = 0x00,
ACI_CLOCK_ACCURACY_250_PPM = 0x01,
ACI_CLOCK_ACCURACY_150_PPM = 0x02,
ACI_CLOCK_ACCURACY_100_PPM = 0x03,
ACI_CLOCK_ACCURACY_75_PPM = 0x04,
ACI_CLOCK_ACCURACY_50_PPM = 0x05,
ACI_CLOCK_ACCURACY_30_PPM = 0x06,
ACI_CLOCK_ACCURACY_20_PPM = 0x07
} _aci_packed_ aci_clock_accuracy_t;
/**
* @enum aci_app_latency_mode_t
* @brief Application latency modes
*/
typedef enum
{
ACI_APP_LATENCY_DISABLE = 0,
ACI_APP_LATENCY_ENABLE = 1
} _aci_packed_ aci_app_latency_mode_t;
/**
* @enum gatt_format_t
* @brief GATT format definitions
*/
typedef enum
{
ACI_GATT_FORMAT_NONE = 0x00, /**< No characteristic format available */
ACI_GATT_FORMAT_BOOLEAN = 0x01, /**< Not Supported */
ACI_GATT_FORMAT_2BIT = 0x02, /**< Not Supported */
ACI_GATT_FORMAT_NIBBLE = 0x03, /**< Not Supported */
ACI_GATT_FORMAT_UINT8 = 0x04,
ACI_GATT_FORMAT_UINT12 = 0x05,
ACI_GATT_FORMAT_UINT16 = 0x06,
ACI_GATT_FORMAT_UINT24 = 0x07,
ACI_GATT_FORMAT_UINT32 = 0x08,
ACI_GATT_FORMAT_UINT48 = 0x09,
ACI_GATT_FORMAT_UINT64 = 0x0A,
ACI_GATT_FORMAT_UINT128 = 0x0B,
ACI_GATT_FORMAT_SINT8 = 0x0C,
ACI_GATT_FORMAT_SINT12 = 0x0D,
ACI_GATT_FORMAT_SINT16 = 0x0E,
ACI_GATT_FORMAT_SINT24 = 0x0F,
ACI_GATT_FORMAT_SINT32 = 0x10,
ACI_GATT_FORMAT_SINT48 = 0x11,
ACI_GATT_FORMAT_SINT64 = 0x12,
ACI_GATT_FORMAT_SINT128 = 0x13,
ACI_GATT_FORMAT_FLOAT32 = 0x14,
ACI_GATT_FORMAT_FLOAT64 = 0x15,
ACI_GATT_FORMAT_SFLOAT = 0x16,
ACI_GATT_FORMAT_FLOAT = 0x17,
ACI_GATT_FORMAT_DUINT16 = 0x18,
ACI_GATT_FORMAT_UTF8S = 0x19,
ACI_GATT_FORMAT_UTF16S = 0x1A,
ACI_GATT_FORMAT_STRUCT = 0x1B
} _aci_packed_ aci_gatt_format_t;
/**
* @brief GATT Bluetooth namespace
*/
typedef enum
{
ACI_GATT_NAMESPACE_INVALID = 0x00,
ACI_GATT_NAMESPACE_BTSIG = 0x01 /**< Bluetooth SIG */
} _aci_packed_ aci_gatt_namespace_t;
/**
* @brief Security key types
*/
typedef enum
{
ACI_KEY_TYPE_INVALID = 0x00,
ACI_KEY_TYPE_PASSKEY = 0x01
} _aci_packed_ aci_key_type_t;
/**
* @enum aci_bond_status_code_t
* @brief Bond status code
*/
typedef enum
{
/**
* Bonding succeeded
*/
ACI_BOND_STATUS_SUCCESS = 0x00,
/**
* Bonding failed
*/
ACI_BOND_STATUS_FAILED = 0x01,
/**
* Bonding error: Timeout can occur when link termination is unexpected or did not get connected OR SMP timer expired
*/
ACI_BOND_STATUS_FAILED_TIMED_OUT = 0x02,
/**
* Bonding error: Passkey entry failed
*/
ACI_BOND_STATUS_FAILED_PASSKEY_ENTRY_FAILED = 0x81,
/**
* Bonding error: OOB unavailable
*/
ACI_BOND_STATUS_FAILED_OOB_UNAVAILABLE = 0x82,
/**
* Bonding error: Authentication request failed
*/
ACI_BOND_STATUS_FAILED_AUTHENTICATION_REQ = 0x83,
/**
* Bonding error: Confirm value failed
*/
ACI_BOND_STATUS_FAILED_CONFIRM_VALUE = 0x84,
/**
* Bonding error: Pairing unsupported
*/
ACI_BOND_STATUS_FAILED_PAIRING_UNSUPPORTED = 0x85,
/**
* Bonding error: Invalid encryption key size
*/
ACI_BOND_STATUS_FAILED_ENCRYPTION_KEY_SIZE = 0x86,
/**
* Bonding error: Unsupported SMP command
*/
ACI_BOND_STATUS_FAILED_SMP_CMD_UNSUPPORTED = 0x87,
/**
* Bonding error: Unspecified reason
*/
ACI_BOND_STATUS_FAILED_UNSPECIFIED_REASON = 0x88,
/**
* Bonding error: Too many attempts
*/
ACI_BOND_STATUS_FAILED_REPEATED_ATTEMPTS = 0x89,
/**
* Bonding error: Invalid parameters
*/
ACI_BOND_STATUS_FAILED_INVALID_PARAMETERS = 0x8A
} _aci_packed_ aci_bond_status_code_t;
ACI_ASSERT_SIZE(aci_bond_status_code_t, 1);
/**
* @enum aci_bond_status_source_t
* @brief Source of a bond status code
*/
typedef enum
{
ACI_BOND_STATUS_SOURCE_INVALID = 0x00,
ACI_BOND_STATUS_SOURCE_LOCAL = 0x01,
ACI_BOND_STATUS_SOURCE_REMOTE = 0x02
} _aci_packed_ aci_bond_status_source_t;
/**
* @enum aci_status_code_t
* @brief ACI status codes
*/
typedef enum
{
/**
* Success
*/
ACI_STATUS_SUCCESS = 0x00,
/**
* Transaction continuation status
*/
ACI_STATUS_TRANSACTION_CONTINUE = 0x01,
/**
* Transaction completed
*/
ACI_STATUS_TRANSACTION_COMPLETE = 0x02,
/**
* Extended status, further checks needed
*/
ACI_STATUS_EXTENDED = 0x03,
/**
* Unknown error.
*/
ACI_STATUS_ERROR_UNKNOWN = 0x80,
/**
* Internal error.
*/
ACI_STATUS_ERROR_INTERNAL = 0x81,
/**
* Unknown command
*/
ACI_STATUS_ERROR_CMD_UNKNOWN = 0x82,
/**
* Command invalid in the current device state
*/
ACI_STATUS_ERROR_DEVICE_STATE_INVALID = 0x83,
/**
* Invalid length
*/
ACI_STATUS_ERROR_INVALID_LENGTH = 0x84,
/**
* Invalid input parameters
*/
ACI_STATUS_ERROR_INVALID_PARAMETER = 0x85,
/**
* Busy
*/
ACI_STATUS_ERROR_BUSY = 0x86,
/**
* Invalid data format or contents
*/
ACI_STATUS_ERROR_INVALID_DATA = 0x87,
/**
* CRC mismatch
*/
ACI_STATUS_ERROR_CRC_MISMATCH = 0x88,
/**
* Unsupported setup format
*/
ACI_STATUS_ERROR_UNSUPPORTED_SETUP_FORMAT = 0x89,
/**
* Invalid sequence number during a write dynamic data sequence
*/
ACI_STATUS_ERROR_INVALID_SEQ_NO = 0x8A,
/**
* Setup data is locked and cannot be modified
*/
ACI_STATUS_ERROR_SETUP_LOCKED = 0x8B,
/**
* Setup error due to lock verification failure
*/
ACI_STATUS_ERROR_LOCK_FAILED = 0x8C,
/**
* Bond required: Local Pipes need bonded/trusted peer
*/
ACI_STATUS_ERROR_BOND_REQUIRED = 0x8D,
/**
* Command rejected as a transaction is still pending
*/
ACI_STATUS_ERROR_REJECTED = 0x8E,
/**
* Pipe Error Event : Data size exceeds size specified for pipe : Transmit failed
*/
ACI_STATUS_ERROR_DATA_SIZE = 0x8F,
/**
* Pipe Error Event : Invalid pipe
*/
ACI_STATUS_ERROR_PIPE_INVALID = 0x90,
/**
* Pipe Error Event : Credit not available
*/
ACI_STATUS_ERROR_CREDIT_NOT_AVAILABLE = 0x91,
/**
* Pipe Error Event : Peer device has sent an error on an pipe operation on the remote characteristic
*/
ACI_STATUS_ERROR_PEER_ATT_ERROR = 0x92,
/**
* Connection was not established before the BTLE advertising was stopped
*/
ACI_STATUS_ERROR_ADVT_TIMEOUT = 0x93,
/**
* Peer has triggered a Security Manager Protocol Error
*/
ACI_STATUS_ERROR_PEER_SMP_ERROR = 0x94,
/**
* Pipe Error Event : Pipe type invalid for the selected operation
*/
ACI_STATUS_ERROR_PIPE_TYPE_INVALID = 0x95,
/**
* Pipe Error Event : Pipe state invalid for the selected operation
*/
ACI_STATUS_ERROR_PIPE_STATE_INVALID = 0x96,
/**
* Invalid key size provided
*/
ACI_STATUS_ERROR_INVALID_KEY_SIZE = 0x97,
/**
* Invalid key data provided
*/
ACI_STATUS_ERROR_INVALID_KEY_DATA = 0x98,
/**
* Reserved range start
*/
ACI_STATUS_RESERVED_START = 0xF0,
/**
* Reserved range end
*/
ACI_STATUS_RESERVED_END = 0xFF
} _aci_packed_ aci_status_code_t;
ACI_ASSERT_SIZE(aci_status_code_t, 1);
/**
* @}
*/
#endif // ACI_H__

435
src/nrf8001/aci_cmds.h Normal file
View File

@ -0,0 +1,435 @@
/* Copyright (c) 2014, Nordic Semiconductor ASA
*
* 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
*
* @ingroup aci
*
* @brief Definitions for the ACI (Application Control Interface) commands
* @remarks
*
*/
#ifndef ACI_CMDS_H__
#define ACI_CMDS_H__
#include "aci.h"
/**
* @enum aci_cmd_opcode_t
* @brief ACI command opcodes
*/
typedef enum
{
/**
* Enter test mode
*/
ACI_CMD_TEST = 0x01,
/**
* Echo (loopback) test command
*/
ACI_CMD_ECHO = 0x02,
/**
* Send a BTLE DTM command to the radio
*/
ACI_CMD_DTM_CMD = 0x03,
/**
* Put the device to sleep
*/
ACI_CMD_SLEEP = 0x04,
/**
* Wakeup the device from deep sleep
*/
ACI_CMD_WAKEUP = 0x05,
/**
* Replace the contents of the internal database with
* user provided data
*/
ACI_CMD_SETUP = 0x06,
/**
* Read the portions of memory required to be restored after a power cycle
*/
ACI_CMD_READ_DYNAMIC_DATA = 0x07,
/**
* Write back the data retrieved using ACI_CMD_READ_DYNAMIC_DATA
*/
ACI_CMD_WRITE_DYNAMIC_DATA = 0x08,
/**
* Retrieve the device's version information
*/
ACI_CMD_GET_DEVICE_VERSION = 0x09,
/**
* Request the Bluetooth address and its type
*/
ACI_CMD_GET_DEVICE_ADDRESS = 0x0A,
/**
* Request the battery level measured by nRF8001
*/
ACI_CMD_GET_BATTERY_LEVEL = 0x0B,
/**
* Request the temperature value measured by nRF8001
*/
ACI_CMD_GET_TEMPERATURE = 0x0C,
/**
* Write to the local Attribute Database
*/
ACI_CMD_SET_LOCAL_DATA = 0x0D,
/**
* Reset the baseband and radio and go back to idle
*/
ACI_CMD_RADIO_RESET = 0x0E,
/**
* Start advertising and wait for a master connection
*/
ACI_CMD_CONNECT = 0x0F,
/**
* Start advertising and wait for a master connection
*/
ACI_CMD_BOND = 0x10,
/**
* Start advertising and wait for a master connection
*/
ACI_CMD_DISCONNECT = 0x11,
/**
* Throttles the Radio transmit power
*/
ACI_CMD_SET_TX_POWER = 0x12,
/**
* Trigger a connection parameter update
*/
ACI_CMD_CHANGE_TIMING = 0x13,
/**
* Open a remote pipe for data reception
*/
ACI_CMD_OPEN_REMOTE_PIPE = 0x14,
/**
* Transmit data over an open pipe
*/
ACI_CMD_SEND_DATA = 0x15,
/**
* Send an acknowledgment of received data
*/
ACI_CMD_SEND_DATA_ACK = 0x16,
/**
* Request data over an open pipe
*/
ACI_CMD_REQUEST_DATA = 0x17,
/**
* NACK a data reception
*/
ACI_CMD_SEND_DATA_NACK = 0x18,
/**
* Set application latency
*/
ACI_CMD_SET_APP_LATENCY = 0x19,
/**
* Set a security key
*/
ACI_CMD_SET_KEY = 0x1A,
/**
* Open Advertising Pipes
*/
ACI_CMD_OPEN_ADV_PIPE = 0x1B,
/**
* Start non-connectable advertising
*/
ACI_CMD_BROADCAST = 0x1C,
/**
* Start a security request in bonding mode
*/
ACI_CMD_BOND_SECURITY_REQUEST = 0x1D,
/**
* Start Directed advertising towards a Bonded Peer
*/
ACI_CMD_CONNECT_DIRECT = 0x1E,
/**
* Close a previously opened remote pipe
*/
ACI_CMD_CLOSE_REMOTE_PIPE = 0x1F,
/**
* Invalid ACI command opcode
*/
ACI_CMD_INVALID = 0xFF
} _aci_packed_ aci_cmd_opcode_t;
ACI_ASSERT_SIZE(aci_cmd_opcode_t, 1);
/**
* @struct aci_cmd_params_test_t
* @brief Structure for the ACI_CMD_TEST ACI command parameters
*/
typedef struct
{
aci_test_mode_change_t test_mode_change; /**< enum aci_test_mode_change_t */
} _aci_packed_ aci_cmd_params_test_t;
ACI_ASSERT_SIZE(aci_cmd_params_test_t, 1);
/**
* @struct aci_cmd_params_echo_t
* @brief Structure for the ACI_CMD_ECHO ACI command parameters
*/
typedef struct
{
uint8_t echo_data[ACI_ECHO_DATA_MAX_LEN];
} _aci_packed_ aci_cmd_params_echo_t;
ACI_ASSERT_SIZE(aci_cmd_params_echo_t, ACI_ECHO_DATA_MAX_LEN);
/**
* @struct aci_cmd_params_dtm_cmd_t
* @brief Structure for the ACI_CMD_DTM_CMD ACI command parameters
*/
typedef struct
{
uint8_t cmd_msb;
uint8_t cmd_lsb;
} _aci_packed_ aci_cmd_params_dtm_cmd_t;
/**
* @struct aci_cmd_params_setup_t
* @brief Structure for the ACI_CMD_SETUP ACI command parameters
*/
typedef struct
{
uint8_t setup_data[1];
} _aci_packed_ aci_cmd_params_setup_t;
ACI_ASSERT_SIZE(aci_cmd_params_setup_t, 1);
/**
* @struct aci_cmd_params_write_dynamic_data_t
* @brief Structure for the ACI_CMD_WRITE_DYNAMIC_DATA ACI command parameters
* @note Dynamic data chunk size in this command is defined to go up to ACI_PACKET_MAX_LEN - 3
*/
typedef struct
{
uint8_t seq_no;
uint8_t dynamic_data[1];
} _aci_packed_ aci_cmd_params_write_dynamic_data_t;
/**
* @define aci_cmd_params_set_local_data_t
* @brief Structure for the ACI_CMD_SET_LOCAL_DATA ACI command parameters
*/
typedef struct
{
aci_tx_data_t tx_data;
} _aci_packed_ aci_cmd_params_set_local_data_t;
/**
* @struct aci_cmd_params_connect_t
* @brief Structure for the ACI_CMD_CONNECT ACI command parameters
*/
typedef struct
{
uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
} _aci_packed_ aci_cmd_params_connect_t;
ACI_ASSERT_SIZE(aci_cmd_params_connect_t, 4);
/**
* @define aci_cmd_params_bond_t
* @brief Structure for the ACI_CMD_BOND ACI command parameters
*/
typedef struct
{
uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
} _aci_packed_ aci_cmd_params_bond_t;
ACI_ASSERT_SIZE(aci_cmd_params_bond_t, 4);
/**
* @struct aci_cmd_params_disconnect_t
* @brief Structure for the ACI_CMD_DISCONNECT ACI command parameters
*/
typedef struct
{
aci_disconnect_reason_t reason; /**< enum aci_disconnect_reason_t */
} _aci_packed_ aci_cmd_params_disconnect_t;
ACI_ASSERT_SIZE(aci_cmd_params_disconnect_t, 1);
/**
* @struct aci_cmd_params_set_tx_power_t
* @brief Structure for the ACI_CMD_SET_TX_POWER ACI command parameters
*/
typedef struct
{
aci_device_output_power_t device_power; /**< enum aci_device_output_power_t */
} _aci_packed_ aci_cmd_params_set_tx_power_t;
ACI_ASSERT_SIZE(aci_cmd_params_set_tx_power_t, 1);
/**
* @struct aci_cmd_params_change_timing_t
* @brief Structure for the ACI_CMD_CHANGE_TIMING ACI command parameters
*/
typedef struct
{
aci_ll_conn_params_t conn_params;
} _aci_packed_ aci_cmd_params_change_timing_t;
ACI_ASSERT_SIZE(aci_cmd_params_change_timing_t, 8);
/**
* @struct aci_cmd_params_open_remote_pipe_t
* @brief Structure for the ACI_CMD_OPEN_REMOTE_PIPE ACI command parameters
*/
typedef struct
{
uint8_t pipe_number;
} _aci_packed_ aci_cmd_params_open_remote_pipe_t;
/**
* @struct aci_cmd_params_send_data_t
* @brief Structure for the ACI_CMD_SEND_DATA ACI command parameters
*/
typedef struct
{
aci_tx_data_t tx_data;
} _aci_packed_ aci_cmd_params_send_data_t;
/**
* @define aci_cmd_params_send_data_ack_t
* @brief Structure for the ACI_CMD_SEND_DATA_ACK ACI command parameters
*/
typedef struct
{
uint8_t pipe_number;
} _aci_packed_ aci_cmd_params_send_data_ack_t;
/**
* @struct aci_cmd_params_send_data_t
* @brief Structure for the ACI_CMD_SEND_DATA ACI command parameters
*/
typedef struct
{
uint8_t pipe_number;
} _aci_packed_ aci_cmd_params_request_data_t;
/**
* @define aci_cmd_params_send_data_nack_t
* @brief Structure for the ACI_CMD_SEND_DATA_NACK ACI command parameters
*/
typedef struct
{
uint8_t pipe_number;
uint8_t error_code;
} _aci_packed_ aci_cmd_params_send_data_nack_t;
ACI_ASSERT_SIZE(aci_cmd_params_send_data_nack_t, 2);
/**
* @define aci_cmd_params_set_app_latency_t
* @brief Structure for the ACI_CMD_SET_APP_LATENCY ACI command parameters
*/
typedef struct
{
aci_app_latency_mode_t mode;
uint16_t latency;
} _aci_packed_ aci_cmd_params_set_app_latency_t;
ACI_ASSERT_SIZE(aci_cmd_params_set_app_latency_t, 3);
/**
* @define aci_cmd_params_set_key_t
* @brief Structure for the ACI_CMD_SET_KEY ACI command parameters
*/
typedef struct
{
aci_key_type_t key_type;
union
{
uint8_t passkey[6];
uint8_t oob_key[16];
} key;
} _aci_packed_ aci_cmd_params_set_key_t;
ACI_ASSERT_SIZE(aci_cmd_params_set_key_t, 17);
/**
* @define aci_cmd_params_open_adv_pipe_t
* @brief Structure for the ACI_CMD_OPEN_ADV_PIPE ACI command parameters
*/
typedef struct
{
uint8_t pipes[8];
} _aci_packed_ aci_cmd_params_open_adv_pipe_t;
/**
* @define aci_cmd_params_broadcast_t
* @brief Structure for the ACI_CMD_BROADCAST ACI command parameters
*/
typedef struct
{
uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
} _aci_packed_ aci_cmd_params_broadcast_t;
/**
* @struct aci_cmd_params_close_remote_pipe_t
* @brief Structure for the ACI_CMD_CLOSE_REMOTE_PIPE ACI command parameters
*/
typedef struct
{
uint8_t pipe_number;
} _aci_packed_ aci_cmd_params_close_remote_pipe_t;
/**
* @struct aci_cmd_t
* @brief Encapsulates a generic ACI command
*/
typedef struct
{
uint8_t len; /**< Length of the ACI command */
aci_cmd_opcode_t cmd_opcode; /**< enum aci_cmd_opcode_t -> Opcode of the ACI command */
union
{
aci_cmd_params_test_t test;
aci_cmd_params_echo_t echo;
aci_cmd_params_dtm_cmd_t dtm_cmd;
aci_cmd_params_setup_t setup;
aci_cmd_params_write_dynamic_data_t write_dynamic_data;
aci_cmd_params_set_local_data_t set_local_data;
aci_cmd_params_connect_t connect;
aci_cmd_params_bond_t bond;
aci_cmd_params_disconnect_t disconnect;
aci_cmd_params_set_tx_power_t set_tx_power;
aci_cmd_params_change_timing_t change_timing;
aci_cmd_params_open_remote_pipe_t open_remote_pipe;
aci_cmd_params_send_data_t send_data;
aci_cmd_params_send_data_ack_t send_data_ack;
aci_cmd_params_request_data_t request_data;
aci_cmd_params_send_data_nack_t send_data_nack;
aci_cmd_params_set_app_latency_t set_app_latency;
aci_cmd_params_set_key_t set_key;
aci_cmd_params_open_adv_pipe_t open_adv_pipe;
aci_cmd_params_broadcast_t broadcast;
aci_cmd_params_close_remote_pipe_t close_remote_pipe;
} params;
} _aci_packed_ aci_cmd_t;
#endif // ACI_CMDS_H__

397
src/nrf8001/aci_evts.h Normal file
View File

@ -0,0 +1,397 @@
/* Copyright (c) 2014, Nordic Semiconductor ASA
*
* 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
*
* @ingroup aci
*
* @brief Definitions for the ACI (Application Control Interface) events
*/
#ifndef ACI_EVTS_H__
#define ACI_EVTS_H__
#include "aci.h"
/**
* @enum aci_evt_opcode_t
* @brief ACI event opcodes
*/
typedef enum
{
/**
* Invalid event code
*/
ACI_EVT_INVALID = 0x00,
/**
* Sent every time the device starts
*/
ACI_EVT_DEVICE_STARTED = 0x81,
/**
* Mirrors the ACI_CMD_ECHO
*/
ACI_EVT_ECHO = 0x82,
/**
* Asynchronous hardware error event
*/
ACI_EVT_HW_ERROR = 0x83,
/**
* Event opcode used as a event response for all commands
*/
ACI_EVT_CMD_RSP = 0x84,
/**
* Link connected
*/
ACI_EVT_CONNECTED = 0x85,
/**
* Link disconnected
*/
ACI_EVT_DISCONNECTED = 0x86,
/**
* Bond completion result
*/
ACI_EVT_BOND_STATUS = 0x87,
/**
* Pipe bitmap for available pipes
*/
ACI_EVT_PIPE_STATUS = 0x88,
/**
* Sent to the application when the radio enters a connected state
* or when the timing of the radio connection changes
*/
ACI_EVT_TIMING = 0x89,
/**
* Notification to the application that transmit credits are
* available
*/
ACI_EVT_DATA_CREDIT = 0x8A,
/**
* Data acknowledgement event
*/
ACI_EVT_DATA_ACK = 0x8B,
/**
* Data received notification event
*/
ACI_EVT_DATA_RECEIVED = 0x8C,
/**
* Error notification event
*/
ACI_EVT_PIPE_ERROR = 0x8D,
/**
* Display Passkey Event
*/
ACI_EVT_DISPLAY_PASSKEY = 0x8E,
/**
* Security Key request
*/
ACI_EVT_KEY_REQUEST = 0x8F
} _aci_packed_ aci_evt_opcode_t;
ACI_ASSERT_SIZE(aci_evt_opcode_t, 1);
/**
* @struct aci_evt_params_device_started_t
* @brief Structure for the ACI_EVT_DEVICE_STARTED event return parameters
*/
typedef struct
{
aci_device_operation_mode_t device_mode; /**< Mode in which the device is being started */
aci_hw_error_t hw_error; /**< Hardware Error if available for the start */
uint8_t credit_available; /**< Flow control credit available for this specific FW build */
} _aci_packed_ aci_evt_params_device_started_t;
ACI_ASSERT_SIZE(aci_evt_params_device_started_t, 3);
/**
* @struct aci_evt_params_hw_error_t
* @brief Structure for the ACI_EVT_HW_ERROR event return parameters
*/
typedef struct
{
uint16_t line_num;
uint8_t file_name[20];
} _aci_packed_ aci_evt_params_hw_error_t;
ACI_ASSERT_SIZE(aci_evt_params_hw_error_t, 22);
/**
* @struct aci_evt_cmd_rsp_params_dtm_cmd_t
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_DTM_CMD event return parameters
*/
typedef struct
{
uint8_t evt_msb;
uint8_t evt_lsb;
} _aci_packed_ aci_evt_cmd_rsp_params_dtm_cmd_t;
/**
* @struct aci_evt_cmd_rsp_read_dynamic_data_t
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_READ_DYNAMIC_DATA event return parameters
* @note Dynamic data chunk size in this event is defined to go up to ACI_PACKET_MAX_LEN - 5
*/
typedef struct
{
uint8_t seq_no;
uint8_t dynamic_data[1];
} _aci_packed_ aci_evt_cmd_rsp_read_dynamic_data_t;
/**
* @struct aci_evt_cmd_rsp_params_get_device_version_t
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_GET_DEVICE_VERSION event return parameters
*/
typedef struct
{
uint16_t configuration_id;
uint8_t aci_version;
uint8_t setup_format;
uint32_t setup_id;
uint8_t setup_status;
} _aci_packed_ aci_evt_cmd_rsp_params_get_device_version_t;
ACI_ASSERT_SIZE(aci_evt_cmd_rsp_params_get_device_version_t, 9);
/**
* @struct aci_evt_cmd_rsp_params_get_device_address_t
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_GET_DEVICE_ADDRESS event return parameters
*/
typedef struct
{
uint8_t bd_addr_own[BTLE_DEVICE_ADDRESS_SIZE];
aci_bd_addr_type_t bd_addr_type;
} _aci_packed_ aci_evt_cmd_rsp_params_get_device_address_t;
ACI_ASSERT_SIZE(aci_evt_cmd_rsp_params_get_device_address_t, BTLE_DEVICE_ADDRESS_SIZE + 1);
/**
* @struct aci_evt_cmd_rsp_params_get_battery_level_t
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_GET_BATTERY_LEVEL event return parameters
*/
typedef struct
{
uint16_t battery_level;
} _aci_packed_ aci_evt_cmd_rsp_params_get_battery_level_t;
/**
* @struct aci_evt_cmd_rsp_params_get_temperature_t
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_GET_TEMPERATURE event return parameters
*/
typedef struct
{
int16_t temperature_value;
} _aci_packed_ aci_evt_cmd_rsp_params_get_temperature_t;
/**
* @struct aci_evt_params_cmd_rsp_t
* @brief Structure for the ACI_EVT_CMD_RSP event return parameters
*/
typedef struct
{
aci_cmd_opcode_t cmd_opcode; /**< Command opcode for which the event response is being sent */
aci_status_code_t cmd_status; /**< Status of the command that was sent. Used in the context of the command. */
union
{
aci_evt_cmd_rsp_params_dtm_cmd_t dtm_cmd;
aci_evt_cmd_rsp_read_dynamic_data_t read_dynamic_data;
aci_evt_cmd_rsp_params_get_device_version_t get_device_version;
aci_evt_cmd_rsp_params_get_device_address_t get_device_address;
aci_evt_cmd_rsp_params_get_battery_level_t get_battery_level;
aci_evt_cmd_rsp_params_get_temperature_t get_temperature;
uint8_t padding[29];
} params;
} _aci_packed_ aci_evt_params_cmd_rsp_t;
ACI_ASSERT_SIZE(aci_evt_params_cmd_rsp_t, 31);
/**
* @struct aci_evt_params_connected_t
* @brief Structure for the ACI_EVT_CONNECTED event return parameters
*/
typedef struct
{
aci_bd_addr_type_t dev_addr_type;
uint8_t dev_addr[BTLE_DEVICE_ADDRESS_SIZE];
uint16_t conn_rf_interval; /**< rf_interval = conn_rf_interval * 1.25 ms Range:0x0006 to 0x0C80 */
uint16_t conn_slave_rf_latency; /**< Number of RF events the slave can skip */
uint16_t conn_rf_timeout; /**< Timeout as a multiple of 10ms i.e timeout = conn_rf_timeout * 10ms Range: 0x000A to 0x0C80 */
aci_clock_accuracy_t master_clock_accuracy; /**< Clock accuracy of Bluetooth master: Enumerated list of values from 500 ppm to 20 ppm */
} _aci_packed_ aci_evt_params_connected_t;
ACI_ASSERT_SIZE(aci_evt_params_connected_t, 14);
/**
* @struct aci_evt_params_disconnected_t
* @brief Structure for the ACI_EVT_DISCONNECTED event return parameters
*/
typedef struct
{
aci_status_code_t aci_status;
uint8_t btle_status;
} _aci_packed_ aci_evt_params_disconnected_t;
ACI_ASSERT_SIZE(aci_evt_params_disconnected_t, 2);
/**
* @struct aci_evt_params_bond_status_t
* @brief Structure for the ACI_EVT_BOND_STATUS event return parameters
*/
typedef struct
{
aci_bond_status_code_t status_code;
aci_bond_status_source_t status_source;
uint8_t secmode1_bitmap;
uint8_t secmode2_bitmap;
uint8_t keys_exchanged_slave;
uint8_t keys_exchanged_master;
} _aci_packed_ aci_evt_params_bond_status_t;
ACI_ASSERT_SIZE(aci_evt_params_bond_status_t, 6);
/**
* @struct aci_evt_params_pipe_status_t
* @brief Structure for the ACI_EVT_PIPE_STATUS event return parameters
*/
typedef struct
{
uint8_t pipes_open_bitmap[8];
uint8_t pipes_closed_bitmap[8];
} _aci_packed_ aci_evt_params_pipe_status_t;
ACI_ASSERT_SIZE(aci_evt_params_pipe_status_t, 16);
/**
* @struct aci_evt_params_timing_t
* @brief Structure for the ACI_EVT_TIMING event return parameters
*/
typedef struct
{
uint16_t conn_rf_interval; /**< rf_interval = conn_rf_interval * 1.25 ms Range:0x0006 to 0x0C80 */
uint16_t conn_slave_rf_latency; /**< Number of RF events the slave can skip */
uint16_t conn_rf_timeout; /**< Timeout as a multiple of 10ms i.e timeout = conn_rf_timeout * 10ms Range: 0x000A to 0x0C80 */
} _aci_packed_ aci_evt_params_timing_t;
ACI_ASSERT_SIZE(aci_evt_params_timing_t, 6);
/**
* @struct aci_evt_params_data_credit_t
* @brief Structure for the ACI_EVT_DATA_CREDIT event return parameters
*/
typedef struct
{
uint8_t credit;
} _aci_packed_ aci_evt_params_data_credit_t;
/**
* @struct aci_evt_params_data_ack_t
* @brief Structure for the ACI_EVT_DATA_ACK event return parameters
*/
typedef struct
{
uint8_t pipe_number;
} _aci_packed_ aci_evt_params_data_ack_t;
/**
* @struct aci_evt_params_data_received_t
* @brief Structure for the ACI_EVT_DATA_RECEIVED event return parameters
*/
typedef struct
{
aci_rx_data_t rx_data;
} _aci_packed_ aci_evt_params_data_received_t;
typedef struct
{
uint8_t content[1];
} _aci_packed_ error_data_t;
/**
* @struct aci_evt_params_pipe_error_t
* @brief Structure for the ACI_EVT_PIPE_ERROR event return parameters
*/
typedef struct
{
uint8_t pipe_number;
uint8_t error_code;
union
{
error_data_t error_data;
} params;
} _aci_packed_ aci_evt_params_pipe_error_t;
/**
* @struct aci_evt_params_display_passkey_t
* @brief Structure for the ACI_EVT_DISPLAY_PASSKEY event return parameters
*/
typedef struct
{
uint8_t passkey[6];
} _aci_packed_ aci_evt_params_display_passkey_t;
/**
* @struct aci_evt_params_key_request_t
* @brief Structure for the ACI_EVT_KEY_REQUEST event return parameters
*/
typedef struct
{
aci_key_type_t key_type;
} _aci_packed_ aci_evt_params_key_request_t;
/**
* @struct aci_event_params_echo_t
* @brief Structure for the ACI_EVT_ECHO ACI event parameters
*/
typedef struct
{
uint8_t echo_data[ACI_ECHO_DATA_MAX_LEN];
} _aci_packed_ aci_evt_params_echo_t;
/**
* @struct aci_evt_t
* @brief Encapsulates a generic ACI event
*/
typedef struct
{
uint8_t len;
aci_evt_opcode_t evt_opcode;
union
{
aci_evt_params_device_started_t device_started;
aci_evt_params_echo_t echo;
aci_evt_params_hw_error_t hw_error;
aci_evt_params_cmd_rsp_t cmd_rsp;
aci_evt_params_connected_t connected;
aci_evt_params_disconnected_t disconnected;
aci_evt_params_bond_status_t bond_status;
aci_evt_params_pipe_status_t pipe_status;
aci_evt_params_timing_t timing;
aci_evt_params_data_credit_t data_credit;
aci_evt_params_data_ack_t data_ack;
aci_evt_params_data_received_t data_received;
aci_evt_params_pipe_error_t pipe_error;
aci_evt_params_display_passkey_t display_passkey;
aci_evt_params_key_request_t key_request;
} params;
} _aci_packed_ aci_evt_t;
ACI_ASSERT_SIZE(aci_evt_t, 33);
#endif // ACI_EVTS_H__

View File

@ -0,0 +1,188 @@
/* Copyright (c) 2014, Nordic Semiconductor ASA
*
* 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.
*/
/*
* This file contents defines for the position of all the fields of ACI
* command or event messages
*/
#ifndef ACI_OFFSET_H__
#define ACI_OFFSET_H__
#define OFFSET_ACI_LL_CONN_PARAMS_T_MIN_CONN_INTERVAL_LSB 0
#define OFFSET_ACI_LL_CONN_PARAMS_T_MIN_CONN_INTERVAL_MSB 1
#define OFFSET_ACI_LL_CONN_PARAMS_T_MAX_CONN_INTERVAL_LSB 2
#define OFFSET_ACI_LL_CONN_PARAMS_T_MAX_CONN_INTERVAL_MSB 3
#define OFFSET_ACI_LL_CONN_PARAMS_T_SLAVE_LATENCY_LSB 4
#define OFFSET_ACI_LL_CONN_PARAMS_T_SLAVE_LATENCY_MSB 5
#define OFFSET_ACI_LL_CONN_PARAMS_T_TIMEOUT_MULT_LSB 6
#define OFFSET_ACI_LL_CONN_PARAMS_T_TIMEOUT_MULT_MSB 7
#define OFFSET_ACI_TX_DATA_T_PIPE_NUMBER 0
#define OFFSET_ACI_TX_DATA_T_ACI_DATA 1
#define OFFSET_ACI_RX_DATA_T_PIPE_NUMBER 0
#define OFFSET_ACI_RX_DATA_T_ACI_DATA 1
#define OFFSET_ACI_CMD_PARAMS_TEST_T_TEST_MODE_CHANGE 0
#define OFFSET_ACI_CMD_PARAMS_ECHO_T_ECHO_DATA 0
#define OFFSET_ACI_CMD_PARAMS_DTM_CMD_T_CMD_MSB 0
#define OFFSET_ACI_CMD_PARAMS_DTM_CMD_T_CMD_LSB 1
#define OFFSET_ACI_CMD_PARAMS_SETUP_T_SETUP_DATA 0
#define OFFSET_ACI_CMD_PARAMS_WRITE_DYNAMIC_DATA_T_SEQ_NO 0
#define OFFSET_ACI_CMD_PARAMS_WRITE_DYNAMIC_DATA_T_DYNAMIC_DATA 1
#define OFFSET_ACI_CMD_PARAMS_SET_LOCAL_DATA_T_TX_DATA 0
#define OFFSET_ACI_CMD_PARAMS_CONNECT_T_TIMEOUT_LSB 0
#define OFFSET_ACI_CMD_PARAMS_CONNECT_T_TIMEOUT_MSB 1
#define OFFSET_ACI_CMD_PARAMS_CONNECT_T_ADV_INTERVAL_LSB 2
#define OFFSET_ACI_CMD_PARAMS_CONNECT_T_ADV_INTERVAL_MSB 3
#define OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_LSB 0
#define OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_MSB 1
#define OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_LSB 2
#define OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_MSB 3
#define OFFSET_ACI_CMD_PARAMS_DISCONNECT_T_REASON 0
#define OFFSET_ACI_CMD_PARAMS_SET_TX_POWER_T_DEVICE_POWER 0
#define OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS 0
#define OFFSET_ACI_CMD_PARAMS_OPEN_REMOTE_PIPE_T_PIPE_NUMBER 0
#define OFFSET_ACI_CMD_PARAMS_SEND_DATA_T_TX_DATA 0
#define OFFSET_ACI_CMD_PARAMS_SEND_DATA_ACK_T_PIPE_NUMBER 0
#define OFFSET_ACI_CMD_PARAMS_REQUEST_DATA_T_PIPE_NUMBER 0
#define OFFSET_ACI_CMD_PARAMS_SEND_DATA_NACK_T_PIPE_NUMBER 0
#define OFFSET_ACI_CMD_PARAMS_SEND_DATA_NACK_T_ERROR_CODE 1
#define OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_MODE 0
#define OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_LATENCY_LSB 1
#define OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_LATENCY_MSB 2
#define OFFSET_ACI_CMD_PARAMS_SET_KEY_T_KEY_TYPE 0
#define OFFSET_ACI_CMD_PARAMS_SET_KEY_T_PASSKEY 1
#define OFFSET_ACI_CMD_PARAMS_SET_KEY_T_OOB_KEY 1
#define OFFSET_ACI_CMD_PARAMS_OPEN_ADV_PIPE_T_PIPES 0
#define OFFSET_ACI_CMD_PARAMS_BROADCAST_T_TIMEOUT_LSB 0
#define OFFSET_ACI_CMD_PARAMS_BROADCAST_T_TIMEOUT_MSB 1
#define OFFSET_ACI_CMD_PARAMS_BROADCAST_T_ADV_INTERVAL_LSB 2
#define OFFSET_ACI_CMD_PARAMS_BROADCAST_T_ADV_INTERVAL_MSB 3
#define OFFSET_ACI_CMD_PARAMS_CLOSE_REMOTE_PIPE_T_PIPE_NUMBER 0
#define OFFSET_ACI_CMD_T_LEN 0
#define OFFSET_ACI_CMD_T_CMD_OPCODE 1
#define OFFSET_ACI_CMD_T_TEST 2
#define OFFSET_ACI_CMD_T_ECHO 2
#define OFFSET_ACI_CMD_T_DTM_CMD 2
#define OFFSET_ACI_CMD_T_SETUP 2
#define OFFSET_ACI_CMD_T_WRITE_DYNAMIC_DATA 2
#define OFFSET_ACI_CMD_T_SET_LOCAL_DATA 2
#define OFFSET_ACI_CMD_T_CONNECT 2
#define OFFSET_ACI_CMD_T_BOND 2
#define OFFSET_ACI_CMD_T_DISCONNECT 2
#define OFFSET_ACI_CMD_T_SET_TX_POWER 2
#define OFFSET_ACI_CMD_T_CHANGE_TIMING 2
#define OFFSET_ACI_CMD_T_OPEN_REMOTE_PIPE 2
#define OFFSET_ACI_CMD_T_SEND_DATA 2
#define OFFSET_ACI_CMD_T_SEND_DATA_ACK 2
#define OFFSET_ACI_CMD_T_REQUEST_DATA 2
#define OFFSET_ACI_CMD_T_SEND_DATA_NACK 2
#define OFFSET_ACI_CMD_T_SET_APP_LATENCY 2
#define OFFSET_ACI_CMD_T_SET_KEY 2
#define OFFSET_ACI_CMD_T_OPEN_ADV_PIPE 2
#define OFFSET_ACI_CMD_T_BROADCAST 2
#define OFFSET_ACI_CMD_T_CLOSE_REMOTE_PIPE 2
#define OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_DEVICE_MODE 0
#define OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_HW_ERROR 1
#define OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_CREDIT_AVAILABLE 2
#define OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_LINE_NUM_LSB 0
#define OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_LINE_NUM_MSB 1
#define OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_FILE_NAME 2
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_DTM_CMD_T_EVT_MSB 0
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_DTM_CMD_T_EVT_LSB 1
#define OFFSET_ACI_EVT_CMD_RSP_READ_DYNAMIC_DATA_T_SEQ_NO 0
#define OFFSET_ACI_EVT_CMD_RSP_READ_DYNAMIC_DATA_T_DYNAMIC_DATA 1
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_CONFIGURATION_ID_LSB 0
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_CONFIGURATION_ID_MSB 1
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_ACI_VERSION 2
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_FORMAT 3
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_LSB0 4
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_LSB1 5
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_MSB0 6
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_MSB1 7
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_STATUS 8
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_ADDRESS_T_BD_ADDR_OWN 0
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_ADDRESS_T_BD_ADDR_TYPE 6
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_BATTERY_LEVEL_T_BATTERY_LEVEL_LSB 0
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_BATTERY_LEVEL_T_BATTERY_LEVEL_MSB 1
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_TEMPERATURE_T_TEMPERATURE_VALUE_LSB 0
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_TEMPERATURE_T_TEMPERATURE_VALUE_MSB 1
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_CMD_OPCODE 0
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_CMD_STATUS 1
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_DTM_CMD 2
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_READ_DYNAMIC_DATA 2
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION 2
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_ADDRESS 2
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_BATTERY_LEVEL 2
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_TEMPERATURE 2
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_DEV_ADDR_TYPE 0
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_DEV_ADDR 1
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_INTERVAL_LSB 7
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_INTERVAL_MSB 8
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_SLAVE_RF_LATENCY_LSB 9
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_SLAVE_RF_LATENCY_MSB 10
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_TIMEOUT_LSB 11
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_TIMEOUT_MSB 12
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_MASTER_CLOCK_ACCURACY 13
#define OFFSET_ACI_EVT_PARAMS_DISCONNECTED_T_ACI_STATUS 0
#define OFFSET_ACI_EVT_PARAMS_DISCONNECTED_T_BTLE_STATUS 1
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_STATUS_CODE 0
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_STATUS_SOURCE 1
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_SECMODE1_BITMAP 2
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_SECMODE2_BITMAP 3
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_KEYS_EXCHANGED_SLAVE 4
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_KEYS_EXCHANGED_MASTER 5
#define OFFSET_ACI_EVT_PARAMS_PIPE_STATUS_T_PIPES_OPEN_BITMAP 0
#define OFFSET_ACI_EVT_PARAMS_PIPE_STATUS_T_PIPES_CLOSED_BITMAP 8
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_INTERVAL_LSB 0
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_INTERVAL_MSB 1
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_SLAVE_RF_LATENCY_LSB 2
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_SLAVE_RF_LATENCY_MSB 3
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_TIMEOUT_LSB 4
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_TIMEOUT_MSB 5
#define OFFSET_ACI_EVT_PARAMS_DATA_CREDIT_T_CREDIT 0
#define OFFSET_ACI_EVT_PARAMS_DATA_ACK_T_PIPE_NUMBER 0
#define OFFSET_ACI_EVT_PARAMS_DATA_RECEIVED_T_RX_DATA 0
#define OFFSET_ERROR_DATA_T_CONTENT 0
#define OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_PIPE_NUMBER 0
#define OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_ERROR_CODE 1
#define OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_ERROR_DATA 2
#define OFFSET_ACI_EVT_PARAMS_DISPLAY_PASSKEY_T_PASSKEY 0
#define OFFSET_ACI_EVT_PARAMS_KEY_REQUEST_T_KEY_TYPE 0
#define OFFSET_ACI_EVT_T_LEN 0
#define OFFSET_ACI_EVT_T_EVT_OPCODE 1
#define OFFSET_ACI_EVT_T_DEVICE_STARTED 2
#define OFFSET_ACI_EVT_T_HW_ERROR 2
#define OFFSET_ACI_EVT_T_CMD_RSP 2
#define OFFSET_ACI_EVT_T_CONNECTED 2
#define OFFSET_ACI_EVT_T_DISCONNECTED 2
#define OFFSET_ACI_EVT_T_BOND_STATUS 2
#define OFFSET_ACI_EVT_T_PIPE_STATUS 2
#define OFFSET_ACI_EVT_T_TIMING 2
#define OFFSET_ACI_EVT_T_DATA_CREDIT 2
#define OFFSET_ACI_EVT_T_DATA_ACK 2
#define OFFSET_ACI_EVT_T_DATA_RECEIVED 2
#define OFFSET_ACI_EVT_T_PIPE_ERROR 2
#define OFFSET_ACI_EVT_T_DISPLAY_PASSKEY 2
#define OFFSET_ACI_EVT_T_KEY_REQUEST 2
#endif //ACI_OFFSET_H__

201
src/nrf8001/aci_queue.cpp Normal file
View File

@ -0,0 +1,201 @@
/* Copyright (c) 2014, Nordic Semiconductor ASA
*
* 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
@brief Implementation of a circular queue for ACI data
*/
#include "hal_aci_tl.h"
#include "aci_queue.h"
void aci_queue_init(aci_queue_t *aci_q)
{
uint8_t loop;
// ble_assert(NULL != aci_q);
aci_q->head = 0;
aci_q->tail = 0;
for(loop=0; loop<ACI_QUEUE_SIZE; loop++)
{
aci_q->aci_data[loop].buffer[0] = 0x00;
aci_q->aci_data[loop].buffer[1] = 0x00;
}
}
bool aci_queue_dequeue(aci_queue_t *aci_q, hal_aci_data_t *p_data)
{
// ble_assert(NULL != aci_q);
// ble_assert(NULL != p_data);
if (aci_queue_is_empty(aci_q))
{
return false;
}
memcpy((uint8_t *)p_data, (uint8_t *)&(aci_q->aci_data[aci_q->head]), sizeof(hal_aci_data_t));
aci_q->head = (aci_q->head + 1) % ACI_QUEUE_SIZE;
return true;
}
bool aci_queue_dequeue_from_isr(aci_queue_t *aci_q, hal_aci_data_t *p_data)
{
// ble_assert(NULL != aci_q);
// ble_assert(NULL != p_data);
if (aci_queue_is_empty_from_isr(aci_q))
{
return false;
}
memcpy((uint8_t *)p_data, (uint8_t *)&(aci_q->aci_data[aci_q->head]), sizeof(hal_aci_data_t));
aci_q->head = (aci_q->head + 1) % ACI_QUEUE_SIZE;
return true;
}
bool aci_queue_enqueue(aci_queue_t *aci_q, hal_aci_data_t *p_data)
{
const uint8_t length = p_data->buffer[0];
// ble_assert(NULL != aci_q);
// ble_assert(NULL != p_data);
if (aci_queue_is_full(aci_q))
{
return false;
}
aci_q->aci_data[aci_q->tail].status_byte = 0;
memcpy((uint8_t *)&(aci_q->aci_data[aci_q->tail].buffer[0]), (uint8_t *)&p_data->buffer[0], length + 1);
aci_q->tail = (aci_q->tail + 1) % ACI_QUEUE_SIZE;
return true;
}
bool aci_queue_enqueue_from_isr(aci_queue_t *aci_q, hal_aci_data_t *p_data)
{
const uint8_t length = p_data->buffer[0];
// ble_assert(NULL != aci_q);
// ble_assert(NULL != p_data);
if (aci_queue_is_full_from_isr(aci_q))
{
return false;
}
aci_q->aci_data[aci_q->tail].status_byte = 0;
memcpy((uint8_t *)&(aci_q->aci_data[aci_q->tail].buffer[0]), (uint8_t *)&p_data->buffer[0], length + 1);
aci_q->tail = (aci_q->tail + 1) % ACI_QUEUE_SIZE;
return true;
}
bool aci_queue_is_empty(aci_queue_t *aci_q)
{
bool state = false;
// ble_assert(NULL != aci_q);
//Critical section
// noInterrupts();
if (aci_q->head == aci_q->tail)
{
state = true;
}
// interrupts();
return state;
}
bool aci_queue_is_empty_from_isr(aci_queue_t *aci_q)
{
// ble_assert(NULL != aci_q);
return aci_q->head == aci_q->tail;
}
bool aci_queue_is_full(aci_queue_t *aci_q)
{
uint8_t next;
bool state;
// ble_assert(NULL != aci_q);
//This should be done in a critical section
// noInterrupts();
next = (aci_q->tail + 1) % ACI_QUEUE_SIZE;
if (next == aci_q->head)
{
state = true;
}
else
{
state = false;
}
// interrupts();
//end
return state;
}
bool aci_queue_is_full_from_isr(aci_queue_t *aci_q)
{
const uint8_t next = (aci_q->tail + 1) % ACI_QUEUE_SIZE;
// ble_assert(NULL != aci_q);
return next == aci_q->head;
}
bool aci_queue_peek(aci_queue_t *aci_q, hal_aci_data_t *p_data)
{
// ble_assert(NULL != aci_q);
// ble_assert(NULL != p_data);
if (aci_queue_is_empty(aci_q))
{
return false;
}
memcpy((uint8_t *)p_data, (uint8_t *)&(aci_q->aci_data[aci_q->head]), sizeof(hal_aci_data_t));
return true;
}
bool aci_queue_peek_from_isr(aci_queue_t *aci_q, hal_aci_data_t *p_data)
{
// ble_assert(NULL != aci_q);
// ble_assert(NULL != p_data);
if (aci_queue_is_empty_from_isr(aci_q))
{
return false;
}
memcpy((uint8_t *)p_data, (uint8_t *)&(aci_q->aci_data[aci_q->head]), sizeof(hal_aci_data_t));
return true;
}

76
src/nrf8001/aci_queue.h Normal file
View File

@ -0,0 +1,76 @@
/* Copyright (c) 2014, Nordic Semiconductor ASA
*
* 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
* @brief Interface for buffer.
*/
/** @defgroup aci_queue aci_queue
@{
@ingroup aci_queue
*/
#ifndef ACI_QUEUE_H__
#define ACI_QUEUE_H__
#include "aci.h"
#include "hal_aci_tl.h"
/*********************************************************************** */
/* The ACI_QUEUE_SIZE determines the memory usage of the system. */
/* Successfully tested to a ACI_QUEUE_SIZE of 4 (interrupt) and 4 (polling) */
/*********************************************************************** */
#define ACI_QUEUE_SIZE 4
/** Data type for queue of data packets to send/receive from radio.
*
* A FIFO queue is maintained for packets. New packets are added (enqueued)
* at the tail and taken (dequeued) from the head. The head variable is the
* index of the next packet to dequeue while the tail variable is the index of
* where the next packet should be queued.
*/
typedef struct {
hal_aci_data_t aci_data[ACI_QUEUE_SIZE];
uint8_t head;
uint8_t tail;
} aci_queue_t;
void aci_queue_init(aci_queue_t *aci_q);
bool aci_queue_dequeue(aci_queue_t *aci_q, hal_aci_data_t *p_data);
bool aci_queue_dequeue_from_isr(aci_queue_t *aci_q, hal_aci_data_t *p_data);
bool aci_queue_enqueue(aci_queue_t *aci_q, hal_aci_data_t *p_data);
bool aci_queue_enqueue_from_isr(aci_queue_t *aci_q, hal_aci_data_t *p_data);
bool aci_queue_is_empty(aci_queue_t *aci_q);
bool aci_queue_is_empty_from_isr(aci_queue_t *aci_q);
bool aci_queue_is_full(aci_queue_t *aci_q);
bool aci_queue_is_full_from_isr(aci_queue_t *aci_q);
bool aci_queue_peek(aci_queue_t *aci_q, hal_aci_data_t *p_data);
bool aci_queue_peek_from_isr(aci_queue_t *aci_q, hal_aci_data_t *p_data);
#endif /* ACI_QUEUE_H__ */
/** @} */

Some files were not shown because too many files have changed in this diff Show More