openchronos-ng
opensource firmware for the ez430 chronos
Data Structures | Defines | Enumerations | Functions
display.h File Reference

openchronos-ng display driver More...

#include <openchronos.h>

Go to the source code of this file.

Data Structures

struct  lcd_screen
 Virtual LCD screen. More...

Defines

#define _printf(scr_nr, segments, fmt, n)   display_chars((scr_nr), (segments), _sprintf((fmt), (n)), SEG_SET)
 pseudo printf function

Enumerations

enum  display_segstate {
  SEG_OFF = 1u, SEG_ON = 2u, SEG_SET = 3u, BLINK_OFF = 4u,
  BLINK_ON = 8u, BLINK_SET = 12u
}
 Enumeration of segment states. More...
enum  display_segment {
  LCD_SYMB_AM = 0, LCD_SYMB_PM = 1, LCD_SYMB_ARROW_UP = 2, LCD_SYMB_ARROW_DOWN = 3,
  LCD_SYMB_PERCENT = 4, LCD_SYMB_TOTAL = 5, LCD_SYMB_AVERAGE = 6, LCD_SYMB_MAX = 7,
  LCD_SYMB_BATTERY = 8, LCD_UNIT_L1_FT = 9, LCD_UNIT_L1_K = 10, LCD_UNIT_L1_M = 11,
  LCD_UNIT_L1_I = 12, LCD_UNIT_L1_PER_S = 13, LCD_UNIT_L1_PER_H = 14, LCD_UNIT_L1_DEGREE = 15,
  LCD_UNIT_L2_KCAL = 16, LCD_UNIT_L2_KM = 17, LCD_UNIT_L2_MI = 18, LCD_ICON_HEART = 19,
  LCD_ICON_STOPWATCH = 20, LCD_ICON_RECORD = 21, LCD_ICON_ALARM = 22, LCD_ICON_BEEPER1 = 23,
  LCD_ICON_BEEPER2 = 24, LCD_ICON_BEEPER3 = 25, LCD_SEG_L1_3 = 26, LCD_SEG_L1_2 = 27,
  LCD_SEG_L1_1 = 28, LCD_SEG_L1_0 = 29, LCD_SEG_L1_COL = 30, LCD_SEG_L1_DP1 = 31,
  LCD_SEG_L1_DP0 = 32, LCD_SEG_L2_5 = 33, LCD_SEG_L2_4 = 34, LCD_SEG_L2_3 = 35,
  LCD_SEG_L2_2 = 36, LCD_SEG_L2_1 = 37, LCD_SEG_L2_0 = 38, LCD_SEG_L2_COL1 = 39,
  LCD_SEG_L2_COL0 = 40, LCD_SEG_L2_DP = 41
}
 Enumeration of all ez430 chronos LCD segments. More...
enum  display_segment_array {
  LCD_SEG_L1_3_2 = 0xc2, LCD_SEG_L1_3_1 = 0xc3, LCD_SEG_L1_3_0 = 0xc4, LCD_SEG_L1_2_1 = 0xb2,
  LCD_SEG_L1_2_0 = 0xb3, LCD_SEG_L1_1_0 = 0xa2, LCD_SEG_L2_5_4 = 0x52, LCD_SEG_L2_5_3 = 0x53,
  LCD_SEG_L2_5_2 = 0x54, LCD_SEG_L2_5_1 = 0x55, LCD_SEG_L2_5_0 = 0x56, LCD_SEG_L2_4_3 = 0x42,
  LCD_SEG_L2_4_2 = 0x43, LCD_SEG_L2_4_1 = 0x44, LCD_SEG_L2_4_0 = 0x45, LCD_SEG_L2_3_2 = 0x32,
  LCD_SEG_L2_3_1 = 0x33, LCD_SEG_L2_3_0 = 0x34, LCD_SEG_L2_2_1 = 0x22, LCD_SEG_L2_2_0 = 0x23,
  LCD_SEG_L2_1_0 = 0x12
}
 Enumeration of LCD segment arrays. More...

Functions

void lcd_init (void)
 Initializes the display.
void lcd_screens_create (uint8_t nr)
 Creates virtual screens.
void lcd_screens_destroy (void)
 Destroys all virtual screen.
void lcd_screen_activate (uint8_t scr_nr)
 Activates a virtual screen.
void display_clear (uint8_t scr_nr, uint8_t line)
 Clears the screen.
