LCD class introduced

This commit is contained in:
Martin Brodbeck 2022-05-30 16:09:09 +02:00
parent a5e3e3c671
commit 55c3b0f80a
2 changed files with 51 additions and 0 deletions

31
lcd.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "lcd.h"
constexpr uint8_t SHIFT_BACKLIGHT = 3;
LCD::LCD(i2c_inst_t *i2c, const uint gpio_sda, const uint gpio_scl,
const uint8_t i2c_addr, uint8_t num_cols, uint8_t num_lines)
: i2c_addr{i2c_addr}, num_cols{num_cols}, num_lines{num_lines} {
i2c_init(i2c1, 100 * 1000);
gpio_set_function(gpio_sda, GPIO_FUNC_I2C);
gpio_set_function(gpio_scl, GPIO_FUNC_I2C);
gpio_pull_up(gpio_sda);
gpio_pull_up(gpio_scl);
}
int LCD::backlight_off() {
uint8_t data = 0;
int ret{0};
ret = i2c_write_blocking(i2c1, i2c_addr, &data, 1, false);
return ret;
}
int LCD::backlight_on() {
uint8_t data = 1 << SHIFT_BACKLIGHT;
int ret{0};
ret = i2c_write_blocking(i2c1, i2c_addr, &data, 1, false);
return ret;
}

20
lcd.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef LCD_H
#define LCD_H
#include "hardware/i2c.h"
#include "pico/stdlib.h"
class LCD {
public:
LCD(i2c_inst_t *i2c, const uint gpio_sda, const uint gpio_scl,
const uint8_t i2c_addr, uint8_t num_cols = 16, uint8_t num_lines = 2);
int backlight_off();
int backlight_on();
private:
uint8_t i2c_addr;
uint8_t num_cols;
uint8_t num_lines;
};
#endif