mirror of
https://github.com/eclipse/upm.git
synced 2025-03-14 20:47:30 +03:00
lcd: added grove-lcd rgb and deleted the old lcm1602 folder
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
This commit is contained in:
parent
e785b0f03b
commit
c60b342e0f
@ -2,15 +2,17 @@ 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)
|
||||
|
||||
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)
|
||||
|
||||
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})
|
||||
|
@ -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();
|
||||
}
|
||||
|
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();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
add_subdirectory (hmc5883l)
|
||||
add_subdirectory (grove)
|
||||
add_subdirectory (lcm1602)
|
||||
add_subdirectory (lcd)
|
||||
add_subdirectory (buzzer)
|
||||
|
4
src/lcd/CMakeLists.txt
Normal file
4
src/lcd/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
set (libname "i2clcd")
|
||||
add_library (i2clcd SHARED iiclcd.cxx lcm1602.cxx jhd1313m1.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (i2clcd ${MAA_LIBRARIES})
|
53
src/lcd/iiclcd.cxx
Normal file
53
src/lcd/iiclcd.cxx
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
90
src/lcd/iiclcd.h
Normal file
90
src/lcd/iiclcd.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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_SETCGRAMADDR 0x40
|
||||
#define LCD_SETDDRAMADDR 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);
|
||||
virtual maa_result_t write (std::string msg) = 0;
|
||||
maa_result_t write (int x, int y, std::string msg);
|
||||
virtual maa_result_t setCursor (int row, int column) = 0;
|
||||
virtual maa_result_t clear () = 0;
|
||||
virtual maa_result_t home () = 0;
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
140
src/lcd/jhd1313m1.cxx
Normal file
140
src/lcd/jhd1313m1.cxx
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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);
|
||||
cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
usleep(4500);
|
||||
cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
usleep(4500);
|
||||
cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
usleep(4500);
|
||||
cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
|
||||
cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
|
||||
clear ();
|
||||
usleep(4500);
|
||||
|
||||
cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
|
||||
LCD_ENTRYLEFT |
|
||||
LCD_ENTRYSHIFTDECREMENT);
|
||||
|
||||
setReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
|
||||
setReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
|
||||
setReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
|
||||
|
||||
setReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
|
||||
setReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
|
||||
setReg (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) {
|
||||
data[1] = msg[i];
|
||||
error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
|
||||
error = maa_i2c_write (m_i2c_lcd_control, data, 2);
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
uint8_t data[2] = { 0x80, offset };
|
||||
error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
|
||||
error = maa_i2c_write (m_i2c_lcd_control, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
Jhd1313m1::clear () {
|
||||
return cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
Jhd1313m1::home () {
|
||||
return cmd (m_i2c_lcd_control, LCD_RETURNHOME);
|
||||
}
|
||||
|
||||
/*
|
||||
* **************
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
Jhd1313m1::setReg (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
|
||||
Jhd1313m1::cmd (maa_i2c_context ctx, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { 0x80, value };
|
||||
error = maa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = maa_i2c_write (ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
48
src/lcd/jhd1313m1.h
Normal file
48
src/lcd/jhd1313m1.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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:
|
||||
maa_result_t cmd (maa_i2c_context ctx, uint8_t value);
|
||||
maa_result_t setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
|
||||
|
||||
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"
|
@ -30,56 +30,13 @@
|
||||
|
||||
#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)
|
||||
{
|
||||
m_address = addr_in;
|
||||
m_bus = bus_in;
|
||||
Lcm1602::Lcm1602(int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
|
||||
m_i2c = maa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2c, m_address);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
usleep(50000);
|
||||
expandWrite(LCD_BACKLIGHT);
|
||||
usleep(50000);
|
||||
expandWrite(LCD_BACKLIGHT);
|
||||
usleep(100000);
|
||||
|
||||
write4bits(0x03 << 4);
|
||||
@ -103,47 +60,52 @@ Lcm1602::Lcm1602(int bus_in, int addr_in)
|
||||
home();
|
||||
}
|
||||
|
||||
int
|
||||
Lcm1602::clear()
|
||||
{
|
||||
return send(LCD_CLEARDISPLAY, 0);
|
||||
}
|
||||
|
||||
int
|
||||
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);
|
||||
Lcm1602::~Lcm1602 () {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* **************
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
Lcm1602::write(std::string msg)
|
||||
{
|
||||
maa_result_t ret = MAA_SUCCESS;
|
||||
for(std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
ret = send(msg[i], LCD_RS);
|
||||
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 ret;
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
Lcm1602::close()
|
||||
{
|
||||
return maa_i2c_stop(m_i2c);
|
||||
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_SETDDRAMADDR | offset, 0);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
Lcm1602::send(uint8_t value, int mode)
|
||||
{
|
||||
maa_result_t ret = MAA_SUCCESS;
|
||||
maa_result_t
|
||||
Lcm1602::clear () {
|
||||
return send(LCD_CLEARDISPLAY, 0);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
Lcm1602::home () {
|
||||
return send(LCD_RETURNHOME, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* **************
|
||||
* 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);
|
||||
@ -164,7 +126,7 @@ maa_result_t
|
||||
Lcm1602::expandWrite(uint8_t value)
|
||||
{
|
||||
uint8_t buffer = value | LCD_BACKLIGHT;
|
||||
return maa_i2c_write_byte(m_i2c, buffer);
|
||||
return maa_i2c_write_byte(m_i2c_lcd_control, buffer);
|
||||
}
|
||||
|
||||
maa_result_t
|
@ -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
|
||||
maa_result_t write(std::string msg);
|
||||
maa_result_t close();
|
||||
|
||||
private:
|
||||
int m_address;
|
||||
int m_bus;
|
||||
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);
|
||||
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"
|
||||
%}
|
@ -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 ()
|
Loading…
x
Reference in New Issue
Block a user