void display_char (uint8_t scr_nr, enum display_segment segment, char chr, enum display_segstate state)
 Displays a single character.
void display_chars (uint8_t scr_nr, enum display_segment_array segments, char const *str, enum display_segstate state)
 Displays several consecutive characters.
void display_symbol (uint8_t scr_nr, enum display_segment symbol, enum display_segstate state)
 Displays a symbol.
char * _sprintf (const char *fmt, int16_t n)
 pseudo sprintf function
char * _itopct (uint32_t low, uint32_t high, uint32_t n)
 Converts an integer from a range into a percent string between 0 and 100.

Detailed Description

openchronos-ng display driver


Data Structure Documentation

struct lcd_screen

Virtual LCD screen.

See also:
lcd_screens_create()
Data Fields
uint8_t * blkmem pointer to blinking memory location
uint8_t * segmem pointer to segment memory location

Define Documentation

#define _printf (   scr_nr,
  segments,
  fmt,
 
)    display_chars((scr_nr), (segments), _sprintf((fmt), (n)), SEG_SET)

pseudo printf function

Displays in screen scr_nr, at segments segments, the string containing the number n formatted according to fmt. This function is equivalent to calling display_chars(scr_nr, segments, _sprintf(fmt, n), SEG_SET).

See also:
display_chars, _sprintf

Enumeration Type Documentation

Enumeration of all ez430 chronos LCD segments.

Enumerator:
LCD_SYMB_AM 

AM symbol segment

LCD_SYMB_PM 

PM symbol segment

LCD_SYMB_ARROW_UP 

little up arrow symbol segment

LCD_SYMB_ARROW_DOWN 

little down arrow symbol segment

LCD_SYMB_PERCENT 

percent symbol segment

LCD_SYMB_TOTAL 

TOTAL symbol segment

LCD_SYMB_AVERAGE 

AVG symbol segment

LCD_SYMB_MAX 

MAX symbol segment

LCD_SYMB_BATTERY 

BATT symbol segment

LCD_UNIT_L1_FT 

FT symbol segment

LCD_UNIT_L1_K 

K symbol segment

LCD_UNIT_L1_M 

M symbol segment

LCD_UNIT_L1_I 

I symbol segment

LCD_UNIT_L1_PER_S 

/s symbol segment

LCD_UNIT_L1_PER_H 

/h symbol segment

LCD_UNIT_L1_DEGREE 

ยบ symbol segment

LCD_UNIT_L2_KCAL 

kcal symbol segment

LCD_UNIT_L2_KM 

Km symbol segment

LCD_UNIT_L2_MI 

MI symbol segment

LCD_ICON_HEART 

HEART symbol segment

LCD_ICON_STOPWATCH 

STOPWATCH symbol segment

LCD_ICON_RECORD 

RECORD symbol segment

LCD_ICON_ALARM 

ALARM symbol segment

LCD_ICON_BEEPER1 

