Compare commits

..

54 Commits

Author SHA1 Message Date
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
3be0cdf5c2 upm: rename generated ipk package
* Version bump to 0.1.2

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-10 11:48:34 +01:00
d1f7df0552 doxygen: Added documentation to led bar (my9221)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 08:08:41 +00:00
0340d736de doxygen: fix to documentaion of buzzer sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 07:27:04 +00:00
a2ca2c1497 doxygen: Added documentation to ultrasonic sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 07:24:56 +00:00
236cc9acc1 doxygen: Added documentation to Buzzer sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 06:54:45 +00:00
864306acf5 cmake: added logic for building a tagged commit
* If the HEAD is 0 away from a tag, i.e. if it has just been tagged,
  removes commit number from version

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-09 19:23:27 +01:00
814cc4a0e8 doxygen: Added documentation for servo base and es08a
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-09 16:00:07 +00:00
1ff0e5ee57 upm: add protection around function for packaging
* Would not build if not building IPK.

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-09 18:00:29 +01:00
38efe2d7a3 max44000: Added new sensor module
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-09 15:37:33 +00:00
fa1753f4ef ipk: add cpack ipk generation
* added similar cmake modules used in libmaa

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-09 17:10:44 +01:00
b73841b28b Doxyfile.in: make doc generation work
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-09 14:45:28 +01:00
9c34b829ef 4digitdisplay.cxx: add Interesting tag and remove pointless array
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-09 14:45:03 +01:00
451d0390b6 doxygen: Added documentation to nrf24l01 module
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 15:40:24 +00:00
7d898e3274 doxygen: added documentation to tm1637 seven segment display
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 13:56:12 +00:00
b4ae08935d Merge branch 'ykiveish-master' 2014-06-06 15:14:53 +01:00
3ee752b297 Merge branch 'master' of github.com:ykiveish/upm into ykiveish-master
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>

Conflicts:
	examples/CMakeLists.txt
	src/CMakeLists.txt
	src/hcsr04/CMakeLists.txt
	src/servo/CMakeLists.txt
2014-06-06 15:14:34 +01:00
557f63edf6 ssd1327: Added new lcd module.
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:41 +00:00
3ce441f0a8 lcd: changed the OOO generalisation.
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:40 +00:00
039b138194 ssd1308: Added new oled display
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:40 +00:00
23d847e380 hcsr04: Added new sonar module (not working properly yet)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:39 +00:00
356b1dd43c servo: Added new module servo
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:39 +00:00
794eb19bd7 COPYING: add MIT license
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-05 16:28:22 +01:00
fdb943c2eb upm: add install options to all current libraries
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-05 15:50:01 +01:00
4896881ea4 cmake: add recursive search for folders
* No need for many add_subdirectory

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-05 13:58:34 +01:00
af09aeadc3 Merge branch 'ykiveish-master' 2014-06-05 13:45:47 +01:00
28b68b71c8 hcsr04: Added new sonar module (not working properly yet)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-04 14:57:19 +00:00
aac51c4850 servo: Added new module servo
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-03 10:52:58 -07:00
f1cf463126 Merge branch 'ykiveish-master' 2014-06-03 12:00:56 +01:00
5b8922f7bf styling: convert TAB to four SPACES
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-03 09:38:34 +00:00
0db7af89f9 general: added stdlib definition to fix broken compilation on maa v0.2.7
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-03 09:35:47 +00:00
fdcd36e1ae styling: remove trailing whitespace from all modules
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-02 11:49:57 +01:00
83c29cc330 Merge branch 'ykiveish-master' 2014-06-02 11:47:56 +01:00
e63076ecf4 nrf24l01 :: Added NRF module with examples.
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-06-02 02:33:21 -07:00
93aa79fe4b 4digitdisplay: added new 4digitdisplay module
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-05-30 06:13:47 -07:00
dd55123062 ledbar: added ledbar module
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-05-30 06:11:12 -07:00
c60b342e0f lcd: added grove-lcd rgb and deleted the old lcm1602 folder
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-05-30 06:04:49 -07:00
e785b0f03b cmake: make required maa version 0.2.6+
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-28 14:22:37 +01:00
81278510c0 Merge branch 'ykiveish-master'
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-28 14:21:01 +01:00
725fc4661c buzzer: added buzzer with example
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-05-28 05:57:28 -07:00
b26cbd09f1 hmc5883l.h: change char to uint8_t
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-27 11:11:45 +01:00
1d74ead4cc Lcm1602: clean up API and use maa_result_t
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-23 14:21:10 +01:00
77d103f396 cmake: update to maa 0.2.6
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-23 14:20:07 +01:00
87 changed files with 5493 additions and 285 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,21 +9,85 @@ 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.5)
pkg_check_modules (MAA REQUIRED maa>=0.2.6)
message (INFO " found libmaa version: ${MAA_VERSION}")
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
# Make a version file containing the current version from git.
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")
endif ()
message (INFO " - UPM Version ${VERSION}")
#parse the version information into pieces.
string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
string (REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${VERSION}")
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
if ("${VERSION_COMMIT}" MATCHES "^v.*")
set (VERSION_COMMIT "")
endif()
set (upm_VERSION_MAJOR ${VERSION_MAJOR})
set (upm_VERSION_MINOR ${VERSION_MINOR})
set (upm_VERSION_PATCH ${VERSION_PATCH})
set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH})
set (CMAKE_SWIG_FLAGS "")
# 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)
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)
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)
target_architecture (DETECTED_ARCH)
message( INFO " - Target arch is ${DETECTED_ARCH}")
set(CPACK_GENERATOR "DEB")
set(OPKG_ARCH ${DETECTED_ARCH})
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
set(upm_PACKAGE_ON_TAG ".")
if ("${VERSION_COMMIT}" STREQUAL "")
set(upm_PACKAGE_ON_TAG "")
endif()
set(CPACK_PACKAGE_VERSION
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
set(CPACK_PACKAGE_NAME "upm")
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DETECTED_ARCH})
set(CPACK_SYSTEM_NAME ${DETECTED_ARCH})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmaa0 (>= ${MAA_VERSION})")
set(CPACK_DEBIAN_PACKAGE_PROVIDES "upm-dev, upm-dbg, upm-doc")
set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
include (CPack)
endif()
add_subdirectory (src)
add_subdirectory (examples)

20
COPYING Normal file
View File

@ -0,0 +1,20 @@
Copyright © 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.

View File

@ -753,9 +753,7 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/hmc5883l/hmc5883l.h \
@CMAKE_CURRENT_SOURCE_DIR@/src/grove/grove.h \
@CMAKE_CURRENT_SOURCE_DIR@/src/lcm1602/lcm1602.h \
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src \
@CMAKE_CURRENT_SOURCE_DIR@/README.md
# This tag can be used to specify the character encoding of the source files
@ -823,7 +821,7 @@ FILE_PATTERNS = *.c \
# be searched for input files as well.
# The default value is: NO.
RECURSIVE = NO
RECURSIVE = YES
# The EXCLUDE tag can be used to specify files and/or directories that should be
# excluded from the INPUT source files. This way you can easily exclude a
@ -832,7 +830,7 @@ RECURSIVE = NO
# Note that relative paths are relative to the directory from which doxygen is
# run.
EXCLUDE =
EXCLUDE = @PROJECT_SOURCE_DIR@/src/doxy2swig.py
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
@ -865,14 +863,14 @@ EXCLUDE_SYMBOLS =
# that contain example code fragments that are included (see the \include
# command).
EXAMPLE_PATH =
EXAMPLE_PATH = @CMAKE_CURRENT_SOURCE_DIR@/examples/
# 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
# *.h) to filter out the source-files in the directories. If left blank all
# files are included.
EXAMPLE_PATTERNS = *
EXAMPLE_PATTERNS = *.cxx
# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
# searched for input files to be used with the \include or \dontinclude commands

View File

