libpifacecad  v0.1.0
A simple static C library for controlling PiFace Control and Display.
 All Files Functions
pifacecad.h
Go to the documentation of this file.
1 
21 #ifndef _PIFACECAD_H
22 #define _PIFACECAD_H
23 
24 #include <stdint.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define DELAY_PULSE_NS 1000 // 1us
31 #define DELAY_SETTLE_NS 40000 // 40us
32 #define DELAY_SETUP_0_NS 15000000L // 15ms
33 #define DELAY_SETUP_1_NS 5000000L // 5ms
34 #define DELAY_SETUP_2_NS 1000000L // 1ms
35 
36 // mcp23s17 GPIOB to HD44780 pin map
37 #define PIN_D4 0
38 #define PIN_D5 1
39 #define PIN_D6 2
40 #define PIN_D7 3
41 #define PIN_ENABLE 4
42 #define PIN_RW 5
43 #define PIN_RS 6
44 #define PIN_BACKLIGHT 7
45 
46 // commands
47 #define LCD_CLEARDISPLAY 0x01
48 #define LCD_RETURNHOME 0x02
49 #define LCD_ENTRYMODESET 0x04
50 #define LCD_DISPLAYCONTROL 0x08
51 #define LCD_CURSORSHIFT 0x10
52 #define LCD_FUNCTIONSET 0x20
53 #define LCD_SETCGRAMADDR 0x40
54 #define LCD_SETDDRAMADDR 0x80
55 #define LCD_NEWLINE 0xC0
56 
57 // flags for display entry mode
58 #define LCD_ENTRYRIGHT 0x00
59 #define LCD_ENTRYLEFT 0x02
60 #define LCD_ENTRYSHIFTINCREMENT 0x01
61 #define LCD_ENTRYSHIFTDECREMENT 0x00
62 
63 // flags for display on/off control
64 #define LCD_DISPLAYON 0x04
65 #define LCD_DISPLAYOFF 0x00
66 #define LCD_CURSORON 0x02
67 #define LCD_CURSOROFF 0x00
68 #define LCD_BLINKON 0x01
69 #define LCD_BLINKOFF 0x00
70 
71 // flags for display/cursor shift
72 #define LCD_DISPLAYMOVE 0x08
73 #define LCD_CURSORMOVE 0x00
74 #define LCD_MOVERIGHT 0x04
75 #define LCD_MOVELEFT 0x00
76 
77 // flags for function set
78 #define LCD_8BITMODE 0x10
79 #define LCD_4BITMODE 0x00
80 #define LCD_2LINE 0x08
81 #define LCD_1LINE 0x00
82 #define LCD_5X10DOTS 0x04
83 #define LCD_5X8DOTS 0x00
84 
85 #define LCD_MAX_LINES 2
86 #define LCD_WIDTH 16
87 #define LCD_RAM_WIDTH 80 // RAM is 80 wide, split over two lines
88 
89 static const uint8_t ROW_OFFSETS[] = {0, 0x40};
90 
102 int pifacecad_open(void);
103 
115 int pifacecad_open_noinit(void);
116 
126 void pifacecad_close(void);
127 
137 void pifacecad_lcd_init(void);
138 
147 uint8_t pifacecad_read_switches(void);
148 
157 uint8_t pifacecad_read_switch(uint8_t switch_num);
158 
170 uint8_t pifacecad_lcd_write(const char * message);
171 
180 uint8_t pifacecad_lcd_set_cursor(uint8_t col, uint8_t row);
181 
190 void pifacecad_lcd_set_cursor_address(uint8_t address);
191 
200 uint8_t pifacecad_lcd_get_cursor_address(void);
201 
210 void pifacecad_lcd_clear(void);
211 
220 void pifacecad_lcd_home(void);
221 
230 void pifacecad_lcd_display_on(void);
231 
240 void pifacecad_lcd_display_off(void);
241 
250 void pifacecad_lcd_blink_on(void);
251 
260 void pifacecad_lcd_blink_off(void);
261 
270 void pifacecad_lcd_cursor_on(void);
271 
280 void pifacecad_lcd_cursor_off(void);
281 
290 void pifacecad_lcd_backlight_on(void);
291 
300 void pifacecad_lcd_backlight_off(void);
301 
310 void pifacecad_lcd_move_left(void);
311 
320 void pifacecad_lcd_move_right(void);
321 
331 void pifacecad_lcd_left_to_right(void);
332 
342 void pifacecad_lcd_right_to_left(void);
343 
352 void pifacecad_lcd_autoscroll_on(void);
353 
362 void pifacecad_lcd_autoscroll_off(void);
363 
373 void pifacecad_lcd_write_custom_bitmap(uint8_t location);
374 
385 void pifacecad_lcd_store_custom_bitmap(uint8_t location, uint8_t bitmap[]);
386 
395 void pifacecad_lcd_send_command(uint8_t command);
396 
405 void pifacecad_lcd_send_data(uint8_t data);
406 
415 void pifacecad_lcd_send_byte(uint8_t byte);
416 
425 void pifacecad_lcd_set_rs(uint8_t state);
426 
435 void pifacecad_lcd_set_rw(uint8_t state);
436 
445 void pifacecad_lcd_set_enable(uint8_t state);
446 
455 void pifacecad_lcd_set_backlight(uint8_t state);
456 
465 void pifacecad_lcd_pulse_enable(void);
466 
475 uint8_t colrow2address(uint8_t col, uint8_t row);
476 
485 uint8_t address2col(uint8_t address);
486 
495 uint8_t address2row(uint8_t address);
496 
497 // int pifacecad_lcd_set_viewport_corner(int col);
498 // int pifacecad_lcd_see_cursor(int col);
499 
500 #ifdef __cplusplus
501 }
502 #endif
503 
504 #endif