ssd1306.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef __FW_SSD1306_H__
  15. #define __FW_SSD1306_H__
  16. #include "fw_hal.h"
  17. #include "string.h"
  18. /* I2C address
  19. * address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
  20. */
  21. #ifndef SSD1306_I2C_ADDR
  22. #define SSD1306_I2C_ADDR 0x78
  23. //#define SSD1306_I2C_ADDR 0x7A
  24. #endif
  25. /* SSD1306 settings */
  26. /* SSD1306 width in pixels */
  27. #ifndef SSD1306_WIDTH
  28. #define SSD1306_WIDTH 128
  29. #endif
  30. /* SSD1306 LCD height in pixels */
  31. #ifndef SSD1306_HEIGHT
  32. #define SSD1306_HEIGHT 64
  33. #endif
  34. #ifndef SSD1306_TIMEOUT
  35. #define SSD1306_TIMEOUT 20000
  36. #endif
  37. /*!< Black color, no pixel */
  38. #define SSD1306_COLOR_BLACK 0x00
  39. /*!< Pixel is set. Color depends on LCD */
  40. #define SSD1306_COLOR_WHITE 0x01
  41. /**
  42. * @brief Writes single byte command to slave
  43. * @param command: command to be written
  44. */
  45. void SSD1306_WriteCommand(uint8_t command);
  46. /**
  47. * @brief Writes single byte data to slave
  48. * @param dat: data to be written
  49. */
  50. void SSD1306_WriteData(uint8_t dat);
  51. /**
  52. * Initializes SSD1306 LCD
  53. */
  54. void SSD1306_Init(void);
  55. /**
  56. * @brief Updates buffer from internal RAM to LCD
  57. * @note This function must be called each time you do some changes to LCD, to update buffer from RAM to LCD
  58. */
  59. void SSD1306_UpdateScreen(void);
  60. /**
  61. * @brief Toggles pixels invertion inside internal RAM
  62. * @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
  63. */
  64. void SSD1306_ToggleInvert(void);
  65. /**
  66. * @brief Fills entire LCD with desired color
  67. * @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
  68. * @param Color: Color to be used for screen fill. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
  69. */
  70. void SSD1306_Fill(uint8_t Color);
  71. /**
  72. * @brief Draws pixel at desired location
  73. * @note @ref SSD1306_UpdateScreen() must called after that in order to see updated LCD screen
  74. * @param x: X location. This parameter can be a value between 0 and SSD1306_WIDTH - 1
  75. * @param y: Y location. This parameter can be a value between 0 and SSD1306_HEIGHT - 1
  76. * @param color: Color to be used for screen fill. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
  77. * @retval None
  78. */
  79. void SSD1306_DrawPixel(uint16_t x, uint16_t y, uint8_t color);
  80. /**
  81. * @brief Sets cursor pointer to desired location for strings
  82. * @param x: X location. This parameter can be a value between 0 and SSD1306_WIDTH - 1
  83. * @param y: Y location. This parameter can be a value between 0 and SSD1306_HEIGHT - 1
  84. * @retval None
  85. */
  86. void SSD1306_GotoXY(uint16_t x, uint16_t y);
  87. /**
  88. * @brief Draws line on LCD
  89. * @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
  90. * @param x0: Line X start point. Valid input is 0 to SSD1306_WIDTH - 1
  91. * @param y0: Line Y start point. Valid input is 0 to SSD1306_HEIGHT - 1
  92. * @param x1: Line X end point. Valid input is 0 to SSD1306_WIDTH - 1
  93. * @param y1: Line Y end point. Valid input is 0 to SSD1306_HEIGHT - 1
  94. * @param c: Color to be used. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
  95. * @retval None
  96. */
  97. void SSD1306_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t c);
  98. #endif