mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
jhd1313m1: Initial C implementation
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
parent
7fe6f856a1
commit
64b142ecf3
@ -123,6 +123,7 @@ add_example (water)
|
||||
add_example (yg1006)
|
||||
add_example (biss0001)
|
||||
add_example (bmi160)
|
||||
add_example (jhd1313m1)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
|
58
examples/c/jhd1313m1.c
Normal file
58
examples/c/jhd1313m1.c
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// initialize a JHD1313m1 on I2C bus 0, LCD address 0x3e, RGB
|
||||
// address 0x62
|
||||
jhd1313m1_context lcd = jhd1313m1_init(0, 0x3e, 0x62);
|
||||
|
||||
if (!lcd)
|
||||
{
|
||||
printf("jhd1313m1_i2c_init() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
jhd1313m1_set_cursor(lcd, 0, 0);
|
||||
jhd1313m1_write(lcd, "Hello World 1", 13);
|
||||
|
||||
upm_delay(3);
|
||||
|
||||
// change background color to a dimmer pure green
|
||||
jhd1313m1_set_color(lcd, 0, 128, 0);
|
||||
|
||||
jhd1313m1_set_cursor(lcd, 1, 0);
|
||||
jhd1313m1_write(lcd, "Hello World 2", 13);
|
||||
|
||||
upm_delay(3);
|
||||
|
||||
jhd1313m1_close(lcd);
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
11
src/jhd1313m1/CMakeLists.txt
Normal file
11
src/jhd1313m1/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
upm_mixed_module_init (NAME jhd1313m1
|
||||
DESCRIPTION "upm JHD1313M1 RGB LCD display driver"
|
||||
C_HDR jhd1313m1.h
|
||||
C_SRC jhd1313m1.c
|
||||
# CPP_HDR jhd1313m1.hpp
|
||||
# CPP_SRC jhd1313m1.cxx
|
||||
# FTI_SRC jhd1313m1_fti.c
|
||||
# CPP_WRAPS_C
|
||||
REQUIRES mraa)
|
||||
# We need hd44780_bits.h from lcm1602
|
||||
include_directories("../lcm1602")
|
82
src/jhd1313m1/hd44780_bits.h
Normal file
82
src/jhd1313m1/hd44780_bits.h
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 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
|
||||
|
||||
// This file contains bit definitions for the HD44780 and compatible
|
||||
// LCD controllers. It is used primarily my the lcm1602 driver and
|
||||
// it's derivatives.
|
||||
//
|
||||
// Those values (DATA, CMD) are specific to the implementation of the
|
||||
// i2C expander in use, so may not be appropriate for inclusion into
|
||||
// this file. But for now, we will leave them here.
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// commands
|
||||
const uint8_t HD44780_CLEARDISPLAY = 0x01;
|
||||
const uint8_t HD44780_RETURNHOME = 0x02;
|
||||
const uint8_t HD44780_ENTRYMODESET = 0x04;
|
||||
const uint8_t HD44780_DISPLAYCONTROL = 0x08;
|
||||
const uint8_t HD44780_CURSORSHIFT = 0x10;
|
||||
const uint8_t HD44780_FUNCTIONSET = 0x20;
|
||||
|
||||
// flags for display entry mode
|
||||
const uint8_t HD44780_ENTRYRIGHT = 0x00;
|
||||
const uint8_t HD44780_ENTRYLEFT = 0x02;
|
||||
const uint8_t HD44780_ENTRYSHIFTINCREMENT = 0x01;
|
||||
const uint8_t HD44780_ENTRYSHIFTDECREMENT = 0x00;
|
||||
|
||||
// flags for display on/off control
|
||||
const uint8_t HD44780_DISPLAYON = 0x04;
|
||||
const uint8_t HD44780_DISPLAYOFF = 0x00;
|
||||
const uint8_t HD44780_CURSORON = 0x02;
|
||||
const uint8_t HD44780_CURSOROFF = 0x00;
|
||||
const uint8_t HD44780_BLINKON = 0x01;
|
||||
const uint8_t HD44780_BLINKOFF = 0x00;
|
||||
|
||||
// flags for display/cursor shift
|
||||
const uint8_t HD44780_DISPLAYMOVE = 0x08;
|
||||
const uint8_t HD44780_MOVERIGHT = 0x04;
|
||||
const uint8_t HD44780_MOVELEFT = 0x00;
|
||||
|
||||
// flags for function set
|
||||
const uint8_t HD44780_8BITMODE = 0x10;
|
||||
const uint8_t HD44780_4BITMODE = 0x00;
|
||||
const uint8_t HD44780_2LINE = 0x08;
|
||||
const uint8_t HD44780_1LINE = 0x00;
|
||||
const uint8_t HD44780_5x10DOTS = 0x04;
|
||||
const uint8_t HD44780_5x8DOTS = 0x00;
|
||||
|
||||
// flags for CGRAM
|
||||
const uint8_t HD44780_SETCGRAMADDR = 0x40;
|
||||
|
||||
// may be implementation specific
|
||||
const uint8_t HD44780_EN = 0x04; // Enable bit
|
||||
const uint8_t HD44780_RW = 0x02; // Read/Write bit
|
||||
const uint8_t HD44780_RS = 0x01; // Register select bit
|
||||
const uint8_t HD44780_DATA = 0x40;
|
||||
const uint8_t HD44780_CMD = 0x80;
|
||||
|
||||
const uint8_t HD44780_BACKLIGHT = 0x08;
|
||||
const uint8_t HD44780_NOBACKLIGHT = 0x00;
|
40
src/jhd1313m1/javaupm_jhd1313m1.i
Normal file
40
src/jhd1313m1/javaupm_jhd1313m1.i
Normal file
@ -0,0 +1,40 @@
|
||||
%module javaupm_i2clcd
|
||||
%include "../upm.i"
|
||||
%include "stdint.i"
|
||||
%include "typemaps.i"
|
||||
%include "arrays_java.i";
|
||||
|
||||
%apply signed char[] {uint8_t []};
|
||||
%ignore BasicFont;
|
||||
|
||||
%typemap(jni) (uint8_t *data, int bytes) "jbyteArray";
|
||||
%typemap(jtype) (uint8_t *data, int bytes) "byte[]";
|
||||
%typemap(jstype) (uint8_t *data, int bytes) "byte[]";
|
||||
|
||||
%typemap(javain) (uint8_t *data, int bytes) "$javainput";
|
||||
|
||||
%typemap(in) (uint8_t *data, int bytes) {
|
||||
$1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL);
|
||||
$2 = JCALL1(GetArrayLength, jenv, $input);
|
||||
}
|
||||
|
||||
%typemap(freearg) (uint8_t *data, int bytes) {
|
||||
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0);
|
||||
}
|
||||
|
||||
%{
|
||||
#include "jhd1313m1.hpp"
|
||||
%}
|
||||
|
||||
%include "jhd1313m1.hpp"
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_i2clcd");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
%}
|
367
src/jhd1313m1/jhd1313m1.c
Normal file
367
src/jhd1313m1/jhd1313m1.c
Normal file
@ -0,0 +1,367 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Based on UPM C++ drivers originally developed by:
|
||||
* 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 <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
|
||||
#include "jhd1313m1.h"
|
||||
#include "hd44780_bits.h"
|
||||
|
||||
jhd1313m1_context jhd1313m1_init(int bus, int lcd_addr, int rgb_addr)
|
||||
{
|
||||
jhd1313m1_context dev =
|
||||
(jhd1313m1_context)malloc(sizeof(struct _jhd1313m1_context));
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
// make sure MRAA is initialized
|
||||
int mraa_rv;
|
||||
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
|
||||
{
|
||||
printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv);
|
||||
jhd1313m1_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset((void *)dev, 0, sizeof(struct _jhd1313m1_context));
|
||||
|
||||
// initialize the MRAA contexts
|
||||
|
||||
if (!(dev->i2cLCD = mraa_i2c_init(bus)))
|
||||
{
|
||||
printf("%s: mraa_i2c_init(LCD) failed.\n", __FUNCTION__);
|
||||
jhd1313m1_close(dev);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// now check the address...
|
||||
if (mraa_i2c_address(dev->i2cLCD, lcd_addr) != MRAA_SUCCESS)
|
||||
{
|
||||
printf("%s: mraa_i2c_address(LCD) failed.\n", __FUNCTION__);
|
||||
|
||||
jhd1313m1_close(dev);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(dev->i2cRGB = mraa_i2c_init(bus)))
|
||||
{
|
||||
printf("%s: mraa_i2c_init(RGB) failed.\n", __FUNCTION__);
|
||||
jhd1313m1_close(dev);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// now check the address...
|
||||
if (mraa_i2c_address(dev->i2cRGB, rgb_addr) != MRAA_SUCCESS)
|
||||
{
|
||||
printf("%s: mraa_i2c_address(RGB) failed.\n", __FUNCTION__);
|
||||
|
||||
jhd1313m1_close(dev);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* HD44780 requires writing three times to initialize or reset
|
||||
according to the hardware errata on page 45 figure 23 of
|
||||
the Hitachi HD44780 datasheet */
|
||||
|
||||
/* First try */
|
||||
upm_delay_us(50000);
|
||||
jhd1313m1_command(dev, HD44780_FUNCTIONSET | HD44780_8BITMODE);
|
||||
|
||||
/* Second try */
|
||||
upm_delay_us(4500);
|
||||
jhd1313m1_command(dev, HD44780_FUNCTIONSET | HD44780_8BITMODE);
|
||||
|
||||
/* Third try */
|
||||
upm_delay_us(150);
|
||||
jhd1313m1_command(dev, HD44780_FUNCTIONSET | HD44780_8BITMODE);
|
||||
|
||||
/* Set 2 row mode and font size */
|
||||
jhd1313m1_command(dev, HD44780_FUNCTIONSET | HD44780_8BITMODE
|
||||
| HD44780_2LINE | HD44780_5x10DOTS);
|
||||
upm_delay_us(100);
|
||||
|
||||
jhd1313m1_display_on(dev, true);
|
||||
upm_delay_us(100);
|
||||
|
||||
jhd1313m1_clear(dev);
|
||||
upm_delay_us(2000);
|
||||
|
||||
jhd1313m1_command(dev, HD44780_ENTRYMODESET | HD44780_ENTRYLEFT
|
||||
| HD44780_ENTRYSHIFTDECREMENT);
|
||||
|
||||
jhd1313m1_backlight_on(dev, true);
|
||||
// full white
|
||||
jhd1313m1_set_color(dev, 0xff, 0xff, 0xff);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void jhd1313m1_close(jhd1313m1_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->i2cLCD)
|
||||
mraa_i2c_stop(dev->i2cLCD);
|
||||
if (dev->i2cRGB)
|
||||
mraa_i2c_stop(dev->i2cRGB);
|
||||
|
||||
free(dev);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_set_color(jhd1313m1_context dev, uint8_t r, uint8_t g,
|
||||
uint8_t b)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
mraa_result_t rv = MRAA_SUCCESS;
|
||||
rv = mraa_i2c_write_byte_data(dev->i2cRGB, 0, 0);
|
||||
rv = mraa_i2c_write_byte_data(dev->i2cRGB, 0, 1);
|
||||
|
||||
rv = mraa_i2c_write_byte_data(dev->i2cRGB, r, 0x04);
|
||||
rv = mraa_i2c_write_byte_data(dev->i2cRGB, g, 0x03);
|
||||
rv = mraa_i2c_write_byte_data(dev->i2cRGB, b, 0x02);
|
||||
|
||||
if (rv)
|
||||
{
|
||||
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_write(const jhd1313m1_context dev, char *buffer,
|
||||
int len)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
upm_result_t error = UPM_SUCCESS;
|
||||
|
||||
int i;
|
||||
for (i=0; i<len; ++i)
|
||||
error = jhd1313m1_data(dev, buffer[i]);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_set_cursor(const jhd1313m1_context dev, unsigned int row,
|
||||
unsigned int column)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
column = column % 16;
|
||||
uint8_t offset = column;
|
||||
|
||||
// this should work for any display with two rows
|
||||
// DDRAM mapping:
|
||||
// 00 .. 27
|
||||
// 40 .. 67
|
||||
offset += row * 0x40;
|
||||
|
||||
return jhd1313m1_command(dev, HD44780_CMD | offset);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_clear(const jhd1313m1_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
upm_result_t ret;
|
||||
ret = jhd1313m1_command(dev, HD44780_CLEARDISPLAY);
|
||||
upm_delay_us(2000); // this command takes awhile
|
||||
return ret;
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_home(const jhd1313m1_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
upm_result_t ret;
|
||||
ret = jhd1313m1_command(dev, HD44780_RETURNHOME);
|
||||
upm_delay_us(2000); // this command takes awhile
|
||||
return ret;
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_create_char(const jhd1313m1_context dev,
|
||||
unsigned int slot,
|
||||
jhd1313m1_custom_char_t data)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
upm_result_t error = UPM_SUCCESS;
|
||||
|
||||
slot &= 0x07; // only have 8 positions we can set
|
||||
|
||||
error = jhd1313m1_command(dev, HD44780_SETCGRAMADDR | (slot << 3));
|
||||
|
||||
if (error == UPM_SUCCESS)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 8; i++) {
|
||||
error = jhd1313m1_data(dev, data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_display_on(const jhd1313m1_context dev, bool on)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (on)
|
||||
dev->displayControl |= HD44780_DISPLAYON;
|
||||
else
|
||||
dev->displayControl &= ~HD44780_DISPLAYON;
|
||||
|
||||
return jhd1313m1_command(dev, HD44780_DISPLAYCONTROL | dev->displayControl);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_cursor_on(const jhd1313m1_context dev, bool on)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (on)
|
||||
dev->displayControl |= HD44780_CURSORON;
|
||||
else
|
||||
dev->displayControl &= ~HD44780_CURSORON;
|
||||
|
||||
return jhd1313m1_command(dev, HD44780_DISPLAYCONTROL | dev->displayControl);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_cursor_blink_on(const jhd1313m1_context dev, bool on)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (on)
|
||||
dev->displayControl |= HD44780_BLINKON;
|
||||
else
|
||||
dev->displayControl &= ~HD44780_BLINKON;
|
||||
|
||||
return jhd1313m1_command(dev, HD44780_DISPLAYCONTROL | dev->displayControl);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_backlight_on(const jhd1313m1_context dev, bool on)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
mraa_result_t rv = MRAA_SUCCESS;
|
||||
if (on)
|
||||
rv = mraa_i2c_write_byte_data(dev->i2cRGB, 0xaa, 0x08);
|
||||
else
|
||||
rv = mraa_i2c_write_byte_data(dev->i2cRGB, 0x00, 0x08);
|
||||
|
||||
if (rv)
|
||||
{
|
||||
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_scroll(const jhd1313m1_context dev, bool direction)
|
||||
{
|
||||
if (direction)
|
||||
return jhd1313m1_scroll_display_left(dev);
|
||||
else
|
||||
return jhd1313m1_scroll_display_right(dev);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_scroll_display_left(const jhd1313m1_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return jhd1313m1_command(dev, HD44780_CURSORSHIFT | HD44780_DISPLAYMOVE
|
||||
| HD44780_MOVELEFT);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_scroll_display_right(const jhd1313m1_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return jhd1313m1_command(dev, HD44780_CURSORSHIFT | HD44780_DISPLAYMOVE
|
||||
| HD44780_MOVERIGHT);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_entry_left_to_right(const jhd1313m1_context dev, bool on)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (on)
|
||||
dev->entryDisplayMode |= HD44780_ENTRYLEFT;
|
||||
else
|
||||
dev->entryDisplayMode &= ~HD44780_ENTRYLEFT;
|
||||
|
||||
return jhd1313m1_command(dev, HD44780_ENTRYMODESET | dev->entryDisplayMode);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_autoscroll_on(const jhd1313m1_context dev, bool on)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (on)
|
||||
dev->entryDisplayMode |= HD44780_ENTRYSHIFTINCREMENT;
|
||||
else
|
||||
dev->entryDisplayMode &= ~HD44780_ENTRYSHIFTINCREMENT;
|
||||
|
||||
return jhd1313m1_command(dev, HD44780_ENTRYMODESET | dev->entryDisplayMode);
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_command(const jhd1313m1_context dev, uint8_t cmd)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (mraa_i2c_write_byte_data(dev->i2cLCD, cmd, HD44780_CMD))
|
||||
{
|
||||
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t jhd1313m1_data(const jhd1313m1_context dev, uint8_t cmd)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (mraa_i2c_write_byte_data(dev->i2cLCD, cmd, HD44780_DATA))
|
||||
{
|
||||
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
250
src/jhd1313m1/jhd1313m1.h
Normal file
250
src/jhd1313m1/jhd1313m1.h
Normal file
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Based on UPM C++ drivers originally developed by:
|
||||
* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <upm.h>
|
||||
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @file jhd1313m1.h
|
||||
* @library jhd1313m1
|
||||
* @brief C API for the JHD1313M1 family of LCD displays, like the
|
||||
* Grove RGB LCD
|
||||
*
|
||||
* @include jhd1313m1.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* Device context
|
||||
*/
|
||||
typedef struct _jhd1313m1_context {
|
||||
// I2C LCD command (lcm1602-like)
|
||||
mraa_i2c_context i2cLCD;
|
||||
// I2C RGB backlight control
|
||||
mraa_i2c_context i2cRGB;
|
||||
|
||||
// display command
|
||||
uint8_t displayControl;
|
||||
uint8_t entryDisplayMode;
|
||||
} *jhd1313m1_context;
|
||||
|
||||
/**
|
||||
* Custom character.
|
||||
*/
|
||||
typedef char jhd1313m1_custom_char_t[8];
|
||||
|
||||
/**
|
||||
* JHD1313M1 I2C initialization.
|
||||
*
|
||||
* @param bus I2C bus to use.
|
||||
* @param lcd_addr I2C address the LCD controller is on.
|
||||
* @param rgb_addr I2C address the RGB backlight controller is on.
|
||||
* @return Device Ccontext, or NULL on error.
|
||||
*/
|
||||
jhd1313m1_context jhd1313m1_init(int bus, int lcd_addr, int rgb_addr);
|
||||
|
||||
/**
|
||||
* JHD1313M1 close.
|
||||
*
|
||||
* @param dev The device context.
|
||||
*/
|
||||
void jhd1313m1_close(jhd1313m1_context dev);
|
||||
|
||||
/**
|
||||
* Writes a string to the LCD.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param buffer Character buffer containing characters to write to
|
||||
* the display; note: only ASCII characters are supported
|
||||
* @param len The number of characters to write.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_write(const jhd1313m1_context dev, char *buffer,
|
||||
int len);
|
||||
|
||||
/**
|
||||
* Sets the cursor to specified coordinates
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param row Row to set the cursor to.
|
||||
* @param column Column to set the cursor to.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_set_cursor(const jhd1313m1_context dev,
|
||||
unsigned int row, unsigned int column);
|
||||
|
||||
/**
|
||||
* Clears the display of all characters.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_clear(const jhd1313m1_context dev);
|
||||
|
||||
/**
|
||||
* Returns to the home coordinates (0,0).
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_home(const jhd1313m1_context dev);
|
||||
|
||||
/**
|
||||
* Sets the color of the backlight
|
||||
* Can be used to change the color even when the backlight is off
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param r 0-255 value for red
|
||||
* @param g 0-255 value for green
|
||||
* @param b 0-255 value for blue
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_set_color(const jhd1313m1_context dev,
|
||||
uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
/**
|
||||
* Create a custom character.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param slot The character slot to write, only 8 are available.
|
||||
* @param data The character data (8 bytes) making up the character.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_create_char(const jhd1313m1_context dev,
|
||||
unsigned int slot,
|
||||
jhd1313m1_custom_char_t data);
|
||||
|
||||
/**
|
||||
* Turn the display on.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param on true to turn display on, false otherwise.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_display_on(const jhd1313m1_context dev, bool on);
|
||||
|
||||
/**
|
||||
* Turn the cursor on.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param on true to turn cursor on, false otherwise.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_cursor_on(const jhd1313m1_context dev, bool on);
|
||||
|
||||
/**
|
||||
* Turn cursor blink on.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param on true to turn cursor blink on, false otherwise.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_cursor_blink_on(const jhd1313m1_context dev,
|
||||
bool on);
|
||||
|
||||
/**
|
||||
* Turn backlight on.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param on true to turn backlight on, false otherwise.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_backlight_on(const jhd1313m1_context dev, bool on);
|
||||
|
||||
/**
|
||||
* Scroll the display left, without changing the character RAM.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_scroll_display_left(const jhd1313m1_context dev);
|
||||
|
||||
/**
|
||||
* Scroll the display right, without changing the character RAM.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_scroll_display_right(const jhd1313m1_context dev);
|
||||
|
||||
/**
|
||||
* Set the entry mode so that characters are added left to right.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param on true to add characters left to right, false for right
|
||||
* to left.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_entry_left_to_right(const jhd1313m1_context dev,
|
||||
bool on);
|
||||
|
||||
/**
|
||||
* Right justify text entered from the cursor.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param on true right justify text, false to left justify text.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_autoscroll_on(const jhd1313m1_context dev, bool on);
|
||||
|
||||
/**
|
||||
* Send a command byte to the LCD controller. This is a low level
|
||||
* function that should not be used directly unless you know what
|
||||
* you are doing.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param cmd The command byte to send.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_command(const jhd1313m1_context dev, uint8_t cmd);
|
||||
|
||||
/**
|
||||
* Send a data byte the LCD controller. This is a low level
|
||||
* function that should not be used directly unless you know what
|
||||
* you are doing.
|
||||
*
|
||||
* @param dev The device context.
|
||||
* @param cmd The command byte to send.
|
||||
* @return UPM result.
|
||||
*/
|
||||
upm_result_t jhd1313m1_data(const jhd1313m1_context dev, uint8_t data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
8
src/jhd1313m1/jsupm_jhd1313m1.i
Normal file
8
src/jhd1313m1/jsupm_jhd1313m1.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_i2clcd
|
||||
%include "../upm.i"
|
||||
%include "../carrays_uint8_t.i"
|
||||
|
||||
%include "jhd1313m1.hpp"
|
||||
%{
|
||||
#include "jhd1313m1.hpp"
|
||||
%}
|
12
src/jhd1313m1/pyupm_jhd1313m1.i
Normal file
12
src/jhd1313m1/pyupm_jhd1313m1.i
Normal file
@ -0,0 +1,12 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_i2clcd
|
||||
%include "../upm.i"
|
||||
%include "../carrays_uint8_t.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "jhd1313m1.hpp"
|
||||
%{
|
||||
#include "jhd1313m1.hpp"
|
||||
%}
|
Loading…
x
Reference in New Issue
Block a user