@ -0,0 +1,222 @@
# - The builtin (binary) CPack Deb generator (Unix only)
# CPackDeb may be used to create Deb package using CPack.
# CPackDeb is a CPack generator thus it uses the CPACK_XXX variables
# used by CPack : http://www.cmake.org/Wiki/CMake:CPackConfiguration
#
# However CPackRPM has specific features which are controlled by
# the specifics CPACK_RPM_XXX variables.You'll find a detailed usage on
# the wiki:
# http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29
# However as a handy reminder here comes the list of specific variables:
#
# CPACK_DEBIAN_PACKAGE_NAME
# Mandatory : YES
# Default : CPACK_PACKAGE_NAME (lower case)
# The debian package summary
# CPACK_DEBIAN_PACKAGE_VERSION
# Mandatory : YES
# Default : CPACK_PACKAGE_VERSION
# The debian package version
# CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# Mandatory : YES
# Default : Output of dpkg --print-architecture or i386
# The debian package architecture
# CPACK_DEBIAN_PACKAGE_DEPENDS
# Mandatory : NO
# Default : -
# May be used to set deb dependencies.
# CPACK_DEBIAN_PACKAGE_MAINTAINER
# Mandatory : YES
# Default : CPACK_PACKAGE_CONTACT
# The debian package maintainer
# CPACK_DEBIAN_PACKAGE_DESCRIPTION
# Mandatory : YES
# Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
# The debian package description
# CPACK_DEBIAN_PACKAGE_SECTION
# Mandatory : YES
# Default : 'devel'
# The debian package section
# CPACK_DEBIAN_PACKAGE_PRIORITY
# Mandatory : YES
# Default : 'optional'
# The debian package priority
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
# Copyright 2007-2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distributed this file outside of CMake, substitute the full
# License text for the above reference.)
# CPack script for creating Debian package
# Author: Mathieu Malaterre
#
# http://wiki.debian.org/HowToPackageForDebian
IF(CMAKE_BINARY_DIR)
MESSAGE(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.")
ENDIF(CMAKE_BINARY_DIR)
IF(NOT UNIX)
MESSAGE(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
ENDIF(NOT UNIX)
# Let's define the control file found in debian package:
# Binary package:
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
# DEBIAN/control
# debian policy enforce lower case for package name
# Package: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_NAME)
STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
ENDIF(NOT CPACK_DEBIAN_PACKAGE_NAME)
# Version: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_VERSION)
IF(NOT CPACK_PACKAGE_VERSION)
MESSAGE(FATAL_ERROR "Debian package requires a package version")
ENDIF(NOT CPACK_PACKAGE_VERSION)
SET(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_VERSION)
# Architecture: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# There is no such thing as i686 architecture on debian, you should use i386 instead
# $ dpkg --print-architecture
FIND_PROGRAM(DPKG_CMD dpkg)
IF(NOT DPKG_CMD)
MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
ENDIF(NOT DPKG_CMD)
EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# have a look at GET_PROPERTY(result GLOBAL PROPERTY ENABLED_FEATURES),
# this returns the successful FIND_PACKAGE() calls, maybe this can help
# Depends:
# You should set: DEBIAN_PACKAGE_DEPENDS
# TODO: automate 'objdump -p | grep NEEDED'
IF(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
MESSAGE(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
# Maintainer: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
IF(NOT CPACK_PACKAGE_CONTACT)
MESSAGE(FATAL_ERROR "Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER")
ENDIF(NOT CPACK_PACKAGE_CONTACT)
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
# Description: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
IF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
MESSAGE(FATAL_ERROR "Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION")
ENDIF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
# Section: (recommended)
IF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
SET(CPACK_DEBIAN_PACKAGE_SECTION "devel")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
# Priority: (recommended)
IF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY )
# Recommends:
# You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
# Suggests:
# You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
# CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
# This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
# Typical examples are:
# - conffiles
# - postinst
# - postrm
# - prerm"
# Usage:
# SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
# "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
# For debian source packages:
# debian/control
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles
# .dsc
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles
# Builds-Depends:
#IF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
# SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
# "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
# )
#ENDIF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
# Description: (mandatory)
#if(NOT CPACK_SECTION)
# message(FATAL_ERROR "opkg package requires a package section")
#endif(NOT CPACK_SECTION)
# Package for opkg
FIND_PROGRAM(OPKG_CMD opkg-build)
if( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )
message("CPack: opkg-build not found. Skipping packaging")
else( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )
SET(CPACK_OPKG_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
FILE(MAKE_DIRECTORY ${CPACK_OPKG_ROOTDIR}/CONTROL)
set(CPACK_OPKG_CONTROL_FILE "${CPACK_OPKG_ROOTDIR}/CONTROL/control")
# Write controlfile
FILE(WRITE ${CPACK_OPKG_CONTROL_FILE}
"Package: ${CPACK_PACKAGE_NAME}
Version: ${CPACK_PACKAGE_VERSION}
Description: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}
Architecture: ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}
Section: ${CPACK_DEBIAN_PACKAGE_SECTION}
Priority: optional
Maintainer: ${CPACK_DEBIAN_PACKAGE_MAINTAINER}
Depends: ${CPACK_DEBIAN_PACKAGE_DEPENDS}
Provides: ${CPACK_DEBIAN_PACKAGE_PROVIDES}
Replaces: ${CPACK_DEBIAN_PACKAGE_REPLACES}
Conflicts: ${CPACK_DEBIAN_PACKAGE_CONFLICTS}
Source: https://github.com/intel-iot-devkit/upm
#Essential: no
")
set(OPKG_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
execute_process(
COMMAND "${OPKG_CMD}" "-o" "0" "${CPACK_PACKAGE_FILE_NAME}" "."
RESULT_VARIABLE _result
OUTPUT_VARIABLE _res_output
ERROR_VARIABLE _res_error
WORKING_DIRECTORY ${CPACK_TOPLEVEL_DIRECTORY}
)
if(${_result})
message("Result '${_result}'")
message("Output '${_res_output}'")
message("Error '${_res_error}'")
else(${_result})
message("CPack: Package ${OPKG_FILE_NAME}.ipk generated.")
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
file(RENAME ${CPACK_TOPLEVEL_DIRECTORY}/${OPKG_FILE_NAME}.ipk ${CPACK_BINARY_DIR}/${OPKG_FILE_NAME}.ipk)
endif(${_result})
endif( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )

View File

@ -0,0 +1,130 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)
# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()
if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()
function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,38 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
set(HEAD_HASH)
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
set(HEAD_HASH "${HEAD_REF}")
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()
if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()

View File

@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,136 @@
# Based on the Qt 5 processor detection code, so should be very accurate
# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h
# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64)
# Regarding POWER/PowerPC, just as is noted in the Qt source,
# "There are many more known variants/revisions that we do not handle/detect."
set(archdetect_c_code "
#if defined(__arm__) || defined(__TARGET_ARCH_ARM)
#if defined(__ARM_ARCH_7__) \\
|| defined(__ARM_ARCH_7A__) \\
|| defined(__ARM_ARCH_7R__) \\
|| defined(__ARM_ARCH_7M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
#error cmake_ARCH armv7
#elif defined(__ARM_ARCH_6__) \\
|| defined(__ARM_ARCH_6J__) \\
|| defined(__ARM_ARCH_6T2__) \\
|| defined(__ARM_ARCH_6Z__) \\
|| defined(__ARM_ARCH_6K__) \\
|| defined(__ARM_ARCH_6ZK__) \\
|| defined(__ARM_ARCH_6M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
#error cmake_ARCH armv6
#elif defined(__ARM_ARCH_5TEJ__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
#error cmake_ARCH armv5
#else
#error cmake_ARCH arm
#endif
#elif defined(__i586) || defined(__i586__)
#error cmake_ARCH i586
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#error cmake_ARCH i386
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
#error cmake_ARCH x86_64
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#error cmake_ARCH ia64
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|| defined(_M_MPPC) || defined(_M_PPC)
#if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#error cmake_ARCH ppc64
#else
#error cmake_ARCH ppc
#endif
#endif
#error cmake_ARCH unknown
")
# Set ppc_support to TRUE before including this file or ppc and ppc64
# will be treated as invalid architectures since they are no longer supported by Apple
function(target_architecture output_var)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
# First let's normalize the order of the values
# Note that it's not possible to compile PowerPC applications if you are using
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
# disable it by default
# See this page for more information:
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
set(osx_arch_ppc TRUE)
elseif("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
set(osx_arch_ppc64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()
# Now add all the architectures in our normalized order
if(osx_arch_ppc)
list(APPEND ARCH ppc)
endif()
if(osx_arch_i386)
list(APPEND ARCH i386)
endif()
if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()
if(osx_arch_ppc64)
list(APPEND ARCH ppc64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
enable_language(C)
# Detect the architecture in a rather creative way...
# This compiles a small C program which is a series of ifdefs that selects a
# particular #error preprocessor directive whose message string contains the
# target architecture. The program will always fail to compile (both because
# file is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in this
# way, we can detect the correct target architecture even when cross-compiling,
# since the program itself never needs to be run (only the compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)
# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due
# to a typo in the code), then set it to unknown
if (NOT ARCH)
set(ARCH unknown)
endif()
endif()
set(${output_var} "${ARCH}" PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,4 @@
#include "version.h"
const char* gVERSION = "@VERSION@";
const char* gVERSION_SHORT = "@VERSION_SHORT@";

View File

@ -0,0 +1,42 @@
/*
* 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 "tm1637.h"
int
main(int argc, char **argv)
{
//! [Interesting]
upm::TM1637 *display = new upm::TM1637(8, 9); // di - 8, dcki - 9
display->write ("1337");
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete display;
return 0;
}

View File

@ -2,12 +2,44 @@ add_executable (compass compass.cxx)
add_executable (groveled groveled.cxx)
add_executable (grovetemp grovetemp.cxx)
add_executable (lcm-lcd lcm-lcd.cxx)
add_executable (rgb-lcd rgb-lcd.cxx)
add_executable (buzzer-sound buzzer-sound.cxx)
add_executable (led-bar led-bar.cxx)
add_executable (seg-lcd 4digitdisplay.cxx)
add_executable (nrf_transmitter nrf_transmitter.cxx)
add_executable (nrf_receiver nrf_receiver.cxx)
add_executable (es08a es08a.cxx)
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)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
include_directories (${PROJECT_SOURCE_DIR}/src/lcm1602)
include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
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)
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (grovetemp grove ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lcm-lcd lcm1602 ${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 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})
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})

69
examples/buzzer-sound.cxx Normal file
View File

@ -0,0 +1,69 @@
/*
* 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 <signal.h>
#include "buzzer.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) {
int chord[] = { DO, RE, MI, FA, SOL, LA, SI, DO, SI };
//! [Interesting]
// create Buzzer instance
upm::Buzzer* sound = new upm::Buzzer(5);
// print sensor name
std::cout << sound->name() << std::endl;
// play sound (DO, RE, ME, etc...)
signal(SIGINT, sig_handler);
while (!running) {
for (int chord_ind = 0; chord_ind < 9; chord_ind++) {
std::cout << sound->playSound(chord[chord_ind]) << std::endl;
usleep(1000);
}
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sound;
return 0;
}

70
examples/es08a.cxx Normal file
View File

@ -0,0 +1,70 @@
/*
* 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 "es08a.h"
#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;
}
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete servo;
return 0;
}

63
examples/hcsr04.cxx Normal file
View File

@ -0,0 +1,63 @@
/*
* 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 "hcsr04.h"
#include <signal.h>
#include <stdlib.h>
#include <sys/time.h>
upm::HCSR04 *sonar = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
sonar->m_doWork = 1;
}
}
//! [Interesting]
void
interrupt (void) {
sonar->ackEdgeDetected ();
}
int
main(int argc, char **argv)
{
sonar = new upm::HCSR04(5, 7, &interrupt);
signal(SIGINT, sig_handler);
printf ("width = %d\n", sonar->getDistance());
std::cout << "exiting application" << std::endl;
delete sonar;
return 0;
}
//! [Interesting]

View File

@ -28,13 +28,13 @@ int
main(int argc, char **argv)
{
upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
lcd->cursor(0,0);
lcd->setCursor(0,0);
lcd->write("Hello World");
lcd->cursor(1,2);
lcd->setCursor(1,2);
lcd->write("Hello World");
lcd->cursor(2,4);
lcd->setCursor(2,4);
lcd->write("Hello World");
lcd->cursor(3,6);
lcd->setCursor(3,6);
lcd->write("Hello World");
lcd->close();
}

63
examples/led-bar.cxx Normal file
View File

@ -0,0 +1,63 @@
/*
* 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 "my9221.h"
#include <signal.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::MY9221 *bar = new upm::MY9221(8, 9);
signal(SIGINT, sig_handler);
while (!running) {
for (int idx = 1; idx < 11; idx++) {
bar->setBarLevel (idx);
usleep(1000);
}
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete bar;
return 0;
}

42
examples/max44000.cxx Normal file
View File

@ -0,0 +1,42 @@
/*
* 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 "max44000.h"
int
main(int argc, char **argv)
{
//! [Interesting]
upm::MAX44000 *sensor = new upm::MAX44000(0, ADDR);
std::cout << "proximity value = " << sensor->getAmbient () << std::endl;
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

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;
}

72
examples/nrf_receiver.cxx Normal file
View File

@ -0,0 +1,72 @@
/*
* 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 "nrf24l01.h"
#include <signal.h>
int running = 0;
upm::NRF24l01 *comm = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
//! [Interesting]
void nrf_handler () {
std::cout << "devi1 :: " << *((uint32_t *)&(comm->m_rxBuffer[0])) << std::endl;
}
//! [Interesting]
int
main(int argc, char **argv)
{
//! [Interesting]
comm = new upm::NRF24l01(7);
comm->nrfSetRXaddr ((uint8_t *) "devi1");
comm->nrfSetTXaddr ((uint8_t *) "devi2");
comm->nrfSetPayload (MAX_BUFFER);
comm->nrfConfigModule ();
comm->dataRecievedHandler = nrf_handler;
signal(SIGINT, sig_handler);
while (!running) {
comm->nrfListenForChannel ();
}
std::cout << "exiting application" << std::endl;
delete comm;
//! [Interesting]
return 0;
}

View File

@ -0,0 +1,74 @@
/*
* 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 "nrf24l01.h"
#include <signal.h>
int running = 0;
upm::NRF24l01 *comm = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
void nrf_handler () {
}
int
main(int argc, char **argv)
{
//! [Interesting]
uint32_t dummyData = 0;
comm = new upm::NRF24l01(7);
comm->nrfSetRXaddr ((uint8_t *) "devi2");
comm->nrfSetTXaddr ((uint8_t *) "devi1");
comm->nrfSetPayload (MAX_BUFFER);
comm->nrfConfigModule ();
comm->dataRecievedHandler = nrf_handler;
signal(SIGINT, sig_handler);
while (!running) {
memcpy (comm->m_txBuffer, &dummyData, sizeof (dummyData));
comm->nrfSend ();
std::cout << "devi2 :: sending data ...." << dummyData << std::endl;
usleep (3000000);
dummyData += 3000;
}
std::cout << "exiting application" << std::endl;
delete comm;
//! [Interesting]
return 0;
}

116
examples/oled-1308.cxx Normal file
View File

@ -0,0 +1,116 @@
/*
* Author: Yevgeniy Kiveish <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 "ssd1308.h"
#define DEVICE_ADDRESS 0x3C
#define BUS_NUMBER 0x0
static uint8_t SeeedLogo[] ={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x60, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0xff, 0xfc, 0x00, 0x00, 0x00, 0x80, 0xf0, 0x20, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0x60, 0xe0, 0xc0,
0xc0, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x80, 0xc0,
0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0,
0x80, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0xc0, 0xf0, 0xf0, 0xf0, 0xc0, 0x00, 0xc0,
0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0,
0xf8, 0xf8, 0x00, 0xd8, 0xd8, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00,
0x00, 0x03, 0x0f, 0x1e, 0x3c, 0x70, 0xe3, 0xcf, 0x9f, 0x30, 0x00, 0x00, 0x00, 0x00, 0x70, 0xbf,
0xcf, 0xe3, 0x70, 0x78, 0x3e, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x33, 0x77, 0x66, 0x66, 0x66, 0x6c,
0x7d, 0x18, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37, 0x07, 0x00, 0x0f, 0x3f, 0x7f,
0x66, 0x66, 0x66, 0x66, 0x77, 0x27, 0x07, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37,
0x07, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x11, 0x37, 0x67, 0x66, 0x66, 0x6c, 0x7d, 0x38, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00, 0x00, 0x1f,
0x3f, 0x70, 0x60, 0x60, 0x70, 0x7f, 0x7f, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31,
0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x06, 0x1f, 0x3b, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3f, 0x1f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0xb0, 0x00, 0xc0, 0x20,
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00,
0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0xf8, 0x08,
0x08, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0x20, 0xa0,
0xa0, 0xa0, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0x08, 0x00, 0x20, 0x40, 0x80, 0x40,
0x20, 0x00, 0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0xe0, 0x00,
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x01, 0x00, 0x01, 0x02,
0x02, 0x02, 0x01, 0x00, 0x01, 0x02, 0x02, 0x02, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00,
0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x02,
0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x01, 0x02,
0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x82, 0x02, 0x00, 0x02, 0x01, 0x01, 0x01,
0x02, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x03, 0x00,
0x00, 0x00, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x82, 0x8c, 0x60, 0x1c, 0x02, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x1e,
0x20, 0x20, 0x00, 0x3e, 0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x1c, 0x2a, 0x2a, 0x2a, 0x0c, 0x00, 0x12, 0x2a, 0x2a,
0x2a, 0x1c, 0x20, 0x1c, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3f, 0x00, 0x02, 0x02, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int
main(int argc, char **argv)
{
upm::SSD1308 *lcd = new upm::SSD1308 (BUS_NUMBER, DEVICE_ADDRESS);
/*
* Simple print hello world
*/
// lcd->setCursor (0, 0);
// lcd->write ("Hello World");
/*
* Simple print hello world
*/
lcd->clear ();
lcd->draw (SeeedLogo, 1024);
lcd->close ();
}

126
examples/oled-1327.cxx Normal file
View File

@ -0,0 +1,126 @@
/*
* Author: Yevgeniy Kiveish <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 "ssd1327.h"
#define DEVICE_ADDRESS 0x3C
#define BUS_NUMBER 0x0
static uint8_t SeeedLogo[] ={
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x80, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x01, 0xC0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x07, 0x80, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x80, 0x01, 0xE0,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x0F, 0x00, 0x01, 0xE0, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
0x0F, 0x80, 0x01, 0xE0, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x0F, 0x80, 0x01, 0xE0,
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x0F, 0x80, 0x03, 0xE0, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1E, 0x07, 0x80, 0x03, 0xE0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E,
0x07, 0x80, 0x03, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x07, 0x80, 0x03, 0xC1,
0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x87, 0xC0, 0x07, 0xC1, 0xF0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0F, 0x83, 0xC0, 0x07, 0x83, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F,
0xC3, 0xC0, 0x07, 0x87, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE1, 0xE0, 0x07, 0x0F,
0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0xE0, 0x0F, 0x0F, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xF8, 0xF0, 0x0E, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xF8, 0x70, 0x1C, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x30, 0x18, 0x7E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x18, 0x30, 0xFC, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x88, 0x21, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0xC4, 0x47, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x0F, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06,
0x00, 0x00, 0x60, 0x00, 0x7E, 0x3F, 0x0F, 0xC3, 0xF0, 0xFA, 0x0F, 0xDF, 0xE1, 0x9F, 0xEC, 0x7E,
0xE6, 0x73, 0x9C, 0xE7, 0x39, 0xCE, 0x1C, 0xDF, 0xE1, 0xB9, 0xEC, 0xE7, 0xE0, 0x61, 0xD8, 0x66,
0x1B, 0x86, 0x1C, 0x06, 0x61, 0xB0, 0x6D, 0xC3, 0x7C, 0x7F, 0xFF, 0xFF, 0xFF, 0x06, 0x0F, 0x86,
0x61, 0xB0, 0x6D, 0x83, 0x3E, 0x7F, 0xFF, 0xFF, 0xFF, 0x06, 0x07, 0xC6, 0x61, 0xB0, 0x6D, 0x83,
0xC3, 0x61, 0x18, 0x46, 0x03, 0x86, 0x18, 0x66, 0x61, 0xB0, 0x6D, 0xC3, 0xFE, 0x7F, 0x9F, 0xE7,
0xF9, 0xFE, 0x1F, 0xE6, 0x3F, 0x9F, 0xEC, 0xFE, 0x7E, 0x3F, 0x0F, 0xC3, 0xF0, 0xFA, 0x0F, 0xC6,
0x3F, 0x9F, 0xEC, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00,
0x00, 0x20, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x20, 0x82, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0xF3, 0xCF, 0x70, 0x9E, 0x79, 0xE7, 0x80, 0x00, 0x00,
0x00, 0x00, 0x7D, 0x9E, 0x68, 0x20, 0xB2, 0xC8, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x9E,
0x6F, 0x20, 0xB2, 0xF9, 0xE7, 0x80, 0x00, 0x00, 0x00, 0x00, 0x46, 0x9A, 0x61, 0x20, 0xB2, 0xCB,
0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xF3, 0xCF, 0x30, 0x9E, 0x79, 0xE7, 0x90, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x02, 0x00, 0x00, 0x82, 0x60, 0x00, 0x00,
0xF8, 0x00, 0x00, 0x40, 0x40, 0x02, 0x00, 0x00, 0x83, 0x60, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x40,
0x60, 0xB7, 0x79, 0xE7, 0x81, 0xC7, 0x92, 0x70, 0x89, 0xE7, 0x9E, 0x78, 0x7C, 0xE2, 0xC9, 0x2C,
0x81, 0xCC, 0xD2, 0x40, 0xFB, 0x21, 0xB2, 0x48, 0x40, 0x62, 0xF9, 0x2C, 0x80, 0x8C, 0xD2, 0x40,
0x8B, 0xE7, 0xB0, 0x48, 0x40, 0xE2, 0xC9, 0x2C, 0x80, 0x84, 0xD2, 0x40, 0x8B, 0x2D, 0x92, 0x48,
0x7D, 0xB3, 0x79, 0x27, 0x80, 0x87, 0x9E, 0x40, 0x8D, 0xE7, 0x9E, 0x48, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int
main(int argc, char **argv)
{
upm::SSD1327 *lcd = new upm::SSD1327 (BUS_NUMBER, 0x3C);
/*
* Simple print hello world
*/
for(uint8_t i = 0; i < 12 ; i++) {
lcd->setCursor (i, 0);
lcd->setGrayLevel (i);
lcd->write ("Hello World");
}
/*
* Simple print hello world
*/
lcd->draw (SeeedLogo, 96 * 96 / 8);
lcd->close ();
}

37
examples/rgb-lcd.cxx Normal file
View File

@ -0,0 +1,37 @@
/*
* Author: Yevgeniy Kiveish <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 "jhd1313m1.h"
int
main(int argc, char **argv)
{
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
lcd->setCursor(0,0);
lcd->write("Hello World");
lcd->setCursor(1,2);
lcd->write("Hello World");
lcd->close();
}

View File

@ -1,3 +1,119 @@
add_subdirectory (hmc5883l)
add_subdirectory (grove)
add_subdirectory (lcm1602)
macro(subdirlist result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
set(dirlist ${dirlist} ${child})
endif()
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-")
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})
endforeach()

View File

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

51
src/buzzer/buzzer.cxx Normal file
View File

@ -0,0 +1,51 @@
/*
* 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 "buzzer.h"
using namespace upm;
Buzzer::Buzzer (int pinNumber) {
m_pwm_context = maa_pwm_init (pinNumber);
m_name = "Buzzer";
}
int Buzzer::playSound (int note) {
maa_pwm_enable (m_pwm_context, 1);
maa_pwm_period_us (m_pwm_context, note);
maa_pwm_write (m_pwm_context, 50.0);
usleep (10000);
maa_pwm_enable (m_pwm_context, 0);
return 0;
}
Buzzer::~Buzzer() {
maa_pwm_close(m_pwm_context);
std::cout << "executed maa_pwm_close" << std::endl;
}

80
src/buzzer/buzzer.h Normal file
View File

@ -0,0 +1,80 @@
/*
* 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/pwm.h>
#define DO 3830000 // 261 Hz
#define RE 3400000 // 294 Hz
#define MI 3038000 // 329 Hz
#define FA 2864000 // 349 Hz
#define SOL 2550000 // 392 Hz
#define LA 2272000 // 440 Hz
#define SI 2028000 // 493 Hz
namespace upm {
/**
* @brief C++ API for Buzzer component
*
* This file defines the Buzzer C++ interface for libbuzzer
*
* @snippet es08a.cxx Interesting
*
*/
class Buzzer {
public:
/**
* Instanciates a Buzzer object
*
* @param pin Buzzer pin number
*/
Buzzer (int pinNumber);
/**
* Buzzer object destructor.
*/
~Buzzer ();
/**
* Play chords.
*
* @param note chords (DO, RE, ME, etc...)
*/
int playSound (int note);
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
protected:
std::string m_name;
private:
maa_pwm_context m_pwm_context;
};
}

View File

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

View File

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

View File

@ -1,39 +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 ()
set (libdescription "upm grove module")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

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

94
src/hcsr04/hcsr04.cxx Normal file
View File

@ -0,0 +1,94 @@
/*
* 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 <functional>
#include "hcsr04.h"
using namespace upm;
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void)) {
maa_result_t error = MAA_SUCCESS;
m_name = "HCSR04";
m_pwmTriggerCtx = maa_pwm_init (triggerPin);
if (m_pwmTriggerCtx == NULL) {
std::cout << "PWM context is NULL" << std::endl;
exit (1);
}
maa_init();
m_echoPinCtx = maa_gpio_init(echoPin);
if (m_echoPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", echoPin);
exit (1);
}
maa_gpio_dir(m_echoPinCtx, MAA_GPIO_IN);
gpio_edge_t edge = MAA_GPIO_EDGE_BOTH;
maa_gpio_isr (m_echoPinCtx, edge, fptr);
}
HCSR04::~HCSR04 () {
maa_result_t error = MAA_SUCCESS;
maa_pwm_close (m_pwmTriggerCtx);
error = maa_gpio_close (m_echoPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
}
int
HCSR04::getDistance () {
maa_pwm_enable (m_pwmTriggerCtx, 1);
maa_pwm_period_us (m_pwmTriggerCtx, MAX_PERIOD);
maa_pwm_pulsewidth_us (m_pwmTriggerCtx, TRIGGER_PULSE);
maa_pwm_enable (m_pwmTriggerCtx, 0);
m_doWork = 0;
m_InterruptCounter = 0;
while (!m_doWork) {
sleep (1);
}
return m_FallingTimeStamp - m_RisingTimeStamp;
}
void
HCSR04::ackEdgeDetected () {
struct timeval timer;
gettimeofday(&timer, NULL);
++m_InterruptCounter;
if (!(m_InterruptCounter % 2)) {
m_FallingTimeStamp = 1000000 * timer.tv_sec + timer.tv_usec;
m_doWork = 1;
} else {
m_RisingTimeStamp = 1000000 * timer.tv_sec + timer.tv_usec;
}
}

99
src/hcsr04/hcsr04.h Normal file
View File

@ -0,0 +1,99 @@
/*
* 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/aio.h>
#include <maa/gpio.h>
#include <maa/pwm.h>
#include <sys/time.h>
#define HIGH 1
#define LOW 0
#define MAX_PERIOD 7968
#define TRIGGER_PULSE 10
namespace upm {
/**
* @brief C++ API for HCSR04 (ultrasonic ranging module) component
*
* This file defines the HCSR04 C++ interface for libhcsr04
*
* @snippet hcsr04.cxx Interesting
*
*/
class HCSR04 {
public:
/**
* Instanciates a HCSR04 object
*
* @param triggerPin pin for triggering the sensor for distance
* @param echoPin pulse response to triggering
* @param fptr function pointer for handling raising and
* falling interrupts
*/
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void));
/**
* HCSR04 object destructor.
*/
~HCSR04 ();
/**
* Get the distance from the sensor.
*/
int getDistance ();
/**
* On each interrupt this function will detect if the interrupt
* was falling edge or rising.
* Should be called from the interrupt handler.
*/
void ackEdgeDetected ();
uint8_t m_doWork; /**< Flag to controll blocking function while waiting for falling edge interrupt */
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
maa_pwm_context m_pwmTriggerCtx;
maa_gpio_context m_echoPinCtx;
uint8_t m_waitEcho;
long m_RisingTimeStamp;
long m_FallingTimeStamp;
uint8_t m_InterruptCounter;
std::string m_name;
};
}

View File

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

View File

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

View File

@ -1,39 +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 ()
set (libdescription "libupm Digital Compass")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -48,13 +48,13 @@ public:
/**
* Updates the values by reading from i2c
*
*
* @return 0 for success
*/
int update();
private:
int m_coor[3];
char m_rx_tx_buf[MAX_BUFFER_LENGTH];
uint8_t m_rx_tx_buf[MAX_BUFFER_LENGTH];
maa_i2c_context m_i2c;
};

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

@ -0,0 +1,5 @@
set (libname "i2clcd")
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()

86
src/lcd/i2clcd.cxx Normal file
View File

@ -0,0 +1,86 @@
/*
* 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 "i2clcd.h"
using namespace upm;
I2CLcd::I2CLcd (int bus, int lcdAddress) {
m_lcd_control_address = lcdAddress;
m_bus = bus;
m_i2c_lcd_control = maa_i2c_init(m_bus);
maa_result_t ret = maa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
if (ret != MAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
}
maa_result_t
I2CLcd::write (int row, int column, std::string msg) {
setCursor (row, column);
write (msg);
}
maa_result_t
I2CLcd::close() {
return maa_i2c_stop(m_i2c_lcd_control);
}
maa_result_t
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 };
error = maa_i2c_address (ctx, deviceAdress);
error = maa_i2c_write (ctx, data, 2);
return error;
}
maa_result_t
I2CLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { LCD_CMD, value };
error = maa_i2c_address (ctx, m_lcd_control_address);
error = maa_i2c_write (ctx, data, 2);
return error;
}
maa_result_t
I2CLcd::i2cData (maa_i2c_context ctx, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { LCD_DATA, value };
error = maa_i2c_address (ctx, m_lcd_control_address);
error = maa_i2c_write (ctx, data, 2);
return error;
}

95
src/lcd/i2clcd.h Normal file
View File

@ -0,0 +1,95 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <maa/i2c.h>
namespace upm {
// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_DATA 0x40
#define LCD_CMD 0x80
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
#define LCD_EN 0x04 // Enable bit
#define LCD_RW 0x02 // Read/Write bit
#define LCD_RS 0x01 // Register select bit
class I2CLcd {
public:
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;
virtual maa_result_t setCursor (int row, int column) = 0;
virtual maa_result_t clear () = 0;
virtual maa_result_t home () = 0;
virtual maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value);
virtual maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
virtual maa_result_t i2cData (maa_i2c_context ctx, uint8_t value);
maa_result_t close();
std::string name()
{
return m_name;
}
protected:
std::string m_name;
int m_lcd_control_address;
int m_bus;
maa_i2c_context m_i2c_lcd_control;
};
}

107
src/lcd/jhd1313m1.cxx Normal file
View File

@ -0,0 +1,107 @@
/*
* 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 "jhd1313m1.h"
using namespace upm;
Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdAddress) {
maa_result_t error = MAA_SUCCESS;
m_rgb_address = rgbAddress;
m_i2c_lcd_rgb = maa_i2c_init(m_bus);
maa_result_t ret = maa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
if (ret != MAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
usleep(50000);
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
i2Cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
clear ();
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
LCD_ENTRYLEFT |
LCD_ENTRYSHIFTDECREMENT);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
}
Jhd1313m1::~Jhd1313m1() {
}
/*
* **************
* virtual area
* **************
*/
maa_result_t
Jhd1313m1::write (std::string msg) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = {0x40, 0};
for (std::string::size_type i = 0; i < msg.size(); ++i) {
error = i2cData (m_i2c_lcd_control, msg[i]);
}
return error;
}
maa_result_t
Jhd1313m1::setCursor (int row, int column) {
maa_result_t error = MAA_SUCCESS;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
uint8_t offset = ((column % 16) + row_addr[row]);
error = i2Cmd (m_i2c_lcd_control, offset);
return error;
}
maa_result_t
Jhd1313m1::clear () {
return i2Cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
}
maa_result_t
Jhd1313m1::home () {
return i2Cmd (m_i2c_lcd_control, LCD_RETURNHOME);
}

45
src/lcd/jhd1313m1.h Normal file
View File

@ -0,0 +1,45 @@
/*
* 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 "i2clcd.h"
namespace upm {
class Jhd1313m1 : public I2CLcd {
public:
Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
~Jhd1313m1 ();
maa_result_t write (std::string msg);
maa_result_t setCursor (int row, int column);
maa_result_t clear ();
maa_result_t home ();
private:
int m_rgb_address;
maa_i2c_context m_i2c_lcd_rgb;
};
}

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

@ -30,50 +30,10 @@
#include "lcm1602.h"
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
#define LCD_EN 0x04 // Enable bit
#define LCD_RW 0x02 // Read/Write bit
#define LCD_RS 0x01 // Register select bit
using namespace upm;
Lcm1602::Lcm1602(int bus_in, int addr_in)
{
address = addr_in;
bus = bus_in;
maa_init();
m_i2c = maa_i2c_init(bus);
maa_i2c_address(m_i2c, address);
Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
maa_result_t error = MAA_SUCCESS;
usleep(50000);
expandWrite(LCD_BACKLIGHT);
@ -98,77 +58,81 @@ Lcm1602::Lcm1602(int bus_in, int addr_in)
send(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT, 0);
home();
}
int
Lcm1602::clear()
{
Lcm1602::~Lcm1602 () {
}
/*
* **************
* virtual area
* **************
*/
maa_result_t
Lcm1602::write (std::string msg) {
maa_result_t error = MAA_SUCCESS;
for (std::string::size_type i = 0; i < msg.size(); ++i) {
error = send (msg[i], LCD_RS);
}
return error;
}
maa_result_t
Lcm1602::setCursor (int row, int column) {
maa_result_t error = MAA_SUCCESS;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
uint8_t offset = ((column % 16) + row_addr[row]);
return send (LCD_CMD | offset, 0);
}
maa_result_t
Lcm1602::clear () {
return send(LCD_CLEARDISPLAY, 0);
}
int
Lcm1602::home()
{
maa_result_t
Lcm1602::home () {
return send(LCD_RETURNHOME, 0);
}
int
Lcm1602::cursor(int row, int column)
{
if (row > 3)
return 99;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
return send(LCD_SETDDRAMADDR | ((column % 16) + row_addr[row]),0);
}
int
Lcm1602::write(std::string msg)
{
int ret = 0;
for(std::string::size_type i = 0; i < msg.size(); ++i) {
ret = send(msg[i], LCD_RS);
}
return 0;
}
int
Lcm1602::close()
{
return maa_i2c_stop(m_i2c);
}
int
Lcm1602::send(char value, int mode)
{
int ret = 0;
char h = value & 0xf0;
char l = (value << 4) & 0xf0;
/*
* **************
* private area
* **************
*/
maa_result_t
Lcm1602::send (uint8_t value, int mode) {
maa_result_t ret = MAA_SUCCESS;
uint8_t h = value & 0xf0;
uint8_t l = (value << 4) & 0xf0;
ret = write4bits(h | mode);
ret = write4bits(l | mode);
return ret;
}
int
Lcm1602::write4bits(char value)
maa_result_t
Lcm1602::write4bits(uint8_t value)
{
int ret = 0;
maa_result_t ret = MAA_SUCCESS;
ret = expandWrite(value);
ret = pulseEnable(value);
return 0;
return ret;
}
int
Lcm1602::expandWrite(char value)
maa_result_t
Lcm1602::expandWrite(uint8_t value)
{
char buffer = value | LCD_BACKLIGHT;
return maa_i2c_write_byte(m_i2c, buffer);
uint8_t buffer = value | LCD_BACKLIGHT;
return maa_i2c_write_byte(m_i2c_lcd_control, buffer);
}
int
Lcm1602::pulseEnable(char value)
maa_result_t
Lcm1602::pulseEnable(uint8_t value)
{
int ret = 0;
maa_result_t ret = MAA_SUCCESS;
ret = expandWrite(value | LCD_EN);
usleep(1);
ret = expandWrite(value & ~LCD_EN);

View File

@ -7,7 +7,7 @@
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* Permission is hereby granted, free of uint8_tge, 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
@ -28,37 +28,28 @@
#pragma once
#include <string>
#include <maa/i2c.h>
#include "i2clcd.h"
namespace upm {
class Lcm1602 {
public:
/** LCM1602 Constructor.
* Calls MAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
Lcm1602(int bus, int address);
// Clear the screen
int clear();
// Set the cursor to home
int home();
// change cursor to row,column.
int cursor(int row, int column);
//write a string at the position
int write(std::string msg);
int close();
private:
int address;
int bus;
int send(char value, int mode);
int write4bits(char value);
int expandWrite(char value);
int pulseEnable(char value);
maa_i2c_context m_i2c;
};
class Lcm1602 : public I2CLcd {
public:
/** LCM1602 Constructor.
* Calls MAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
Lcm1602(int bus, int address);
~Lcm1602();
maa_result_t write (std::string msg);
maa_result_t setCursor (int row, int column);
maa_result_t clear ();
maa_result_t home ();
private :
maa_result_t send (uint8_t value, int mode);
maa_result_t write4bits(uint8_t value);
maa_result_t expandWrite(uint8_t value);
maa_result_t pulseEnable(uint8_t value);
};
}

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"
%}

139
src/lcd/ssd1308.cxx Normal file
View File

@ -0,0 +1,139 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string>
#include <unistd.h>
#include "ssd1308.h"
using namespace upm;
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);
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
usleep (4500);
setNormalDisplay (); // set to normal display '1' is ON
clear ();
setAddressingMode (PAGE);
}
SSD1308::~SSD1308 () {
}
maa_result_t
SSD1308::draw (uint8_t *data, int bytes) {
maa_result_t error = MAA_SUCCESS;
setAddressingMode (HORIZONTAL);
for (int idx = 0; idx < bytes; idx++) {
i2cData (m_i2c_lcd_control, data[idx]);
}
return error;
}
/*
* **************
* virtual area
* **************
*/
maa_result_t
SSD1308::write (std::string msg) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = {0x40, 0};
setAddressingMode (PAGE);
for (std::string::size_type i = 0; i < msg.size(); ++i) {
writeChar (m_i2c_lcd_control, msg[i]);
}
return error;
}
maa_result_t
SSD1308::setCursor (int row, int column) {
maa_result_t error = MAA_SUCCESS;
error = i2Cmd (m_i2c_lcd_control, BASE_PAGE_START_ADDR + row); // set page address
error = i2Cmd (m_i2c_lcd_control, BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F)); // set column lower address
error = i2Cmd (m_i2c_lcd_control, BASE_HIGH_COLUMN_ADDR + ((8 * column >> 4) & 0x0F)); // set column higher address
return error;
}
maa_result_t
SSD1308::clear () {
maa_result_t error = MAA_SUCCESS;
uint8_t columnIdx, rowIdx;
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
for(rowIdx = 0; rowIdx < 8; rowIdx++) {
setCursor (rowIdx, 0);
// clear all columns
for(columnIdx = 0; columnIdx < 16; columnIdx++) {
writeChar (m_i2c_lcd_control, ' ');
}
}
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
home ();
return MAA_SUCCESS;
}
maa_result_t
SSD1308::home () {
return setCursor (0, 0);
}
/*
* **************
* private area
* **************
*/
maa_result_t
SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
if (value < 0x20 || value > 0x7F) {
value = 0x20; // space
}
for (uint8_t idx = 0; idx < 8; idx++) {
i2cData (m_i2c_lcd_control, BasicFont[value - 32][idx]);
}
}
maa_result_t
SSD1308::setNormalDisplay () {
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
}
maa_result_t
SSD1308::setAddressingMode (displayAddressingMode mode) {
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); //set addressing mode
i2Cmd (m_i2c_lcd_control, mode); //set page addressing mode
}

170
src/lcd/ssd1308.h Normal file
View File

@ -0,0 +1,170 @@
/*
* 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 "i2clcd.h"
namespace upm {
#define DISPLAY_CMD_OFF 0xAE
#define DISPLAY_CMD_ON 0xAF
#define BASE_LOW_COLUMN_ADDR 0x00
#define BASE_HIGH_COLUMN_ADDR 0x10
#define BASE_PAGE_START_ADDR 0xB0
#define DISPLAY_CMD_MEM_ADDR_MODE 0x20
#define DISPLAY_CMD_SET_NORMAL 0xA6
const uint8_t BasicFont[][8] =
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
};
typedef enum {
HORIZONTAL = 0,
VERTICAL = 1,
PAGE = 2
} displayAddressingMode;
class SSD1308 : public I2CLcd {
public:
/** SSD1308 Constructor.
* Calls MAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
SSD1308 (int bus, int address);
~SSD1308 ();
maa_result_t draw(uint8_t *data, int bytes);
// pure virtual methods
maa_result_t write (std::string msg);
maa_result_t setCursor (int row, int column);
maa_result_t clear ();
maa_result_t home ();
private:
maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
maa_result_t setNormalDisplay ();
maa_result_t setAddressingMode (displayAddressingMode mode);
};
}

276
src/lcd/ssd1327.cxx Normal file
View File

@ -0,0 +1,276 @@
/*
* 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>
#include <unistd.h>
#include "ssd1327.h"
using namespace upm;
#define INIT_SLEEP 50000
#define CMD_SLEEP 10000
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
usleep (INIT_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x12);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xAE); // Set display off
usleep (INIT_SLEEP);
i2Cmd (m_i2c_lcd_control, 0xA8); // set multiplex ratio
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x5F); // 96
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xA1); // set display start line
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x00); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xA2); // set display offset
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x60);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xA0); // set remap
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x46);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xAB); // set vdd internal
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x01); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x81); // set contrasr
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x53); // 100 nit
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xB1); // Set Phase Length
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0X51); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xB3); // Set Display Clock Divide Ratio/Oscillator Frequency
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x01); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xB9); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xBC); // set pre_charge voltage/VCOMH
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x08); // (0x08);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xBE); // set VCOMH
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0X07); // (0x07);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xB6); // Set second pre-charge period
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x01); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xD5); // enable second precharge and enternal vsl
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0X62); // (0x62);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xA4); // Set Normal Display Mode
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x2E); // Deactivate Scroll
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xAF); // Switch on display
usleep (INIT_SLEEP);
// Row Address
error = i2Cmd (m_i2c_lcd_control, 0x75); // Set Row Address
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x00); // Start 0
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x5f); // End 95
usleep (INIT_SLEEP);
// Column Address
error = i2Cmd (m_i2c_lcd_control, 0x15); // Set Column Address
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(segments)
usleep (INIT_SLEEP);
clear ();
setNormalDisplay ();
setVerticalMode ();
}
SSD1327::~SSD1327 () {
}
maa_result_t
SSD1327::draw (uint8_t *data, int bytes) {
maa_result_t error = MAA_SUCCESS;
setHorizontalMode ();
for (int row = 0; row < bytes; row++) {
for (uint8_t col = 0; col < 8; col+=2) {
uint8_t value = 0x0;
uint8_t bitOne = (data[row] << col) & 0x80;
uint8_t bitTwo = (data[row] << (col + 1)) & 0x80;
value |= (bitOne) ? grayHigh : 0x00;
value |= (bitTwo) ? grayLow : 0x00;
i2cData (m_i2c_lcd_control, value);
usleep (CMD_SLEEP - 2000);
}
}
return error;
}
/*
* **************
* virtual area
* **************
*/
maa_result_t
SSD1327::write (std::string msg) {
maa_result_t error = MAA_SUCCESS;
setVerticalMode ();
for (std::string::size_type i = 0; i < msg.size(); ++i) {
writeChar (m_i2c_lcd_control, msg[i]);
}
return error;
}
maa_result_t
SSD1327::setCursor (int row, int column) {
maa_result_t error = MAA_SUCCESS;
//Column Address
i2Cmd (m_i2c_lcd_control, 0x15); /* Set Column Address */
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x08 + (column * 4)); /* Start Column: Start from 8 */
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x37); /* End Column */
usleep (CMD_SLEEP);
// Row Address
i2Cmd (m_i2c_lcd_control, 0x75); /* Set Row Address */
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x00 + (row * 8)); /* Start Row*/
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x07 + (row * 8)); /* End Row*/
usleep (CMD_SLEEP);
return error;
}
maa_result_t
SSD1327::clear () {
maa_result_t error = MAA_SUCCESS;
uint8_t columnIdx, rowIdx;
for(rowIdx = 0; rowIdx < 12; rowIdx++) {
// clear all columns
for(columnIdx = 0; columnIdx < 12; columnIdx++) {
writeChar (m_i2c_lcd_control, ' ');
}
}
return MAA_SUCCESS;
}
maa_result_t
SSD1327::home () {
return setCursor (0, 0);
}
maa_result_t
SSD1327::setGrayLevel (uint8_t level) {
grayHigh = (level << 4) & 0xF0;
grayLow = level & 0x0F;
}
/*
* **************
* private area
* **************
*/
maa_result_t
SSD1327::writeChar (maa_i2c_context ctx, uint8_t value) {
if (value < 0x20 || value > 0x7F) {
value = 0x20; // space
}
for (uint8_t row = 0; row < 8; row=row+2) {
for (uint8_t col = 0; col < 8; col++) {
uint8_t data = 0x0;
uint8_t bitOne = ((BasicFont[value - 32][row]) >> col) & 0x1;
uint8_t bitTwo = ((BasicFont[value - 32][row + 1]) >> col) & 0x1;
data |= (bitOne) ? grayHigh : 0x00;
data |= (bitTwo) ? grayLow : 0x00;
i2cData (m_i2c_lcd_control, data);
usleep (CMD_SLEEP - 2000);
}
}
}
maa_result_t
SSD1327::setNormalDisplay () {
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
}
maa_result_t
SSD1327::setHorizontalMode () {
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x42); // horizontal mode
usleep (CMD_SLEEP);
// Row Address
i2Cmd (m_i2c_lcd_control, 0x75); // Set Row Address
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x00); // Start 0
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x5f); // End 95
usleep (CMD_SLEEP);
// Column Address
i2Cmd (m_i2c_lcd_control, 0x15); // Set Column Address
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments)
usleep (CMD_SLEEP);
}
maa_result_t
SSD1327::setVerticalMode () {
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x46); // Vertical mode
usleep (CMD_SLEEP);
}

