Compare commits

..

22 Commits

Author SHA1 Message Date
b291f372d7 CMakeLists.txt: up version to 0.1.4
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-17 11:44:04 +01:00
8d8485be82 CMakeLists.txt: depend on maa 0.2.9+
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-17 11:41:11 +01:00
b4f25c84a5 CMakeLists.txt: add soversion to libs in UPM
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-17 11:41:05 +01:00
4c7fa11bb2 gfx.h: fix global maa.h header location
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-17 11:34:02 +01:00
c18a9433fc gy65: Added new digital pressure sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-16 16:43:05 +00:00
8fe679494c st7735: Added text feature and documentation with license
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-16 12:32:59 +00:00
2c1baf66b5 max31855: add sensor and documentation on creation of a UPM sensor
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-13 16:45:55 +01:00
3e12ed6719 st7735: added new spi lcd module (missing bitmap and text)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-13 13:50:55 +00:00
e24df89ebd docs: Added intial documentation for UPM and start of a porting walkthrough
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-13 11:53:51 +01:00
186dd03b79 servo: removed defines from es08a and made engine move smoothly
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-12 15:26:01 +00:00
0050f92b06 lcd: rename from iiclcd to i2clcd, add swig
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-12 14:16:39 +01:00
058c40e340 servo: update to use cmake macro for servo
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-12 11:44:17 +01:00
cea5816c43 upm: new standard for modules cmake file
* Update all previously updated modules

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-12 11:39:10 +01:00
54a4afc6a7 my9221 mma7455: corrected spelling mistake
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 20:50:19 +01:00
1dd8626044 mma7455: added new accelerometer module
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-11 13:21:58 +00:00
1c138d9167 ledbar: rename to my9221
* Use new cmake macro

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 15:11:36 +01:00
3dccffe055 4digitdisplay: rename to tm1637
* Use new cmake macro

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 15:07:21 +01:00
34e343869c upm: update past modules to use new CMake macro
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 15:02:44 +01:00
d71e4e5dc2 cmake: update swig support
* Bumped required CMake Version

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 14:36:56 +01:00
7e3358b586 doc: make docs not generate by default. BUILDDOC
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 14:36:56 +01:00
ca0b0cce44 doxygen: added documentation to new public methods
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 13:39:02 +00:00
12b2ab6991 max44000: Added swig to the module and set i2c methods as public
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 13:34:27 +00:00
90 changed files with 3399 additions and 351 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.8.11)
project (upm)
find_package (SWIG)
@ -9,7 +9,7 @@ endif ()
find_package (Threads REQUIRED)
find_package (PkgConfig REQUIRED)
# force the libmaa version to be the required version
pkg_check_modules (MAA REQUIRED maa>=0.2.6)
pkg_check_modules (MAA REQUIRED maa>=0.2.9)
message (INFO " found libmaa version: ${MAA_VERSION}")
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
@ -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 libmaa!")
set (VERSION "v0.1.2-dirty")
set (VERSION "v0.1.4-dirty")
endif ()
message (INFO " - UPM Version ${VERSION}")
@ -39,22 +39,28 @@ endif()
set (upm_VERSION_MAJOR ${VERSION_MAJOR})
set (upm_VERSION_MINOR ${VERSION_MINOR})
set (upm_VERSION_PATCH ${VERSION_PATCH})
set (upm_VERSION_STRING ${maa_VERSION_MAJOR}.${maa_VERSION_MINOR}.${maa_VERSION_PATCH})
set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH})
set (CMAKE_SWIG_FLAGS "")
option (IPK "Generate IPK using CPack" OFF)
option (BUILDDOC "Build all doc." OFF)
option (BUILDSWIG "Build swig modules." ON)
option (BUILDSWIGPYTHON "Build swig python modules." ON)
option (BUILDSWIGNODE "Build swig node modules." ON)
# add a target to generate API documentation with Doxygen
find_package (Doxygen)
if (DOXYGEN_FOUND)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target (doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif (DOXYGEN_FOUND)
if (BUILDDOC)
# add a target to generate API documentation with Doxygen
find_package (Doxygen)
if (DOXYGEN_FOUND)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target (doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif (DOXYGEN_FOUND)
endif()
if (IPK)
include (TargetArch)

View File

@ -754,6 +754,7 @@ WARN_LOGFILE =
# Note: If this tag is empty the current directory is searched.
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src \
@CMAKE_CURRENT_SOURCE_DIR@/docs \
@CMAKE_CURRENT_SOURCE_DIR@/README.md
# This tag can be used to specify the character encoding of the source files
@ -863,7 +864,9 @@ EXCLUDE_SYMBOLS =
# that contain example code fragments that are included (see the \include
# command).
EXAMPLE_PATH = @CMAKE_CURRENT_SOURCE_DIR@/examples/
EXAMPLE_PATH = @CMAKE_CURRENT_SOURCE_DIR@/examples/ \
@CMAKE_CURRENT_SOURCE_DIR@/docs/ \
@CMAKE_CURRENT_SOURCE_DIR@/src/max31855/
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and

View File

@ -12,15 +12,20 @@ to provide identification/pin location on the board.
Typically an update() function will be called in order to get new data from the
sensor in order to reduce load when doing multiple reads to sensor data.
A basic sensor is expected to work as such:
s = new sensor();
print(sensor->read());
sleep(1);
s->update();
print(sensor->read();
### Example
A sensor/acturo is expected to work as such (here is the servo ES08A api):
@snippet es08a.cxx Interesting
However implementation and API design is compeltely up to the developer, some
enumerable sensors for example may provide much clever instanciation. Displays
may also create more complex structures in order to interface with them.
For more information on maa, see the maa documentation
### Building UPM
See @ref building
### Making your own UPM module
@ref porting has more information on making new UPM modules

31
docs/building.md Normal file
View File

@ -0,0 +1,31 @@
Building UPM {#building}
============
UPM uses cmake in order to make compilation relatively painless. Cmake runs
build out of tree so the recommended way is to clone from git and make a build/
directory.
UPM will attempt to build all directories inside src/ and they must contain
individual CMakeLists.txt files.
~~~~~~~~~~~~~{.sh}
mkdir build
cd build
cmake ..
make
~~~~~~~~~~~~~
Our cmake configure has a number of options, `cmake -i` will ask you all sorts
of interesting questions, you can disable swig modules, build documentation
etc...
Few recommended options:
Changing install path from /usr/local to /usr
-DCMAKE_INSTALL_PREFIX:PATH=/usr
Building debug build:
-DCMAKE_BUILD_TYPE=DEBUG
Using clang instead of gcc:
-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang

16
docs/contributions.md Normal file
View File

@ -0,0 +1,16 @@
Contributing a module {#contributions}
=====================
Here are the rules of contribution:
- Try not to break master. In any commit.
- 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
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
LICENSE file in src/<mymodule>/
- Please test your module builds before contributing and make sure it works on
the latest version of maa. If you tested on a specific board/platform please
tell us what this was in your PR.

96
docs/max31855.md Normal file
View File

@ -0,0 +1,96 @@
Making a UPM module for MAX31855 {#max31855}
================================
The Maxim Integrated MAX31855 is a thermocouple amplifier allowing you to read
from a K type themocouple. My board comes from the Pmod kit form Maxim
(MAX31855PMB1) but you can get this from many different sources. The adafruit
people made arduino code already so we'll use that as a
[reference](https://github.com/adafruit/Adafruit-MAX31855-library/blob/master/Adafruit_MAX31855.cpp).
### Basics
This is a spi module so we will use the maa spi functions to build our module.
First thing to do is to create a tree structure like this in upm/src/max31855:
* max31855.cxx
* max31855.h
* jsupm_max31855.i
* pyupm_max31855.i
* CMakeLists.txt
And then an example file to use & test our lib with in upm/examples/max31855.cxx.
### Swig
The .i files are used by swig, there is one for each python & javascript. They
contain essentially the same thing and are very simple. The only thing to
change between the javascript & node.js one is the argument to %module.
@snippet jsupm_max31855.i Interesting
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.
### API
Then we create the header (max31855.h) , a very simple header in our case we
will have only a very basic api. We provide a getTemp() function which will
return the same type as in the arduino library, a double.
@snippet max31855.h Interesting
Note that the header contains both the io that we will use, the gpio is in this
case used as the chip select pin.
### Implementing our API
In the adafruit library the read function (our chip is a 3pin SPI so only read
is possible), the spiread32() does all the work. It starts by setting up the io
so we will do the same in our constructor.
Note unlike on Arduino, we'll just set a 2Mhz clock and let the chip do the
work.
@snippet src/max31855/max31855.cxx Constructor
Then we also need to implement a nice cleanup in our destructor.
@snippet src/max31855/max31855.cxx Destructor
Then to read data, we will use spi_write_buf which will allow us to write a
whole uint32_t in order to get one back, which is what the arduino code does in
spiread32. Obviously we set our chip select to low first. Here is the start of
the implementation of MAX31855::getTemp()
@snippet src/max31855/max31855.cxx spi
Then using the arduino code as reference we simply reconstruct form the 4
uint8_t values a 32bit int value and select only the valuable parts of
information from that. The MAX31855 datahseet explains exactly which bits are
useful, we will just do the same as the adafruit code, first checking the error
bit and then scrapping everything but the 14bit of thermocouple data that are
useful to us and converting it to a double.
@snippet src/max31855/max31855.cxx conversion
### Finalizing
Our final example, very easy to use api!
@snippet examples/max31855.cxx Interesting
### Building
The we need to add it to the examples/CMakeLists.txt. Only three lines are required
~~~~~~~~~~~
add_executable (max31855-example max31855.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/max31855)
target_link_libraries (max31855-example max31855 ${CMAKE_THREAD_LIBS_INIT})
~~~~~~~~~~~
Note you dont have to rebuild everything, cmake keeps target lists so if you
named your example target <modulename>-example you can simply do make
max31855-example and both the library & example will build.

24
docs/naming.md Normal file
View File

@ -0,0 +1,24 @@
Naming a module {#naming}
===============
UPM attemps to follow a clear naming pattern. Modules should be sensibly named
and then placed in /usr/lib/upm and headers in /usr/include/upm.
### Choosing a name
1. Pick a name
2. Use it
### Rules for name picking
1. Your lib must belong to namespace UPM
2. Usually picking the name of the chip of your sensor/actuator might make
sense. Other times this does not. Try to pick a generic name so people with a
similar sensor can inherit your class if they only have minor changes.
3. Avoid brand names
### Doubt
If ever, give me a ping via email: brendan.le.foll@intel.com and I'll try
suggest decent names for your module.

65
docs/porting.md Normal file
View File

@ -0,0 +1,65 @@
Porting a module from Arduino {#porting}
=============================
Porting arduino libraries to libmaa as UPM libraries is usually fairly easy.
The issues typically come from misunderstanding of how a non real time OS deals
with interupts and timers. It also highly depends on the sensor. A concrete
example is explained in detail on @ref max31855
### Adding a new module to UPM
1. Choose a name for your module (see @ref naming)
2. Make a new folder in src/<modulename>
3. Create a CMakeLists.txt file inside src/<modulename>
### CmakeLists.txt
By default you need a header called <modulename>.h and a C++ file called
<modulename>.cxx. You can have multiple headers and source files. Only public
headers need to be added to module_h and all source files need to be in
module_src.
~~~~~~~~~~~
set (libname "modulename")
set (libdescription "Module Description")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()
~~~~~~~~~~~
### Making your API
The easiest way to do this is to have a look at a similar sensor to yours.
Typically create a class for your sensor with a constructor that defines the
pins it is on. This constructor will create the maa_*_context structs that are
required to talk to the board's IO. An I2c sensor will create a
maa_i2c_context, keep it as a private member and require a bus number and slave
address in it's constructor.
Typically in sensors a simple object->read() function is prefered, depending on
your sensor/actuaotr this may or may not be easy or not even make sense. Most
UPM apis have a simple set of functions.
### Mapping arduino API to libmaa
Your constructor is similar to the setup() function in arduino, you should
initialise your IO the way you want it. This means initialising contexts
(private members) and setting the correct modes for them.
See the maa API documentation for exact API.
### Building
To build your module just follow @ref building. By creating a folder and the
CMakelists.txt file you have done all that is required to add your sensor to
the UPM build system.
### Sending your module to us for inclusion in UPM
The last step is when you're happy with your module and it works send us a pull
request! We'd love to include your sensor in our repository.
If you don't like github you can also send brendan.le.foll@intel.com a git
formatted patch if your sensor. More details are on @ref contributing and on
https://help.github.com/articles/creating-a-pull-request

View File

@ -13,17 +13,25 @@ add_executable (son-hcsr04 hcsr04.cxx)
add_executable (oled-1308 oled-1308.cxx)
add_executable (oled-1327 oled-1327.cxx)
add_executable (proximity max44000.cxx)
add_executable (accelerometer mma7455.cxx)
add_executable (lcd st7735.cxx)
add_executable (max31855-example max31855.cxx)
add_executable (gy65-example gy65.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
include_directories (${PROJECT_SOURCE_DIR}/src/ledbar)
include_directories (${PROJECT_SOURCE_DIR}/src/4digitdisplay)
include_directories (${PROJECT_SOURCE_DIR}/src/my9221)
include_directories (${PROJECT_SOURCE_DIR}/src/tm1637)
include_directories (${PROJECT_SOURCE_DIR}/src/nrf24l01)
include_directories (${PROJECT_SOURCE_DIR}/src/servo)
include_directories (${PROJECT_SOURCE_DIR}/src/hcsr04)
include_directories (${PROJECT_SOURCE_DIR}/src/max44000)
include_directories (${PROJECT_SOURCE_DIR}/src/mma7455)
include_directories (${PROJECT_SOURCE_DIR}/src/st7735)
include_directories (${PROJECT_SOURCE_DIR}/src/max31855)
include_directories (${PROJECT_SOURCE_DIR}/src/gy65)
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
@ -31,8 +39,8 @@ target_link_libraries (grovetemp grove ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lcm-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (rgb-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (buzzer-sound buzzer ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (led-bar ledbar ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (seg-lcd 4digitdisplay ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (led-bar my9221 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (seg-lcd tm1637 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf_transmitter nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf_receiver nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (es08a servo ${CMAKE_THREAD_LIBS_INIT})
@ -40,3 +48,7 @@ target_link_libraries (son-hcsr04 hcsr04 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (oled-1308 i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (oled-1327 i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (proximity max44000 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (accelerometer mma7455 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lcd st7735 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (max31855-example max31855 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (gy65-example gy65 ${CMAKE_THREAD_LIBS_INIT})

View File

@ -28,40 +28,19 @@
#include <signal.h>
#include <stdlib.h>
int running = 0;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
int
main(int argc, char **argv)
{
//! [Interesting]
upm::ES08A *servo = new upm::ES08A(5);
signal(SIGINT, sig_handler);
int clock = 0;
while (!running) {
for (int i = 0; i < 18; i++) {
servo->setAngle (clock);
clock += 10;
}
for (int i = 0; i < 18; i++) {
servo->setAngle (clock);
clock -= 10;
}
}
upm::ES08A *servo = new upm::ES08A(5);
servo->setAngle (180);
//! [Interesting]
servo->setAngle (90);
servo->setAngle (0);
servo->setAngle (90);
servo->setAngle (180);
std::cout << "exiting application" << std::endl;
delete servo;

77
examples/gy65.cxx Normal file
View File

@ -0,0 +1,77 @@
/*
* 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 "gy65.h"
#include <signal.h>
int doWork = 0;
upm::GY65 *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]
uint32_t presure = 0;
float temperature = 0;
float altitude = 0;
uint32_t sealevel = 0;
sensor = new upm::GY65(0, ADDR);
while (!doWork) {
presure = sensor->getPressure ();
temperature = sensor->getTemperature ();
altitude = sensor->getAltitude ();
sealevel = sensor->getSealevelPressure ();
std::cout << "pressure value = " <<
presure <<
", atitude value = " <<
altitude <<
", sealevel value = " <<
sealevel <<
", temperature = " <<
temperature << std::endl;
usleep (100000);
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

41
examples/max31855.cxx Normal file
View File

@ -0,0 +1,41 @@
/*
* 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 <signal.h>
//! [Interesting]
#include "max31855.h"
int
main(int argc, char **argv)
{
upm::MAX31855 *temp = new upm::MAX31855(0, 8);
std::cout << temp->getTemp() << std::endl;
return 0;
}
//! [Interesting]

64
examples/mma7455.cxx Normal file
View File

@ -0,0 +1,64 @@
/*
* 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 "mma7455.h"
#include <signal.h>
#include <pthread.h>
int doWork = 0;
upm::MMA7455 *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::MMA7455(0, ADDR);
short x, y, z;
while (!doWork) {
sensor->readData(&x, &y, &z);
std::cout << "Accelerometer X(" << x << ") Y(" << y << ") Z(" << z << ")" << std::endl;
usleep (100000);
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

79
examples/st7735.cxx Normal file
View File

@ -0,0 +1,79 @@
/*
* 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 <string.h>
#include <unistd.h>
#include <iostream>
#include "st7735.h"
#include <signal.h>
int
main(int argc, char **argv)
{
//! [Interesting]
upm::ST7735 * lcd = new upm::ST7735(7, 4, 9, 8);
lcd->fillScreen (ST7735_RED);
lcd->refresh ();
lcd->fillScreen (ST7735_CYAN);
lcd->refresh ();
lcd->fillScreen (ST7735_BLACK);
lcd->refresh ();
lcd->drawLine(10, 10, 10, 100, ST7735_MAGENTA);
lcd->drawLine(20, 20, 10, 100, ST7735_YELLOW);
lcd->drawLine(30, 30, 50, 100, ST7735_WHITE);
lcd->refresh ();
lcd->drawPixel (20, 20, ST7735_GREEN);
lcd->refresh ();
lcd->drawTriangle (50, 50, 80, 80, 60, 90, ST7735_GREEN);
lcd->refresh ();
lcd->drawCircle (100, 110, 10, ST7735_BLUE);
lcd->refresh ();
lcd->setTextWrap(0x0);
lcd->setCursor(0, 30);
lcd->setTextColor(ST7735_RED, ST7735_RED);
lcd->setTextSize(1);
lcd->print("Hello World!");
lcd->setCursor(10, 50);
lcd->setTextColor(ST7735_RED, ST7735_YELLOW);
lcd->setTextSize(2);
lcd->print("BIG");
lcd->refresh ();
std::cout << "exiting application" << std::endl;
delete lcd;
//! [Interesting]
return 0;
}

View File

@ -1,12 +0,0 @@
set (libname "4digitdisplay")
add_library (4digitdisplay SHARED tm1637.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (4digitdisplay ${MAA_LIBRARIES})
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES tm1637.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm 4 Digit Buzzer")
endif()

View File

@ -8,6 +8,116 @@ macro(subdirlist result curdir)
endforeach()
set(${result} ${dirlist})
endmacro()
macro (upm_CREATE_INSTALL_PKGCONFIG generated_file install_location)
configure_file (${PROJECT_SOURCE_DIR}/src/pkgconfig.in
${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
endmacro (upm_CREATE_INSTALL_PKGCONFIG)
macro(upm_SWIG_PYTHON)
if(BUILDSWIGPYTHON)
set (CMAKE_C_FLAGS -DSWIGPYTHON=${SWIG_FOUND})
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} ${MAA_LIBRARIES})
target_include_directories ( ${SWIG_MODULE_pyupm_${libname}_REAL_NAME}
PUBLIC
"${PYTHON_INCLUDE_PATH}"
"${PYTHON_INCLUDE_DIRS}"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_pyupm_${libname}.so
${CMAKE_CURRENT_BINARY_DIR}/pyupm_${libname}.py
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/
COMPONENT ${libname})
endif()
endmacro()
macro(upm_SWIG_NODE)
if(BUILDSWIGNODE)
set (CMAKE_CXX_FLAGS -DBUILDING_NODE_EXTENSION)
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})
swig_link_libraries (jsupm_${libname} ${MAA_LIBRARIES} ${NODE_LIBRARIES})
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
PUBLIC
"${NODE_INCLUDE_DIRS}"
)
set_target_properties (jsupm_${libname} PROPERTIES
PREFIX ""
SUFFIX ".node"
)
createpackagejson(${libname})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
endif()
endmacro()
macro(upm_doxygen)
if (DOXYGEN_FOUND)
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
)
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)
endif ()
endmacro()
if (SWIG_FOUND)
if(BUILDSWIGPYTHON)
find_package (PythonLibs)
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
endif(BUILDSWIGPYTHON)
if(BUILDSWIGNODE)
find_path (NODE_ROOT_DIR "node/node.h")
set (NODE_INCLUDE_DIRS
${NODE_ROOT_DIR}/src
${NODE_ROOT_DIR}/node
${NODE_ROOT_DIR}/deps/v8/include
${NODE_ROOT_DIR}/deps/uv/include
)
macro(createpackagejson)
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
endmacro()
endif(BUILDSWIGNODE)
endif()
macro(upm_module_init)
add_library (${libname} SHARED ${module_src})
include_directories (${MAA_INCLUDE_DIR} .)
target_link_libraries (${libname} ${MAA_LIBRARIES})
set_target_properties(
${libname}
PROPERTIES PREFIX "libupm-"
SOVERSION ${upm_VERSION_MAJOR}
VERSION ${upm_VERSION_STRING}
)
upm_create_install_pkgconfig (upm-${libname}.pc lib${LIB_SUFFIX}/pkgconfig)
if (SWIG_FOUND)
upm_swig_python()
upm_swig_node()
upm_doxygen()
endif()
install (TARGETS ${libname} DESTINATION lib COMPONENT ${libname})
install (FILES ${module_h} DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "${libdescription}")
endif()
endmacro(upm_module_init)
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
foreach(subdir ${SUBDIRS})
add_subdirectory(${subdir})

View File

@ -1,12 +1,5 @@
set (libname "buzzer")
add_library (buzzer SHARED buzzer.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (buzzer ${MAA_LIBRARIES})
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES buzzer.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm buzzer")
endif()
set (libdescription "upm buzzer")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -1,47 +1,5 @@
set (libname "grove")
add_library (grove SHARED grove.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (grove ${MAA_LIBRARIES})
if (SWIG_FOUND)
find_package (PythonLibs)
include_directories (
${PYTHON_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
${MAA_INCLUDE_DIR}
.
)
set_source_files_properties (pyupm_grove.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_grove.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_grove.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (pyupm_grove python pyupm_grove.i grove.cxx)
# swig_add_module (jsupm_grove javascript jsupm_grove.i grove.cxx)
swig_link_libraries (pyupm_grove ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
# swig_link_libraries (jsupm_grove ${MAA_LIBRARIES})
if (DOXYGEN_FOUND)
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
)
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_grove_REAL_NAME} ${libname}doc_i)
endif ()
endif ()
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES grove.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm grove libary")
endif()
set (libdescription "upm grove module")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

5
src/gy65/CMakeLists.txt Normal file
View File

@ -0,0 +1,5 @@
set (libname "gy65")
set (libdescription "upm GY65")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

222
src/gy65/gy65.cxx Normal file
View File

@ -0,0 +1,222 @@
/*
* 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 "gy65.h"
using namespace upm;
GY65::GY65 (int bus, int devAddr, uint8_t mode) {
m_name = "GY65";
m_controlAddr = devAddr;
m_bus = bus;
m_i2ControlCtx = maa_i2c_init(m_bus);
maa_result_t ret = maa_i2c_address(m_i2ControlCtx, m_controlAddr);
if (ret != MAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
if (i2cReadReg_8 (0xD0) != 0x55) {
std::cout << "Error :: Cannot continue" << std::endl;
return;
}
if (mode > BMP085_ULTRAHIGHRES) {
mode = BMP085_ULTRAHIGHRES;
}
oversampling = mode;
/* read calibration data */
ac1 = i2cReadReg_16 (BMP085_CAL_AC1);
ac2 = i2cReadReg_16 (BMP085_CAL_AC2);
ac3 = i2cReadReg_16 (BMP085_CAL_AC3);
ac4 = i2cReadReg_16 (BMP085_CAL_AC4);
ac5 = i2cReadReg_16 (BMP085_CAL_AC5);
ac6 = i2cReadReg_16 (BMP085_CAL_AC6);
b1 = i2cReadReg_16 (BMP085_CAL_B1);
b2 = i2cReadReg_16 (BMP085_CAL_B2);
mb = i2cReadReg_16 (BMP085_CAL_MB);
mc = i2cReadReg_16 (BMP085_CAL_MC);
md = i2cReadReg_16 (BMP085_CAL_MD);
}
GY65::~GY65() {
maa_i2c_stop(m_i2ControlCtx);
}
int32_t
GY65::getPressure () {
int32_t UT, UP, B3, B5, B6, X1, X2, X3, p;
uint32_t B4, B7;
UT = getTemperatureRaw();
UP = getPressureRaw();
B5 = computeB5(UT);
// do pressure calcs
B6 = B5 - 4000;
X1 = ((int32_t)b2 * ( (B6 * B6)>>12 )) >> 11;
X2 = ((int32_t)ac2 * B6) >> 11;
X3 = X1 + X2;
B3 = ((((int32_t)ac1*4 + X3) << oversampling) + 2) / 4;
X1 = ((int32_t)ac3 * B6) >> 13;
X2 = ((int32_t)b1 * ((B6 * B6) >> 12)) >> 16;
X3 = ((X1 + X2) + 2) >> 2;
B4 = ((uint32_t)ac4 * (uint32_t)(X3 + 32768)) >> 15;
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
if (B7 < 0x80000000) {
p = (B7 * 2) / B4;
} else {
p = (B7 / B4) * 2;
}
X1 = (p >> 8) * (p >> 8);
X1 = (X1 * 3038) >> 16;
X2 = (-7357 * p) >> 16;
p = p + ((X1 + X2 + (int32_t)3791)>>4);
return p;
}
int32_t
GY65::getPressureRaw () {
uint32_t raw;
i2cWriteReg (BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6));
if (oversampling == BMP085_ULTRALOWPOWER) {
usleep(5000);
} else if (oversampling == BMP085_STANDARD) {
usleep(8000);
} else if (oversampling == BMP085_HIGHRES) {
usleep(14000);
} else {
usleep(26000);
}
raw = i2cReadReg_16 (BMP085_PRESSUREDATA);
raw <<= 8;
raw |= i2cReadReg_8 (BMP085_PRESSUREDATA + 2);
raw >>= (8 - oversampling);
return raw;
}
int16_t
GY65::getTemperatureRaw () {
i2cWriteReg (BMP085_CONTROL, BMP085_READTEMPCMD);
usleep(5000);
return i2cReadReg_16 (BMP085_TEMPDATA);
}
float
GY65::getTemperature () {
int32_t UT, B5; // following ds convention
float temp;
UT = getTemperatureRaw ();
B5 = computeB5 (UT);
temp = (B5 + 8) >> 4;
temp /= 10;
return temp;
}
int32_t
GY65::getSealevelPressure(float altitudeMeters) {
float pressure = getPressure ();
return (int32_t)(pressure / pow(1.0-altitudeMeters/44330, 5.255));
}
float
GY65::getAltitude (float sealevelPressure) {
float altitude;
float pressure = getPressure ();
altitude = 44330 * (1.0 - pow(pressure /sealevelPressure,0.1903));
return altitude;
}
int32_t
GY65::computeB5(int32_t UT) {
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
int32_t X2 = ((int32_t)mc << 11) / (X1+(int32_t)md);
return X1 + X2;
}
maa_result_t
GY65::i2cWriteReg (uint8_t reg, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { reg, value };
error = maa_i2c_address (m_i2ControlCtx, m_controlAddr);
error = maa_i2c_write (m_i2ControlCtx, data, 2);
return error;
}
uint16_t
GY65::i2cReadReg_16 (int reg) {
uint16_t data;
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
maa_i2c_write_byte(m_i2ControlCtx, reg);
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
maa_i2c_read(m_i2ControlCtx, (uint8_t *)&data, 0x2);
uint8_t high = (data & 0xFF00) >> 8;
data = (data << 8) & 0xFF00;
data |= high;
return data;
}
uint8_t
GY65::i2cReadReg_8 (int reg) {
uint8_t data;
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
maa_i2c_write_byte(m_i2ControlCtx, reg);
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
maa_i2c_read(m_i2ControlCtx, &data, 0x1);
return data;
}

161
src/gy65/gy65.h Normal file
View File

@ -0,0 +1,161 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Credits to Adafruit.
* Based on Adafruit BMP085 library.
*
* 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 <maa/i2c.h>
#include <math.h>
#define ADDR 0x77 // device address
// registers address
#define BMP085_ULTRALOWPOWER 0
#define BMP085_STANDARD 1
#define BMP085_HIGHRES 2
#define BMP085_ULTRAHIGHRES 3
#define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits)
#define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits)
#define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits)
#define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits)
#define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits)
#define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits)
#define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits)
#define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits)
#define BMP085_CAL_MB 0xBA // R Calibration data (16 bits)
#define BMP085_CAL_MC 0xBC // R Calibration data (16 bits)
#define BMP085_CAL_MD 0xBE // R Calibration data (16 bits)
#define BMP085_CONTROL 0xF4
#define BMP085_TEMPDATA 0xF6
#define BMP085_PRESSUREDATA 0xF6
#define BMP085_READTEMPCMD 0x2E
#define BMP085_READPRESSURECMD 0x34
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for GY65 chip (Atmospheric Pressure Sensor)
*
* This file defines the gy65 C++ interface for libgy65
*
* @snippet gy65.cxx Interesting
*/
class GY65 {
public:
/**
* Instanciates a GY65 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
GY65 (int bus, int devAddr, uint8_t mode = BMP085_ULTRAHIGHRES);
/**
* GY65 object destructor, basicaly it close i2c connection.
*/
~GY65 ();
/**
* Return calculated pressure
*/
int32_t getPressure ();
/**
*
* Get raw pressure data
*/
int32_t getPressureRaw ();
/**
* Get raw temperature data from chip
*/
int16_t getTemperatureRaw ();
/**
* Return calculated temperature
*/
float getTemperature ();
/**
* With given absolute altitude sea level can be calculated
*
* @param altitudeMeters altitude
*/
int32_t getSealevelPressure(float altitudeMeters = 0);
/**
* With given sea level altitude in meters can be calculated
*
* @param sealevelPressure Sea level
*/
float getAltitude (float sealevelPressure = 101325);
/**
* Calculation of B5 (check spec for more information)
*
* @param UT
*/
int32_t computeB5 (int32_t UT);
/**
* Read two bytes register
*
* @param reg address of a register
*/
uint16_t i2cReadReg_16 (int reg);
/**
* Write to one byte register
*
* @param reg address of a register
* @param value byte to be written
*/
maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
/**
* Read one byte register
*
* @param reg address of a register
*/
uint8_t i2cReadReg_8 (int reg);
private:
std::string m_name;
int m_controlAddr;
int m_bus;
maa_i2c_context m_i2ControlCtx;
uint8_t oversampling;
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
uint16_t ac4, ac5, ac6;
};
}

7
src/gy65/jsupm_gy65.i Normal file
View File

@ -0,0 +1,7 @@
%module jsupm_gy65
%{
#include "gy65.h"
%}
%include "gy65.h"

10
src/gy65/pyupm_gy65.i Normal file
View File

@ -0,0 +1,10 @@
%module pyupm_gy65
%include "stdint.i"
%feature("autodoc", "3");
%include "gy65.h"
%{
#include "gy65.h"
%}

View File

@ -1,12 +1,5 @@
set (libname "hcsr04")
add_library (hcsr04 SHARED hcsr04.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (hcsr04 ${MAA_LIBRARIES})
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES hcsr04.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm proximity sensor")
endif()
set (libdescription "upm proximity sensor")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -1,47 +1,5 @@
set (libname "hmc5883l")
add_library (hmc5883l SHARED hmc5883l.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (hmc5883l ${MAA_LIBRARIES})
if (SWIG_FOUND)
find_package (PythonLibs)
include_directories (
${PYTHON_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
${MAA_INCLUDE_DIR}
.
)
set_source_files_properties (pyupm_hmc5883l.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_hmc5883l.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_hmc5883l.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (pyupm_hmc5883l python pyupm_hmc5883l.i hmc5883l.cxx)
# swig_add_module (jsupm_hmc5883l javascript jsupm_hmc5883l.i hmc5883l.cxx)
swig_link_libraries (pyupm_hmc5883l ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
# swig_link_libraries (jsupm_hmc5883l ${MAA_LIBRARIES})
if (DOXYGEN_FOUND)
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
)
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_hmc5883l_REAL_NAME} ${libname}doc_i)
endif ()
endif ()
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES hmc5883l.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm Digital Compass")
endif()
set (libdescription "libupm Digital Compass")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -1,12 +1,5 @@
set (libname "i2clcd")
add_library (i2clcd SHARED iiclcd.cxx lcm1602.cxx jhd1313m1.cxx ssd1308.cxx ssd1327.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (i2clcd ${MAA_LIBRARIES})
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES iiclcd.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm lcd")
endif()
set (libdescription "upm lcd/oled displays")
set (module_src i2clcd.cxx lcm1602.cxx jhd1313m1.cxx ssd1308.cxx ssd1327.cxx)
set (module_h i2clcd.h lcm1602.h jhd1313m1.h ssd1308.h ssd1327.h)
upm_module_init()

View File

@ -25,11 +25,11 @@
#include <iostream>
#include <unistd.h>
#include "iiclcd.h"
#include "i2clcd.h"
using namespace upm;
IICLcd::IICLcd (int bus, int lcdAddress) {
I2CLcd::I2CLcd (int bus, int lcdAddress) {
m_lcd_control_address = lcdAddress;
m_bus = bus;
@ -42,18 +42,18 @@ IICLcd::IICLcd (int bus, int lcdAddress) {
}
maa_result_t
IICLcd::write (int row, int column, std::string msg) {
I2CLcd::write (int row, int column, std::string msg) {
setCursor (row, column);
write (msg);
}
maa_result_t
IICLcd::close() {
I2CLcd::close() {
return maa_i2c_stop(m_i2c_lcd_control);
}
maa_result_t
IICLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
I2CLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { addr, value };
@ -64,7 +64,7 @@ IICLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value)
}
maa_result_t
IICLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) {
I2CLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { LCD_CMD, value };
@ -75,7 +75,7 @@ IICLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) {
}
maa_result_t
IICLcd::i2cData (maa_i2c_context ctx, uint8_t value) {
I2CLcd::i2cData (maa_i2c_context ctx, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { LCD_DATA, value };

View File

@ -67,9 +67,9 @@ namespace upm {
#define LCD_RW 0x02 // Read/Write bit
#define LCD_RS 0x01 // Register select bit
class IICLcd {
class I2CLcd {
public:
IICLcd (int bus, int lcdAddress);
I2CLcd (int bus, int lcdAddress);
maa_result_t write (int x, int y, std::string msg);
virtual maa_result_t write (std::string msg) = 0;

View File

@ -29,7 +29,7 @@
using namespace upm;
Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : IICLcd(bus, lcdAddress) {
Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdAddress) {
maa_result_t error = MAA_SUCCESS;
m_rgb_address = rgbAddress;

View File

@ -24,11 +24,11 @@
#pragma once
#include <string>
#include "iiclcd.h"
#include "i2clcd.h"
namespace upm {
class Jhd1313m1 : public IICLcd {
class Jhd1313m1 : public I2CLcd {
public:
Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
~Jhd1313m1 ();

21
src/lcd/jsupm_i2clcd.i Normal file
View File

@ -0,0 +1,21 @@
%module jsupm_i2clcd
%include "i2clcd.h"
%{
#include "i2clcd.h"
%}
%include "jhd1313m1.h"
%{
#include "jhd1313m1.h"
%}
%include "lcm1602.h"
%{
#include "lcm1602.h"
%}
%include "ssd1327.h"
%{
#include "ssd1327.h"
%}

View File

@ -1,7 +0,0 @@
%module jsupm_jhd1313m1
%{
#include "jhd1313m1.h"
%}
%include "jhd1313m1.h"

View File

@ -1,7 +0,0 @@
%module jsupm_lcm1602
%{
#include "lcm1602.h"
%}
%include "lcm1602.h"

View File

@ -1,7 +0,0 @@
%module jsupm_ssd1308
%{
#include "ssd1308.h"
%}
%include "ssd1308.h"

View File

@ -1,7 +0,0 @@
%module jsupm_ssd1327
%{
#include "ssd1327.h"
%}
%include "ssd1327.h"

View File

@ -32,7 +32,7 @@
using namespace upm;
Lcm1602::Lcm1602(int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
maa_result_t error = MAA_SUCCESS;
usleep(50000);

View File

@ -28,11 +28,11 @@
#pragma once
#include <string>
#include "iiclcd.h"
#include "i2clcd.h"
namespace upm {
class Lcm1602 : public IICLcd {
class Lcm1602 : public I2CLcd {
public:
/** LCM1602 Constructor.
* Calls MAA initialisation functions.

23
src/lcd/pyupm_i2clcd.i Normal file
View File

@ -0,0 +1,23 @@
%module pyupm_i2clcd
%feature("autodoc", "3");
%include "i2clcd.h"
%{
#include "i2clcd.h"
%}
%include "jhd1313m1.h"
%{
#include "jhd1313m1.h"
%}
%include "lcm1602.h"
%{
#include "lcm1602.h"
%}
%include "ssd1327.h"
%{
#include "ssd1327.h"
%}

View File

@ -1,8 +0,0 @@
%module pyupm_jhd1313m1
%feature("autodoc", "3");
%include "jhd1313m1.h"
%{
#include "jhd1313m1.h"
%}

View File

@ -1,12 +0,0 @@
%module pyupm_lcm1602
%feature("autodoc", "3");
#ifdef DOXYGEN
%include "lcm1602_doc.i"
#endif
%include "lcm1602.h"
%{
#include "lcm1602.h"
%}

View File

@ -1,8 +0,0 @@
%module pyupm_ssd1308
%feature("autodoc", "3");
%include "ssd1308.h"
%{
#include "ssd1308.h"
%}

View File

@ -1,8 +0,0 @@
%module pyupm_ssd1327
%feature("autodoc", "3");
%include "ssd1327.h"
%{
#include "ssd1327.h"
%}

View File

@ -29,7 +29,7 @@
using namespace upm;
SSD1308::SSD1308 (int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
SSD1308::SSD1308 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
printf ("NO_GDB :: DISPLAY_CMD_OFF \n");
usleep (4500);

View File

@ -25,7 +25,7 @@
#pragma once
#include <string>
#include "iiclcd.h"
#include "i2clcd.h"
namespace upm {
@ -145,7 +145,7 @@ typedef enum {
PAGE = 2
} displayAddressingMode;
class SSD1308 : public IICLcd {
class SSD1308 : public I2CLcd {
public:
/** SSD1308 Constructor.
* Calls MAA initialisation functions.

View File

@ -32,7 +32,7 @@ using namespace upm;
#define INIT_SLEEP 50000
#define CMD_SLEEP 10000
SSD1327::SSD1327 (int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
SSD1327::SSD1327 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
maa_result_t error = MAA_SUCCESS;
usleep (INIT_SLEEP);
i2Cmd (m_i2c_lcd_control, 0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands

View File

@ -25,7 +25,7 @@
#pragma once
#include <string>
#include "iiclcd.h"
#include "i2clcd.h"
namespace upm {
/*
@ -145,7 +145,7 @@ typedef enum {
PAGE = 2
} displayAddressingMode;
class SSD1327 : public IICLcd {
class SSD1327 : public I2CLcd {
public:
/** SSD1308 Constructor.
* Calls MAA initialisation functions.

View File

@ -1,13 +0,0 @@
set (libname "ledbar")
add_library (ledbar SHARED my9221.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (ledbar ${MAA_LIBRARIES})
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES my9221.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm LEDBAR")
endif()

View File

@ -0,0 +1,5 @@
set (libname "max31855")
set (libdescription "K type thermistor amplifier")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,9 @@
//! [Interesting]
%module jsupm_max31855
%{
#include "max31855.h"
%}
%include "max31855.h"
//! [Interesting]

103
src/max31855/max31855.cxx Normal file
View File

@ -0,0 +1,103 @@
/*
* 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 <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <functional>
#include <string.h>
#include "max31855.h"
using namespace upm;
//! [Constructor]
MAX31855::MAX31855(int bus, int cs)
{
// initialise chip select as a normal gpio
m_gpio = maa_gpio_init(cs);
maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
// initialise the spi bus with a 2Mhz clock
m_sensor = maa_spi_init(bus);
maa_spi_frequency(m_sensor, 2000000);
}
//! [Constructor]
//! [Destructor]
MAX31855::~MAX31855()
{
// close both m_sensor & m_gpio cleanly
maa_result_t error;
error = maa_spi_stop(m_sensor);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close(m_gpio);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
//! [Destructor]
double
MAX31855::getTemp()
{
//! [spi]
// set chip select low
maa_gpio_write(m_gpio, 0);
uint8_t buf[4];
// set our input buffer to 0, this is clean but not required
memset(buf, 0, sizeof(uint8_t)*4);
// Write buffer to the spi slave
uint8_t* x = maa_spi_write_buf(m_sensor, buf, 4);
//! [spi]
//! [conversion]
// Endian correct way of making our char array into an 32bit int
int32_t temp = (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3];;
// maa_spi_write_buf does not free the return buffer
free(x);
if (temp & 0x7) {
std::cerr << "Something went very wrong!" << std::endl;
}
// scrap all the data we dont care about
temp >>= 18;
// LSB = 0.25 degrees C
double c = (double) temp;
c *= 0.25;
//! [conversion]
// set chip select high
maa_gpio_write(m_gpio, 1);
return c;
}

69
src/max31855/max31855.h Normal file
View File

@ -0,0 +1,69 @@
/*
* 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.
*/
#pragma once
#include <string>
#include <maa/spi.h>
#include <maa/gpio.h>
namespace upm {
/**
* @brief C++ API for MAX31855
*
* This file defines the max31855 SPI sensor
*
* @snippet examples/max31855.cxx Interesting
*
*/
//! [Interesting]
class MAX31855 {
public:
/**
* Instanciates a MAX31855 object
*
* @param bus The spi bus to use
* @param cs The chip select pin
*/
MAX31855(int bus, int cs);
/**
* MAX31855 object destructor
*/
~MAX31855();
/**
* Get the distance from the sensor
*
* @return value in degrees celcius
*/
double getTemp();
private:
maa_spi_context m_sensor;
maa_gpio_context m_gpio;
};
//! [Interesting]
}

View File

@ -0,0 +1,10 @@
%module pyupm_max31855
%include "stdint.i"
%feature("autodoc", "3");
%include "max31855.h"
%{
#include "max31855.h"
%}

View File

@ -1,12 +1,5 @@
set (libname "max44000")
add_library (max44000 SHARED max44000.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (max44000 ${MAA_LIBRARIES})
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES max44000.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm MAX44000")
endif()
set (libdescription "upm MAX44000")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -43,8 +43,8 @@ MAX44000::MAX44000 (int bus, int devAddr) {
fprintf(stderr, "Messed up i2c bus\n");
}
i2cWriteReg (MCR, 0x2C);
i2cWriteReg (TCR, 0x6);
// i2cWriteReg (MCR, 0x2C);
// i2cWriteReg (TCR, 0x6);
}
MAX44000::~MAX44000() {

View File

@ -29,12 +29,23 @@
#define ADDR 0x4A // device address
// registers address
#define ALSDATA_HIGH 0x04 // ambient sensor data high byte
#define ALSDATA_LOW 0x05 // ambient sensor data low byte
#define PRXDATA 0x15 // proximity sensor data
#define ISR 0x00 // Interrupt Status Register
#define MCR 0x01 // Main Configuration Register
#define RCR 0x02 // Receive Configuration Register
#define TCR 0x03 // Transmit Configuration Register
#define ALSDATA_HIGH 0x04 // ambient sensor data high byte
#define ALSDATA_LOW 0x05 // ambient sensor data low byte
#define PRXDATA 0x15 // proximity sensor data
#define ALS_UP_THRESH_HIGH 0x06 // ALS Interrupt Threshold Registers High
#define ALS_UP_THRESH_LOW 0x07 // ALS Interrupt Threshold Registers LOW
#define ALS_LO_THRESH_HIGH 0x08 // ALS Interrupt Threshold Registers High
#define ALS_LO_THRESH_LOW 0x09 // ALS Interrupt Threshold Registers Low
#define TPTR 0x0A // ALS/PROX Threshold Persist Timer Register
#define PROX_THRESH_IND 0x0B // Proximity Threshold Register
#define PROX_THRESH 0x0C // Proximity Threshold Register
#define TRIM_GAIN_GREEN 0x0F // Digital Gain Trim Register
#define TRIM_GAIN_IR 0x10 // Digital Gain Trim Register
#define HIGH 1
#define LOW 0
@ -90,14 +101,30 @@ class MAX44000 {
{
return m_name;
}
private:
uint16_t getALSData ();
uint16_t getPRXData ();
/**
* Read one byte register
*
* @param reg address of a register
*/
uint8_t i2cReadReg_8 (int reg);
/**
* Read two bytes register
*
* @param reg address of a register
*/
uint16_t i2cReadReg_16 (int reg);
/**
* Write to one byte register
*
* @param reg address of a register
* @param value byte to be written
*/
maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
private:
std::string m_name;
int m_maxControlAddr;

View File

@ -1,5 +1,7 @@
%module pyupm_max44000
%include "stdint.i"
%feature("autodoc", "3");
%include "max44000.h"

View File

@ -0,0 +1,5 @@
set (libname "mma7455")
set (libdescription "upm MMA7455")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,7 @@
%module jsupm_mma7455
%{
#include "mma7455.h"
%}
%include "mma7455.h"

176
src/mma7455/mma7455.cxx Normal file
View File

@ -0,0 +1,176 @@
/*
* 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 <string.h>
#include <pthread.h>
#include <math.h>
#include "mma7455.h"
using namespace upm;
MMA7455::MMA7455 (int bus, int devAddr) {
unsigned char data = 0;
int nBytes = 0;
m_name = "MMA7455";
m_controlAddr = devAddr;
m_bus = bus;
m_i2ControlCtx = maa_i2c_init(m_bus);
maa_result_t error = maa_i2c_address(m_i2ControlCtx, m_controlAddr);
if (error != MAA_SUCCESS) {
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);
if (error != MAA_SUCCESS) {
std::cout << "ERROR :: MMA7455 instance wan not created (Mode)" << std::endl;
return;
}
if (MAA_SUCCESS != calibrate ()) {
std::cout << "ERROR :: MMA7455 instance wan not created (Calibrate)" << std::endl;
return;
}
}
MMA7455::~MMA7455() {
maa_i2c_stop(m_i2ControlCtx);
}
maa_result_t
MMA7455::calibrate () {
maa_result_t error = MAA_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 (MAA_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 != MAA_SUCCESS) {
return error;
}
} while ( ++i < 3 );
return error;
}
maa_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 == MAA_SUCCESS);
if (nBytes == MAA_SUCCESS) {
std::cout << "NO_GDB :: 1" << std::endl;
return MAA_SUCCESS;
}*/
nBytes = ic2ReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
if (nBytes == 0) {
std::cout << "NO_GDB :: 2" << std::endl;
return MAA_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;
}
// The result is the g-force in units of 64 per 'g'.
*ptrX = xyz.value.x;
*ptrY = xyz.value.y;
*ptrZ = xyz.value.z;
return MAA_SUCCESS;
}
int
MMA7455::ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size) {
if (MAA_SUCCESS != maa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
return 0;
}
if (MAA_SUCCESS != maa_i2c_write_byte(m_i2ControlCtx, reg)) {
return 0;
}
if (MAA_SUCCESS != maa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
return 0;
}
return (int) maa_i2c_read(m_i2ControlCtx, buf, size);
}
maa_result_t
MMA7455::ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[size + 1];
data[0] = reg;
memcpy(&data[1], buf, size);
error = maa_i2c_address (m_i2ControlCtx, m_controlAddr);
if (error != MAA_SUCCESS) {
return error;
}
error = maa_i2c_write (m_i2ControlCtx, data, size + 1);
if (error != MAA_SUCCESS) {
return error;
}
return error;
}

223
src/mma7455/mma7455.h Normal file
View File

@ -0,0 +1,223 @@
/*
* 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 <maa/i2c.h>
#define ADDR 0x1D // device address
// Register names according to the datasheet.
// Register 0x1C is sometimes called 'PW', and sometimes 'PD'.
// The two reserved registers can not be used.
#define MMA7455_XOUTL 0x00 // Read only, Output Value X LSB
#define MMA7455_XOUTH 0x01 // Read only, Output Value X MSB
#define MMA7455_YOUTL 0x02 // Read only, Output Value Y LSB
#define MMA7455_YOUTH 0x03 // Read only, Output Value Y MSB
#define MMA7455_ZOUTL 0x04 // Read only, Output Value Z LSB
#define MMA7455_ZOUTH 0x05 // Read only, Output Value Z MSB
#define MMA7455_XOUT8 0x06 // Read only, Output Value X 8 bits
#define MMA7455_YOUT8 0x07 // Read only, Output Value Y 8 bits
#define MMA7455_ZOUT8 0x08 // Read only, Output Value Z 8 bits
#define MMA7455_STATUS 0x09 // Read only, Status Register
#define MMA7455_DETSRC 0x0A // Read only, Detection Source Register
#define MMA7455_TOUT 0x0B // Temperature Output Value (Optional)
#define MMA7455_RESERVED1 0x0C // Reserved
#define MMA7455_I2CAD 0x0D // Read/Write, I2C Device Address
#define MMA7455_USRINF 0x0E // Read only, User Information (Optional)
#define MMA7455_WHOAMI 0x0F // Read only, "Who am I" value (Optional)
#define MMA7455_XOFFL 0x10 // Read/Write, Offset Drift X LSB
#define MMA7455_XOFFH 0x11 // Read/Write, Offset Drift X MSB
#define MMA7455_YOFFL 0x12 // Read/Write, Offset Drift Y LSB
#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_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
#define MMA7455_LDTH 0x1A // Read/Write, Level Detection Threshold Limit Value
#define MMA7455_PDTH 0x1B // Read/Write, Pulse Detection Threshold Limit Value
#define MMA7455_PD 0x1C // Read/Write, Pulse Duration Value
#define MMA7455_LT 0x1D // Read/Write, Latency Time Value (between pulses)
#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
// between bit number and binary definition.
// By using the bit number, programming the MMA7455
// is like programming an AVR microcontroller.
// But instead of using "(1<<X)", or "_BV(X)",
// the Arduino "bit(X)" is used.
#define MMA7455_D0 0
#define MMA7455_D1 1
#define MMA7455_D2 2
#define MMA7455_D3 3
#define MMA7455_D4 4
#define MMA7455_D5 5
#define MMA7455_D6 6
#define MMA7455_D7 7
// Status Register
#define MMA7455_DRDY MMA7455_D0
#define MMA7455_DOVR MMA7455_D1
#define MMA7455_PERR MMA7455_D2
// Mode Control Register
#define MMA7455_MODE0 MMA7455_D0
#define MMA7455_MODE1 MMA7455_D1
#define MMA7455_GLVL0 MMA7455_D2
#define MMA7455_GLVL1 MMA7455_D3
#define MMA7455_STON MMA7455_D4
#define MMA7455_SPI3W MMA7455_D5
#define MMA7455_DRPD MMA7455_D6
// Control 1 Register
#define MMA7455_INTPIN MMA7455_D0
#define MMA7455_INTREG0 MMA7455_D1
#define MMA7455_INTREG1 MMA7455_D2
#define MMA7455_XDA MMA7455_D3
#define MMA7455_YDA MMA7455_D4
#define MMA7455_ZDA MMA7455_D5
#define MMA7455_THOPT MMA7455_D6
#define MMA7455_DFBW MMA7455_D7
// Control 2 Register
#define MMA7455_LDPL MMA7455_D0
#define MMA7455_PDPL MMA7455_D1
#define MMA7455_DRVO MMA7455_D2
// Interrupt Latch Reset Register
#define MMA7455_CLR_INT1 MMA7455_D0
#define MMA7455_CLR_INT2 MMA7455_D1
// Detection Source Register
#define MMA7455_INT1 MMA7455_D0
#define MMA7455_INT2 MMA7455_D1
#define MMA7455_PDZ MMA7455_D2
#define MMA7455_PDY MMA7455_D3
#define MMA7455_PDX MMA7455_D4
#define MMA7455_LDZ MMA7455_D5
#define MMA7455_LDY MMA7455_D6
#define MMA7455_LDX MMA7455_D7
// I2C Device Address Register
#define MMA7455_I2CDIS MMA7455_D7
#define HIGH 1
#define LOW 0
namespace upm {
union accelData {
struct {
unsigned char x_lsb;
unsigned char x_msb;
unsigned char y_lsb;
unsigned char y_msb;
unsigned char z_lsb;
unsigned char z_msb;
} reg;
struct {
short x;
short y;
short z;
} value;
};
#define BIT(n) (1<<n)
/**
* @brief C++ API for MMA7455 chip (accelerometer)
*
* This file defines the MMA7455 C++ interface for libmma7455
*
* @snippet mma7455.cxx Interesting
*
*/
class MMA7455 {
public:
/**
* Instanciates a MMA7455 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
MMA7455 (int bus, int devAddr);
/**
* MMA7455 object destructor, basicaly it close i2c connection.
*/
~MMA7455 ();
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
/**
* Calibrate the sensor
*/
maa_result_t calibrate ();
/**
* Read X, Y and Z acceleration data
*
* @param ptrX X axis
* @param ptrY Y axis
* @param ptrZ Z axis
*/
maa_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 size buffer size
*/
maa_result_t ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
private:
std::string m_name;
int m_controlAddr;
int m_bus;
maa_i2c_context m_i2ControlCtx;
};
}

View File

@ -0,0 +1,8 @@
%module pyupm_mma7455
%feature("autodoc", "3");
%include "mma7455.h"
%{
#include "mma7455.h"
%}

View File

@ -0,0 +1,5 @@
set (libname "my9221")
set (libdescription "upm ledbar")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -1,12 +1,5 @@
set (libname "nrf24l01")
add_library (nrf24l01 SHARED nrf24l01.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (nrf24l01 ${MAA_LIBRARIES})
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES nrf24l01.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm NRF tx/rx")
endif()
set (libdescription "libupm NRF tx/rx")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

8
src/package.json.in Normal file
View File

@ -0,0 +1,8 @@
{
"name" : "jsupm_@libname@",
"main" : "./jsupm_@libname@.node",
"engines": {
"node": ">= 1.0.x"
},
"license": "MIT"
}

11
src/pkgconfig.in Normal file
View File

@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib@LIB_SUFFIX@
includedir=${prefix}/include
Name: upm-@libname@
Description: upm lib @libname@
Version: @upm_VERSION_STRING@
Libs: -L${libdir} -lupm-@libname@
Cflags: -I${includedir}/upm

View File

@ -1,12 +1,5 @@
set (libname "servo")
add_library (servo SHARED servo.cxx es08a.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (servo ${MAA_LIBRARIES})
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
install (FILES servo.h DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm servo")
endif()
set (libdescription "upm servo")
set (module_src servo.cxx es08a.cxx)
set (module_h servo.h es08a.h)
upm_module_init()

View File

@ -30,8 +30,10 @@
using namespace upm;
ES08A::ES08A (int pin) : Servo(pin) {
m_name = "ES08A";
m_maxAngle = 180.0;
m_name = "ES08A";
m_maxAngle = 180.0;
m_minPulseWidth = 600;
m_maxPulseWidth = 2200;
}
ES08A::~ES08A() {

View File

@ -28,9 +28,6 @@
namespace upm {
#define MIN_PULSE_WIDTH 600
#define MAX_PULSE_WIDTH 2500
/**
* @brief C++ API for ES08A servo component
*

View File

@ -1,7 +0,0 @@
%module jsupm_es08a
%{
#include "es08a.h"
%}
%include "es08a.h"

7
src/servo/jsupm_servo.i Normal file
View File

@ -0,0 +1,7 @@
%module jsupm_servo
%{
#include "servo.h"
%}
%include "servo.h"

View File

@ -1,4 +1,4 @@
%module pyupm_es08a
%module pyupm_servo
%feature("autodoc", "3");

View File

@ -25,6 +25,7 @@
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include "servo.h"
@ -33,13 +34,21 @@ using namespace upm;
Servo::Servo (int pin) {
maa_result_t error = MAA_SUCCESS;
m_minPulseWidth = MIN_PULSE_WIDTH;
m_maxPulseWidth = MAX_PULSE_WIDTH;
m_maxPeriod = MAX_PERIOD;
m_maxAngle = 180.0;
m_servoPin = pin;
m_pwmServoContext = maa_pwm_init (m_servoPin);
m_currAngle = 180;
setAngle (0);
}
Servo::~Servo () {
maa_pwm_close (m_pwmServoContext);
}
/*
@ -58,15 +67,27 @@ maa_result_t Servo::setAngle (int angle) {
std::cout << "PWM context is NULL" << std::endl;
return MAA_ERROR_UNSPECIFIED;
}
if (angle > m_maxAngle || angle < 0) {
return MAA_ERROR_UNSPECIFIED;
}
int period = (m_maxPulseWidth - m_minPulseWidth) / m_maxAngle;
int cycles = (int)(100.0 * (abs (m_currAngle - angle) / m_maxAngle));
// int cycles = (int)(100.0 * ((float)angle / (float)m_maxAngle));
maa_pwm_enable (m_pwmServoContext, 1);
for (int cycles = 0; cycles < 128; cycles++) {
maa_pwm_period_us (m_pwmServoContext, MAX_PERIOD);
for (int cycle = 0; cycle < cycles; cycle++) {
maa_pwm_period_us (m_pwmServoContext, m_maxPeriod);
maa_pwm_pulsewidth_us (m_pwmServoContext, calcPulseTraveling(angle));
}
maa_pwm_enable (m_pwmServoContext, 0);
std::cout << "angle = " << angle << " ,pulse = " << calcPulseTraveling(angle) << std::endl;
std::cout << "angle = " << angle << " ,pulse = " << calcPulseTraveling(angle) << ", cycles " << cycles << std::endl;
m_currAngle = angle;
}
/*
@ -75,14 +96,44 @@ maa_result_t Servo::setAngle (int angle) {
int Servo::calcPulseTraveling (int value) {
// if bigger than the boundaries
if (value > m_maxAngle) {
return MAX_PULSE_WIDTH;
return m_maxPulseWidth;
}
// if less than the boundaries
if (value < 0) {
return MIN_PULSE_WIDTH;
return m_minPulseWidth;
}
// the conversion
return (int) ((float)MIN_PULSE_WIDTH + ((float)value / m_maxAngle) * ((float)MAX_PULSE_WIDTH - (float)MIN_PULSE_WIDTH));
return (int) ((float)m_minPulseWidth + ((float)value / m_maxAngle) * ((float)m_maxPulseWidth - (float)m_minPulseWidth));
}
void
Servo::setMinPulseWidth (int width) {
m_minPulseWidth = width;
}
void
Servo::setMaxPulseWidth (int width) {
m_maxPulseWidth = width;
}
void
Servo::setMaxPeriod (int width) {
m_maxPeriod = width;
}
int
Servo::getMinPulseWidth () {
return m_minPulseWidth;
}
int
Servo::getMaxPulseWidth () {
return m_maxPulseWidth;
}
int
Servo::getMaxPeriod () {
return m_maxPeriod;
}

View File

@ -79,6 +79,43 @@ class Servo {
{
return m_name;
}
/**
* Set min pulse width
*
* @param width HIGH signal width
*/
void setMinPulseWidth (int width);
/**
* Set max pulse width
*
* @param width HIGH signal width
*/
void setMaxPulseWidth (int width);
/**
* Set max period width
*
* @param width PWM period width
*/
void setMaxPeriod (int width);
/**
* Return min pulse width
*/
int getMinPulseWidth ();
/**
* Return max pulse width
*/
int getMaxPulseWidth ();
/**
* Return max PWM period width
*/
int getMaxPeriod ();
protected:
int calcPulseTraveling (int value);
@ -86,7 +123,11 @@ class Servo {
int m_servoPin;
float m_maxAngle;
maa_pwm_context m_pwmServoContext;
// maa_gpio_context m_servoPinCtx;
int m_currAngle;
int m_minPulseWidth;
int m_maxPulseWidth;
int m_maxPeriod;
};
}

View File

@ -0,0 +1,5 @@
set (libname "st7735")
set (libdescription "libupm SPI LCD")
set (module_src gfx.cxx st7735.cxx)
set (module_h gfx.h st7735.h)
upm_module_init()

231
src/st7735/gfx.cxx Normal file
View File

@ -0,0 +1,231 @@
/*
* 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 "gfx.h"
using namespace upm;
GFX::GFX (int width, int height, uint8_t * screenBuffer, const unsigned char * font) : WIDTH(width), HEIGHT(height) {
m_height = height;
m_width = width;
m_font = font;
m_map = screenBuffer;
}
GFX::~GFX () {
}
maa_result_t
GFX::setPixel (int x, int y, uint16_t color) {
if((x < 0) ||(x >= m_width) || (y < 0) || (y >= m_height)) {
return MAA_ERROR_UNSPECIFIED;
}
int index = ((y * m_width) + x) * sizeof(uint16_t);
m_map[index] = (uint8_t) (color >> 8);
m_map[++index] = (uint8_t)(color);
return MAA_SUCCESS;
}
void
GFX::fillScreen (uint16_t color) {
fillRect(0, 0, m_width, m_height, color);
}
void
GFX::fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
for (int16_t i=x; i<x+w; i++) {
drawFastVLine(i, y, h, color);
}
}
void
GFX::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
drawLine(x, y, x, y+h-1, color);
}
void
GFX::drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
swap(x0, y0);
swap(x1, y1);
}
if (x0 > x1) {
swap(x0, x1);
swap(y0, y1);
}
int16_t dx, dy;
dx = x1 - x0;
dy = abs (y1 - y0);
int16_t err = dx / 2;
int16_t ystep;
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
for (; x0 <= x1; x0++) {
if (steep) {
setPixel(y0, x0, color);
} else {
setPixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
}
void
GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
drawLine(x0, y0, x1, y1, color);
drawLine(x1, y1, x2, y2, color);
drawLine(x2, y2, x0, y0, color);
}
void
GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
setPixel(x0 , y0+r, color);
setPixel(x0 , y0-r, color);
setPixel(x0+r, y0 , color);
setPixel(x0-r, y0 , color);
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
setPixel(x0 + x, y0 + y, color);
setPixel(x0 - x, y0 + y, color);
setPixel(x0 + x, y0 - y, color);
setPixel(x0 - x, y0 - y, color);
setPixel(x0 + y, y0 + x, color);
setPixel(x0 - y, y0 + x, color);
setPixel(x0 + y, y0 - x, color);
setPixel(x0 - y, y0 - x, color);
}
}
void
GFX::setCursor (int16_t x, int16_t y) {
m_cursorX = x;
m_cursorY = y;
}
void
GFX::setTextColor (uint16_t textColor, uint16_t textBGColor) {
m_textColor = textColor;
m_textBGColor = textBGColor;
}
void
GFX::setTextSize (uint8_t size) {
m_textSize = (size > 0) ? size : 1;
}
void
GFX::setTextWrap (uint8_t wrap) {
m_wrap = wrap;
}
void
GFX::drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size) {
if( (x >= m_width) || // Clip right
(y >= m_height) || // Clip bottom
((x + 6 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
for (int8_t i=0; i<6; i++ ) {
uint8_t line;
if (i == 5) {
line = 0x0;
} else {
line = *(m_font+(data * 5)+i);
for (int8_t j = 0; j<8; j++) {
if (line & 0x1) {
if (size == 1) // default size
setPixel (x+i, y+j, color);
else { // big size
fillRect (x+(i*size), y+(j*size), size, size, color);
}
} else if (bg != color) {
if (size == 1) // default size
setPixel (x+i, y+j, bg);
else { // big size
fillRect (x+i*size, y+j*size, size, size, bg);
}
}
line >>= 1;
}
}
}
}
void
GFX::print (std::string msg) {
int len = msg.length();
for (int idx = 0; idx < len; idx++) {
if (msg[idx] == '\n') {
m_cursorY += m_textSize * 8;
m_cursorX = 0;
} else if (msg[idx] == '\r') {
// skip em
} else {
drawChar(m_cursorX, m_cursorY, msg[idx], m_textColor, m_textBGColor, m_textSize);
m_cursorX += m_textSize * 6;
if (m_wrap && (m_textColor > (m_width - m_textSize * 6))) {
m_cursorY += m_textSize * 8;
m_cursorX = 0;
}
}
}
}

216
src/st7735/gfx.h Normal file
View File

@ -0,0 +1,216 @@
/*
* 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 <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <maa.h>
#define swap(a, b) { int16_t t = a; a = b; b = t; }
namespace upm {
/**
* @brief GFX helper class
*
* This file used by the screen.
*/
class GFX {
public:
/**
* Instanciates a GFX object
*
* @param width screen width
* @param height screen height
* @param screenBuffer pointer to screen buffer
* @param font pointer to font map
*/
GFX (int width, int height, uint8_t * screenBuffer, const unsigned char * font);
/**
* GFX object destructor
*/
~GFX ();
/**
* Set the window address
*
* @param x0 first coordinate
* @param y0 first coordinate
* @param x1 second coordinate
* @param y1 second coordinate
*/
virtual void setAddrWindow (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) = 0;
/**
* Send pixel collor (RGB) to the chip. Must be implemented by
* inherited class.
*
* @param x axis on horizontal scale
* @param y axis on vertical scale
* @param color rgb value
*/
virtual void drawPixel (int16_t x, int16_t y, uint16_t color) = 0;
/**
* Copy the buffer to the chip via SPI interface.
*/
virtual void refresh () = 0;
/**
*
*
* @param x axis on horizontal scale
* @param y axis on vertical scale
* @param data character to write
* @param color character's color
* @param bg character's background color
* @param size size of the font
*/
void drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size);
/**
* Print the message to the screen
*
* @param msg message which will be printed
*/
void print (std::string msg);
/**
* Print the message to the screen
*
* @param x axis on horizontal scale
* @param y axis on vertical scale
* @param color pixel's color
*/
maa_result_t setPixel (int x, int y, uint16_t color);
/**
* Fill screen with selected color
*
* @param color selected's color
*/
void fillScreen (uint16_t color);
/**
* Fill rectangle with selected color
*
* @param x axis on horizontal scale (top left corner)
* @param y axis on vertical scale (top left corner)
* @param w distanse from x
* @param h distanse from y
* @param color selected color
*/
void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
/**
* Draw line in vertical scale.
*
* @param x axis on horizontal scale
* @param y axis on vertical scale
* @param h distanse from y
* @param color selected color
*/
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
/**
* Draw line from coordinate C0 to coordinate C1
*
* @param x0 first coordinate
* @param y0 first coordinate
* @param x1 second coordinate
* @param y1 second coordinate
* @param color selected color
*/
void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
/**
* Draw a triangle
*
* @param x0 first coordinate
* @param y0 first coordinate
* @param x1 second coordinate
* @param y1 second coordinate
* @param x2 third coordinate
* @param y2 third coordinate
* @param color selected color
*/
void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
/**
* Draw a circle
*
* @param x center of circule on X scale
* @param y center of circule on Y scale
*/
void drawCircle (int16_t x, int16_t y, int16_t r, uint16_t color);
/**
* Set cursor for text message
*
* @param x axis on horizontal scale
* @param y axis on vertical scale
*/
void setCursor (int16_t x, int16_t y);
/**
* Set text color for the message
*
* @param textColor font color
* @param textBGColor background color
*/
void setTextColor (uint16_t textColor, uint16_t textBGColor);
/**
* Set the size of the font
*
* @param size font size
*/
void setTextSize (uint8_t size);
/**
* Wrap printed message.
*
* @param wrap true (0x1) or false (0x0)
*/
void setTextWrap (uint8_t wrap);
int m_height; /**< Screen height */
int m_width; /**< Screen width */
int m_textSize; /**< Printed text size */
int m_textColor; /**< Printed text color */
int m_textBGColor; /**< Printed text background color */
int m_cursorX; /**< Cursor X coordinate */
int m_cursorY; /**< Cursor Y coordinate */
int m_wrap; /**< Wrapper flag (true or false) */
uint8_t * m_map; /**< Screens buffer */
protected:
const int16_t WIDTH, HEIGHT;
const unsigned char * m_font;
};
}

View File

@ -0,0 +1,7 @@
%module jsupm_st7735
%{
#include "st7735.h"
%}
%include "st7735.h"

24
src/st7735/license.txt Normal file
View File

@ -0,0 +1,24 @@
Software License Agreement (BSD License)
Copyright (c) 2012 Adafruit Industries. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,8 @@
%module pyupm_st7735
%feature("autodoc", "3");
%include "st7735.h"
%{
#include "st7735.h"
%}

319
src/st7735/st7735.cxx Normal file
View File

@ -0,0 +1,319 @@
/*
* 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 <stdio.h>
#include <string.h>
#include "st7735.h"
using namespace upm;
ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160, 128, m_map, font) {
maa_init();
m_csLCD = csLCD;
m_cSD = cSD;
m_rST = rst;
m_rS = rs;
initModule ();
configModule ();
}
ST7735::~ST7735 () {
maa_result_t error = MAA_SUCCESS;
error = maa_spi_stop(m_spi);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_csLCDPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_cSDPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_rSTPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_rSPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
void
ST7735::initModule () {
maa_result_t error = MAA_SUCCESS;
m_height = 160;
m_width = 128;
m_csLCDPinCtx = maa_gpio_init (m_csLCD);
if (m_csLCDPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csLCD);
exit (1);
}
m_cSDPinCtx = maa_gpio_init (m_cSD);
if (m_cSDPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_cSD);
exit (1);
}
m_rSTPinCtx = maa_gpio_init (m_rST);
if (m_rSTPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_rST);
exit (1);
}
m_rSPinCtx = maa_gpio_init (m_rS);
if (m_rSPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_rS);
exit (1);
}
error = maa_gpio_dir (m_csLCDPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
error = maa_gpio_dir (m_cSDPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
error = maa_gpio_dir (m_rSTPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
error = maa_gpio_dir (m_rSPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
m_spi = maa_spi_init (0);
error = maa_spi_frequency(m_spi, 15 * 1000000);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
lcdCSOn ();
}
void
ST7735::write (uint8_t value) {
rsLOW ();
maa_spi_write (m_spi, value);
}
void
ST7735::data (uint8_t value) {
rsHIGH ();
maa_spi_write (m_spi, value);
}
void
ST7735::executeCMDList(const uint8_t *addr) {
uint8_t numCommands, numArgs;
uint16_t ms;
numCommands = *(addr++); // Number of commands to follow
while(numCommands--) { // For each command...
write (*(addr++)); // Read, issue command
numArgs = *(addr++); // Number of args to follow
ms = numArgs & DELAY; // If hibit set, delay follows args
numArgs &= ~DELAY; // Mask out delay bit
while(numArgs--) { // For each argument...
data (*(addr++)); // Read, issue argument
}
if(ms) {
ms = *(addr++); // Read post-command delay time (ms)
if (ms == 255) {
ms = 500; // If 255, delay for 500 ms
}
usleep (ms * 1000);
}
}
}
void
ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
uint8_t colstart, rowstart;
colstart = rowstart = 0;
write (ST7735_CASET); // Column addr set
rsHIGH ();
m_spiBuffer[0] = 0x00;
m_spiBuffer[1] = x0 + colstart; // XSTART
m_spiBuffer[2] = 0x00;
m_spiBuffer[3] = x1 + colstart; // XEND
maa_spi_write_buf(m_spi, m_spiBuffer, 4);
write (ST7735_RASET); // Row addr set
rsHIGH ();
m_spiBuffer[0] = 0x00;
m_spiBuffer[1] = y0 + rowstart; // YSTART
m_spiBuffer[2] = 0x00;
m_spiBuffer[3] = y1 + rowstart; // YEND
maa_spi_write_buf(m_spi, m_spiBuffer, 4);
write (ST7735_RAMWR); // write to RAM
}
void
ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
if (MAA_SUCCESS != setPixel (x, y, color)) {
return;
}
refresh ();
}
void
ST7735::refresh () {
rsHIGH ();
int fragmentSize = m_height * m_width * 2 / 20;
for (int fragment = 0; fragment < 20; fragment++) {
maa_spi_write_buf(m_spi, &m_map[fragment * fragmentSize], fragmentSize);
}
}
void
ST7735::configModule() {
rsHIGH ();
lcdCSOff ();
lcdCSOn ();
maa_gpio_write (m_rSTPinCtx, HIGH);
usleep (500000);
maa_gpio_write (m_rSTPinCtx, LOW);
usleep (500000);
maa_gpio_write (m_rSTPinCtx, HIGH);
usleep (500000);
executeCMDList (Rcmd1);
executeCMDList (Rcmd2red);
executeCMDList (Rcmd3);
write (ST7735_MADCTL);
data (0xC0);
setAddrWindow (0, 0, m_width - 1, m_height - 1);
fillScreen (ST7735_BLACK);
refresh ();
}
maa_result_t
ST7735::lcdCSOn () {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_write (m_csLCDPinCtx, LOW);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
error = maa_gpio_write (m_cSDPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
return error;
}
maa_result_t
ST7735::lcdCSOff () {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_write (m_csLCDPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
return error;
}
maa_result_t
ST7735::sdCSOn () {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_write (m_cSDPinCtx, LOW);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
error = maa_gpio_write (m_csLCDPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
return error;
}
maa_result_t
ST7735::sdCSOff () {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_write (m_cSDPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
return error;
}
maa_result_t
ST7735::rsHIGH () {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_write (m_rSPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
return error;
}
maa_result_t
ST7735::rsLOW () {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_write (m_rSPinCtx, LOW);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
return error;
}

632
src/st7735/st7735.h Normal file
View File

@ -0,0 +1,632 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Credits to Adafruit.
* Based on Adafruit ST7735 library, see original license in license.txt file.
*
* 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 <maa/aio.h>
#include <maa/gpio.h>
#include <maa/spi.h>
#include <gfx.h>
#define INITR_GREENTAB 0x0
#define INITR_REDTAB 0x1
#define INITR_BLACKTAB 0x2
#define ST7735_TFTWIDTH 128
#define ST7735_TFTHEIGHT 160
#define ST7735_NOP 0x00
#define ST7735_SWRESET 0x01
#define ST7735_RDDID 0x04
#define ST7735_RDDST 0x09
#define ST7735_SLPIN 0x10
#define ST7735_SLPOUT 0x11
#define ST7735_PTLON 0x12
#define ST7735_NORON 0x13
#define ST7735_INVOFF 0x20
#define ST7735_INVON 0x21
#define ST7735_DISPOFF 0x28
#define ST7735_DISPON 0x29
#define ST7735_CASET 0x2A
#define ST7735_RASET 0x2B
#define ST7735_RAMWR 0x2C
#define ST7735_RAMRD 0x2E
#define ST7735_PTLAR 0x30
#define ST7735_COLMOD 0x3A
#define ST7735_MADCTL 0x36
#define ST7735_FRMCTR1 0xB1
#define ST7735_FRMCTR2 0xB2
#define ST7735_FRMCTR3 0xB3
#define ST7735_INVCTR 0xB4
#define ST7735_DISSET5 0xB6
#define ST7735_PWCTR1 0xC0
#define ST7735_PWCTR2 0xC1
#define ST7735_PWCTR3 0xC2
#define ST7735_PWCTR4 0xC3
#define ST7735_PWCTR5 0xC4
#define ST7735_VMCTR1 0xC5
#define ST7735_RDID1 0xDA
#define ST7735_RDID2 0xDB
#define ST7735_RDID3 0xDC
#define ST7735_RDID4 0xDD
#define ST7735_PWCTR6 0xFC
#define ST7735_GMCTRP1 0xE0
#define ST7735_GMCTRN1 0xE1
// Color definitions
#define ST7735_BLACK 0x0000
#define ST7735_BLUE 0x001F
#define ST7735_RED 0xF800
#define ST7735_GREEN 0x07E0
#define ST7735_CYAN 0x07FF
#define ST7735_MAGENTA 0xF81F
#define ST7735_YELLOW 0xFFE0
#define ST7735_WHITE 0xFFFF
#define HIGH 1
#define LOW 0
#define DELAY 0x80
namespace upm {
static const uint8_t Bcmd[] = {
// Initialization commands for 7735B screens
18, // 18 commands in list:
ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay
50, // 50 ms delay
ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay
255, // 255 = 500 ms delay
ST7735_COLMOD , 1+DELAY, // 3: Set color mode, 1 arg + delay:
0x05, // 16-bit color
10, // 10 ms delay
ST7735_FRMCTR1, 3+DELAY, // 4: Frame rate control, 3 args + delay:
0x00, // fastest refresh
0x06, // 6 lines front porch
0x03, // 3 lines back porch
10, // 10 ms delay
ST7735_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg:
0x08, // Row addr/col addr, bottom to top refresh
ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay:
0x15, // 1 clk cycle nonoverlap, 2 cycle gate
// rise, 3 cycle osc equalize
0x02, // Fix on VTL
ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg:
0x0, // Line inversion
ST7735_PWCTR1 , 2+DELAY, // 8: Power control, 2 args + delay:
0x02, // GVDD = 4.7V
0x70, // 1.0uA
10, // 10 ms delay
ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay:
0x05, // VGH = 14.7V, VGL = -7.35V
ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay:
0x01, // Opamp current small
0x02, // Boost frequency
ST7735_VMCTR1 , 2+DELAY, // 11: Power control, 2 args + delay:
0x3C, // VCOMH = 4V
0x38, // VCOML = -1.1V
10, // 10 ms delay
ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay:
0x11, 0x15,
ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay:
0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what
0x21, 0x1B, 0x13, 0x19, // these config values represent)
0x17, 0x15, 0x1E, 0x2B,
0x04, 0x05, 0x02, 0x0E,
ST7735_GMCTRN1,16+DELAY, // 14: Sparkles and rainbows, 16 args + delay:
0x0B, 0x14, 0x08, 0x1E, // (ditto)
0x22, 0x1D, 0x18, 0x1E,
0x1B, 0x1A, 0x24, 0x2B,
0x06, 0x06, 0x02, 0x0F,
10, // 10 ms delay
ST7735_CASET , 4 , // 15: Column addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 2
0x00, 0x81, // XEND = 129
ST7735_RASET , 4 , // 16: Row addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 1
0x00, 0x81, // XEND = 160
ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay
10, // 10 ms delay
ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay
255 }, // 255 = 500 ms delay
Rcmd1[] = { // Init for 7735R, part 1 (red or green tab)
15, // 15 commands in list:
ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay
150, // 150 ms delay
ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay
255, // 500 ms delay
ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args:
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args:
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args:
0x01, 0x2C, 0x2D, // Dot inversion mode
0x01, 0x2C, 0x2D, // Line inversion mode
ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay:
0x07, // No inversion
ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay:
0xA2,
0x02, // -4.6V
0x84, // AUTO mode
ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay:
0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay:
0x0A, // Opamp current small
0x00, // Boost frequency
ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay:
0x8A, // BCLK/2, Opamp current small & Medium low
0x2A,
ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay:
0x8A, 0xEE,
ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay:
0x0E,
ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay
ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg:
0xC8, // row addr/col addr, bottom to top refresh
ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay:
0x05 }, // 16-bit color
Rcmd2green[] = { // Init for 7735R, part 2 (green tab only)
2, // 2 commands in list:
ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 0
0x00, 0x7F+0x02, // XEND = 127
ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
0x00, 0x01, // XSTART = 0
0x00, 0x9F+0x01 }, // XEND = 159
Rcmd2red[] = { // Init for 7735R, part 2 (red tab only)
2, // 2 commands in list:
ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x7F, // XEND = 127
ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x9F }, // XEND = 159
Rcmd3[] = { // Init for 7735R, part 3 (red or green tab)
4, // 4 commands in list:
ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay:
0x02, 0x1c, 0x07, 0x12,
0x37, 0x32, 0x29, 0x2d,
0x29, 0x25, 0x2B, 0x39,
0x00, 0x01, 0x03, 0x10,
ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay:
0x03, 0x1d, 0x07, 0x06,
0x2E, 0x2C, 0x29, 0x2D,
0x2E, 0x2E, 0x37, 0x3F,
0x00, 0x00, 0x02, 0x10,
ST7735_NORON , DELAY, // 3: Normal display on, no args, w/delay
10, // 10 ms delay
ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay
100 }; // 100 ms delay
#define swap(a, b) { int16_t t = a; a = b; b = t; }
const unsigned char font[] = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x21, 0x54, 0x54, 0x78, 0x41,
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0xF0, 0x29, 0x24, 0x29, 0xF0,
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x32, 0x48, 0x48, 0x48, 0x32,
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x39, 0x44, 0x44, 0x44, 0x39,
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0xAA, 0x00, 0x55, 0x00, 0xAA,
0xAA, 0x55, 0xAA, 0x55, 0xAA,
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0x7C, 0x2A, 0x2A, 0x3E, 0x14,
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00
};
/**
* @brief C++ API for ST7735 SPI LCD module
*
* This file defines the ST7735 C++ interface for libst7735
*
* @snippet st7735.cxx Interesting
*/
class ST7735 : public GFX {
public:
/**
* Instanciates a ST7735 object
*
* @param csLCD LCD chip select pin
* @param cSD SD card chip select pin
* @param rs data/command pin
* @param rst reset pin
*/
ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst);
/**
* ST7735 object destructor
*/
~ST7735 ();
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
/**
* Initialize the modules GPIOs
*/
void initModule ();
/**
* Configure the chip via SPI interface
*/
void configModule ();
/**
* Send command to SPI bus (rs must be LOW)
*
* @param value command number
*/
void write (uint8_t value);
/**
* Send data to SPI bus (rs must be HIGH)
*
* @param value command number
*/
void data (uint8_t value);
/**
* Execute set of commands and data
*
* @param *addr pointer to start of the commands/data section
*/
void executeCMDList (const uint8_t *addr);
/**
* Set the window size inside the screen where the pixels data
* will be written.
*
* @param x0 first coordinate
* @param y0 first coordinate
* @param x1 second coordinate
* @param y1 second coordinate
*/
void setAddrWindow (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
/**
* Send pixel collor (RGB) to the chip.
*
* @param x axis on horizontal scale
* @param y axis on vertical scale
* @param color rgb (16bit) color (R[0-4], G[5-10], B[11-15])
*/
void drawPixel (int16_t x, int16_t y, uint16_t color);
/**
* Copy the buffer to the chip via SPI interface.
*/
void refresh ();
/**
* LCD chip select LOW.
*/
maa_result_t lcdCSOn ();
/**
* LCD chip select HIGH.
*/
maa_result_t lcdCSOff ();
/**
* CD card chip select LOW.
*/
maa_result_t sdCSOn ();
/**
* CD card select HIGH.
*/
maa_result_t sdCSOff ();
/**
* Data select HIGH.
*/
maa_result_t rsHIGH ();
/**
* Data select LOW.
*/
maa_result_t rsLOW ();
uint8_t m_map[160 * 128 * 2]; /**< Screens buffer */
private:
maa_spi_context m_spi;
uint8_t m_csLCD;
uint8_t m_cSD;
uint8_t m_rST;
uint8_t m_rS;
maa_gpio_context m_csLCDPinCtx;
maa_gpio_context m_cSDPinCtx;
maa_gpio_context m_rSTPinCtx;
maa_gpio_context m_rSPinCtx;
uint8_t m_spiBuffer[32];
std::string m_name;
};
}

View File

@ -0,0 +1,5 @@
set (libname "tm1637")
set (libdescription "upm 4 digit display tm1637")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()