📄 hal_lcd.c
字号:
/**************************************************************************************************
Filename: hal_lcd.c
Revised: $Date: 2007-05-29 22:13:37 -0700 (Tue, 29 May 2007) $
Revision: $Revision: 14456 $
Description:
This file contains the interface to the HAL LCD Service. - CC2430
Notes:
Copyright (c) 2006 by Texas Instruments, Inc.
All Rights Reserved. Permission to use, reproduce, copy, prepare
derivative works, modify, distribute, perform, display or sell this
software and/or its documentation for any purpose is prohibited
without the express written consent of Texas Instruments, Inc.
**************************************************************************************************/
/**************************************************************************************************
* INCLUDES
**************************************************************************************************/
#include "hal_types.h"
#include "hal_lcd.h"
#include "OSAL.h"
#include "OnBoard.h"
#ifdef ZTOOL_PORT
#include "DebugTrace.h"
#endif
/**************************************************************************************************
* CONSTANTS
**************************************************************************************************/
#define LCD_MAX_BUF 25
// General I/O definitions
#define IO_GIO 0 // General purpose I/O
#define IO_PER 1 // Peripheral function
#define IO_IN 0 // Input pin
#define IO_OUT 1 // Output pin
#define IO_PUD 0 // Pullup/pulldn input
#define IO_TRI 1 // Tri-state input
#define IO_PUP 0 // Pull-up input pin
#define IO_PDN 1 // Pull-down input pin
// LCD port/bit definitions
#define LCD_CLK_PORT 2
#define LCD_CLK_PIN 0 // P2_0
#define LCD_DATA_PORT 1
#define LCD_DATA_PIN 2 // P1_2
/* LCD Line Address */
#define LCD_LINE1_ADDR 0x80
#define LCD_LINE2_ADDR 0xC0
// LCD device definitions
#define LCD_ADDR 0x76 // SM-Bus address of the LCD controller
#define CH1_ADDR 0x08
#define LCD_RS_0 0x00 // RS = 0 => selects instruction register for write/busy flag
#define LCD_RS_1 0x40 // RS = 1 => selects the data register for both read and write
/**************************************************************************************************
* MACROS
**************************************************************************************************/
// Removed to allow PNAME macro to expand -
// Problem: in ioCC2430.h, #define P PSW_bit.P
#undef P
/* I/O PORT CONFIGURATION */
#define CAT1(x,y) x##y // Concatenates 2 strings
#define CAT2(x,y) CAT1(x,y) // Forces evaluation of CAT1
// LCD port I/O defintions
// Builds I/O port name: PNAME(1,INP) ==> P1INP
#define PNAME(y,z) CAT2(P,CAT2(y,z))
// Builds I/O bit name: BNAME(1,2) ==> P1_2
#define BNAME(port,pin) CAT2(CAT2(P,port),CAT2(_,pin))
#define LCD_SCL BNAME(LCD_CLK_PORT, LCD_CLK_PIN)
#define LCD_SDA BNAME(LCD_DATA_PORT, LCD_DATA_PIN)
// LCD port I/O defintions
#define LCD_SCL BNAME(LCD_CLK_PORT, LCD_CLK_PIN)
#define LCD_SDA BNAME(LCD_DATA_PORT, LCD_DATA_PIN)
#define IO_DIR_PORT_PIN(port, pin, dir) \
{\
if ( dir == IO_OUT ) \
PNAME(port,DIR) |= (1<<(pin)); \
else \
PNAME(port,DIR) &= ~(1<<(pin)); \
}
#define LCD_DATA_HIGH()\
{ \
IO_DIR_PORT_PIN(LCD_DATA_PORT, LCD_DATA_PIN, IO_IN); \
}
#define LCD_DATA_LOW() \
{ \
IO_DIR_PORT_PIN(LCD_DATA_PORT, LCD_DATA_PIN, IO_OUT); \
LCD_SDA = 0;\
}
#define IO_FUNC_PORT_PIN(port, pin, func) \
{ \
if( port < 2 ) \
{ \
if ( func == IO_PER ) \
PNAME(port,SEL) |= (1<<(pin)); \
else \
PNAME(port,SEL) &= ~(1<<(pin)); \
} \
else \
{ \
if ( func == IO_PER ) \
P2SEL |= (1<<(pin>>1)); \
else \
P2SEL &= ~(1<<(pin>>1)); \
} \
}
#define IO_IMODE_PORT_PIN(port, pin, mode) \
{ \
if ( mode == IO_TRI ) \
PNAME(port,INP) |= (1<<(pin)); \
else \
PNAME(port,INP) &= ~(1<<(pin)); \
}
#define IO_PUD_PORT(port, dir) \
{ \
if ( dir == IO_PDN ) \
P2INP |= (1<<(port+5)); \
else \
P2INP &= ~(1<<(port+5)); \
}
/**************************************************************************************************
* TYPEDEFS
**************************************************************************************************/
/**************************************************************************************************
* GLOBAL VARIABLES
**************************************************************************************************/
#ifdef LCD_HW
static uint8 *Lcd_Line1;
#endif
/**************************************************************************************************
* FUNCTIONS - API
**************************************************************************************************/
#if (defined LCD_HW) && (HAL_LCD == TRUE)
static void initLcd( void );
static void initSmb( void );
static void lcdUpdateLine( uint8 line, uint8 *pLine );
static byte lcdConvertChar( byte aChar );
static void smbSend( uint8 *buffer, uint8 len );
static bool smbSendByte( uint8 dByte );
static void smbWrite( bool dBit );
static void smbClock( bool dir );
static void smbStart( void );
static void smbStop( void );
static void smbWait( void );
#endif
/**************************************************************************************************
* @fn HalLcdInit
*
* @brief Initilize LCD Service
*
* @param init - pointer to void that contains the initialized value
*
* @return None
**************************************************************************************************/
void HalLcdInit(void)
{
#if (HAL_LCD == TRUE)
#ifdef LCD_HW
Lcd_Line1 = NULL;
initLcd();
#endif
#endif /* HAL_LCD */
}
/*************************************************************************************************
* LCD EMULATION FUNCTIONS
*
* Some evaluation boards are equipped with Liquid Crystal Displays
* (LCD) which may be used to display diagnostic information. These
* functions provide LCD emulation, sending the diagnostic strings
* to Z-Tool via the RS232 serial port. These functions are enabled
* when the "LCD_SUPPORTED" compiler flag is placed in the makefile.
*
* Most applications update both lines (1 and 2) of the LCD whenever
* text is posted to the device. This emulator assumes that line 1 is
* updated first (saved locally) and the formatting and send operation
* is triggered by receipt of line 2. Nothing will be transmitted if
* only line 1 is updated.
*
*************************************************************************************************/
/**************************************************************************************************
* @fn HalLcdWriteString
*
* @brief Write a string to the LCD
*
* @param str - pointer to the string that will be displayed
* option - display options
*
* @return None
**************************************************************************************************/
void HalLcdWriteString ( char *str, uint8 option)
{
#if (HAL_LCD == TRUE)
#ifdef LCD_SD
byte x;
byte bln;
byte sln;
char *buf;
if ( Lcd_Line1 == NULL )
{
// Set up system start-up message
Lcd_Line1 = osal_mem_alloc( MAX_LCD_CHARS+1 );
HalLcdWriteString( "Figure8 Wireless", HAL_LCD_LINE_1 );
}
sln = (byte)osal_strlen( str );
// Check boundries
if ( sln > MAX_LCD_CHARS )
sln = MAX_LCD_CHARS;
if ( option == HAL_LCD_LINE_1 ) {
// Line 1 gets saved for later
osal_memcpy( Lcd_Line1, str, sln );
Lcd_Line1[sln] = '\0';
}
else {
// Line 2 triggers action
x = (byte)osal_strlen( (char*)Lcd_Line1 );
bln = x + 1 + sln + 1;
buf = osal_mem_alloc( bln );
if ( buf != NULL ) {
// Concatenate strings
osal_memcpy( buf, Lcd_Line1, x );
buf[x++] = ' ';
osal_memcpy( &buf[x], str, sln );
buf[x+sln] = '\0';
// Send it out
#ifdef ZTOOL_PORT
debug_str( (byte*)buf );
#endif
osal_mem_free( buf );
}
}
#endif // LCD_SD
#ifdef LCD_HW
lcdUpdateLine( option, (byte*)str );
#endif
#endif /* HAL_LCD */
}
/**************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -