PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

312 lines
9.7KB

  1. /*
  2. * This is free software: you can redistribute it and/or modify
  3. * it under the terms of the GNU Lesser General Public License as published by
  4. * the Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * DogLcd is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Lesser General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU Lesser General Public License
  13. * along with DogLcd. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. * Copyright 2010 Eberhard Fahle <e.fahle@wayoda.org>
  16. */
  17. #ifndef DOG_LCD_h
  18. #define DOG_LCD_h
  19. #include <inttypes.h>
  20. #include "Print.h"
  21. /** Define the available models */
  22. #define DOG_LCD_M081 1
  23. #define DOG_LCD_M162 2
  24. #define DOG_LCD_M163 3
  25. /** define the supply voltage for the display */
  26. #define DOG_LCD_VCC_5V 0
  27. #define DOG_LCD_VCC_3V3 1
  28. /**
  29. * A class for Dog text LCD's using the
  30. * SPI-feature of the controller.
  31. */
  32. class DogLcd : public Print {
  33. private:
  34. /** The model-type of the display connected */
  35. int model;
  36. /** The number of lines on the display */
  37. int rows;
  38. /** The number of vivible columns on the display */
  39. int cols;
  40. /** The size of the character memory on each row */
  41. int memSize;
  42. /** The starting address of each row */
  43. int startAddress[3];
  44. /** The (arduino-)pin used for the serial data */
  45. int lcdSI;
  46. /** The (arduino-)pin used for the serial clock */
  47. int lcdCLK;
  48. /**
  49. * The (arduino-)pin that toggles between sending a command
  50. * or character data to the display
  51. */
  52. int lcdRS;
  53. /** The (arduino-)pin used selecting the display */
  54. int lcdCSB;
  55. /** The (arduino-)pin used for resetting the dislay */
  56. int lcdRESET;
  57. /** The (arduino-)pin used for switching the backlight */
  58. int backLight;
  59. /**
  60. * The supply voltage used for the display. This is
  61. * one of the constants <code>DOG_LCD_VCC_5V</code>
  62. * or <code>DOG_LCD_VCC_3V3</code>.
  63. */
  64. int vcc;
  65. /** The contrast setting for the dipslay */
  66. int contrast;
  67. /** the mode the cursor is in */
  68. int cursorMode;
  69. /** the mode the display is in */
  70. int displayMode;
  71. /** the blink setting for the cursor */
  72. int blinkMode;
  73. /** the entrymode currently used */
  74. int entryMode;
  75. /** The template for changing the instruction set */
  76. uint8_t instructionSetTemplate;
  77. public:
  78. /**
  79. * Creates a new instance of DogLcd and asigns the (arduino-)pins
  80. * used to control the display.
  81. * @param lcdSI The (arduino-)pin connected to the SI-pin on the display
  82. * @param lcdCLK The (arduino-)pin connected to the CLK-pin on the display
  83. * @param lcdRS The (arduino-)pin connected to the RS-pin on the display
  84. * @param lcdCSB The (arduino-)pin connected to the CSB-pin on the display
  85. * @param backLight If you hardware supports switching the backlight
  86. * on the display from software this is the (arduino-)pin to be used.
  87. * @param lcdRESET If you want your code to reset the display from
  88. * software this is the (arduino-)pin where the RESET-pin of
  89. * the display is connected. If you don't need this feature simply
  90. * connect the RESET-pin on the display to VCC.
  91. */
  92. DogLcd(int lcdSI, int lcdCLK, int lcdRS, int lcdCSB,
  93. int lcdRESET=-1, int backLight=-1);
  94. /**
  95. * Resets and initializes the Display.
  96. * @param model the type of display that is connected.
  97. * This must be one of the constants <code>DOG_LCD_M081</code>,
  98. * <code>OG_LCD_M162</code> or <code>DOG_LCD_M163</code>
  99. * defined in this class.
  100. * @param contrast the contrast setting for the display. Values
  101. * between 0x00 and 0x3f are allowed. The default 0x28 is a valuen that
  102. * worked well with all displays I have tested so far.
  103. * @param vcc the supply voltage on which the display runs. This must
  104. * one of the constants <code>DOG_LCD_VCC_5V</code>
  105. * or <code>DOG_LCD_VCC_3V3</code>
  106. * @return 0 if the display was sucessfully initialized,
  107. * -1 otherwise.
  108. */
  109. int begin(int model, int contrast=0x28, int vcc=DOG_LCD_VCC_5V);
  110. /**
  111. * Reset the display.
  112. */
  113. void reset();
  114. /**
  115. * Set the contrast for the display.
  116. * @param contrast the contrast to be used for the display. Setting
  117. * the contrast to a value < 32 will probably give the impression
  118. * that the display isn't working because nothing is printed.
  119. * The displays that I tested worked firn with a contrast >= 0x28.
  120. * The valid range for the contrast value is 0.63 (0x00..0x3F hex).
  121. * If the value is outside the valid range the method does nothing.
  122. */
  123. void setContrast(int contrast);
  124. /**
  125. * Clears the display and moves the cursor back to
  126. * the start of the first line.
  127. */
  128. void clear();
  129. /**
  130. * Moves the cursor back to the start of the first line
  131. * without clearing the display.
  132. */
  133. void home();
  134. /**
  135. * Switches the display off
  136. */
  137. void noDisplay();
  138. /**
  139. * Switches the display on
  140. */
  141. void display();
  142. /**
  143. * Disables blinking of the cursor
  144. */
  145. void noBlink();
  146. /**
  147. *Enables blinking of the cursor
  148. */
  149. void blink();
  150. /**
  151. * Disables the (underline-)cursor
  152. */
  153. void noCursor();
  154. /**
  155. * Enables the (underline-)cursor
  156. */
  157. void cursor();
  158. /**
  159. * Scroll the contents of the display to the left
  160. */
  161. void scrollDisplayLeft();
  162. /**
  163. * Scroll the contents of the display to the right
  164. */
  165. void scrollDisplayRight();
  166. /**
  167. * Calling this method will change the way new characters
  168. * are printed at the current cursor-position.
  169. * The character is printed and then the cursor is advanced to the
  170. * column on the right of the character.
  171. * This is "sort of" the standard editor behaviour we are
  172. * used to with western european languages.
  173. * It is also the standard behaviuor when the display is reset.
  174. */
  175. void leftToRight();
  176. /**
  177. * Calling this method will change the way new characters
  178. * are printed at the current cursor-position.
  179. * The character is printed and then the cursor is advanced to the
  180. * column on the left of the character.
  181. */
  182. void rightToLeft();
  183. void autoscroll();
  184. void noAutoscroll();
  185. /**
  186. * Set one of the eight user-defineable chars
  187. * @param charCode the code of the char you want to define.
  188. * Values from 0..7 are allowed here
  189. * @param charMap an array of 8 bytes that contains the char
  190. * definition.
  191. */
  192. void createChar(int charCode, uint8_t charMap[]);
  193. /**
  194. * Set the cursor to a new loaction.
  195. * @param col the column to move the cursor to
  196. * @param row the row to move the cursor to
  197. * If the column- or row-index does exceed
  198. * the number of columns/rows on the hardware
  199. * the cursor stays where it is.
  200. */
  201. void setCursor(int col, int row);
  202. /*
  203. Using namespace Print::write makes it possible to
  204. to send data to the Lcd via the lcd.write(const char *) or
  205. a lcd.write(const uint8_t *,int) methods.
  206. */
  207. using Print::write;
  208. #if ARDUINO >= 100
  209. //The Print::write() signatuire was changed with Arduino versions >= 1.0
  210. /**
  211. * Implements the write()-method from the base-class that
  212. * is called whenever a character is to be printed to the
  213. * display.
  214. * @param c the character to be printed.
  215. * @return int number of characters written
  216. */
  217. virtual size_t write(uint8_t c) { writeChar(c); return 1; }
  218. #else
  219. //This keeps the library compatible with pre-1.0 versions of the Arduino core
  220. /**
  221. * Implements the write()-method from the base-class that
  222. * is called whenever a character is to be printed to the
  223. * display.
  224. * @param c the character to be printed.
  225. */
  226. virtual void write(uint8_t c) { writeChar(c); }
  227. #endif
  228. /**
  229. * Set the backlight. This is obviously only possible
  230. * if you have build a small circuit for switching/dimming the
  231. * backlight of the display.
  232. * @param value the new value for the backlight. If the
  233. * backlight driver circuit is connected to a normal digital IO-pin
  234. * on the arduino using value=LOW or value=HIGH will switch
  235. * off/on as expected.
  236. * @param usePWM set this to true if the driver is connected to
  237. * a PWM pin on the arduino you can set any dim the backlight
  238. * with values from 0..255
  239. */
  240. void setBacklight(int value,bool PWM=false);
  241. private:
  242. /**
  243. * Set the intruction set to use for the next command
  244. * @param is the index of the instructionSet to use
  245. */
  246. void setInstructionSet(int is);
  247. /**
  248. * Call the displaymode function when cursor settings
  249. * have been changed
  250. */
  251. void writeDisplayMode();
  252. /**
  253. * Send a command to the display
  254. * @param cmd the command to send.
  255. * @param executionTime the hardware needs some time to
  256. * execute the instruction just send. This is the time in
  257. * microseconds the code should wait after trandd´sfrerring the data
  258. */
  259. void writeCommand(int cmd, int executionTime);
  260. /**
  261. * Send a character to the display
  262. * @param c the character to send.
  263. */
  264. void writeChar(int c);
  265. /**
  266. * Implements the low-level transfer of the data
  267. * to the hardware.
  268. * @param executionTime the hardware needs some time to
  269. * execute the instruction just send. This is the time in
  270. * microseconds the code should wait after trandd´sfrerring the data
  271. */
  272. void spiTransfer(int c,int executionTime);
  273. };
  274. #endif