175
src/lcd/ssd1327.h Normal file
View File

@ -0,0 +1,175 @@
/*
* 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 "i2clcd.h"
namespace upm {
/*
#define DISPLAY_CMD_OFF 0xAE
#define DISPLAY_CMD_ON 0xAF
#define BASE_LOW_COLUMN_ADDR 0x00
#define BASE_HIGH_COLUMN_ADDR 0x10
#define BASE_PAGE_START_ADDR 0xB0
#define DISPLAY_CMD_MEM_ADDR_MODE 0x20
*/
#define DISPLAY_CMD_SET_NORMAL 0xA4
const uint8_t BasicFont[][8] =
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
};
typedef enum {
HORIZONTAL = 0,
VERTICAL = 1,
PAGE = 2
} displayAddressingMode;
class SSD1327 : public I2CLcd {
public:
/** SSD1308 Constructor.
* Calls MAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
SSD1327 (int bus, int address);
~SSD1327 ();
maa_result_t draw(uint8_t *data, int bytes);
// virtual methods
maa_result_t write (std::string msg);
maa_result_t setCursor (int row, int column);
maa_result_t clear ();
maa_result_t home ();
maa_result_t setGrayLevel (uint8_t level);
private:
maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
maa_result_t setNormalDisplay ();
maa_result_t setHorizontalMode ();
maa_result_t setVerticalMode ();
uint8_t grayHigh;
uint8_t grayLow;
};
}

View File

@ -1,39 +0,0 @@
set (libname "lcm1602")
add_library (lcm1602 SHARED lcm1602.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (lcm1602 ${MAA_LIBRARIES})
if (SWIG_FOUND)
find_package (PythonLibs)
include_directories (
${PYTHON_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
${MAA_INCLUDE_DIR}
.
)
set_source_files_properties (pyupm_lcm1602.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_lcm1602.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_lcm1602.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (pyupm_lcm1602 python pyupm_lcm1602.i lcm1602.cxx)
# swig_add_module (jsupm_lcm1602 javascript jsupm_lcm1602.i lcm1602.cxx)
swig_link_libraries (pyupm_lcm1602 ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
# swig_link_libraries (jsupm_lcm1602 ${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_lcm1602_REAL_NAME} ${libname}doc_i)
endif ()
endif ()

View File

@ -1,7 +0,0 @@
%module jsupm_lcm1602
%{
#include "lcm1602.h"
%}
%include "lcm1602.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

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

View File

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

114
src/max44000/max44000.cxx Normal file
View File

@ -0,0 +1,114 @@
/*
* 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 "max44000.h"
using namespace upm;
MAX44000::MAX44000 (int bus, int devAddr) {
m_name = "MAX44000";
m_maxControlAddr = devAddr;
m_bus = bus;
m_i2cMaxControlCtx = maa_i2c_init(m_bus);
maa_result_t ret = maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
if (ret != MAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
// i2cWriteReg (MCR, 0x2C);
// i2cWriteReg (TCR, 0x6);
}
MAX44000::~MAX44000() {
maa_i2c_stop(m_i2cMaxControlCtx);
}
uint16_t
MAX44000::getProximity () {
uint16_t data = 0;
data = (i2cReadReg_8 (ALSDATA_HIGH) & 0x7F) << 8;
data = data | i2cReadReg_8 (ALSDATA_LOW);
return data;
}
uint16_t
MAX44000::getAmbient () {
uint16_t data = 0;
data = (i2cReadReg_8 (ALSDATA_HIGH) & 0x7F) << 8;
data = data | i2cReadReg_8 (ALSDATA_LOW);
return data;
}
/*
* **************
* private area
* **************
*/
uint8_t
MAX44000::i2cReadReg_8 (int reg) {
uint8_t data;
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
maa_i2c_write_byte(m_i2cMaxControlCtx, reg);
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
maa_i2c_read(m_i2cMaxControlCtx, &data, 0x1);
return data;
}
uint16_t
MAX44000::i2cReadReg_16 (int reg) {
uint16_t data;
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
maa_i2c_write_byte(m_i2cMaxControlCtx, reg);
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
maa_i2c_read(m_i2cMaxControlCtx, (uint8_t *)&data, 0x2);
return data;
}
maa_result_t
MAX44000::i2cWriteReg (uint8_t reg, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { reg, value };
error = maa_i2c_address (m_i2cMaxControlCtx, m_maxControlAddr);
error = maa_i2c_write (m_i2cMaxControlCtx, data, 2);
return error;
}

135
src/max44000/max44000.h Normal file
View File

@ -0,0 +1,135 @@
/*
* 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 0x4A // device address
// registers address
#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
namespace upm {
/**
* @brief C++ API for MAX44000 chip (Ambient and Infrared Proximity Sensor)
*
* This file defines the MAX44000 C++ interface for libmax44000
*
* @snippet proximity.cxx Interesting
*
* PMOD pins for MAX44000PMB1 board
*
* ( -= J1 =- )
* (1) - NUL
* (2) - IRQ
* (3) - SCL
* (4) - SDA
* (5) - GND
* (6) - VCC
*
*/
class MAX44000 {
public:
/**
* Instanciates a MAX44000 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
MAX44000 (int bus, int devAddr);
/**
* MAX44000 object destructor, basicaly it close i2c connection.
*/
~MAX44000 ();
/**
* Read the proximity value from the chip (based on ambient data).
*/
uint16_t getProximity ();
/**
* Read the ambient value from the chip (based on ambient data).
*/
uint16_t getAmbient ();
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
/**
* 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;
int m_bus;
maa_i2c_context m_i2cMaxControlCtx;
};
}

View File

@ -0,0 +1,10 @@
%module pyupm_max44000
%include "stdint.i"
%feature("autodoc", "3");
%include "max44000.h"
%{
#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

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

119
src/my9221/my9221.cxx Normal file
View File

@ -0,0 +1,119 @@
/*
* 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 "my9221.h"
using namespace upm;
MY9221::MY9221 (uint8_t di, uint8_t dcki) {
maa_result_t error = MAA_SUCCESS;
maa_init();
// init clock context
m_clkPinCtx = maa_gpio_init(dcki);
if (m_clkPinCtx == NULL) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
exit(1);
}
// init data context
m_dataPinCtx = maa_gpio_init(di);
if (m_dataPinCtx == NULL) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
exit(1);
}
// set direction (out)
error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
// set direction (out)
error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
MY9221::~MY9221() {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_close (m_dataPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_clkPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
maa_result_t
MY9221::setBarLevel (uint8_t level) {
if (level > 10) {
return MAA_ERROR_INVALID_PARAMETER;
}
send16bitBlock (CMDMODE);
for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
}
lockData ();
}
maa_result_t
MY9221::lockData () {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_write (m_dataPinCtx, LOW);
usleep(100);
for(int idx = 0; idx < 4; idx++) {
error = maa_gpio_write (m_dataPinCtx, HIGH);
error = maa_gpio_write (m_dataPinCtx, LOW);
}
}
maa_result_t
MY9221::send16bitBlock (short data) {
maa_result_t error = MAA_SUCCESS;
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
uint32_t state = (data & 0x8000) ? HIGH : LOW;
error = maa_gpio_write (m_dataPinCtx, state);
state = maa_gpio_read (m_clkPinCtx);
if (state) {
state = LOW;
} else {
state = HIGH;
}
error = maa_gpio_write (m_clkPinCtx, state);
data <<= 1;
}
}

85
src/my9221/my9221.h Normal file
View File

@ -0,0 +1,85 @@
/*
* 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/aio.h>
#include <maa/gpio.h>
#define MAX_BIT_PER_BLOCK 16
#define CMDMODE 0x0000
#define BIT_HIGH 0x00ff
#define BIT_LOW 0x0000
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for MY9221 led bar module
*
* This file defines the MY9221 C++ interface for libmy9221
*
* @snippet led-bar.cxx Interesting
*/
class MY9221 {
public:
/**
* Instanciates a MY9221 object
*
* @param di data pin
* @param dcki clock pin
*/
MY9221 (uint8_t di, uint8_t dcki);
/**
* MY9221 object destructor
*/
~MY9221 ();
/**
* Set the level bar
*
* @param level selected level for the bar (1 - 10)
*/
maa_result_t setBarLevel (uint8_t level);
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
maa_result_t lockData ();
maa_result_t send16bitBlock (short data);
std::string m_name;
maa_gpio_context m_clkPinCtx;
maa_gpio_context m_dataPinCtx;
};
}

View File

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

View File

@ -0,0 +1,5 @@
set (libname "nrf24l01")
set (libdescription "libupm NRF tx/rx")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

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

320
src/nrf24l01/nrf24l01.cxx Normal file
View File

@ -0,0 +1,320 @@
/*
* 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 "nrf24l01.h"
using namespace upm;
NRF24l01::NRF24l01 (uint8_t cs) {
maa_init();
nrfInitModule (cs, 8);
}
NRF24l01::~NRF24l01 () {
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_cePinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_csnPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
void
NRF24l01::nrfInitModule (uint8_t chip_select, uint8_t chip_enable) {
maa_result_t error = MAA_SUCCESS;
m_csn = chip_select;
m_ce = chip_enable;
m_channel = 1;
m_csnPinCtx = maa_gpio_init (m_csn);
if (m_csnPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csn);
exit (1);
}
m_cePinCtx = maa_gpio_init (m_ce);
if (m_cePinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_ce);
exit (1);
}
error = maa_gpio_dir (m_csnPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
error = maa_gpio_dir (m_cePinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
nrfCELow ();
m_spi = maa_spi_init (0);
}
void
NRF24l01::nrfConfigModule() {
/* Set RF channel */
nrfConfigRegister (RF_CH, m_channel);
/* Set length of incoming payload */
nrfConfigRegister (RX_PW_P0, m_payload);
nrfConfigRegister (RX_PW_P1, m_payload);
/* Set length of incoming payload for broadcast */
nrfConfigRegister (RX_PW_P2, m_payload);
/* Start receiver */
nrfPowerUpRX ();
nrfFlushRX ();
}
/* Clocks only one byte into the given MiRF register */
void
NRF24l01::nrfConfigRegister(uint8_t reg, uint8_t value) {
nrfCSOn ();
maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
maa_spi_write (m_spi, value);
nrfCSOff ();
}
void
NRF24l01::nrfPowerUpRX() {
m_ptx = 0;
nrfCELow();
nrfConfigRegister(CONFIG, NRF_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
nrfCEHigh();
nrfConfigRegister(STATUS,(1 << TX_DS) | (1 << MAX_RT));
}
void
NRF24l01::nrfFlushRX() {
nrfCSOn ();
maa_spi_write (m_spi, FLUSH_RX);
nrfCSOff ();
}
/* Sets the receiving address */
void
NRF24l01::nrfSetRXaddr(uint8_t * addr) {
nrfCELow();
nrfWriteRegister(RX_ADDR_P1, addr, ADDR_LEN);
nrfCEHigh();
}
/* Sets the transmitting address */
void
NRF24l01::nrfSetTXaddr(uint8_t * addr)
{
/* RX_ADDR_P0 must be set to the sending addr for auto ack to work. */
nrfWriteRegister (RX_ADDR_P0, addr, ADDR_LEN);
nrfWriteRegister (TX_ADDR, addr, ADDR_LEN);
}
/* The broadcast address should be 0xFFFFF */
void
NRF24l01::nrfSetBroadcastAddr (uint8_t * addr) {
nrfCELow ();
nrfWriteRegister (RX_ADDR_P2, addr, ADDR_LEN);
nrfCEHigh ();
}
void
NRF24l01::nrfSetPayload (uint8_t load) {
m_payload = load;
}
void
NRF24l01::nrfWriteRegister(uint8_t reg, uint8_t * value, uint8_t len)
{
nrfCSOn ();
maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
nrfTransmitSync(value, len);
nrfCSOff ();
}
void
NRF24l01::nrfTransmitSync(uint8_t *dataout, uint8_t len){
uint8_t i;
for(i = 0; i < len; i++) {
maa_spi_write (m_spi, dataout[i]);
}
}
/* Checks if data is available for reading */
bool
NRF24l01::nrfDataReady() {
uint8_t status = nrfGetStatus();
if ( status & (1 << RX_DR) ) {
return 1;
}
return !nrfRXFifoEmpty();
}
uint8_t
NRF24l01::nrfGetStatus () {
uint8_t rv;
nrfReadRegister (STATUS, &rv, 1);
return rv;
}
/* Reads an array of bytes from the given start position in the MiRF registers. */
void
NRF24l01::nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len)
{
nrfCSOn ();
maa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
nrfTransferSync (value, value, len);
nrfCSOff ();
}
void
NRF24l01::nrfTransferSync (uint8_t *dataout,uint8_t *datain,uint8_t len) {
uint8_t i;
for(i = 0;i < len;i++) {
datain[i] = maa_spi_write (m_spi, dataout[i]);
}
}
bool
NRF24l01::nrfRXFifoEmpty () {
uint8_t fifo_status;
nrfReadRegister (FIFO_STATUS, &fifo_status, sizeof(fifo_status));
return (fifo_status & (1 << RX_EMPTY));
}
/* Reads payload bytes into data array */
void
NRF24l01::nrfGetData (uint8_t * data)
{
nrfCSOn ();
/* Send cmd to read rx payload */
maa_spi_write (m_spi, R_RX_PAYLOAD);
/* Read payload */
nrfTransferSync(data, data, m_payload);
nrfCSOff ();
nrfConfigRegister(STATUS, (1<<RX_DR));
}
/* Sends a data package to the default address. Be sure to send the correct
* amount of bytes as configured as payload on the receiver. */
void
NRF24l01::nrfSend(uint8_t * value) {
uint8_t status;
status = nrfGetStatus();
while (m_ptx) {
status = nrfGetStatus();
if((status & ((1 << TX_DS) | (1 << MAX_RT)))){
m_ptx = 0;
break;
}
} // Wait until last paket is send
nrfCELow();
nrfPowerUpTX(); // Set to transmitter mode , Power up
nrfCSOn ();
maa_spi_write (m_spi, FLUSH_TX); // Write cmd to flush tx fifo
nrfCSOff ();
nrfCSOn ();
maa_spi_write (m_spi, W_TX_PAYLOAD); // Write cmd to write payload
nrfTransmitSync(value, m_payload); // Write payload
nrfCSOff ();
nrfCEHigh(); // Start transmission
}
void
NRF24l01::nrfSend () {
nrfSend (m_txBuffer);
}
bool
NRF24l01::nrfIsSending () {
uint8_t status;
if (m_ptx) { // Sending mode.
status = nrfGetStatus();
/* if sending successful (TX_DS) or max retries exceded (MAX_RT). */
if((status & ((1 << TX_DS) | (1 << MAX_RT)))){
nrfPowerUpRX();
return false;
}
return true;
}
return false;
}
void
NRF24l01::nrfPowerUpTX () {
m_ptx = 1;
nrfConfigRegister (CONFIG, NRF_CONFIG | ( (1<<PWR_UP) | (0<<PRIM_RX) ) );
}
void
NRF24l01::nrfPowerDown () {
nrfCELow ();
nrfConfigRegister (CONFIG, NRF_CONFIG);
}
maa_result_t
NRF24l01::nrfCEHigh () {
return maa_gpio_write (m_cePinCtx, HIGH);
}
maa_result_t
NRF24l01::nrfCELow () {
return maa_gpio_write (m_cePinCtx, LOW);
}
maa_result_t
NRF24l01::nrfCSOn () {
return maa_gpio_write (m_csnPinCtx, LOW);
}
maa_result_t
NRF24l01::nrfCSOff () {
return maa_gpio_write (m_csnPinCtx, HIGH);
}
void
NRF24l01::nrfListenForChannel() {
if(!nrfIsSending() && nrfDataReady()) {
nrfGetData(m_rxBuffer);
dataRecievedHandler(); /* let know that data arrived */
}
}

347
src/nrf24l01/nrf24l01.h Normal file
View File

@ -0,0 +1,347 @@
/*
* 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/aio.h>
#include <maa/gpio.h>
#include <maa/spi.h>
/* Memory Map */
#define CONFIG 0x00
#define EN_AA 0x01
#define EN_RXADDR 0x02
#define SETUP_AW 0x03
#define SETUP_RETR 0x04
#define RF_CH 0x05
#define RF_SETUP 0x06
#define STATUS 0x07
#define OBSERVE_TX 0x08
#define CD 0x09
#define RX_ADDR_P0 0x0A
#define RX_ADDR_P1 0x0B
#define RX_ADDR_P2 0x0C
#define RX_ADDR_P3 0x0D
#define RX_ADDR_P4 0x0E
#define RX_ADDR_P5 0x0F
#define TX_ADDR 0x10
#define RX_PW_P0 0x11
#define RX_PW_P1 0x12
#define RX_PW_P2 0x13
#define RX_PW_P3 0x14
#define RX_PW_P4 0x15
#define RX_PW_P5 0x16
#define FIFO_STATUS 0x17
/* Bit Mnemonics */
#define MASK_RX_DR 6
#define MASK_TX_DS 5
#define MASK_MAX_RT 4
#define EN_CRC 3
#define CRCO 2
#define PWR_UP 1
#define PRIM_RX 0
#define ENAA_P5 5
#define ENAA_P4 4
#define ENAA_P3 3
#define ENAA_P2 2
#define ENAA_P1 1
#define ENAA_P0 0
#define ERX_P5 5
#define ERX_P4 4
#define ERX_P3 3
#define ERX_P2 2
#define ERX_P1 1
#define ERX_P0 0
#define AW 0
#define ARD 4
#define ARC 0
#define PLL_LOCK 4
#define RF_DR 3
#define RF_PWR 1
#define LNA_HCURR 0
#define RX_DR 6
#define TX_DS 5
#define MAX_RT 4
#define RX_P_NO 1
#define TX_FULL 0
#define PLOS_CNT 4
#define ARC_CNT 0
#define TX_REUSE 6
#define FIFO_FULL 5
#define TX_EMPTY 4
#define RX_FULL 1
#define RX_EMPTY 0
/* Instruction Mnemonics */
#define R_REGISTER 0x00
#define W_REGISTER 0x20
#define REGISTER_MASK 0x1F
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xA0
#define FLUSH_TX 0xE1
#define FLUSH_RX 0xE2
#define REUSE_TX_PL 0xE3
#define NOP 0xFF
/* Nrf24l settings */
#define ADDR_LEN 5
#define NRF_CONFIG ((1<<EN_CRC) | (0<<CRCO) )
#define MAX_BUFFER 32
#define HIGH 1
#define LOW 0
namespace upm {
typedef void (* funcPtrVoidVoid) ();
/**
* @brief C++ API for NRF24l01 transceiver module
*
* This file defines the NRF24l01 C++ interface for libnrf24l01
*
* @snippet nrf_receiver.cxx Interesting
* @snippet nrf_transmitter.cxx Interesting
*/
class NRF24l01 {
public:
/**
* Instanciates a NRF24l01 object
*
* @param cs chip select pin
*/
NRF24l01 (uint8_t cs);
/**
* NRF24l01 object destructor
*/
~NRF24l01 ();
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
/**
* Initialize needed Gpio pins and SPI interface
*
* @param chipSelect setting up the chip select pin
* @param chipEnable setting up the chip enable pin
*/
void nrfInitModule (uint8_t chipSelect, uint8_t chipEnable);
/**
* Configure NRF24l01 chip
*/
void nrfConfigModule ();
/**
* Send the buffer data
*
* @param *value pointer to the buffer
*/
void nrfSend (uint8_t *value);
/**
* Send the data located in inner bufer, user must fill the
* m_txBuffer buffer
*/
void nrfSend ();
/**
* Set recieving address of the device
*
* @param addr 5 bytes addres
*/
void nrfSetRXaddr (uint8_t * addr);
/**
* Set recipient address. nrfSend method will send the data buffer
* to this address
*
* @param addr 5 bytes addres
*/
void nrfSetTXaddr (uint8_t * addr);
/**
* Set broadcasting address.
*
* @param addr 5 bytes addres
*/
void nrfSetBroadcastAddr (uint8_t * addr);
/**
* Set payload size.
*
* @param load size of the payload (MAX 32)
*/
void nrfSetPayload (uint8_t load);
/**
* Check if data arrived
*/
bool nrfDataReady ();
/**
* Check if chip in sending mode
*/
bool nrfIsSending ();
/**
* Check if recieving stack is empty
*/
bool nrfRXFifoEmpty ();
/**
* Check if transmitting stack is empty
*/
bool nrfTXFifoEmpty ();
/**
* Sink all arrived data into the provided buffer
*
* @param load size of the payload (MAX 32)
*/
void nrfGetData (uint8_t * data);
/**
* Check the chip state
*/
uint8_t nrfGetStatus ();
/**
* Transmit provided data to the chip
*
* @param *dataout pointer to the buffer with data
* @param len length of the buffer
*/
void nrfTransmitSync (uint8_t *dataout, uint8_t len);
/**
* Recieve data from the chip
*
* @param *dataout pointer to the buffer with data
* @param *datain pointer to the buffer where the arrived data
* will be sinked
* @param len length of the buffer
*/
void nrfTransferSync (uint8_t *dataout ,uint8_t *datain, uint8_t len);
/**
* Write byte value into a register
*
* @param reg register address
* @param value the value to write
*/
void nrfConfigRegister (uint8_t reg, uint8_t value);
/**
* Read continues data from register
*
* @param reg register address
* @param *value pointer to the buffer
* @param len length of the buffer
*/
void nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len);
/**
* Write continues data to register
*
* @param reg register address
* @param *value pointer to the buffer
* @param len length of the buffer
*/
void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);
/**
* Power up reciever
*/
void nrfPowerUpRX ();
/**
* Power up transmitter
*/
void nrfPowerUpTX ();
/**
* Power down all
*/
void nrfPowerDown ();
/**
* Set chip enable pin HIGH
*/
maa_result_t nrfCEHigh ();
/**
* Set chip enable LOW
*/
maa_result_t nrfCELow ();
/**
* Set chip select pin LOW
*/
maa_result_t nrfCSOn ();
/**
* Set chip select pin HIGH
*/
maa_result_t nrfCSOff ();
/**
* Flush reciver stack
*/
void nrfFlushRX ();
/**
* Pulling method which listenning for arrived data, if data
* arrived dataRecievedHandler will be triggered
*/
void nrfListenForChannel();
uint8_t m_rxBuffer[MAX_BUFFER]; /**< Reciver buffer */
uint8_t m_txBuffer[MAX_BUFFER]; /**< Transmit buffer */
funcPtrVoidVoid dataRecievedHandler; /**< Data arrived handler */
private:
maa_spi_context m_spi;
uint8_t m_ce;
uint8_t m_csn;
uint8_t m_channel;
uint8_t m_ptx;
uint8_t m_payload;
uint8_t m_localAddress[5];
maa_gpio_context m_csnPinCtx;
maa_gpio_context m_cePinCtx;
std::string m_name;
};
}