segment 1 of ((( symbol

LCD_ICON_BEEPER2 

segment 2 of ((( symbol

LCD_ICON_BEEPER3 

segment 3 of ((( symbol

LCD_SEG_L1_3 

line1, 4th segment

LCD_SEG_L1_2 

line1, 3rd segment

LCD_SEG_L1_1 

line1, 2nd segment

LCD_SEG_L1_0 

line1, 1st segment

LCD_SEG_L1_COL 

line1, : segment

LCD_SEG_L1_DP1 

??

LCD_SEG_L1_DP0 

??

LCD_SEG_L2_5 

line2, 6th segment

LCD_SEG_L2_4 

line2, 5th segment

LCD_SEG_L2_3 

line2, 4th segment

LCD_SEG_L2_2 

line2, 3rd segment

LCD_SEG_L2_1 

line2, 2nd segment

LCD_SEG_L2_0 

line2, 1st segment

LCD_SEG_L2_COL1 

line2, 2nd : segment

LCD_SEG_L2_COL0 

line2, 1st : segment

LCD_SEG_L2_DP 

??

Enumeration of LCD segment arrays.

The LCD_SEG_L1_3_2 member means the segments on line 1 from position 3 to 2 (inclusive). Segments are numbered from right to left.

See also:
display_chars()
Enumerator:
LCD_SEG_L1_3_2 

line1, segments 3-2

LCD_SEG_L1_3_1 

line1, segments 3-1

LCD_SEG_L1_3_0 

line1, segments 3-0

LCD_SEG_L1_2_1 

line1, segments 2-1

LCD_SEG_L1_2_0 

line1, segments 2-0

LCD_SEG_L1_1_0 

line1, segments 1-0

LCD_SEG_L2_5_4 

line2, segments 5-4

LCD_SEG_L2_5_3 

line2, segments 5-3

LCD_SEG_L2_5_2 

line2, segments 3-2

LCD_SEG_L2_5_1 

line2, segments 3-1

LCD_SEG_L2_5_0 

line2, segments 1-0

LCD_SEG_L2_4_3 

line2, segments 4-3

LCD_SEG_L2_4_2 

line2, segments 4-2

LCD_SEG_L2_4_1 

line2, segments 4-1

LCD_SEG_L2_4_0 

line2, segments 4-0

LCD_SEG_L2_3_2 

line2, segments 3-2

LCD_SEG_L2_3_1 

line2, segments 3-1

LCD_SEG_L2_3_0 

line2, segments 3-0

LCD_SEG_L2_2_1 

line2, segments 2-1

LCD_SEG_L2_2_0 

line2, segments 2-0

LCD_SEG_L2_1_0 

line2, segments 1-0

Enumeration of segment states.

Enumerator:
SEG_OFF 

turn selected segment bits to OFF

SEG_ON 

turn selected segment bits to ON

SEG_SET 

turn OFF all bits of segment, then turn ON only selected bits

BLINK_OFF 

turn blinking OFF on selected segment bits

BLINK_ON 

turn blinking ON on selected segment bits

BLINK_SET 

turn blinking OFF on all bits of segment, then turn blinking ON on only selected bits


Function Documentation

char* _itopct ( uint32_t  low,
uint32_t  high,
uint32_t  n 
)

Converts an integer from a range into a percent string between 0 and 100.

Takes the number n and returns a string representation of that number as a percent between low and high. The returned string is 3 characters long.

Example:

        // this returns "4F"
        uint8_t *s = _itoa(0x4F, 2, 0);
Returns:
a string representation of n
Parameters:
lowthe 0% value
highthe 100% value
char* _sprintf ( const char *  fmt,
int16_t  n 
)

pseudo sprintf function

Returns a pointer to the string containing the number n formatted according to fmt. The format is NOT compatible with stdio's format. Example:

        // returns " 8"
        _sprintf("%2u", 8);
        
        // returns "0020"
        _sprintf("%04u", 20);

        // returns "-048"
        _sprintf("%03s", -48);

        // returns " 048"
        _sprintf("%03s", 48);

        // returns "0xff"
        _sprintf("0x%02", 0xff);

        // returns "st1x"
        _sprintf("st%1ux", 1)

WARNING: You must always specify the number of digits or bad results will happen! "%u" formats are not allowed!

Returns:
a pointer to a string
Parameters:
fmtthe format specifier
nthe number to be used in the format specifier
void display_char ( uint8_t  scr_nr,
enum display_segment  segment,
char  chr,
enum display_segstate  state 
)

Displays a single character.

Changes the state of segment state according to bits calculated from chr. If no virtual screens are created, the argument scr_nr is ignored, otherwise it selects which screen the operation will affect.

For example, the following line:

        display_char(0, LCD_SEG_L1_3, 'C', SEG_SET);<br />

Changes the bits of the 4th segment (from the right) of first line to show a 'C' character. The 'C' character is shown in the real screen.

Another but a little more complex example:

        // changes the bits of the 4th segment (from the right) of first line to show the '1' character in the real screen.
        display_char(0, LCD_SEG_L1_3, '1', SEG_SET);

        // makes all bits of the segment to blink. because only the bits corresponding to the '1' character are being shown, only the displayed '1' blinks.
        display_char(0, LCD_SEG_L1_3, '8', BLINK_ON);

        // changes the bits of the segment to show the '8' character. this operation doesn't change the blinking bits, so the displayed '8' will blink.
        display_char(0, LCD_SEG_L1_3, '8', SEG_SET);

        // turns off blinking for the bits corresponding to the '-' character. In this case because the bits of '8' were blinking, turning off '-' will make the bits of '0' continue blinking, while the '-' remains static.
        display_char(0, LCD_SEG_L1_3, '-', BLINK_OFF);
See also:
display_chars()
Parameters:
scr_nrthe virtual screen number where to display
segmentA segment
chrThe character to be displayed
stateA bitfield with state operations to be performed on the segment
void display_chars ( uint8_t  scr_nr,
enum display_segment_array  segments,
char const *  str,
enum display_segstate  state 
)

Displays several consecutive characters.

Smiliar to display_char() except it works with a vector of chars.

Example:

        // changes the bits of the 4th to 1st segments (from the right) of the first line to show the "4321" string in the real screen.
        display_chars(0, LCD_SEG_L1_3_0, "4321", SEG_SET);

        // makes all bits of the first three segments to blink. because only the bits corresponding to the "4321" characters are being shown, only the first three displayed "432" segments blink.
        display_chars(0, LCD_SEG_L1_3_0, "888 ", BLINK_ON);

        // changes the bits of the segments to show the "8888" string. this operation doesn't change the blinking bits, so the first three displayed "888" segments will blink, while the last '8' segment is static.
        display_chars(0, LCD_SEG_L1_3_0, "8888", SEG_SET);

        // turns off blinking for the bits corresponding to the "----" characters. In this case because the bits of "888 " were blinking, turning off "----" will actually set the blinking bits to "000 ". Because the "8888" string is being displayed, only the first three "000" bits will blink, the first three "---" bits will remain static and the last segment remains static.
        display_chars(0, LCD_SEG_L1_3_0, "----", BLINK_OFF);

Also, passing NULL as the str argument is equivalent of passing a vector of '8' characters. Consider the previous example, where the string "8888" can equivalently be replaced with NULL.

Note:
See _sprintf() on how to convert decimals into a string.
See also:
display_char(), _sprintf()
Parameters:
scr_nrthe virtual screen number where to display
segmentsA segment array
strA pointer to a vector of chars to be displayed
stateA bitfield with state operations to be performed on the segment
void display_clear ( uint8_t  scr_nr,
uint8_t  line 
)

Clears the screen.

Clears the screen as instructed by line. If no virtual screens are created, the argument scr_nr is ignored, otherwise it selects which screen the operation will affect.

Parameters:
scr_nrthe virtual screen number to clear
lineIf zero, clears the entire screen (symbols and lines).
If one, clears the first line.
If two, clears the second line.
void display_symbol ( uint8_t  scr_nr,
enum display_segment  symbol,
enum display_segstate  state 
)

Displays a symbol.

Changes the state of the segment of symbol. If no virtual screens are created, the argument scr_nr is ignored, otherwise it selects which screen the operation will affect. Example:

        // turns on the "heart" segment and make it blink
        display_symbol(0, LCD_ICON_HEART, SEG_SET | BLINK_ON);
Parameters:
scr_nrthe virtual screen number
symbolthe segment to display
stateA bitfield with state operations to be performed on the segment
void lcd_init ( void  )

Initializes the display.

This functions is called once upon system initialization.

Note:
Modules are strictly forbidden to call this function.
void lcd_screen_activate ( uint8_t  scr_nr)

Activates a virtual screen.

Virtual screens are used to display data outside of the real screen. See lcd_screens_create() on how to create virtual screens.
This function selects the active screen. The active screen is the screen where any writes to it will be imediately displayed in the real screen.

Note:
If you set the scr_nr to 0xff, the next screen will be automatically activated.
See also:
lcd_screens_destroy(), lcd_screens_create()
Parameters:
scr_nrthe screen number to activate, or 0xff
void lcd_screens_create ( uint8_t  nr)

Creates virtual screens.

Virtual screens are used to display data outside of the real screen. After creating nr number of screens, you can select which screen to write data to using the scr_nr argument available in any of the display functions:
display_symbol()
display_char()
display_chars()
display_clear()

After creating the virtual screens using this function, the screen 0 is always selected as the active screen. This means that any writes to screen 0 will actually be imediately displayed on the real screen, while writes to other screens will be saved until lcd_screen_activate() is called.

Note:
Each virtual screen takes 24bytes of memory. It is less than the code that you would actually need to write to handle the cases where these functions are meant to be used. However, RAM memory on the ez430 chronos is limited too so don't use a bazilion of screens.
Never, ever forget to destroy the created screens using lcd_screens_destroy() !
See also:
lcd_screens_destroy(), lcd_screen_activate()
Parameters:
nrthe number of screens to create
void lcd_screens_destroy ( void  )

Destroys all virtual screen.

Destroys all lcd_screen created by lcd_screens_create()

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines