mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
Lcm1602: clean up API and use maa_result_t
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
parent
77d103f396
commit
1d74ead4cc
@ -68,12 +68,15 @@ using namespace upm;
|
|||||||
|
|
||||||
Lcm1602::Lcm1602(int bus_in, int addr_in)
|
Lcm1602::Lcm1602(int bus_in, int addr_in)
|
||||||
{
|
{
|
||||||
address = addr_in;
|
m_address = addr_in;
|
||||||
bus = bus_in;
|
m_bus = bus_in;
|
||||||
maa_init();
|
|
||||||
m_i2c = maa_i2c_init(bus);
|
|
||||||
|
|
||||||
maa_i2c_address(m_i2c, address);
|
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);
|
usleep(50000);
|
||||||
expandWrite(LCD_BACKLIGHT);
|
expandWrite(LCD_BACKLIGHT);
|
||||||
@ -98,7 +101,6 @@ Lcm1602::Lcm1602(int bus_in, int addr_in)
|
|||||||
send(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT, 0);
|
send(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT, 0);
|
||||||
|
|
||||||
home();
|
home();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -122,53 +124,53 @@ Lcm1602::cursor(int row, int column)
|
|||||||
return send(LCD_SETDDRAMADDR | ((column % 16) + row_addr[row]),0);
|
return send(LCD_SETDDRAMADDR | ((column % 16) + row_addr[row]),0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
maa_result_t
|
||||||
Lcm1602::write(std::string msg)
|
Lcm1602::write(std::string msg)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
maa_result_t ret = MAA_SUCCESS;
|
||||||
for(std::string::size_type i = 0; i < msg.size(); ++i) {
|
for(std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||||
ret = send(msg[i], LCD_RS);
|
ret = send(msg[i], LCD_RS);
|
||||||
}
|
}
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
maa_result_t
|
||||||
Lcm1602::close()
|
Lcm1602::close()
|
||||||
{
|
{
|
||||||
return maa_i2c_stop(m_i2c);
|
return maa_i2c_stop(m_i2c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
maa_result_t
|
||||||
Lcm1602::send(char value, int mode)
|
Lcm1602::send(uint8_t value, int mode)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
maa_result_t ret = MAA_SUCCESS;
|
||||||
char h = value & 0xf0;
|
uint8_t h = value & 0xf0;
|
||||||
char l = (value << 4) & 0xf0;
|
uint8_t l = (value << 4) & 0xf0;
|
||||||
ret = write4bits(h | mode);
|
ret = write4bits(h | mode);
|
||||||
ret = write4bits(l | mode);
|
ret = write4bits(l | mode);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
maa_result_t
|
||||||
Lcm1602::write4bits(char value)
|
Lcm1602::write4bits(uint8_t value)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
maa_result_t ret = MAA_SUCCESS;
|
||||||
ret = expandWrite(value);
|
ret = expandWrite(value);
|
||||||
ret = pulseEnable(value);
|
ret = pulseEnable(value);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
maa_result_t
|
||||||
Lcm1602::expandWrite(char value)
|
Lcm1602::expandWrite(uint8_t value)
|
||||||
{
|
{
|
||||||
char buffer = value | LCD_BACKLIGHT;
|
uint8_t buffer = value | LCD_BACKLIGHT;
|
||||||
return maa_i2c_write_byte(m_i2c, buffer);
|
return maa_i2c_write_byte(m_i2c, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
maa_result_t
|
||||||
Lcm1602::pulseEnable(char value)
|
Lcm1602::pulseEnable(uint8_t value)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
maa_result_t ret = MAA_SUCCESS;
|
||||||
ret = expandWrite(value | LCD_EN);
|
ret = expandWrite(value | LCD_EN);
|
||||||
usleep(1);
|
usleep(1);
|
||||||
ret = expandWrite(value & ~LCD_EN);
|
ret = expandWrite(value & ~LCD_EN);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* 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
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
* the Software without restriction, including without limitation the rights to
|
* the Software without restriction, including without limitation the rights to
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
@ -48,16 +48,16 @@ public:
|
|||||||
// change cursor to row,column.
|
// change cursor to row,column.
|
||||||
int cursor(int row, int column);
|
int cursor(int row, int column);
|
||||||
//write a string at the position
|
//write a string at the position
|
||||||
int write(std::string msg);
|
maa_result_t write(std::string msg);
|
||||||
int close();
|
maa_result_t close();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int address;
|
int m_address;
|
||||||
int bus;
|
int m_bus;
|
||||||
int send(char value, int mode);
|
maa_result_t send(uint8_t value, int mode);
|
||||||
int write4bits(char value);
|
maa_result_t write4bits(uint8_t value);
|
||||||
int expandWrite(char value);
|
maa_result_t expandWrite(uint8_t value);
|
||||||
int pulseEnable(char value);
|
maa_result_t pulseEnable(uint8_t value);
|
||||||
maa_i2c_context m_i2c;
|
maa_i2c_context m_i2c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user