View File

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

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

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

@ -0,0 +1,5 @@
set (libname "servo")
set (libdescription "upm servo")
set (module_src servo.cxx es08a.cxx)
set (module_h servo.h es08a.h)
upm_module_init()

39
src/servo/es08a.cxx Normal file
View File

@ -0,0 +1,39 @@
/*
* 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 "es08a.h"
using namespace upm;
ES08A::ES08A (int pin) : Servo(pin) {
m_name = "ES08A";
m_maxAngle = 180.0;
}
ES08A::~ES08A() {
}

57
src/servo/es08a.h Normal file
View File

@ -0,0 +1,57 @@
/*
* 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 "servo.h"
namespace upm {
#define MIN_PULSE_WIDTH 600
#define MAX_PULSE_WIDTH 2500
/**
* @brief C++ API for ES08A servo component
*
* This file defines the ES08A C++ interface for libes08a
*
* @snippet es08a.cxx Interesting
*
*/
class ES08A : public Servo {
public:
/**
* Instanciates a ES08A object
*
* @param pin servo pin number
*/
ES08A (int pin);
/**
* ES08A object destructor.
*/
~ES08A ();
};
}

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

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

8
src/servo/pyupm_servo.i Normal file
View File

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

88
src/servo/servo.cxx Normal file
View File

