112 lines
3.0 KiB
C++
112 lines
3.0 KiB
C++
#ifndef LCD2004_HPP
|
|
#define LCD2004_HPP
|
|
|
|
#include "driver/i2c_master.h"
|
|
#include <stdint.h>
|
|
|
|
#define LCD2004_CLK_SPEED_HZ 100000
|
|
|
|
#define I2C_MASTER_TIMEOUT_MS 1000
|
|
|
|
class LCD2004I2C {
|
|
private:
|
|
i2c_master_dev_handle_t lcd_device_handle;
|
|
/// Weather or not the backlight is on.
|
|
/// `BACKLIGHT_MASK` if backlight is on,
|
|
/// `0` if backlight is off.
|
|
uint8_t backlight;
|
|
/// The mask for the display control command.
|
|
uint8_t display_control;
|
|
uint8_t entry_mode;
|
|
|
|
void send_cmd(uint8_t cmd);
|
|
void send_data(uint8_t data);
|
|
void send4_cmd(uint8_t cmd);
|
|
|
|
public:
|
|
/// Constructs a new LCD2004 device.
|
|
LCD2004I2C();
|
|
|
|
/// Initializes the LCD2004 device. Must be called before any other methods.
|
|
///
|
|
/// The address is usually `0x27`.
|
|
void init(uint8_t addr);
|
|
|
|
/// Gets the state of the backlight of the module.
|
|
bool get_backlight();
|
|
|
|
/// Sets the backlight of the module to be on or off.
|
|
void set_backlight(bool backlight);
|
|
|
|
/// Clears the display, and resets the cursor to
|
|
void clear();
|
|
|
|
/// Moves the cursor to `row` and `col`.
|
|
void move_cursor(uint8_t row, uint8_t col);
|
|
|
|
/// Returns `true` iff the display is showing.
|
|
bool get_show_hide();
|
|
|
|
/// Shows or hides the display.
|
|
void show_hide(bool show);
|
|
|
|
/// Returns `true` iff the cursor display is showing.
|
|
bool get_show_cursor();
|
|
|
|
/// Shows or hides the cursor.
|
|
void show_cursor(bool show_cursor);
|
|
|
|
/// Returns `true` iff the cursor is blinking.
|
|
///
|
|
/// This value is stored even if the cursor is not visible.
|
|
bool get_blink_cursor();
|
|
|
|
/// Blinks or stops blinking the cursor.
|
|
void blink_cursor(bool blink_cursor);
|
|
|
|
/// Sets the cursor show state and blink state.
|
|
void show_blink_cursor(bool show_cursor, bool blink_cursor);
|
|
|
|
/// Returns `true` iff the display scrolls left to right.
|
|
bool get_scroll_direction();
|
|
|
|
/// Sets the scroll direction for the display.
|
|
void scroll_direction(bool left_to_right);
|
|
|
|
/// Returns `true` iff the display is shifting with the cursor.
|
|
bool get_display_shift();
|
|
|
|
/// Sets the display to shift with the cursor.
|
|
///
|
|
/// This is like autoscrolling.
|
|
void shift_display(bool shift_display);
|
|
|
|
/// Shifts the cursor left 1
|
|
void shift_cursor_left();
|
|
|
|
/// Shifts the cursor right 1
|
|
void shift_cursor_right();
|
|
|
|
/// Shifts the display left 1
|
|
void shift_display_left();
|
|
|
|
/// Shifts the display right 1
|
|
void shift_display_right();
|
|
|
|
/// Sets the character map for a custom character.
|
|
///
|
|
/// There are 8 locations (0..=7), for 8 characters.
|
|
/// You can print these characters by sending '\x00' - '\x07'.
|
|
void create_custom_char(uint8_t location, const uint8_t char_map[8]);
|
|
|
|
/// Prints a single character to the display.
|
|
void print_char(char c);
|
|
|
|
/// Prints a single byte to the display.
|
|
void print_u8(uint8_t b);
|
|
|
|
/// Writes a string to the display.
|
|
void write_str(const char* s);
|
|
};
|
|
|
|
#endif // LCD2004_HPP
|