Files
Embedded-Hacking/0x0017_constants/lcd_1602.h
T
2025-10-24 17:34:51 -04:00

75 lines
2.5 KiB
C

/**
* @file lcd_1602.h
* @brief Header for PCF8574-backed HD44780 (16x2) LCD driver
* @author Kevin Thomas
* @date 2025
*
* MIT License
*
* Copyright (c) 2025 Kevin Thomas
*
* 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.
*/
#ifndef LCD_1602_H
#define LCD_1602_H
#include <stdint.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
/**
* @brief Initialize the LCD driver over I2C
*
* Configures the internal driver state and performs the HD44780 initialization
* sequence. The driver does not configure I2C pins or call i2c_init; that
* must be done by the caller prior to calling this function.
*
* @param i2c Pointer to the I2C instance (e.g. i2c0 or i2c1)
* @param pcf_addr PCF8574 I2C address (commonly 0x27 or 0x3F)
* @param nibble_shift Bit shift applied to 4-bit nibbles (commonly 4 or 0)
* @param backlight_mask PCF8574 bit mask that controls the backlight
*/
void lcd_i2c_init(i2c_inst_t *i2c, uint8_t pcf_addr, int nibble_shift, uint8_t backlight_mask);
/**
* @brief Clear the LCD display
*
* Clears the display and returns the cursor to the home position. This
* call blocks for the duration required by the HD44780 controller.
*/
void lcd_clear(void);
/**
* @brief Set the cursor position
*
* @param line Line number (0 or 1)
* @param position Column (0..15)
*/
void lcd_set_cursor(int line, int position);
/**
* @brief Write a null-terminated string to the display
*
* @param s The string to write (ASCII)
*/
void lcd_puts(const char *s);
#endif // LCD_1602_H