@ -0,0 +1,88 @@
/*
* 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 "servo.h"
using namespace upm;
Servo::Servo (int pin) {
maa_result_t error = MAA_SUCCESS;
m_maxAngle = 180.0;
m_servoPin = pin;
m_pwmServoContext = maa_pwm_init (m_servoPin);
}
Servo::~Servo () {
}
/*
* X = between (MIN_PULSE_WIDTH , MAX_PULSE_WIDTH)
*
* X usec
* _______
* |_______________________________________
* 20000 usec
*
* Max period can be only 7968750(nses) which is ~8(msec)
* so the servo wil not work as expected.
* */
maa_result_t Servo::setAngle (int angle) {
if (m_pwmServoContext == NULL) {
std::cout << "PWM context is NULL" << std::endl;
return MAA_ERROR_UNSPECIFIED;
}
maa_pwm_enable (m_pwmServoContext, 1);
for (int cycles = 0; cycles < 128; cycles++) {
maa_pwm_period_us (m_pwmServoContext, MAX_PERIOD);
maa_pwm_pulsewidth_us (m_pwmServoContext, calcPulseTraveling(angle));
}
maa_pwm_enable (m_pwmServoContext, 0);
std::cout << "angle = " << angle << " ,pulse = " << calcPulseTraveling(angle) << std::endl;
}
/*
* Calculating relative pulse time to the value.
* */
int Servo::calcPulseTraveling (int value) {
// if bigger than the boundaries
if (value > m_maxAngle) {
return MAX_PULSE_WIDTH;
}
// if less than the boundaries
if (value < 0) {
return MIN_PULSE_WIDTH;
}
// the conversion
return (int) ((float)MIN_PULSE_WIDTH + ((float)value / m_maxAngle) * ((float)MAX_PULSE_WIDTH - (float)MIN_PULSE_WIDTH));
}

