samples: drivers: adding sample to use Cyclone V SoC FPGA DK LCD display
LCD display is connected to the I2C bus SoC bus in the development kit, this sample guides the user on how to use the LCD display with I2C commands Signed-off-by: Esteban Valverde <esteban.valverde.vega@intel.com>
This commit is contained in:
parent
74ae6f654e
commit
3158b1bc26
5 changed files with 212 additions and 0 deletions
11
samples/drivers/lcd_cyclonev_socdk/CMakeLists.txt
Normal file
11
samples/drivers/lcd_cyclonev_socdk/CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Copyright (c) 2022 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Description
|
||||
# CMakeList file to generate example for LCD disply on Cyclone V SoC DevKit
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(lcd_cyclonev_socdk)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
1
samples/drivers/lcd_cyclonev_socdk/prj.conf
Normal file
1
samples/drivers/lcd_cyclonev_socdk/prj.conf
Normal file
|
@ -0,0 +1 @@
|
|||
# nothing here
|
16
samples/drivers/lcd_cyclonev_socdk/sample.yaml
Normal file
16
samples/drivers/lcd_cyclonev_socdk/sample.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
sample:
|
||||
description: Cyclone V Soc Devkit LCD sample
|
||||
name: lcd_cyclonev_socdk
|
||||
common:
|
||||
tags: introduction
|
||||
integration_platforms:
|
||||
- native_posix
|
||||
harness: console
|
||||
harness_config:
|
||||
type: one_line
|
||||
regex:
|
||||
- "Hello World! (.*)"
|
||||
tests:
|
||||
sample.basic.helloworld:
|
||||
platform_allow: cyclonev_socdk
|
||||
tags: introduction
|
79
samples/drivers/lcd_cyclonev_socdk/src/commands.h
Normal file
79
samples/drivers/lcd_cyclonev_socdk/src/commands.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright (C) 2022, Intel Corporation
|
||||
* Description:
|
||||
* Example to use LCD disply in Cyclone V SoC DevKit
|
||||
* Reference: https://datasheetspdf.com/pdf-file/746090/Newhaven/NHD-0216K3Z-NSW-BBW/1
|
||||
*/
|
||||
|
||||
/* Insert Prefix 0xFE before executing command */
|
||||
#define DISPLAY_ON 0x41
|
||||
#define DISPLAY_OFF 0x42
|
||||
#define SET_CURSOR 0x45 /*1 byte param in range (0x00 - 0x4F) 2x16 display */
|
||||
#define CURSOR_HOME 0x46
|
||||
#define UNDERLINE_ON 0x47
|
||||
#define UNDERLINE_OFF 0x48
|
||||
#define MOVE_CUR_LEFT 0x49
|
||||
#define MOVE_CUR_RIGHT 0x4a
|
||||
#define BLINK_ON 0x4b
|
||||
#define BLINK_OFF 0x4c
|
||||
#define BACKSPACE 0x4e
|
||||
#define CLEAR_SCREEN 0x51
|
||||
#define SET_CONTRAST 0x52 /* 1 byte param in range (1 - 50) 40 default */
|
||||
#define SET_BACKLIGHT 0x53 /* 1 byte param in range (1 - 8) 1 default */
|
||||
|
||||
#define LD_CUSTOM_CHAR 0x54 /* 9 byte param 1st param: 1-byte */
|
||||
|
||||
/* Syntax prefix LD_CUSTOM_CHAR [addr] [d0 …d7]
|
||||
*
|
||||
* Parameter Length Description
|
||||
* [addr] 1 byte Custom character address, 0 – 7
|
||||
* [D0...D7] 8 bytes Custom character pattern bit map
|
||||
*
|
||||
* Example: ¿ Character
|
||||
* Bit 7 6 5 4 3 2 1 0 Hex
|
||||
* Byte1 0 0 0 0 0 1 0 0 0x04
|
||||
* Byte2 0 0 0 0 0 0 0 0 0x00
|
||||
* Byte3 0 0 0 0 0 1 0 0 0x04
|
||||
* Byte4 0 0 0 0 1 0 0 0 0x08
|
||||
* Byte5 0 0 0 1 0 0 0 0 0x10
|
||||
* Byte6 0 0 0 1 0 0 0 1 0x11
|
||||
* Byte7 0 0 0 0 1 1 1 0 0x0E
|
||||
* Byte8 0 0 0 0 0 0 0 0 0x00
|
||||
*/
|
||||
|
||||
#define MOVE_DISP_LEFT 0x55
|
||||
#define MOVE_DISP_RIGHT 0x56
|
||||
#define CHGE_RS232_BAUD 0x61 /* 1 byte param in range (1 - 8) */
|
||||
|
||||
/* Syntax prefix CHGE_RS232_BAUD [param]
|
||||
*
|
||||
* Param BAUD
|
||||
* 1 300
|
||||
* 2 1200
|
||||
* 3 2400
|
||||
* 4 9600
|
||||
* 5 14400
|
||||
* 6 19.2K
|
||||
* 7 57.6K
|
||||
* 8 115.2K
|
||||
*/
|
||||
|
||||
#define CHGE_I2C_ADDR 0X62 /* 1 byte param in range (0x00 - 0xFE), LSB = 0 */
|
||||
#define DISP_FIRMW_VER 0x70
|
||||
#define DISP_RS232_BAUD 0x71
|
||||
#define DISP_I2C_ADDR 0x72
|
||||
|
||||
/* Functions definitions */
|
||||
|
||||
void send_ascii(char c);
|
||||
|
||||
void send_string(uint8_t *str_ptr, int len);
|
||||
|
||||
void send_command_no_param(uint8_t command_id);
|
||||
|
||||
void send_command_one_param(uint8_t command_id, uint8_t param);
|
||||
|
||||
void clear(void);
|
||||
|
||||
void next_line(void);
|
105
samples/drivers/lcd_cyclonev_socdk/src/main.c
Normal file
105
samples/drivers/lcd_cyclonev_socdk/src/main.c
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright (C) 2022, Intel Corporation
|
||||
* Description:
|
||||
* Example to use LCD Display in Cyclone V SoC FPGA devkit
|
||||
*/
|
||||
|
||||
#include <sys/printk.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <drivers/i2c.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include "commands.h"
|
||||
#define I2C_INST DT_NODELABEL(i2c0)
|
||||
#define LCD_ADDRESS 0x28
|
||||
|
||||
const struct device *i2c = DEVICE_DT_GET(I2C_INST);
|
||||
|
||||
void send_ascii(char c)
|
||||
{
|
||||
|
||||
const uint8_t buf = c;
|
||||
int ret;
|
||||
|
||||
ret = i2c_write(i2c, &buf, sizeof(buf), LCD_ADDRESS);
|
||||
|
||||
if (ret != 0) {
|
||||
printf("Fail!\n");
|
||||
} else {
|
||||
printf("Success!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void send_string(uint8_t *str_ptr, int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = i2c_write(i2c, str_ptr, len, LCD_ADDRESS);
|
||||
|
||||
if (ret != 0) {
|
||||
printf("Fail!\n");
|
||||
} else {
|
||||
printf("Success!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void send_command_no_param(uint8_t command_id)
|
||||
{
|
||||
const uint8_t buf[] = {0xFE, command_id};
|
||||
|
||||
int ret;
|
||||
|
||||
ret = i2c_write(i2c, (const uint8_t *) &buf, sizeof(buf), LCD_ADDRESS);
|
||||
|
||||
if (ret != 0) {
|
||||
printf("Fail!\n");
|
||||
} else {
|
||||
printf("Success!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void send_command_one_param(uint8_t command_id, uint8_t param)
|
||||
{
|
||||
const uint8_t buf[] = { 0xFE, command_id, param};
|
||||
|
||||
int ret;
|
||||
|
||||
ret = i2c_write(i2c, (const uint8_t *) &buf, sizeof(buf), LCD_ADDRESS);
|
||||
|
||||
if (ret != 0) {
|
||||
printf("Fail!\n");
|
||||
} else {
|
||||
printf("Success!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
{
|
||||
send_command_no_param(CLEAR_SCREEN);
|
||||
}
|
||||
|
||||
void next_line(void)
|
||||
{
|
||||
send_command_one_param(SET_CURSOR, 0x40);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
printk("Hello World! %s\n", CONFIG_BOARD);
|
||||
static const unsigned char string[] = "Hello world!";
|
||||
int len = strlen((const unsigned char *) &string);
|
||||
|
||||
if (!device_is_ready(i2c)) {
|
||||
printf("i2c is not ready!\n");
|
||||
} else {
|
||||
printf("i2c is ready\n");
|
||||
}
|
||||
|
||||
send_ascii('A');
|
||||
k_sleep(K_MSEC(1000));
|
||||
next_line();
|
||||
k_sleep(K_MSEC(10));
|
||||
send_string((uint8_t *)&string, len);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue