clang-format

This commit is contained in:
Martin Brodbeck 2022-05-31 09:47:43 +02:00
parent 275e012695
commit 440359d775
2 changed files with 43 additions and 76 deletions

40
lcd.cpp
View file

@ -29,8 +29,7 @@ constexpr int LCD_ENABLE_BIT = 0x04;
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{i2c}, i2c_addr{i2c_addr}, num_cols{num_cols}, num_lines{num_lines}
{
: i2c{i2c}, 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);
@ -54,9 +53,7 @@ void LCD::setCursor(int line, int position) {
sendByte(val, Mode::COMMAND);
}
void LCD::sendChar(char val) {
sendByte(val, Mode::CHARACTER);
}
void LCD::sendChar(char val) { sendByte(val, Mode::CHARACTER); }
void LCD::sendString(const std::string &str) {
for (const char &c : str) {
@ -64,17 +61,13 @@ void LCD::sendString(const std::string &str) {
}
}
void LCD::clear() {
sendByte(LCD_CLEARDISPLAY, Mode::COMMAND);
}
void LCD::clear() { sendByte(LCD_CLEARDISPLAY, Mode::COMMAND); }
void LCD::i2cWriteByte(uint8_t val)
{
void LCD::i2cWriteByte(uint8_t val) {
i2c_write_blocking(i2c, i2c_addr, &val, 1, false);
}
void LCD::toggleEnable(uint8_t val)
{
void LCD::toggleEnable(uint8_t val) {
// Toggle enable pin on LCD display
// We cannot do this too quickly or things don't work
constexpr uint64_t DELAY_US = 600;
@ -86,8 +79,7 @@ void LCD::toggleEnable(uint8_t val)
}
// The display is sent a byte as two separate nibble transfers
void LCD::sendByte(uint8_t val, Mode mode)
{
void LCD::sendByte(uint8_t val, Mode mode) {
uint8_t high = static_cast<int>(mode) | (val & 0xF0) | LCD_BACKLIGHT;
uint8_t low = static_cast<int>(mode) | ((val << 4) & 0xF0) | LCD_BACKLIGHT;
@ -96,23 +88,3 @@ void LCD::sendByte(uint8_t val, Mode mode)
i2cWriteByte(low);
toggleEnable(low);
}
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()
{
int ret{0};
/*uint8_t data = 1 << SHIFT_BACKLIGHT;
ret = i2c_write_blocking(i2c1, i2c_addr, &data, 1, false);*/
return ret;
}

15
lcd.h
View file

@ -6,19 +6,14 @@
#include "hardware/i2c.h"
#include "pico/stdlib.h"
enum class Mode
{
COMMAND,
CHARACTER
};
enum class Mode { COMMAND, CHARACTER };
class LCD
{
class LCD {
public:
LCD(i2c_inst_t *i2c, const uint gpio_sda, const uint gpio_scl,
const uint8_t i2c_addr = 0x27, uint8_t num_cols = 16, uint8_t num_lines = 2);
int backlight_off();
int backlight_on();
const uint8_t i2c_addr = 0x27, uint8_t num_cols = 16,
uint8_t num_lines = 2);
void sendString(const std::string &str);
void setCursor(int line, int position);
void clear();