92
src/servo/servo.h Normal file
View File

@ -0,0 +1,92 @@
/*
* 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/pwm.h>
namespace upm {
#define MIN_PULSE_WIDTH 600
#define MAX_PULSE_WIDTH 2500
#define MAX_PERIOD 7968
#define HIGH 1
#define LOW 0
/**
* @brief Base class for other servo components
*
* PMOD pins for MAX44000PMB1 board
*
*/
class Servo {
public:
/**
* Instanciates a servo object
*
* @param pin servo pin number
*/
Servo (int pin);
/**
* Servo object destructor.
*/
~Servo();
/**
* Set the of the servo engine.
*
* X = between (MIN_PULSE_WIDTH , MAX_PULSE_WIDTH)
*
* X usec
* _______
* |_______________________________________
* 20000 usec
*
* Max period can be only 7968750(nses) which is ~8(msec)
* so the servo will not work as expected.
*
* @param angle number between 0 and 180
*/
maa_result_t setAngle (int angle);
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
protected:
int calcPulseTraveling (int value);
std::string m_name;
int m_servoPin;
float m_maxAngle;
maa_pwm_context m_pwmServoContext;
// maa_gpio_context m_servoPinCtx;
};
}

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()

View File

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

View File

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

191
src/tm1637/tm1637.cxx Normal file
View File

@ -0,0 +1,191 @@
/*
* 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 "tm1637.h"
using namespace upm;
const uint8_t digitToSegment[] = {
// XGFEDCBA
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111, // 9
0b01110111, // A
0b01111100, // B
0b00111001, // C
0b01000111, // D
0b01111001, // E
0b01110001 // F
};
TM1637::TM1637 (uint8_t di, uint8_t dcki) {
maa_result_t error = MAA_SUCCESS;
maa_init();
// init clock context
m_clkPinCtx = maa_gpio_init(dcki);
if (m_clkPinCtx == NULL) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
exit(1);
}
// init data context
m_dataPinCtx = maa_gpio_init(di);
if (m_dataPinCtx == NULL) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
exit(1);
}
// set direction (out)
error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_IN);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
// set direction (out)
error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_IN);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_write (m_dataPinCtx, LOW);
error = maa_gpio_write (m_clkPinCtx, LOW);
}
TM1637::~TM1637() {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_close (m_dataPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_clkPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
maa_result_t
TM1637::setBrightness (uint8_t level) {
m_brightness = level;
}
maa_result_t
TM1637::setSegments (const uint8_t segments[], uint8_t length, uint8_t pos) {
start();
writeByte(TM1637_I2C_COMM1);
stop();
start();
writeByte(TM1637_I2C_COMM2 + (pos & 0x03));
for (uint8_t idx = 0; idx < length; idx++) {
writeByte(segments[idx]);
}
stop();
start();
writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
stop();
}
maa_result_t
TM1637::write (std::string msg) {
char leter = '\0';
uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
for (uint8_t idx = 0; idx < msg.length(); idx++) {
leter = msg[idx];
if (idx < 4) {
data[idx] = digitToSegment[strtol(&leter, NULL, 16)];
}
}
setBrightness (0x0f);
setSegments(data);
}
maa_result_t
TM1637::pinMode (maa_gpio_context ctx, gpio_dir_t mode) {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_dir(ctx, mode);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
maa_result_t
TM1637::start() {
pinMode (m_dataPinCtx, MAA_GPIO_OUT);
usleep(PULSE_LENGTH);
}
maa_result_t
TM1637::stop() {
pinMode (m_dataPinCtx, MAA_GPIO_OUT);
usleep(PULSE_LENGTH);
pinMode (m_clkPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
pinMode (m_dataPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
}
maa_result_t
TM1637::writeByte(uint8_t value) {
for (uint8_t idx = 0; idx < 8; idx++) {
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
usleep(PULSE_LENGTH);
if (value & 0x01) {
pinMode(m_dataPinCtx, MAA_GPIO_IN);
} else {
pinMode(m_dataPinCtx, MAA_GPIO_OUT);
}
usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
value = value >> 1;
}
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
pinMode(m_dataPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
uint8_t ack = maa_gpio_read (m_dataPinCtx);
if (ack == 0) {
pinMode(m_dataPinCtx, MAA_GPIO_OUT);
} usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
usleep(50);
}

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

@ -0,0 +1,125 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <maa/aio.h>
#include <maa/gpio.h>
#define SEG_A 0b00000001
#define SEG_B 0b00000010
#define SEG_C 0b00000100
#define SEG_D 0b00001000
#define SEG_E 0b00010000
#define SEG_F 0b00100000
#define SEG_G 0b01000000
#define TM1637_I2C_COMM1 0x40
#define TM1637_I2C_COMM2 0xC0
#define TM1637_I2C_COMM3 0x80
#define PULSE_LENGTH 50
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for Seven segments screen
*
* This file defines the TM1637 C++ interface for lib4digitdisplay
*
* @snippet 4digitdisplay.cxx Interesting
*
* A
* ---
* F | | B
* -G-
* E | | C
* ---
* D
*
*/
class TM1637 {
public:
/**
* Instanciates a TM1637 object
*
* @param di data pin
* @param dcki clock pin
*/
TM1637 (uint8_t di, uint8_t dcki);
/**
* TM1637 object destructor, this will close all used Gpio
* pins (di and dcki)
*/
~TM1637 ();
/**
* Set the brightness of the seven segment display
*
* @param level The brightness level of leds
*/
maa_result_t setBrightness (uint8_t level);
/**
* Set the the segment screen data and number of segments
*
* @param segments[] data to write on the segments, each elemnt
* in array is segment
* @param length number of elements in segments array
* @param pos data writing offset
*/
maa_result_t setSegments (const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
/**
* Write message on the screen.
*
* @param msg The message to be written on the sreen
*/
maa_result_t write (std::string msg);
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
maa_result_t start();
maa_result_t stop();
maa_result_t writeByte (uint8_t value);
maa_result_t pinMode (maa_gpio_context ctx, gpio_dir_t mode);
maa_gpio_context m_clkPinCtx;
maa_gpio_context m_dataPinCtx;
std::string m_name;
uint8_t m_brightness;
};
}