openchronos-ng
opensource firmware for the ez430 chronos
|
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. |
openchronos-ng display driver
struct lcd_screen |
Virtual LCD screen.
Data Fields | ||
---|---|---|
uint8_t * | blkmem | pointer to blinking memory location |
uint8_t * | segmem | pointer to segment memory location |
#define _printf | ( | scr_nr, | |
segments, | |||
fmt, | |||
n | |||
) | 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).
enum display_segment |
Enumeration of all ez430 chronos LCD segments.
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.
enum display_segstate |
Enumeration of segment states.
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);
low | the 0% value |
high | the 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!
fmt | the format specifier |
n | the 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);
scr_nr | the virtual screen number where to display |
segment | A segment |
chr | The character to be displayed |
state | A 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.
scr_nr | the virtual screen number where to display |
segments | A segment array |
str | A pointer to a vector of chars to be displayed |
state | A 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.
scr_nr | the virtual screen number to clear |
line | If 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);
scr_nr | the virtual screen number |
symbol | the segment to display |
state | A 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.
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.
scr_nr | the 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.
nr | the number of screens to create |
void lcd_screens_destroy | ( | void | ) |
Destroys all virtual screen.
Destroys all lcd_screen created by lcd_screens_create()