mirror of
https://github.com/eclipse/upm.git
synced 2025-07-06 20:01:12 +03:00
Compare commits
42 Commits
Author | SHA1 | Date | |
---|---|---|---|
3be0cdf5c2 | |||
d1f7df0552 | |||
0340d736de | |||
a2ca2c1497 | |||
236cc9acc1 | |||
864306acf5 | |||
814cc4a0e8 | |||
1ff0e5ee57 | |||
38efe2d7a3 | |||
fa1753f4ef | |||
b73841b28b | |||
9c34b829ef | |||
451d0390b6 | |||
7d898e3274 | |||
b4ae08935d | |||
3ee752b297 | |||
557f63edf6 | |||
3ce441f0a8 | |||
039b138194 | |||
23d847e380 | |||
356b1dd43c | |||
794eb19bd7 | |||
fdb943c2eb | |||
4896881ea4 | |||
af09aeadc3 | |||
28b68b71c8 | |||
aac51c4850 | |||
f1cf463126 | |||
5b8922f7bf | |||
0db7af89f9 | |||
fdcd36e1ae | |||
83c29cc330 | |||
e63076ecf4 | |||
93aa79fe4b | |||
dd55123062 | |||
c60b342e0f | |||
e785b0f03b | |||
81278510c0 | |||
725fc4661c | |||
b26cbd09f1 | |||
1d74ead4cc | |||
77d103f396 |
@ -9,11 +9,42 @@ 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 ${maa_VERSION_MAJOR}.${maa_VERSION_MINOR}.${maa_VERSION_PATCH})
|
||||
|
||||
set (CMAKE_SWIG_FLAGS "")
|
||||
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
|
||||
# add a target to generate API documentation with Doxygen
|
||||
find_package (Doxygen)
|
||||
if (DOXYGEN_FOUND)
|
||||
@ -25,5 +56,32 @@ if (DOXYGEN_FOUND)
|
||||
)
|
||||
endif (DOXYGEN_FOUND)
|
||||
|
||||
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
20
COPYING
Normal 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.
|
12
Doxyfile.in
12
Doxyfile.in
@ -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
|
||||
|
222
cmake/modules/CPackDeb.cmake
Normal file
222
cmake/modules/CPackDeb.cmake
Normal 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" )
|
130
cmake/modules/GetGitRevisionDescription.cmake
Normal file
130
cmake/modules/GetGitRevisionDescription.cmake
Normal 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()
|
38
cmake/modules/GetGitRevisionDescription.cmake.in
Normal file
38
cmake/modules/GetGitRevisionDescription.cmake.in
Normal 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()
|
23
cmake/modules/LICENSE_1_0.txt
Normal file
23
cmake/modules/LICENSE_1_0.txt
Normal 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.
|
136
cmake/modules/TargetArch.cmake
Normal file
136
cmake/modules/TargetArch.cmake
Normal 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()
|
4
cmake/modules/version.c.in
Normal file
4
cmake/modules/version.c.in
Normal file
@ -0,0 +1,4 @@
|
||||
#include "version.h"
|
||||
|
||||
const char* gVERSION = "@VERSION@";
|
||||
const char* gVERSION_SHORT = "@VERSION_SHORT@";
|
42
examples/4digitdisplay.cxx
Normal file
42
examples/4digitdisplay.cxx
Normal 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;
|
||||
}
|
@ -2,12 +2,41 @@ 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)
|
||||
|
||||
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/ledbar)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/4digitdisplay)
|
||||
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)
|
||||
|
||||
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 ledbar ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (seg-lcd 4digitdisplay ${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})
|
||||
|
69
examples/buzzer-sound.cxx
Normal file
69
examples/buzzer-sound.cxx
Normal 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
70
examples/es08a.cxx
Normal 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
63
examples/hcsr04.cxx
Normal 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]
|
@ -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
63
examples/led-bar.cxx
Normal 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
42
examples/max44000.cxx
Normal 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;
|
||||
}
|
72
examples/nrf_receiver.cxx
Normal file
72
examples/nrf_receiver.cxx
Normal 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;
|
||||
}
|
74
examples/nrf_transmitter.cxx
Normal file
74
examples/nrf_transmitter.cxx
Normal 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
116
examples/oled-1308.cxx
Normal 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
126
examples/oled-1327.cxx
Normal 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
37
examples/rgb-lcd.cxx
Normal 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();
|
||||
}
|
12
src/4digitdisplay/CMakeLists.txt
Normal file
12
src/4digitdisplay/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
set (libname "4digitdisplay")
|
||||
add_library (4digitdisplay SHARED tm1637.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (4digitdisplay ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES tm1637.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm 4 Digit Buzzer")
|
||||
endif()
|
7
src/4digitdisplay/jsupm_tm1637.i
Normal file
7
src/4digitdisplay/jsupm_tm1637.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_tm1637
|
||||
|
||||
%{
|
||||
#include "tm1637.h"
|
||||
%}
|
||||
|
||||
%include "tm1637.h"
|
8
src/4digitdisplay/pyupm_tm1637.i
Normal file
8
src/4digitdisplay/pyupm_tm1637.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_tm1637
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "tm1637.h"
|
||||
%{
|
||||
#include "tm1637.h"
|
||||
%}
|
191
src/4digitdisplay/tm1637.cxx
Normal file
191
src/4digitdisplay/tm1637.cxx
Normal 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/4digitdisplay/tm1637.h
Normal file
125
src/4digitdisplay/tm1637.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
@ -1,3 +1,14 @@
|
||||
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()
|
||||
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
foreach(subdir ${SUBDIRS})
|
||||
add_subdirectory(${subdir})
|
||||
endforeach()
|
||||
|
12
src/buzzer/CMakeLists.txt
Normal file
12
src/buzzer/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
set (libname "buzzer")
|
||||
add_library (buzzer SHARED buzzer.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (buzzer ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES buzzer.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm buzzer")
|
||||
endif()
|
51
src/buzzer/buzzer.cxx
Normal file
51
src/buzzer/buzzer.cxx
Normal 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
80
src/buzzer/buzzer.h
Normal 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;
|
||||
};
|
||||
}
|
7
src/buzzer/jsupm_buzzer.i
Normal file
7
src/buzzer/jsupm_buzzer.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_buzzer
|
||||
|
||||
%{
|
||||
#include "buzzer.h"
|
||||
%}
|
||||
|
||||
%include "buzzer.h"
|
8
src/buzzer/pyupm_buzzer.i
Normal file
8
src/buzzer/pyupm_buzzer.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_buzzer
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "buzzer.h"
|
||||
%{
|
||||
#include "buzzer.h"
|
||||
%}
|
@ -37,3 +37,11 @@ if (SWIG_FOUND)
|
||||
endif ()
|
||||
|
||||
endif ()
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES grove.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm grove libary")
|
||||
endif()
|
||||
|
12
src/hcsr04/CMakeLists.txt
Normal file
12
src/hcsr04/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
set (libname "hcsr04")
|
||||
add_library (hcsr04 SHARED hcsr04.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (hcsr04 ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES hcsr04.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm proximity sensor")
|
||||
endif()
|
94
src/hcsr04/hcsr04.cxx
Normal file
94
src/hcsr04/hcsr04.cxx
Normal 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
99
src/hcsr04/hcsr04.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
7
src/hcsr04/jsupm_hcsr04.i
Normal file
7
src/hcsr04/jsupm_hcsr04.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_hcsr04
|
||||
|
||||
%{
|
||||
#include "hcsr04.h"
|
||||
%}
|
||||
|
||||
%include "hcsr04.h"
|
8
src/hcsr04/pyupm_hcsr04.i
Normal file
8
src/hcsr04/pyupm_hcsr04.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_hcsr04
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "hcsr04.h"
|
||||
%{
|
||||
#include "hcsr04.h"
|
||||
%}
|
@ -37,3 +37,11 @@ if (SWIG_FOUND)
|
||||
endif ()
|
||||
|
||||
endif ()
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES hmc5883l.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm Digital Compass")
|
||||
endif()
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
12
src/lcd/CMakeLists.txt
Normal file
12
src/lcd/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
set (libname "i2clcd")
|
||||
add_library (i2clcd SHARED iiclcd.cxx lcm1602.cxx jhd1313m1.cxx ssd1308.cxx ssd1327.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (i2clcd ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES iiclcd.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm lcd")
|
||||
endif()
|
86
src/lcd/iiclcd.cxx
Normal file
86
src/lcd/iiclcd.cxx
Normal 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 "iiclcd.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
IICLcd::IICLcd (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
|
||||
IICLcd::write (int row, int column, std::string msg) {
|
||||
setCursor (row, column);
|
||||
write (msg);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
IICLcd::close() {
|
||||
return maa_i2c_stop(m_i2c_lcd_control);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
IICLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
|
||||
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
|
||||
IICLcd::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
|
||||
IICLcd::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/iiclcd.h
Normal file
95
src/lcd/iiclcd.h
Normal 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 IICLcd {
|
||||
public:
|
||||
IICLcd (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
107
src/lcd/jhd1313m1.cxx
Normal 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) : IICLcd(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
45
src/lcd/jhd1313m1.h
Normal 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 "iiclcd.h"
|
||||
|
||||
namespace upm {
|
||||
|
||||
class Jhd1313m1 : public IICLcd {
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
7
src/lcd/jsupm_jhd1313m1.i
Normal file
7
src/lcd/jsupm_jhd1313m1.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_jhd1313m1
|
||||
|
||||
%{
|
||||
#include "jhd1313m1.h"
|
||||
%}
|
||||
|
||||
%include "jhd1313m1.h"
|
7
src/lcd/jsupm_ssd1308.i
Normal file
7
src/lcd/jsupm_ssd1308.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_ssd1308
|
||||
|
||||
%{
|
||||
#include "ssd1308.h"
|
||||
%}
|
||||
|
||||
%include "ssd1308.h"
|
7
src/lcd/jsupm_ssd1327.i
Normal file
7
src/lcd/jsupm_ssd1327.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_ssd1327
|
||||
|
||||
%{
|
||||
#include "ssd1327.h"
|
||||
%}
|
||||
|
||||
%include "ssd1327.h"
|
@ -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) : IICLcd (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);
|
@ -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 "iiclcd.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 IICLcd {
|
||||
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);
|
||||
};
|
||||
}
|
8
src/lcd/pyupm_jhd1313m1.i
Normal file
8
src/lcd/pyupm_jhd1313m1.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_jhd1313m1
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "jhd1313m1.h"
|
||||
%{
|
||||
#include "jhd1313m1.h"
|
||||
%}
|
8
src/lcd/pyupm_ssd1308.i
Normal file
8
src/lcd/pyupm_ssd1308.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_ssd1308
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "ssd1308.h"
|
||||
%{
|
||||
#include "ssd1308.h"
|
||||
%}
|
8
src/lcd/pyupm_ssd1327.i
Normal file
8
src/lcd/pyupm_ssd1327.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_ssd1327
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "ssd1327.h"
|
||||
%{
|
||||
#include "ssd1327.h"
|
||||
%}
|
139
src/lcd/ssd1308.cxx
Normal file
139
src/lcd/ssd1308.cxx
Normal 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) : IICLcd (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
170
src/lcd/ssd1308.h
Normal 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 "iiclcd.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 IICLcd {
|
||||
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
276
src/lcd/ssd1327.cxx
Normal 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) : IICLcd (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
175
src/lcd/ssd1327.h
Normal 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 "iiclcd.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 IICLcd {
|
||||
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;
|
||||
};
|
||||
}
|
@ -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 ()
|
13
src/ledbar/CMakeLists.txt
Normal file
13
src/ledbar/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
set (libname "ledbar")
|
||||
add_library (ledbar SHARED my9221.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (ledbar ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES my9221.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm LEDBAR")
|
||||
endif()
|
||||
|
7
src/ledbar/jsupm_my9221.i
Normal file
7
src/ledbar/jsupm_my9221.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_my9221
|
||||
|
||||
%{
|
||||
#include "my9221.h"
|
||||
%}
|
||||
|
||||
%include "my9221.h"
|
119
src/ledbar/my9221.cxx
Normal file
119
src/ledbar/my9221.cxx
Normal 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/ledbar/my9221.h
Normal file
85
src/ledbar/my9221.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
8
src/ledbar/pyupm_my9221.i
Normal file
8
src/ledbar/pyupm_my9221.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_my9221
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "my9221.h"
|
||||
%{
|
||||
#include "my9221.h"
|
||||
%}
|
12
src/max44000/CMakeLists.txt
Normal file
12
src/max44000/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
set (libname "max44000")
|
||||
add_library (max44000 SHARED max44000.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (max44000 ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES max44000.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm MAX44000")
|
||||
endif()
|
7
src/max44000/jsupm_max44000.i
Normal file
7
src/max44000/jsupm_max44000.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_max44000
|
||||
|
||||
%{
|
||||
#include "max44000.h"
|
||||
%}
|
||||
|
||||
%include "max44000.h"
|
114
src/max44000/max44000.cxx
Normal file
114
src/max44000/max44000.cxx
Normal 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;
|
||||
}
|
108
src/max44000/max44000.h
Normal file
108
src/max44000/max44000.h
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 ALSDATA_HIGH 0x04 // ambient sensor data high byte
|
||||
#define ALSDATA_LOW 0x05 // ambient sensor data low byte
|
||||
#define PRXDATA 0x15 // proximity sensor data
|
||||
#define MCR 0x01 // Main Configuration Register
|
||||
#define RCR 0x02 // Receive Configuration Register
|
||||
#define TCR 0x03 // Transmit Configuration 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;
|
||||
}
|
||||
private:
|
||||
uint16_t getALSData ();
|
||||
uint16_t getPRXData ();
|
||||
|
||||
uint8_t i2cReadReg_8 (int reg);
|
||||
uint16_t i2cReadReg_16 (int reg);
|
||||
maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
std::string m_name;
|
||||
|
||||
int m_maxControlAddr;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2cMaxControlCtx;
|
||||
};
|
||||
|
||||
}
|
8
src/max44000/pyupm_max44000.i
Normal file
8
src/max44000/pyupm_max44000.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_max44000
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "max44000.h"
|
||||
%{
|
||||
#include "max44000.h"
|
||||
%}
|
12
src/nrf24l01/CMakeLists.txt
Normal file
12
src/nrf24l01/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
set (libname "nrf24l01")
|
||||
add_library (nrf24l01 SHARED nrf24l01.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (nrf24l01 ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES nrf24l01.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm NRF tx/rx")
|
||||
endif()
|
7
src/nrf24l01/jsupm_nrf24l01.i
Normal file
7
src/nrf24l01/jsupm_nrf24l01.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_nrf24l01
|
||||
|
||||
%{
|
||||
#include "nrf24l01.h"
|
||||
%}
|
||||
|
||||
%include "nrf24l01.h"
|
320
src/nrf24l01/nrf24l01.cxx
Normal file
320
src/nrf24l01/nrf24l01.cxx
Normal 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
347
src/nrf24l01/nrf24l01.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
8
src/nrf24l01/pyupm_nrf24l01.i
Normal file
8
src/nrf24l01/pyupm_nrf24l01.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_nrf24l01
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "nrf24l01.h"
|
||||
%{
|
||||
#include "nrf24l01.h"
|
||||
%}
|
12
src/servo/CMakeLists.txt
Normal file
12
src/servo/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
set (libname "servo")
|
||||
add_library (servo SHARED servo.cxx es08a.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (servo ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES servo.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm servo")
|
||||
endif()
|
39
src/servo/es08a.cxx
Normal file
39
src/servo/es08a.cxx
Normal 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
57
src/servo/es08a.h
Normal 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_es08a.i
Normal file
7
src/servo/jsupm_es08a.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_es08a
|
||||
|
||||
%{
|
||||
#include "es08a.h"
|
||||
%}
|
||||
|
||||
%include "es08a.h"
|
8
src/servo/pyupm_es08a.i
Normal file
8
src/servo/pyupm_es08a.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_es08a
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "es08a.h"
|
||||
%{
|
||||
#include "es08a.h"
|
||||
%}
|
88
src/servo/servo.cxx
Normal file
88
src/servo/servo.cxx
Normal 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
92
src/servo/servo.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user