Blame view

RIOT/drivers/include/pcd8544.h 6.05 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  /*
   * Copyright (C) 2015 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    drivers_pcd8544 PCD8544 LCD driver
   * @ingroup     drivers_actuators
   * @brief       Driver for PCD8544 LCD displays
   *
   * @{
   *
   * @file
   * @brief       Interface definition for the PCD8544 LCD driver
   *
   * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
   */
  
  #ifndef PCD8544_H
  #define PCD8544_H
  
  #include <stdint.h>
  
  #include "periph/gpio.h"
  #include "periph/spi.h"
  
  #ifdef __cplusplus
   extern "C" {
  #endif
  
  /**
   * @name    Definition of display dimensions
   * @{
   */
  #define PCD8544_RES_X                   (84U)   /**< pixels per row */
  #define PCD8544_RES_Y                   (48U)   /**< pixels per column */
  #define PCD8544_COLS                    (14U)   /**< characters per row */
  #define PCD8544_ROWS                    (6U)    /**< characters per column */
  /** @} */
  
  /**
   * @name    Default values for temperature compensation and contrast
   * @{
   */
  #define PCD8544_DEFAULT_CONTRAST        (45U)
  #define PCD8544_DEFAULT_BIAS            (3U)
  #define PCD8544_DEFAULT_TEMPCOEF        (0U)
  /** @} */
  
  /**
   * @brief   PCD8544 device descriptor
   */
  typedef struct {
      spi_t spi;          /**< SPI bus the display is connected to */
      gpio_t cs;          /**< chip-select pin, low: active */
      gpio_t reset;       /**< reset pin, low: active */
      gpio_t mode;        /**< mode pin: low: cmd mode, high: data mode */
      uint8_t inverted;   /**< internal flag to keep track of inversion state */
  } pcd8544_t;
  
  /**
   * @brief   Initialize the given display
   *
   * @param[in] dev           device descriptor of display to use
   * @param[in] spi           SPI bus the display is connected to
   * @param[in] cs            GPIO pin that is connected to the CS pin
   * @param[in] reset         GPIO pin that is connected to the RESET pin
   * @param[in] mode          GPIO pin that is connected to the MODE pin
   *
   * @return      0 on success
   * @return      <0 on error
   */
  int pcd8544_init(pcd8544_t *dev, spi_t spi, gpio_t cs,
                   gpio_t reset, gpio_t mode);
  
  /**
   * @brief   Set the contrast for the given display
   *
   * @note    A contrast value of 45 yields good results for 3V3
   *
   * @param[in] dev           display device descriptor
   * @param[in] contrast      targeted contrast value [0 - 127]
   */
  void pcd8544_set_contrast(const pcd8544_t *dev, uint8_t contrast);
  
  /**
   * @brief   Set the temperature coefficient for the given display
   *
   * @note    Look at the datasheet for more information
   *
   * @param[in] dev           device descriptor of display to use
   * @param[in] coef          temperature coefficient to use [0 - 3]
   */
  void pcd8544_set_tempcoef(const pcd8544_t *dev, uint8_t coef);
  
  /**
   * @brief   Set the internal BIAS for the given display
   *
   * @note    Look at the datasheet for more information
   *
   * @param[in] dev           device descriptor of display to use
   * @param[in] bias          the BIAS to use [0 - 7]
   *
   */
  void pcd8544_set_bias(const pcd8544_t *dev, uint8_t bias);
  
  /**
   * @brief   Write an image to memory of the given display
   *
   * The image must be given as a char array with 504 elements. Each bit in the
   * array represents one pixel on the display. Each byte in the array contains
   * 8 stacked pixels, from top to bottom. So byte[0] contains the pixels from
   * (0,0) to (0,7), byte[1] (1,0) to (1,7) and byte[503] the pixels from
   * (83,40) to (83,47) -> see the 'horizontal addressing' section in the
   * datasheet.
   *
   * @param[in] dev           device descriptor of display to use
   * @param[in] img           char array with image data (must be of size := 504)
   */
  void pcd8544_write_img(const pcd8544_t *dev, const char img[]);
  
  /**
   * @brief   Write a single ASCII character to the display
   *
   * The position of the character is specified in columns (x) and rows (y)
   *
   * @param[in] dev           device descriptor of display to use
   * @param[in] x             column to put the character [0 - 13]
   * @param[in] y             row to put the character [0 - 5]
   * @param[in] c             ASCII code for the character to write
   */
  void pcd8544_write_c(const pcd8544_t *dev, uint8_t x, uint8_t y, const char c);
  
  /**
   * @brief   Write a string to a given position on the display
   *
   * This function prints a given string to the given position on the display. The
   * position is given in terms of columns (x) and rows (y). If a string does not
   * fit completely in the given position (it overflows its row), the overflowing
   * part of the string is cut off.
   *
   * @param[in] dev           device descriptor of display to use
   * @param[in] x             starting column of the string [0 - 13]
   * @param[in] y             row to write the string to [0 - 5]
   * @param[in] str           string to write to the display
   */
  void pcd8544_write_s(const pcd8544_t *dev, uint8_t x, uint8_t y, const char* str);
  
  /**
   * @brief   Clear the current display (clear the display memory)
   *
   * @param[in] dev           device descriptor of display to use
   */
  void pcd8544_clear(const pcd8544_t *dev);
  
  /**
   * @brief   Invert the display (toggles dark and bright pixels)
   *
   * @param[in] dev           device descriptor of display to use
   */
  void pcd8544_invert(pcd8544_t *dev);
  
  /**
   * @brief   Get the current inversion status of the display
   *
   * @param[in] dev           device descriptor of display to use
   *
   * @return      0 -> display is not inverted
   * @return      1 -> display is inverted
   */
  int pcd8544_is_inverted(const pcd8544_t *dev);
  
  /**
   * @brief   Power on the display
   *
   * @param[in] dev           device descriptor of display to use
   */
  void pcd8544_poweron(const pcd8544_t *dev);
  
  /**
   * @brief   Poser off the display
   *
   * @param[in] dev           device descriptor of display to use
   */
  void pcd8544_poweroff(const pcd8544_t *dev);
  
  /**
   * @brief   I wonder what this does -> find out!
   *
   * @param[in] dev           device descriptor of display to use
   */
  void pcd8544_riot(const pcd8544_t *dev);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* PCD8544_H */
  /** @} */